Skip to content

Commit 4a75ade

Browse files
Working Implementation
1 parent 1aee990 commit 4a75ade

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

critical-path-css.gemspec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ Gem::Specification.new do |s|
66
s.description = 'Critical Path CSS'
77
s.authors = ['Michael Misshore']
88
s.email = 'mmisshore@gmail.com'
9-
s.files = ['lib/critical-path-css.rb']
109
s.homepage = 'http://rubygems.org/gems/critical-path-css'
1110
s.license = 'MIT'
1211

1312
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'
1417
end

lib/critical-path-css.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
class CriticalPathCss
22
require 'phantomjs'
33

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}"
79

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
915

10-
def penthouse_path
11-
'penthouse/penthouse.js'
16+
def self.fetch (route)
17+
Rails.cache.read(route, namespace: CACHE_NAMESPACE) || ''
1218
end
1319
end

0 commit comments

Comments
 (0)