Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rails generate critical_path_css:install

The generator adds the following files:

* `config/critical_path_css.yml`
* `config/critical_path_css.yml` **Note:** This file supports ERB.
* `lib/tasks/critical_path_css.rake`


Expand Down
10 changes: 7 additions & 3 deletions lib/critical-path-css-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ module CriticalPathCss
CACHE_NAMESPACE = 'critical-path-css'

def self.generate(route)
Rails.cache.write(route, CssFetcher.new.fetch_route(route),
namespace: CACHE_NAMESPACE, expires_in: nil)
Rails.cache.write(
route,
CssFetcher.new.fetch_route(route),
namespace: CACHE_NAMESPACE,
expires_in: nil
)
end

def self.generate_all
Expand All @@ -19,7 +23,7 @@ def self.clear(route)
end

def self.clear_matched(routes)
Rails.cache.delete_matched(routes,namespace: CACHE_NAMESPACE)
Rails.cache.delete_matched(routes, namespace: CACHE_NAMESPACE)
end

def self.fetch(route)
Expand Down
12 changes: 10 additions & 2 deletions lib/critical_path_css/css_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ def fetch_route(route)
css_for_route route
end

protected
protected

def css_for_route(route)
Phantomjs.run(PENTHOUSE_PATH, @config.base_url + route, @config.css_path)
url = @config.base_url + route

Phantomjs.run(
'--ignore-ssl-errors=true',
'--ssl-protocol=tlsv1',
PENTHOUSE_PATH,
url,
@config.css_path
)
end
end
end
2 changes: 1 addition & 1 deletion lib/critical_path_css/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module CriticalPathCSS
module Rails
VERSION = '0.3.0'
VERSION = '0.3.1'
PENTHOUSE_VERSION = '0.3.4'
end
end
9 changes: 5 additions & 4 deletions lib/tasks/critical_path_css.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ namespace :critical_path_css do
task generate: :environment do
CriticalPathCss.generate_all
end

desc 'Clear all critical CSS from the cache'
task clear_all: :environment do
# Use the following for Redis cache implmentations
CriticalPathCss.clear_matched('*')
# Some other cache implementations may require the following syntax instead
# CriticalPathCss.clear_matched(/.*/)
# Use the following for Redis cache implmentations
CriticalPathCss.clear_matched('*')
# Some other cache implementations may require the following syntax instead
# CriticalPathCss.clear_matched(/.*/)
end
end

Expand Down