diff --git a/CHANGELOG.md b/CHANGELOG.md index bf1f58c..cd411e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# 0.4.6 + +* [fix] Implement new engine interface for future sprockets versions #70 +* [bugfix] Fix issue where helper is not a defined method on controller (e.g. ActionController::API:Class) #65 + +# 0.4.5 + +* [bugfix] fix sprockets engine registering for older sprocket-rails versions #68 + # 0.4.4 * [bugfix] fix compatibility with with sprockts-rails version 3.x, see #62 diff --git a/README.md b/README.md index 77af792..d1b3805 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,8 @@ Gem for splitting up stylesheets that go beyond the IE limit of 4096 selectors, ### Development status -Since the original developers of this gem are not actively using it in any project at the moment, it is currently in **limited maintenance** mode. Issues are read and pull requests will be reviewed and merged, but there is currently no acitve maintenance/development. - -If you are an active user of the gem and would be able to help out maintaining it, it would be greatly appreciated. Just look at the current issues/pull requests. +Fortunately, the problem of too large CSS files is long gone. This repo is unmaintained. +It remains as an artefact of dark times in the history of web browsers. ## Installation @@ -100,14 +99,13 @@ Since 0.4.1 in development split stylesheets have `debug: false` option by defau ## Credits & License -This is a joint project by the two German Rails shops [Zweitag](http://zweitag.de) and [Railslove](http://railslove.com), therefore the GitHub name "Zweilove". +This is a joint project by the two German Rails shops [Zweitag](https://zweitag.de) and [Railslove](https://railslove.com), therefore the GitHub name "Zweilove". -The original code was written by [Christian Peters](mailto:christian.peters@zweitag.de) and [Thomas Hollstegge](mailto:thomas.hollstegge@zweitag.de) (see this [Gist](https://gist.github.com/2398394)) and turned into a gem by [Jakob Hilden](mailto:jakobhilden@gmail.com). +The original code was written by Christian Peters and Thomas Hollstegge (see this [Gist](https://gist.github.com/2398394)) and turned into a gem by Jakob Hilden. **Major Contributors** * [@Umofomia](https://github.com/Umofomia) * [@kruszczynski](https://github.com/kruszczynski) -This project rocks and uses MIT-LICENSE. - +This project uses MIT-LICENSE. diff --git a/lib/css_splitter/engine.rb b/lib/css_splitter/engine.rb index 2f50392..05a1fae 100644 --- a/lib/css_splitter/engine.rb +++ b/lib/css_splitter/engine.rb @@ -1,14 +1,19 @@ module CssSplitter class Engine < ::Rails::Engine initializer 'css_splitter.sprockets_engine', after: 'sprockets.environment', group: :all do |app| - app.config.assets.configure do |assets| - assets.register_bundle_processor 'text/css', CssSplitter::SprocketsEngine + if app.config.assets.public_methods.include? :configure + app.config.assets.configure do |assets| + assets.register_bundle_processor 'text/css', CssSplitter::SprocketsEngine + end + else + app.assets.register_bundle_processor 'text/css', CssSplitter::SprocketsEngine end end initializer 'css_splitter.action_controller' do |app| ActiveSupport.on_load :action_controller do - helper CssSplitter::ApplicationHelper + # Not all controllers use helpers (such as API based controllers) + helper CssSplitter::ApplicationHelper if respond_to?(:helper) end end end diff --git a/lib/css_splitter/sprockets_engine.rb b/lib/css_splitter/sprockets_engine.rb index f6ae2a8..551af8c 100644 --- a/lib/css_splitter/sprockets_engine.rb +++ b/lib/css_splitter/sprockets_engine.rb @@ -10,6 +10,22 @@ def self.engine_initialized? def prepare end + def self.call(input) + data_in = input[:data] + + # Instantiate Sprockets::Context to pass along helper methods for Tilt + # processors + context = input[:environment].context_class.new(input) + + # Pass the asset file contents as a block to the template engine, + # then get the results of the engine rendering + engine = self.new { data_in } + rendered_data = engine.render(context, {}) + + # Return the data and any metadata (ie file dependencies, etc) + context.metadata.merge(data: rendered_data.to_str) + end + def evaluate(scope, locals, &block) # Evaluate the split if the asset is named with a trailing _split2, _split3, etc. if scope.logical_path =~ /_split(\d+)$/ diff --git a/lib/css_splitter/version.rb b/lib/css_splitter/version.rb index 06e4f4e..57859d1 100644 --- a/lib/css_splitter/version.rb +++ b/lib/css_splitter/version.rb @@ -1,3 +1,3 @@ module CssSplitter - VERSION = "0.4.4" + VERSION = "0.4.6" end diff --git a/test/css_splitter_test.rb b/test/css_splitter_test.rb index 5090a3d..012cf89 100644 --- a/test/css_splitter_test.rb +++ b/test/css_splitter_test.rb @@ -13,18 +13,17 @@ class CssSplitterTest < ActiveSupport::TestCase part2 = "#test{background-color:green}" * CssSplitter::Splitter::MAX_SELECTORS_DEFAULT part3 = "#test{background-color:blue}" - assert_equal "#{part1}#{part2}#{part3}\n", assets["erb_stylesheet"].to_s - assert_equal "#{part2}\n", assets["erb_stylesheet_split2"].to_s - assert_equal "#{part3}\n", assets["erb_stylesheet_split3"].to_s + assert_equal "#{part1}#{part2}#{part3}", assets["erb_stylesheet"].to_s.gsub(/\s/, '') + assert_equal "#{part2}", assets["erb_stylesheet_split2"].to_s.gsub(/\s/, '') + assert_equal "#{part3}", assets["erb_stylesheet_split3"].to_s.gsub(/\s/, '') end test "asset pipeline stylesheet splitting on stylesheet combined using requires" do red = "#test{background-color:red}" * 100 green = "#test{background-color:green}" * CssSplitter::Splitter::MAX_SELECTORS_DEFAULT blue = "#test{background-color:blue}" - - assert_equal "#{red}#{green}#{blue}\n", assets["combined"].to_s - assert_equal "#{"#test{background-color:green}" * 100}#{blue}\n", assets["combined_split2"].to_s + assert_equal "#{red}#{green}#{blue}", assets["combined"].to_s.gsub(/\s/, '') + assert_equal "#{"#test{background-color:green}" * 100}#{blue}", assets["combined_split2"].to_s.gsub(/\s/, '') end private diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 4e42755..7a5b60e 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -38,7 +38,8 @@ class Application < Rails::Application # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] - + config.sass.line_comments = false + config.assets.compress = true # Enable escaping HTML in JSON. config.active_support.escape_html_entities_in_json = true