From 1dd4325da4d91b495ce330980cd723d5e885c1a1 Mon Sep 17 00:00:00 2001 From: Seb Ashton Date: Thu, 23 Oct 2014 11:34:33 +0100 Subject: [PATCH 1/2] Use Railtie to initialize stuff --- lib/css_splitter.rb | 6 +++++- lib/css_splitter/engine.rb | 10 ---------- lib/css_splitter/railtie.rb | 13 +++++++++++++ 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 lib/css_splitter/railtie.rb diff --git a/lib/css_splitter.rb b/lib/css_splitter.rb index a5b2457..3e6e979 100644 --- a/lib/css_splitter.rb +++ b/lib/css_splitter.rb @@ -1,4 +1,8 @@ -require "css_splitter/engine" if defined?(Rails) +if defined? Rails + require 'css_splitter/railtie' + require 'css_splitter/engine' +end + require "css_splitter/sprockets_engine" require "css_splitter/splitter" diff --git a/lib/css_splitter/engine.rb b/lib/css_splitter/engine.rb index c51574e..dcfb606 100644 --- a/lib/css_splitter/engine.rb +++ b/lib/css_splitter/engine.rb @@ -1,15 +1,5 @@ module CssSplitter class Engine < ::Rails::Engine isolate_namespace CssSplitter - - initializer 'css_splitter.sprockets_engine', after: 'sprockets.environment', group: :all do |app| - app.assets.register_bundle_processor 'text/css', CssSplitter::SprocketsEngine - end - - initializer 'css_splitter.action_controller' do |app| - ActiveSupport.on_load :action_controller do - helper CssSplitter::ApplicationHelper - end - end end end diff --git a/lib/css_splitter/railtie.rb b/lib/css_splitter/railtie.rb new file mode 100644 index 0000000..4b65b6d --- /dev/null +++ b/lib/css_splitter/railtie.rb @@ -0,0 +1,13 @@ +module CssSplitter + class Railtie < ::Rails::Railtie + initializer 'css_splitter.sprockets_engine', after: 'sprockets.environment', group: :all do |app| + app.assets.register_bundle_processor 'text/css', CssSplitter::SprocketsEngine + end + + initializer 'css_splitter.action_controller' do |app| + ActiveSupport.on_load :action_controller do + helper CssSplitter::ApplicationHelper + end + end + end +end \ No newline at end of file From e600b860ca31c538d3633a672fa826d067f9ddec Mon Sep 17 00:00:00 2001 From: Seb Ashton Date: Thu, 23 Oct 2014 12:24:33 +0100 Subject: [PATCH 2/2] EOF newline --- lib/css_splitter/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/css_splitter/railtie.rb b/lib/css_splitter/railtie.rb index 4b65b6d..ac88306 100644 --- a/lib/css_splitter/railtie.rb +++ b/lib/css_splitter/railtie.rb @@ -10,4 +10,4 @@ class Railtie < ::Rails::Railtie end end end -end \ No newline at end of file +end