File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,12 @@ Gem::Specification.new do |s|
6
6
s . description = 'Critical Path CSS'
7
7
s . authors = [ 'Michael Misshore' ]
8
8
s . email = 'mmisshore@gmail.com'
9
- s . files = [ 'lib/critical-path-css.rb' ]
10
9
s . homepage = 'http://rubygems.org/gems/critical-path-css'
11
10
s . license = 'MIT'
12
11
13
12
s . add_runtime_dependency 'phantomjs' , [ '~> 1.9.8.0' ]
13
+
14
+ s . files = `git ls-files` . split ( "\n " )
15
+ s . executables = `git ls-files -- bin/*` . split ( "\n " ) . map { |f | File . basename ( f ) }
16
+ s . require_path = 'lib'
14
17
end
Original file line number Diff line number Diff line change 1
1
class CriticalPathCss
2
2
require 'phantomjs'
3
3
4
- def self . generate_css
5
- Phantomjs . run ( "#{ penthouse_path } http://google.com google.css > critical-css-google.css" )
6
- end
4
+ CACHE_NAMESPACE = 'critical-path-css'
5
+ PENTHOUSE_PATH = "#{ File . dirname ( __FILE__ ) } /penthouse/penthouse.js"
6
+
7
+ def self . generate ( main_css_path , base_url , routes )
8
+ full_main_css_path = "#{ Rails . root . to_s } /public#{ main_css_path } "
7
9
8
- private
10
+ routes . each do |route |
11
+ css = Phantomjs . run ( PENTHOUSE_PATH , base_url + route , full_main_css_path )
12
+ Rails . cache . write ( route , css , namespace : CACHE_NAMESPACE )
13
+ end
14
+ end
9
15
10
- def penthouse_path
11
- 'penthouse/penthouse.js '
16
+ def self . fetch ( route )
17
+ Rails . cache . read ( route , namespace : CACHE_NAMESPACE ) || ' '
12
18
end
13
19
end
You can’t perform that action at this time.
0 commit comments