Skip to content

Commit e924fc4

Browse files
Add rake task
1 parent dec8904 commit e924fc4

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/generators/critical_path_css/install_generator.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ module CriticalPathCss
44
class InstallGenerator < Rails::Generators::Base
55
source_root File.expand_path('..', __FILE__)
66

7-
# Copy all needed stylesheets in the asset directory of the application
8-
def copy_stylesheets
9-
FileUtils.mkdir_p "app/assets/stylesheets/bootstrap_overrides"
10-
11-
copy_file "../../../app/assets/stylesheets/twitter/bootstrap.css.scss", "app/assets/stylesheets/bootstrap_overrides/base.css.scss"
12-
copy_file "../../../app/assets/stylesheets/twitter/bootstrap/_variables.scss", "app/assets/stylesheets/bootstrap_overrides/variables.css.scss"
13-
copy_file "templates/bootstrap_overrides.css.scss", "app/assets/stylesheets/bootstrap_overrides/bootstrap_overrides.css.scss"
7+
# Copy the needed rake task for generating critical CSS
8+
def copy_rake_task
9+
task_filename = 'critical_path_css.rake'
10+
copy_file "../../tasks/#{task_filename}", "lib/tasks/#{task_filename}"
1411
end
1512
end
1613
end

lib/tasks/critical_path_css.rake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'critical-path-css'
2+
3+
namespace :critical_path_css do
4+
@base_url = Rails.env.production? ? 'http://example.com' : 'http://localhost:3000'
5+
@routes = %w{
6+
/
7+
}
8+
9+
desc "Generate critical CSS for the routes defined"
10+
task :generate => :environment do
11+
@main_css_path = ActionController::Base.helpers.stylesheet_path('application.css').to_s
12+
13+
CriticalPathCss.generate(@main_css_path, @base_url, @routes)
14+
end
15+
end

0 commit comments

Comments
 (0)