File tree Expand file tree Collapse file tree 3 files changed +28
-11
lines changed Expand file tree Collapse file tree 3 files changed +28
-11
lines changed Original file line number Diff line number Diff line change 1
1
# This configuration was generated by
2
2
# `rubocop --auto-gen-config`
3
- # on 2015-10-01 20:43:37 -0500 using RuboCop version 0.34.1.
3
+ # on 2015-10-03 13:02:27 -0500 using RuboCop version 0.34.1.
4
4
# The point is for the user to remove these configuration records
5
5
# one by one as the offenses are removed from the code base.
6
6
# Note that changes in the inspected code, or installation of new
7
7
# versions of RuboCop, may require this file to be generated again.
8
8
9
- # Offense count: 2
9
+ # Offense count: 1
10
10
# Configuration parameters: AllowURI, URISchemes.
11
11
Metrics/LineLength :
12
12
Max : 90
Original file line number Diff line number Diff line change
1
+ module CriticalPathCss
2
+ class CssFetcher
3
+ require 'phantomjs'
4
+ require 'critical_path_css/configuration'
5
+
6
+ PENTHOUSE_PATH = "#{ File . dirname ( __FILE__ ) } /../penthouse/penthouse.js"
7
+
8
+ def initialize ( main_css_relative_path )
9
+ @main_css_path = "#{ Rails . root } /public#{ main_css_relative_path } "
10
+ @config = Configuration . new
11
+ end
12
+
13
+ def fetch
14
+ @config . routes . map { |route | [ route , css_for_route ( route ) ] } . to_h
15
+ end
16
+
17
+ private
18
+
19
+ def css_for_route ( route )
20
+ Phantomjs . run ( PENTHOUSE_PATH , @config . base_url + route , @main_css_path )
21
+ end
22
+ end
23
+ end
Original file line number Diff line number Diff line change 1
1
module CriticalPathCss
2
- require 'phantomjs '
2
+ require 'critical_path_css/css_fetcher '
3
3
4
4
CACHE_NAMESPACE = 'critical-path-css'
5
- PENTHOUSE_PATH = "#{ File . dirname ( __FILE__ ) } /penthouse/penthouse.js"
6
-
7
- def self . generate ( main_css_path )
8
- full_main_css_path = "#{ Rails . root } /public#{ main_css_path } "
9
- config = CriticalPathCss ::Configuration . new ( Rails . root , Rails . env )
10
-
11
- config . routes . each do |route |
12
- css = Phantomjs . run ( PENTHOUSE_PATH , config . base_url + route , full_main_css_path )
13
5
6
+ def self . generate ( main_css_relative_path )
7
+ CssFetcher . new ( main_css_relative_path ) . fetch . each do |route , css |
14
8
Rails . cache . write ( route , css , namespace : CACHE_NAMESPACE )
15
9
end
16
10
end
You can’t perform that action at this time.
0 commit comments