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..ac88306 --- /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