From e26643e1cda194a23083143ca9d213749b2a0035 Mon Sep 17 00:00:00 2001 From: cj Date: Mon, 29 Jul 2013 00:17:10 -0500 Subject: [PATCH 01/70] Updated dependencies to work with rails4 --- css_splitter.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css_splitter.gemspec b/css_splitter.gemspec index 84286e8..b6b6a6e 100644 --- a/css_splitter.gemspec +++ b/css_splitter.gemspec @@ -17,5 +17,5 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"] s.test_files = Dir["test/**/*"] - s.add_dependency "rails", "~> 3.1" + s.add_dependency "rails", ">= 3.1" end From babe2ab11738d60f7461d4682d820a96285cc240 Mon Sep 17 00:00:00 2001 From: Bitdeli Chef Date: Sat, 28 Sep 2013 18:32:41 +0000 Subject: [PATCH 02/70] Add a Bitdeli badge to README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a52bd97..09883ca 100644 --- a/README.md +++ b/README.md @@ -119,3 +119,7 @@ This is a joint project by the two German Rails shops [Zweitag](http://zweitag.d 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). This project rocks and uses MIT-LICENSE. + + +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/zweilove/css_splitter/trend.png)](https://bitdeli.com/free "Bitdeli Badge") + From 882c87e498c82ca08c6a66a55f60379be7467d27 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Wed, 16 Oct 2013 10:33:04 +0200 Subject: [PATCH 03/70] bump version --- CHANGELOG.md | 4 ++++ lib/css_splitter/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89a9235..b51ff78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.2.0 + +* loosen dependency to make it compatible with rails 4 + # 0.1.1 * Added license info ("MIT") to gemspec diff --git a/lib/css_splitter/version.rb b/lib/css_splitter/version.rb index d866b50..da541da 100644 --- a/lib/css_splitter/version.rb +++ b/lib/css_splitter/version.rb @@ -1,3 +1,3 @@ module CssSplitter - VERSION = "0.1.1" + VERSION = "0.2.0" end From 8e356bc0dd9c34097b93b8b0cde736b48d93cf31 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Wed, 16 Oct 2013 10:34:14 +0200 Subject: [PATCH 04/70] gemfile.lock --- Gemfile.lock | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 90fb3a8..12db0ff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,8 @@ PATH remote: . specs: - css_splitter (0.1.1) - rails (~> 3.1) + css_splitter (0.2.0) + rails (>= 3.1) GEM remote: http://rubygems.org/ @@ -54,12 +54,11 @@ GEM railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.7.7) - mail (2.5.3) - i18n (>= 0.4.0) + mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) method_source (0.8.1) - mime-types (1.21) + mime-types (1.25) multi_json (1.7.1) polyglot (0.3.3) pry (0.9.12) @@ -107,10 +106,10 @@ GEM tilt (~> 1.1, != 1.3.0) thor (0.17.0) tilt (1.3.6) - treetop (1.4.12) + treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.37) + tzinfo (0.3.38) uglifier (1.3.0) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) From 840f4b2284f72bb2872da517b67a2b0837cfac7a Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Sat, 2 Nov 2013 06:56:20 +1030 Subject: [PATCH 05/70] Correctly split @media blocks across files --- README.md | 6 ------ lib/css_splitter/splitter.rb | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 09883ca..bce30e1 100644 --- a/README.md +++ b/README.md @@ -105,12 +105,6 @@ If you have `require_self` in the stylesheet that you're splitting, as shown bel Currently the gem only supports stylesheets that need to be split into 2 files. It could theoretically create more splits (e.g. if you should have more than 8190 selectors), but in that case you should probably refactor your stylesheets anyway. Contact us, if you have this requirement. -**@media queries** - -The selector counting algorithm is currently not counting `@media` queries correctly. For each `@media` query it is adding one additional selector to the count (which is actually not a problem in most cases). - -If you have a `@media` query spawning right over the 4096 selector barrier, it will probably get ripped apart into the two splits and ultimately produce broken CSS. You can either try to move the `@media` queries (e.g. before the 4096 selector barrier) or help us fix this issue. - ## Credits & License diff --git a/lib/css_splitter/splitter.rb b/lib/css_splitter/splitter.rb index c979faf..f6a9d70 100644 --- a/lib/css_splitter/splitter.rb +++ b/lib/css_splitter/splitter.rb @@ -26,20 +26,45 @@ def self.extract_part(rules, part = 1, max_selectors = MAX_SELECTORS_DEFAULT) selectors_count = 0 selector_range = max_selectors * (part - 1) + 1 .. max_selectors * part # e.g (4096..8190) + current_media = nil + first_hit = true rules.each do |rule| + media_part = extract_media!(rule) + if media_part + current_media = media_part + elsif rule =~ /^\s*}$/ + current_media = nil + end + rule_selectors_count = count_selectors_of_rule rule selectors_count += rule_selectors_count if selector_range.cover? selectors_count # add rule to current output if within selector_range + if media_part + output << media_part + elsif first_hit && current_media + output << current_media + end output << rule + first_hit = false elsif selectors_count > selector_range.end # stop writing to output break end end + if current_media + output << '}' + end + output end + def self.extract_media!(rule) + if rule.sub!(/^\s*(@media[^{]*{)([^{}]*{[^}]*})$/) { $2 } + $1 + end + end + # count selectors of one individual CSS rule def self.count_selectors_of_rule(rule) strip_comments(rule).partition(/\{/).first.scan(/,/).count.to_i + 1 From d59ec0a320a40964831d71cef82bc4256b5f4261 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Sat, 2 Nov 2013 06:49:58 +1030 Subject: [PATCH 06/70] Be more flexible about where we can find the split-point Only looking in the extname doesn't work so well if we're not the last processor in the chain. Plus, if we extract it from the '_splitN' part, we don't need to define separate extension processors for each. Also, default to the second part: the zeroth part is not very useful, and you can just use the un-split file if you want the first. --- README.md | 4 ++-- lib/css_splitter/sprockets_engine.rb | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 09883ca..ae336fd 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ You also need to remember to add those new files to the asset pipeline, so they Here is a checklist of requirements for your split stylesheet: 1. It needs to have different filename than orginal, e.g. `original_stylesheet_split2` or `application_split2` -2. It needs to have `.split2` as the terminal file extension, e.g. `.css.split2` or `.css.sass.split2` -3. It needs to include the content of the orginal stylesheet, e.g. through `//= include 'application'` +2. It needs to have `.split2` as a file extension, e.g. `.css.split2`, `.css.sass.split2`, or `.css.split2.erb` +3. It needs to include the content of the orginal stylesheet, e.g. through `//= include 'application'` or `<%= environment.find_asset('application') %>` 4. It needs to be added to list of precompiled assets diff --git a/lib/css_splitter/sprockets_engine.rb b/lib/css_splitter/sprockets_engine.rb index 9f40c03..fc40759 100644 --- a/lib/css_splitter/sprockets_engine.rb +++ b/lib/css_splitter/sprockets_engine.rb @@ -11,9 +11,13 @@ def prepare end def evaluate(scope, locals, &block) - split = scope.pathname.extname =~ /(\d+)$/ && $1 || 0 # determine which is the current split (e.g. split2, split3) - CssSplitter::Splitter.split_string data, split.to_i + # determine which is the current split (e.g. split2, split3) + split = if scope.pathname.extname =~ /(\d+)$/; $1 + elsif scope.pathname.basename.to_s =~ /_split(\d+)\.css/; $1 + else 2 + end + CssSplitter::Splitter.split_string(data, split.to_i) end end -end \ No newline at end of file +end From 602e77d53849fb980bb6754a6f2a5f4d90e34fe1 Mon Sep 17 00:00:00 2001 From: Siem Kok Date: Wed, 12 Feb 2014 14:16:15 +0100 Subject: [PATCH 07/70] Fix for closing media tags exactly on the split This fixes the issue where the assets cannot be compiled because the end of a media tag would be inserted exactly at the next new file. In other words, it fixes this issue: Invalid CSS after "@charset "UTF-8"; ": expected selector or at-rule, was "}" --- lib/css_splitter/splitter.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/css_splitter/splitter.rb b/lib/css_splitter/splitter.rb index f6a9d70..991d32a 100644 --- a/lib/css_splitter/splitter.rb +++ b/lib/css_splitter/splitter.rb @@ -40,6 +40,7 @@ def self.extract_part(rules, part = 1, max_selectors = MAX_SELECTORS_DEFAULT) selectors_count += rule_selectors_count if selector_range.cover? selectors_count # add rule to current output if within selector_range + next if first_hit and rule =~ /^\s*}$/ # skip the line if the close bracket is the first rule for the new file if media_part output << media_part elsif first_hit && current_media From c4c9fe6e89f6cbb37988a244ff8ee6b70cfde275 Mon Sep 17 00:00:00 2001 From: Dan Reynolds Date: Tue, 18 Mar 2014 10:54:57 -0400 Subject: [PATCH 08/70] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 09883ca..4f6530b 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ CssSplitter integrates with the Rails 3.1+ Asset Pipeline to generate additional ### 1. Splitting your stylesheets -The first step is indentifying the stylesheets that have more than 4095 selectors and therefore need to be split for IE. +The first step is identifying the stylesheets that have more than 4095 selectors and therefore need to be split for IE. Once you know which stylesheets need to be split, you need to create a second "container file" for those stylesheets with the file extension `.split2`, that will contain the styles beyond the 4095 selector limit. From 053cf83eac245187b3b7cdf5221f0c1b0002eca3 Mon Sep 17 00:00:00 2001 From: Siem Kok Date: Mon, 7 Apr 2014 17:43:55 +0200 Subject: [PATCH 09/70] Added unit tests for media blocks Tests media block: - closing on split, rules are in part 1 - opening on split, no rules in part 1 - opening before split, rules in part 1 and 2 Tests extract_media separately as well --- lib/css_splitter/splitter.rb | 27 ++++++---- test/unit/splitter_test.rb | 97 ++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 11 deletions(-) diff --git a/lib/css_splitter/splitter.rb b/lib/css_splitter/splitter.rb index 991d32a..ea9a9d4 100644 --- a/lib/css_splitter/splitter.rb +++ b/lib/css_splitter/splitter.rb @@ -27,25 +27,30 @@ def self.extract_part(rules, part = 1, max_selectors = MAX_SELECTORS_DEFAULT) selector_range = max_selectors * (part - 1) + 1 .. max_selectors * part # e.g (4096..8190) current_media = nil + selectors_in_media = 0 first_hit = true rules.each do |rule| - media_part = extract_media!(rule) + media_part = extract_media(rule) if media_part current_media = media_part - elsif rule =~ /^\s*}$/ - current_media = nil + selectors_in_media = 0 end rule_selectors_count = count_selectors_of_rule rule selectors_count += rule_selectors_count if selector_range.cover? selectors_count # add rule to current output if within selector_range - next if first_hit and rule =~ /^\s*}$/ # skip the line if the close bracket is the first rule for the new file + if rule =~ /^\s*}$/ + current_media = nil + # skip the line if the close bracket is the first rule for the new file + next if first_hit + end if media_part output << media_part elsif first_hit && current_media output << current_media end + selectors_in_media += rule_selectors_count if current_media.present? output << rule first_hit = false elsif selectors_count > selector_range.end # stop writing to output @@ -53,19 +58,13 @@ def self.extract_part(rules, part = 1, max_selectors = MAX_SELECTORS_DEFAULT) end end - if current_media + if current_media.present? and selectors_in_media > 0 output << '}' end output end - def self.extract_media!(rule) - if rule.sub!(/^\s*(@media[^{]*{)([^{}]*{[^}]*})$/) { $2 } - $1 - end - end - # count selectors of one individual CSS rule def self.count_selectors_of_rule(rule) strip_comments(rule).partition(/\{/).first.scan(/,/).count.to_i + 1 @@ -87,6 +86,12 @@ def self.count_selectors(css_file) private + def self.extract_media(rule) + if rule.sub!(/^\s*(@media[^{]*{)([^{}]*{[^}]*})$/) { $2 } + $1 + end + end + # extracts potential charset declaration from the first rule def self.extract_charset(rule) if rule.include?('charset') diff --git a/test/unit/splitter_test.rb b/test/unit/splitter_test.rb index 42bb29e..4af26ad 100644 --- a/test/unit/splitter_test.rb +++ b/test/unit/splitter_test.rb @@ -44,12 +44,109 @@ class CssSplitterTest < ActiveSupport::TestCase assert_equal ['@charset "UTF-8";', ' .foo { color: black; }'], CssSplitter::Splitter.send(:extract_charset, first_rule) end + # --- extract_media --- + + test '#extract_media with no media block' do + first_rule = ".foo { color: black; }" + assert_equal nil, CssSplitter::Splitter.send(:extract_media, first_rule) + end + + test '#extract_media with media block' do + first_rule = <<< ".a#{n} { color: black; }" + end + css_rules << "@media only screen and (-webkit-min-device-pixel-ratio: 0) and (device-width: 768px), only screen and (-webkit-min-device-pixel-ratio: 0) and (device-width: 1280px), only screen and (-webkit-min-device-pixel-ratio: 0) and (device-width: 800px) {" + css_rules << ".first-in-media-after-split { color: black; } }" + last_part = ".first-after-media { color: black; }" + + first_contents = css_rules.join("").gsub(/\s/, '') + last_contents = last_part.gsub(/\s/, '') + css_contents = "#{first_contents}#{last_contents}" + + assert_equal first_contents, CssSplitter::Splitter.split_string(css_contents, 1, max_selectors) + assert_equal last_contents, CssSplitter::Splitter.split_string(css_contents, 2, max_selectors) + end + + test '#split_string where the media part would overlap the split, no rules in media before the split' do + # This tests the following situation: + # Part 1: CssSplitter::Splitter::MAX_SELECTORS_DEFAULT + # Part 2: Opens with media block with 1 rule inside and one after + + # Change this line to any number, for example 4, if it failes to ease debugging + max_selectors = CssSplitter::Splitter::MAX_SELECTORS_DEFAULT + + css_rules = [] + max_selectors.times do |n| + css_rules << ".a#{n} { color: black; }" + end + media_rule = "@media only screen and (-webkit-min-device-pixel-ratio: 0) and (device-width: 768px), only screen and (-webkit-min-device-pixel-ratio: 0) and (device-width: 1280px), only screen and (-webkit-min-device-pixel-ratio: 0) and (device-width: 800px) {" + last_part = "#{media_rule} .first-in-media-after-split { color: black; } } .first-after-media { color: black; }" + + first_contents = css_rules.join("").gsub(/\s/, '') + last_contents = last_part.gsub(/\s/, '') + css_contents = "#{first_contents}#{last_contents}" + + assert_equal first_contents, CssSplitter::Splitter.split_string(css_contents, 1, max_selectors) + assert_equal last_contents, CssSplitter::Splitter.split_string(css_contents, 2, max_selectors) + end + + test '#split_string where the media part would overlap the split, with rules in media before the split' do + # This tests the following situation: + # Part 1: CssSplitter::Splitter::MAX_SELECTORS_DEFAULT - 1 rules + # + Media block and first rule inside the media block + # Part 2: Opens with media block with last rule inside and one after + + # Change this line to any number, for example 4, if it failes to ease debugging + max_selectors = CssSplitter::Splitter::MAX_SELECTORS_DEFAULT + + css_rules = [] + (max_selectors - 1).times do |n| + css_rules << ".a#{n} { color: black; }" + end + css_rules << media_rule = "@media only screen and (-webkit-min-device-pixel-ratio: 0) and (device-width: 768px), only screen and (-webkit-min-device-pixel-ratio: 0) and (device-width: 1280px), only screen and (-webkit-min-device-pixel-ratio: 0) and (device-width: 800px) {" + css_rules << ".last-before-split { color: black; }" + + after_split = ".last-after-split { color: black; } } .first-after-media { color: black; }".gsub(/\s/, '') + + first_contents = css_rules.join("").gsub(/\s/, '') + css_contents = "#{first_contents}#{after_split}" + + # The last part should open with the media, followed by the rules defined in after_split + last_contents = "#{media_rule}#{after_split}".gsub(/\s/, '') + + # The first file should be closed neatly, as the media part opened before the last rule + # it should be closed as well. + assert_equal "#{first_contents}}", CssSplitter::Splitter.split_string(css_contents, 1, max_selectors) + + # The second part should open with the media definition, followed by one rule inside + # the media block and one rule after. + assert_equal last_contents, CssSplitter::Splitter.split_string(css_contents, 2, max_selectors) + end + # --- strip_comments --- test '#strip_comments: strip single line CSS coment' do From e65a4fb45fb9ba31551e3593b63d4e528a8c9cb9 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Fri, 18 Apr 2014 18:24:37 +0200 Subject: [PATCH 10/70] updated dummy app to rails 4.1 --- Gemfile.lock | 132 +++++++++--------- test/dummy/config/application.rb | 1 - test/dummy/config/environments/development.rb | 2 + test/dummy/config/environments/production.rb | 2 + test/dummy/config/environments/test.rb | 2 + .../css_splitter/application_helper_test.rb | 4 +- 6 files changed, 74 insertions(+), 69 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 12db0ff..3a6fc5c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,35 +7,34 @@ PATH GEM remote: http://rubygems.org/ specs: - actionmailer (3.2.13) - actionpack (= 3.2.13) - mail (~> 2.5.3) - actionpack (3.2.13) - activemodel (= 3.2.13) - activesupport (= 3.2.13) - builder (~> 3.0.0) + actionmailer (4.1.0) + actionpack (= 4.1.0) + actionview (= 4.1.0) + mail (~> 2.5.4) + actionpack (4.1.0) + actionview (= 4.1.0) + activesupport (= 4.1.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + actionview (4.1.0) + activesupport (= 4.1.0) + builder (~> 3.1) erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.5) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) - activemodel (3.2.13) - activesupport (= 3.2.13) - builder (~> 3.0.0) - activerecord (3.2.13) - activemodel (= 3.2.13) - activesupport (= 3.2.13) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.13) - activemodel (= 3.2.13) - activesupport (= 3.2.13) - activesupport (3.2.13) - i18n (= 0.6.1) - multi_json (~> 1.0) - arel (3.0.2) - builder (3.0.4) + activemodel (4.1.0) + activesupport (= 4.1.0) + builder (~> 3.1) + activerecord (4.1.0) + activemodel (= 4.1.0) + activesupport (= 4.1.0) + arel (~> 5.0.0) + activesupport (4.1.0) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + arel (5.0.1.20140414130214) + builder (3.2.2) coderay (1.0.9) columnize (0.3.6) debugger (1.5.0) @@ -47,20 +46,20 @@ GEM erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) - hike (1.2.1) - i18n (0.6.1) - journey (1.0.4) + hike (1.2.3) + i18n (0.6.9) jquery-rails (2.2.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - json (1.7.7) + json (1.8.1) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) method_source (0.8.1) - mime-types (1.25) - multi_json (1.7.1) - polyglot (0.3.3) + mime-types (1.25.1) + minitest (5.3.3) + multi_json (1.9.2) + polyglot (0.3.4) pry (0.9.12) coderay (~> 1.0.5) method_source (~> 0.8) @@ -68,48 +67,49 @@ GEM pry-debugger (0.2.2) debugger (~> 1.3) pry (~> 0.9.10) - rack (1.4.5) - rack-cache (1.2) - rack (>= 0.4) - rack-ssl (1.3.3) - rack + rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) - rails (3.2.13) - actionmailer (= 3.2.13) - actionpack (= 3.2.13) - activerecord (= 3.2.13) - activeresource (= 3.2.13) - activesupport (= 3.2.13) - bundler (~> 1.0) - railties (= 3.2.13) - railties (3.2.13) - actionpack (= 3.2.13) - activesupport (= 3.2.13) - rack-ssl (~> 1.3.2) + rails (4.1.0) + actionmailer (= 4.1.0) + actionpack (= 4.1.0) + actionview (= 4.1.0) + activemodel (= 4.1.0) + activerecord (= 4.1.0) + activesupport (= 4.1.0) + bundler (>= 1.3.0, < 2.0) + railties (= 4.1.0) + sprockets-rails (~> 2.0) + railties (4.1.0) + actionpack (= 4.1.0) + activesupport (= 4.1.0) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) - rake (10.0.3) - rdoc (3.12.2) - json (~> 1.4) - sass (3.2.6) - sass-rails (3.2.6) - railties (~> 3.2.0) - sass (>= 3.1.10) - tilt (~> 1.3) + thor (>= 0.18.1, < 2.0) + rake (10.3.1) + sass (3.2.19) + sass-rails (4.0.3) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.0) + sprockets (~> 2.8, <= 2.11.0) + sprockets-rails (~> 2.0) slop (3.4.4) - sprockets (2.2.2) + sprockets (2.11.0) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - thor (0.17.0) - tilt (1.3.6) + sprockets-rails (2.1.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) + thor (0.19.1) + thread_safe (0.3.3) + tilt (1.4.1) treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.38) + tzinfo (1.1.0) + thread_safe (~> 0.1) uglifier (1.3.0) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 9f787b4..6a0af91 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -3,7 +3,6 @@ # require 'rails/all' require "action_controller/railtie" require "action_mailer/railtie" -require "active_resource/railtie" require "rails/test_unit/railtie" require "sprockets/railtie" diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index 50105b3..ef8997c 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -34,4 +34,6 @@ # Expands the lines which load the assets config.assets.debug = true + + config.eager_load = false end diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb index b178724..5f2d7d7 100644 --- a/test/dummy/config/environments/production.rb +++ b/test/dummy/config/environments/production.rb @@ -64,4 +64,6 @@ # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) # config.active_record.auto_explain_threshold_in_seconds = 0.5 + + config.eager_load = true end diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 6feb3d2..284daa5 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -34,4 +34,6 @@ # Print deprecation notices to the stderr config.active_support.deprecation = :stderr + + config.eager_load = false end diff --git a/test/unit/helpers/css_splitter/application_helper_test.rb b/test/unit/helpers/css_splitter/application_helper_test.rb index 1fedb0a..294b6bb 100644 --- a/test/unit/helpers/css_splitter/application_helper_test.rb +++ b/test/unit/helpers/css_splitter/application_helper_test.rb @@ -5,12 +5,12 @@ class ApplicationHelperTest < ActionView::TestCase test "should work w/out options" do output = split_stylesheet_link_tag("too_big_stylesheet") - assert_equal "\n", output + assert_equal "\n", output end test "should work with options and multiple stylesheets" do output = split_stylesheet_link_tag("too_big_stylesheet", "foo", media: "print") - assert_equal "\n\n", output + assert_equal "\n\n", output end end From e25280723e7713a53082bdbca44d8778afdccc56 Mon Sep 17 00:00:00 2001 From: Clyde Law Date: Wed, 23 Apr 2014 12:03:15 -0700 Subject: [PATCH 11/70] Properly handle media query closing braces --- lib/css_splitter/splitter.rb | 14 ++++++------ test/unit/splitter_test.rb | 41 ++++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/lib/css_splitter/splitter.rb b/lib/css_splitter/splitter.rb index ea9a9d4..eda1d4c 100644 --- a/lib/css_splitter/splitter.rb +++ b/lib/css_splitter/splitter.rb @@ -39,12 +39,13 @@ def self.extract_part(rules, part = 1, max_selectors = MAX_SELECTORS_DEFAULT) rule_selectors_count = count_selectors_of_rule rule selectors_count += rule_selectors_count + if rule =~ /^\s*}$/ + current_media = nil + # skip the line if the close bracket is the first rule for the new file + next if first_hit + end + if selector_range.cover? selectors_count # add rule to current output if within selector_range - if rule =~ /^\s*}$/ - current_media = nil - # skip the line if the close bracket is the first rule for the new file - next if first_hit - end if media_part output << media_part elsif first_hit && current_media @@ -67,7 +68,8 @@ def self.extract_part(rules, part = 1, max_selectors = MAX_SELECTORS_DEFAULT) # count selectors of one individual CSS rule def self.count_selectors_of_rule(rule) - strip_comments(rule).partition(/\{/).first.scan(/,/).count.to_i + 1 + parts = strip_comments(rule).partition(/\{/) + parts.second.empty? ? 0 : parts.first.scan(/,/).count.to_i + 1 end diff --git a/test/unit/splitter_test.rb b/test/unit/splitter_test.rb index 4af26ad..b5c4b59 100644 --- a/test/unit/splitter_test.rb +++ b/test/unit/splitter_test.rb @@ -2,12 +2,15 @@ class CssSplitterTest < ActiveSupport::TestCase test "#count_selectors" do - assert_equal 2938, CssSplitter::Splitter.count_selectors('test/unit/too_many_selectors.css') + assert_equal 2937, CssSplitter::Splitter.count_selectors('test/unit/too_many_selectors.css') end test "#count_selectors_of_rule" do assert_equal 1, CssSplitter::Splitter.count_selectors_of_rule('foo { color: baz; }') assert_equal 2, CssSplitter::Splitter.count_selectors_of_rule('foo, bar { color: baz; }') + + # split_string_into_rules splits the closing brace of a media query into its own rule + assert_equal 0, CssSplitter::Splitter.count_selectors_of_rule('}') end # --- split_string_into_rules --- @@ -32,6 +35,11 @@ class CssSplitterTest < ActiveSupport::TestCase assert_equal ["a{foo:url(//assets.server.com);}", "b{bar:url(//assets/server.com);}"], CssSplitter::Splitter.split_string_into_rules(simple) end + test '#split_string_into_rules containing media queries' do + has_media = "a{foo:bar;}@media print{b{baz:qux;}c{quux:corge;}}d{grault:garply;}" + assert_equal ["a{foo:bar;}", "@media print{b{baz:qux;}", "c{quux:corge;}", "}", "d{grault:garply;}"], CssSplitter::Splitter.split_string_into_rules(has_media) + end + # --- extract_charset --- test '#extract_charset with no charset' do @@ -72,7 +80,7 @@ class CssSplitterTest < ActiveSupport::TestCase # + Media block and first rule inside the media block # Part 2: Ignore the close tag of the media block and outputs the last rule outside the media block - # Change this line to any number, for example 4, if it failes to ease debugging + # Change this line to any number, for example 4, if it fails to ease debugging max_selectors = CssSplitter::Splitter::MAX_SELECTORS_DEFAULT css_rules = [] @@ -96,7 +104,7 @@ class CssSplitterTest < ActiveSupport::TestCase # Part 1: CssSplitter::Splitter::MAX_SELECTORS_DEFAULT # Part 2: Opens with media block with 1 rule inside and one after - # Change this line to any number, for example 4, if it failes to ease debugging + # Change this line to any number, for example 4, if it fails to ease debugging max_selectors = CssSplitter::Splitter::MAX_SELECTORS_DEFAULT css_rules = [] @@ -120,7 +128,7 @@ class CssSplitterTest < ActiveSupport::TestCase # + Media block and first rule inside the media block # Part 2: Opens with media block with last rule inside and one after - # Change this line to any number, for example 4, if it failes to ease debugging + # Change this line to any number, for example 4, if it fails to ease debugging max_selectors = CssSplitter::Splitter::MAX_SELECTORS_DEFAULT css_rules = [] @@ -147,6 +155,31 @@ class CssSplitterTest < ActiveSupport::TestCase assert_equal last_contents, CssSplitter::Splitter.split_string(css_contents, 2, max_selectors) end + test '#split_string where the media part comes before the split' do + # This tests the following situation: + # Part 1: Media block with rule inside media block + # + CssSplitter::Splitter::MAX_SELECTORS_DEFAULT - 1 rules outside media block + # Part 2: Outputs the last rule outside media block + + # Change this line to any number, for example 4, if it fails to ease debugging + max_selectors = CssSplitter::Splitter::MAX_SELECTORS_DEFAULT + + css_rules = [] + css_rules << "@media print { .media-rule { color: black; } }" + + (max_selectors - 1).times do |n| + css_rules << ".a#{n} { color: black; }" + end + + first_contents = css_rules.join("").gsub(/\s/, '') + last_contents = ".first-after-split { color: black; }".gsub(/\s/, '') + + css_contents = "#{first_contents}#{last_contents}" + + assert_equal first_contents, CssSplitter::Splitter.split_string(css_contents, 1, max_selectors) + assert_equal last_contents, CssSplitter::Splitter.split_string(css_contents, 2, max_selectors) + end + # --- strip_comments --- test '#strip_comments: strip single line CSS coment' do From 08889fd2c68e4395e9e8e54036ce07d917074f05 Mon Sep 17 00:00:00 2001 From: Clyde Law Date: Thu, 24 Apr 2014 12:31:18 -0700 Subject: [PATCH 12/70] Gemfile.lock should not be checked into version control for a gem. Fixes #31. --- .gitignore | 1 + Gemfile.lock | 125 --------------------------------------------------- 2 files changed, 1 insertion(+), 125 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index 1dfe31e..a9ecfb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .bundle/ +Gemfile.lock log/*.log pkg/ test/dummy/db/*.sqlite3 diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 3a6fc5c..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,125 +0,0 @@ -PATH - remote: . - specs: - css_splitter (0.2.0) - rails (>= 3.1) - -GEM - remote: http://rubygems.org/ - specs: - actionmailer (4.1.0) - actionpack (= 4.1.0) - actionview (= 4.1.0) - mail (~> 2.5.4) - actionpack (4.1.0) - actionview (= 4.1.0) - activesupport (= 4.1.0) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - actionview (4.1.0) - activesupport (= 4.1.0) - builder (~> 3.1) - erubis (~> 2.7.0) - activemodel (4.1.0) - activesupport (= 4.1.0) - builder (~> 3.1) - activerecord (4.1.0) - activemodel (= 4.1.0) - activesupport (= 4.1.0) - arel (~> 5.0.0) - activesupport (4.1.0) - i18n (~> 0.6, >= 0.6.9) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.1) - tzinfo (~> 1.1) - arel (5.0.1.20140414130214) - builder (3.2.2) - coderay (1.0.9) - columnize (0.3.6) - debugger (1.5.0) - columnize (>= 0.3.1) - debugger-linecache (~> 1.2.0) - debugger-ruby_core_source (~> 1.2.0) - debugger-linecache (1.2.0) - debugger-ruby_core_source (1.2.0) - erubis (2.7.0) - execjs (1.4.0) - multi_json (~> 1.0) - hike (1.2.3) - i18n (0.6.9) - jquery-rails (2.2.1) - railties (>= 3.0, < 5.0) - thor (>= 0.14, < 2.0) - json (1.8.1) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) - method_source (0.8.1) - mime-types (1.25.1) - minitest (5.3.3) - multi_json (1.9.2) - polyglot (0.3.4) - pry (0.9.12) - coderay (~> 1.0.5) - method_source (~> 0.8) - slop (~> 3.4) - pry-debugger (0.2.2) - debugger (~> 1.3) - pry (~> 0.9.10) - rack (1.5.2) - rack-test (0.6.2) - rack (>= 1.0) - rails (4.1.0) - actionmailer (= 4.1.0) - actionpack (= 4.1.0) - actionview (= 4.1.0) - activemodel (= 4.1.0) - activerecord (= 4.1.0) - activesupport (= 4.1.0) - bundler (>= 1.3.0, < 2.0) - railties (= 4.1.0) - sprockets-rails (~> 2.0) - railties (4.1.0) - actionpack (= 4.1.0) - activesupport (= 4.1.0) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.3.1) - sass (3.2.19) - sass-rails (4.0.3) - railties (>= 4.0.0, < 5.0) - sass (~> 3.2.0) - sprockets (~> 2.8, <= 2.11.0) - sprockets-rails (~> 2.0) - slop (3.4.4) - sprockets (2.11.0) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.1.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (~> 2.8) - thor (0.19.1) - thread_safe (0.3.3) - tilt (1.4.1) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - tzinfo (1.1.0) - thread_safe (~> 0.1) - uglifier (1.3.0) - execjs (>= 0.3.0) - multi_json (~> 1.0, >= 1.0.2) - -PLATFORMS - ruby - -DEPENDENCIES - css_splitter! - jquery-rails - pry-debugger - sass-rails - uglifier From 88c99a933374a67312090f47e85e9a4d58d61362 Mon Sep 17 00:00:00 2001 From: Clyde Law Date: Mon, 5 May 2014 16:08:23 -0700 Subject: [PATCH 13/70] Convert splitter engine to be a Sprockets bundle processor. --- lib/css_splitter/engine.rb | 2 +- lib/css_splitter/sprockets_engine.rb | 12 ++++++------ .../test_stylesheet_with_media_queries_split2.css | 3 +++ ...t_stylesheet_with_media_queries_split2.css.split2 | 1 - .../assets/stylesheets/too_big_stylesheet_split2.css | 3 +++ .../stylesheets/too_big_stylesheet_split2.css.split2 | 1 - 6 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 test/dummy/app/assets/stylesheets/test_stylesheet_with_media_queries_split2.css delete mode 100644 test/dummy/app/assets/stylesheets/test_stylesheet_with_media_queries_split2.css.split2 create mode 100644 test/dummy/app/assets/stylesheets/too_big_stylesheet_split2.css delete mode 100644 test/dummy/app/assets/stylesheets/too_big_stylesheet_split2.css.split2 diff --git a/lib/css_splitter/engine.rb b/lib/css_splitter/engine.rb index 4352159..c51574e 100644 --- a/lib/css_splitter/engine.rb +++ b/lib/css_splitter/engine.rb @@ -3,7 +3,7 @@ class Engine < ::Rails::Engine isolate_namespace CssSplitter initializer 'css_splitter.sprockets_engine', after: 'sprockets.environment', group: :all do |app| - app.assets.register_engine '.split2', CssSplitter::SprocketsEngine + app.assets.register_bundle_processor 'text/css', CssSplitter::SprocketsEngine end initializer 'css_splitter.action_controller' do |app| diff --git a/lib/css_splitter/sprockets_engine.rb b/lib/css_splitter/sprockets_engine.rb index fc40759..f6ae2a8 100644 --- a/lib/css_splitter/sprockets_engine.rb +++ b/lib/css_splitter/sprockets_engine.rb @@ -11,12 +11,12 @@ def prepare end def evaluate(scope, locals, &block) - # determine which is the current split (e.g. split2, split3) - split = if scope.pathname.extname =~ /(\d+)$/; $1 - elsif scope.pathname.basename.to_s =~ /_split(\d+)\.css/; $1 - else 2 - end - CssSplitter::Splitter.split_string(data, split.to_i) + # Evaluate the split if the asset is named with a trailing _split2, _split3, etc. + if scope.logical_path =~ /_split(\d+)$/ + CssSplitter::Splitter.split_string(data, $1.to_i) + else + data + end end end diff --git a/test/dummy/app/assets/stylesheets/test_stylesheet_with_media_queries_split2.css b/test/dummy/app/assets/stylesheets/test_stylesheet_with_media_queries_split2.css new file mode 100644 index 0000000..23b2f80 --- /dev/null +++ b/test/dummy/app/assets/stylesheets/test_stylesheet_with_media_queries_split2.css @@ -0,0 +1,3 @@ +/* + *= require 'test_stylesheet_with_media_queries' + */ diff --git a/test/dummy/app/assets/stylesheets/test_stylesheet_with_media_queries_split2.css.split2 b/test/dummy/app/assets/stylesheets/test_stylesheet_with_media_queries_split2.css.split2 deleted file mode 100644 index b8ab087..0000000 --- a/test/dummy/app/assets/stylesheets/test_stylesheet_with_media_queries_split2.css.split2 +++ /dev/null @@ -1 +0,0 @@ -//= include 'test_stylesheet_with_media_queries' \ No newline at end of file diff --git a/test/dummy/app/assets/stylesheets/too_big_stylesheet_split2.css b/test/dummy/app/assets/stylesheets/too_big_stylesheet_split2.css new file mode 100644 index 0000000..1cf401d --- /dev/null +++ b/test/dummy/app/assets/stylesheets/too_big_stylesheet_split2.css @@ -0,0 +1,3 @@ +/* + *= require 'too_big_stylesheet.css' + */ diff --git a/test/dummy/app/assets/stylesheets/too_big_stylesheet_split2.css.split2 b/test/dummy/app/assets/stylesheets/too_big_stylesheet_split2.css.split2 deleted file mode 100644 index ffa49f3..0000000 --- a/test/dummy/app/assets/stylesheets/too_big_stylesheet_split2.css.split2 +++ /dev/null @@ -1 +0,0 @@ -//= include 'too_big_stylesheet.css' \ No newline at end of file From ddee67fa5de1fc3574ce446cb54b1c670e2f3a71 Mon Sep 17 00:00:00 2001 From: Clyde Law Date: Mon, 5 May 2014 17:53:15 -0700 Subject: [PATCH 14/70] Test asset pipeline stylesheet splitting. --- test/css_splitter_test.rb | 34 +++++++++++++++++++ .../app/assets/stylesheets/combined.css.scss | 4 +++ .../assets/stylesheets/combined_split2.css | 3 ++ .../stylesheets/erb_stylesheet.css.scss.erb | 7 ++++ .../stylesheets/erb_stylesheet_split2.css | 3 ++ .../stylesheets/erb_stylesheet_split3.css | 3 ++ .../assets/stylesheets/green_max.css.scss.erb | 3 ++ .../assets/stylesheets/red_100.css.scss.erb | 3 ++ 8 files changed, 60 insertions(+) create mode 100644 test/dummy/app/assets/stylesheets/combined.css.scss create mode 100644 test/dummy/app/assets/stylesheets/combined_split2.css create mode 100644 test/dummy/app/assets/stylesheets/erb_stylesheet.css.scss.erb create mode 100644 test/dummy/app/assets/stylesheets/erb_stylesheet_split2.css create mode 100644 test/dummy/app/assets/stylesheets/erb_stylesheet_split3.css create mode 100644 test/dummy/app/assets/stylesheets/green_max.css.scss.erb create mode 100644 test/dummy/app/assets/stylesheets/red_100.css.scss.erb diff --git a/test/css_splitter_test.rb b/test/css_splitter_test.rb index 7fd8634..5090a3d 100644 --- a/test/css_splitter_test.rb +++ b/test/css_splitter_test.rb @@ -1,7 +1,41 @@ require 'test_helper' class CssSplitterTest < ActiveSupport::TestCase + + setup :clear_assets_cache + test "truth" do assert_kind_of Module, CssSplitter end + + test "asset pipeline stylesheet splitting" do + part1 = "#test{background-color:red}" * CssSplitter::Splitter::MAX_SELECTORS_DEFAULT + 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 + 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 + end + + private + + def clear_assets_cache + assets_cache = Rails.root.join("tmp/cache/assets") + assets_cache.rmtree if assets_cache.exist? + end + + def assets + Rails.application.assets + end + end diff --git a/test/dummy/app/assets/stylesheets/combined.css.scss b/test/dummy/app/assets/stylesheets/combined.css.scss new file mode 100644 index 0000000..5fd8ab4 --- /dev/null +++ b/test/dummy/app/assets/stylesheets/combined.css.scss @@ -0,0 +1,4 @@ +//= require 'red_100' +//= require 'green_max' + +#test { background-color: blue; } diff --git a/test/dummy/app/assets/stylesheets/combined_split2.css b/test/dummy/app/assets/stylesheets/combined_split2.css new file mode 100644 index 0000000..cc3963c --- /dev/null +++ b/test/dummy/app/assets/stylesheets/combined_split2.css @@ -0,0 +1,3 @@ +/* + *= require 'combined' + */ diff --git a/test/dummy/app/assets/stylesheets/erb_stylesheet.css.scss.erb b/test/dummy/app/assets/stylesheets/erb_stylesheet.css.scss.erb new file mode 100644 index 0000000..de64edc --- /dev/null +++ b/test/dummy/app/assets/stylesheets/erb_stylesheet.css.scss.erb @@ -0,0 +1,7 @@ +<% CssSplitter::Splitter::MAX_SELECTORS_DEFAULT.times do %> +#test { background-color: red; } +<% end %> +<% CssSplitter::Splitter::MAX_SELECTORS_DEFAULT.times do %> +#test { background-color: green; } +<% end %> +#test { background-color: blue; } diff --git a/test/dummy/app/assets/stylesheets/erb_stylesheet_split2.css b/test/dummy/app/assets/stylesheets/erb_stylesheet_split2.css new file mode 100644 index 0000000..2c6b6e1 --- /dev/null +++ b/test/dummy/app/assets/stylesheets/erb_stylesheet_split2.css @@ -0,0 +1,3 @@ +/* + *= require 'erb_stylesheet.css' + */ diff --git a/test/dummy/app/assets/stylesheets/erb_stylesheet_split3.css b/test/dummy/app/assets/stylesheets/erb_stylesheet_split3.css new file mode 100644 index 0000000..2c6b6e1 --- /dev/null +++ b/test/dummy/app/assets/stylesheets/erb_stylesheet_split3.css @@ -0,0 +1,3 @@ +/* + *= require 'erb_stylesheet.css' + */ diff --git a/test/dummy/app/assets/stylesheets/green_max.css.scss.erb b/test/dummy/app/assets/stylesheets/green_max.css.scss.erb new file mode 100644 index 0000000..df75a7f --- /dev/null +++ b/test/dummy/app/assets/stylesheets/green_max.css.scss.erb @@ -0,0 +1,3 @@ +<% CssSplitter::Splitter::MAX_SELECTORS_DEFAULT.times do %> +#test { background-color: green; } +<% end %> diff --git a/test/dummy/app/assets/stylesheets/red_100.css.scss.erb b/test/dummy/app/assets/stylesheets/red_100.css.scss.erb new file mode 100644 index 0000000..ae6effd --- /dev/null +++ b/test/dummy/app/assets/stylesheets/red_100.css.scss.erb @@ -0,0 +1,3 @@ +<% 100.times do %> +#test { background-color: red; } +<% end %> From d2b16168bee8c029ab8fe5003b0e985c0c1882be Mon Sep 17 00:00:00 2001 From: Clyde Law Date: Mon, 5 May 2014 19:04:35 -0700 Subject: [PATCH 15/70] Add split_count option to split_stylesheet_link_tag helper and fix ordering of split stylesheets. --- .../css_splitter/application_helper.rb | 22 ++++++++++--------- .../css_splitter/application_helper_test.rb | 7 +++++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/helpers/css_splitter/application_helper.rb b/app/helpers/css_splitter/application_helper.rb index 644a071..af5061d 100644 --- a/app/helpers/css_splitter/application_helper.rb +++ b/app/helpers/css_splitter/application_helper.rb @@ -1,18 +1,20 @@ module CssSplitter module ApplicationHelper def split_stylesheet_link_tag(*sources) - original_sources = sources.dup + options = sources.extract_options! + split_count = options.delete(:split_count) || 2 - options = sources.extract_options! - sources.collect!{ |source| "#{source}_split2" } - sources << options + sources.map do |source| + split_sources = (2..split_count).map { |index| "#{source}_split#{index}" } + split_sources << options - [ - stylesheet_link_tag(*original_sources), - "" - ].join("\n").html_safe + [ + stylesheet_link_tag(source, options), + "" + ] + end.flatten.join("\n").html_safe end end end \ No newline at end of file diff --git a/test/unit/helpers/css_splitter/application_helper_test.rb b/test/unit/helpers/css_splitter/application_helper_test.rb index 294b6bb..e42a401 100644 --- a/test/unit/helpers/css_splitter/application_helper_test.rb +++ b/test/unit/helpers/css_splitter/application_helper_test.rb @@ -10,7 +10,12 @@ class ApplicationHelperTest < ActionView::TestCase test "should work with options and multiple stylesheets" do output = split_stylesheet_link_tag("too_big_stylesheet", "foo", media: "print") - assert_equal "\n\n", output + assert_equal "\n\n\n", output + end + + test "should work with split_count option" do + output = split_stylesheet_link_tag("too_big_stylesheet", split_count: 3) + assert_equal "\n", output end end From e4d0fa631d60fff379b63196226418ba6fe6651f Mon Sep 17 00:00:00 2001 From: Clyde Law Date: Mon, 5 May 2014 19:28:11 -0700 Subject: [PATCH 16/70] Update README with changes. --- README.md | 63 +++++++++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index af242e6..f6a544c 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,17 @@ CssSplitter integrates with the Rails 3.1+ Asset Pipeline to generate additional The first step is identifying the stylesheets that have more than 4095 selectors and therefore need to be split for IE. -Once you know which stylesheets need to be split, you need to create a second "container file" for those stylesheets with the file extension `.split2`, that will contain the styles beyond the 4095 selector limit. +Once you know which stylesheets need to be split, you need to create a second "container file" for those stylesheets with the `_split2` suffix appended to the base filename that will contain the styles beyond the 4095 selector limit. The extension of this file should be just `.css` without any additional preprocessor extensions. -For example, if you want to split `too_big_stylesheet.css`, you need to create a new file `too_big_stylesheet_split2.css.split2` in the same directory. The only content of that container, will be an include of the original file, e.g.: +For example, if you want to split `too_big_stylesheet.css.scss`, you need to create a new file `too_big_stylesheet_split2.css` in the same directory. The only content of that container, will contain a `require` directive to the name of the original asset, e.g.: - # app/assets/stylesheets/too_big_stylesheet_split2.css.split2 + # app/assets/stylesheets/too_big_stylesheet_split2.css - //= include 'too_big_stylesheet.css' + /* + *= require 'too_big_stylesheet' + */ + +If your stylesheet is big enough to need splitting into more than two more files, simply create additional `_split3`, `_split4`, etc. files, the contents of which should be identical to the `_split2` file. You also need to remember to add those new files to the asset pipeline, so they will be compiled. For example: @@ -43,12 +47,10 @@ You also need to remember to add those new files to the asset pipeline, so they Here is a checklist of requirements for your split stylesheet: -1. It needs to have different filename than orginal, e.g. `original_stylesheet_split2` or `application_split2` -2. It needs to have `.split2` as a file extension, e.g. `.css.split2`, `.css.sass.split2`, or `.css.split2.erb` -3. It needs to include the content of the orginal stylesheet, e.g. through `//= include 'application'` or `<%= environment.find_asset('application') %>` -4. It needs to be added to list of precompiled assets - - +1. It needs to have the `_splitN` suffix appended to the original asset name, e.g. `original_stylesheet_split2` or `application_split2` +2. It needs to have `.css` as a file extension. +3. It needs to require the orginal stylesheet. +4. It needs to be added to list of precompiled assets. ### 2. Including your split stylesheets @@ -60,51 +62,28 @@ You can just use our `split_stylesheet_link_tag` helper, which would look someth <%= split_stylesheet_link_tag "too_big_stylesheet", :media => "all" %> # output - + +If your stylesheet is split into more than two files, add the `split_count` option to specify the total number of files. + + <%= split_stylesheet_link_tag "too_big_stylesheet", :split_count => 3 %> + Or you can just create similar HTML as in the above example yourself. If you want to use the `split_stylesheet_link_tag` helper you need to make sure the gem is loaded in production, so you can't put it in the `:assets` group in your Gemfile. ## How it works -Basically, CssSplitter is registering a new `Sprockets::Engine` for the `.split2` file extension, that will fill those files with all the selectors beyond the 4095th. Unfortunately, those `.split2` files need to be created manually, because we haven't figured out a way for a `Sprockets::Engine` to output multiple files. They need to present before the compile step. +Basically, CssSplitter is registering a new Sprockets bundle processor that looks for CSS assets named with the `_splitN` suffix and will fill those files with all the selectors beyond the 4095th. Unfortunately, those `_splitN` files need to be created manually, because we haven't figured out a way for a `Sprockets::Engine` to output multiple files. They need to present before the compile step. If you have more questions about how it works, look at the code or contact us. ## Gotchas -#### Having a JS asset with the same name as the the split stylesheet - -If you want to split a style (e.g. `assets/stylesheets/application.*`) and have a JS asset with the same name (`assets/javascripts/application.*`) in your asset load_path (as is the default in Rails), you need to include the stylesheet along with the file extension `// = include 'application.css'` because otherwise it will try to include the JS asset of the same name instead. Sprocket's `= include` directive doesn't seem to differentiate between different types/folders and just takes the first asset it can find for any given name (see #10). - -#### Don't use Sprocket's `= require_tree .` or `= require_self` for stylesheets -It's recommended that you **always use Sass's `@import`** for all your stylesheets in favor of Sprocket's `= require` directives, just as the official `sass-rails` gem says: https://github.com/rails/sass-rails#important-note - -If you have a `.split2` stylesheet in your tree that in turn includes the base stylesheet like shown below, you will end up with a nasty `Sprockets::CircularDependencyError`! - - /* assets/stylesheets/application.css */ - /* = require_tree . - - /* assets/stylesheets/application_split2.css.split2 */ - /* = include 'application.css' */ - -If you have `require_self` in the stylesheet that you're splitting, as shown below, the `.split2` will end up having **both** the original stylesheet and the split contents. You'll end up with an even bigger stylesheet. - - /* assets/stylesheets/application.css */ - /* = require_self - - /* assets/stylesheets/application_split2.css.split2 */ - /* = include 'application.css' */ - - -## Limitations & Known Issues - -**More than 8190 selectors** - -Currently the gem only supports stylesheets that need to be split into 2 files. It could theoretically create more splits (e.g. if you should have more than 8190 selectors), but in that case you should probably refactor your stylesheets anyway. Contact us, if you have this requirement. +#### Differences from previous versions +Note that if you used the 0.x.x versions of this gem, the naming and contents of the split files have changed. Split files no longer need to have the `.split2` extension and now use the `require` directive rather than the `include` directive. The previous prohibition against using `require_tree .` and `require_self` directives also no longer applies. ## Credits & License From ef4fb8e5fd704c50c7c6d613e4774a05fdf09865 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Tue, 6 May 2014 10:18:39 +0200 Subject: [PATCH 17/70] bumped version to 0.4.0 and updated CHANGELOG+README --- CHANGELOG.md | 10 ++++++++++ README.md | 13 +++++++------ lib/css_splitter/version.rb | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b51ff78..d4f3764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# 0.4.0 + +* **Breaking changes!** +* The `CssSplitter::SprocketsEngine` is now registered as a bundle_processor to avoid issues with sprockets directives #29 +** `.split2` extension is no longer necessary/supported, now we rely on `_splitN` at the end of the filename +** Now you need to use the `require` rather than the `include` directive in the split stylesheet +** Prohibition against using `require_tree .` and `require_self` directives no longer applies +** Better tests +** Thanks a lot to @Umofomia + # 0.2.0 * loosen dependency to make it compatible with rails 4 diff --git a/README.md b/README.md index f6a544c..38f02d3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# CssSplitter [![Build Status](https://travis-ci.org/zweilove/css_splitter.png?branch=master)](https://travis-ci.org/zweilove/css_splitter) [![Dependency Status](https://gemnasium.com/zweilove/css_splitter.png)](https://gemnasium.com/zweilove/css_splitter) +# CssSplitter [![Build Status](https://travis-ci.org/zweilove/css_splitter.png?branch=master)](https://travis-ci.org/zweilove/css_splitter) Gem for splitting up stylesheets that go beyond the IE limit of 4096 selectors, for Rails 3.1+ apps using the Asset Pipeline. You can read this [blogpost](http://railslove.com/blog/2013/03/08/overcoming-ies-4096-selector-limit-using-the-css-splitter-gem) for an explanation of this gem's background story. @@ -16,8 +16,8 @@ CssSplitter integrates with the Rails 3.1+ Asset Pipeline to generate additional ## Dependencies -* Rails 3.1+ -* Asset Pipeline +* Sprockets 2.0+ +* e.g. Rails 3.1+ with the asset pipeline ## Documentation @@ -83,7 +83,7 @@ If you have more questions about how it works, look at the code or contact us. #### Differences from previous versions -Note that if you used the 0.x.x versions of this gem, the naming and contents of the split files have changed. Split files no longer need to have the `.split2` extension and now use the `require` directive rather than the `include` directive. The previous prohibition against using `require_tree .` and `require_self` directives also no longer applies. +Note that if you used versions below `0.4.0` of this gem, the naming and contents of the split files have changed. Split files no longer need to have the `.split2` extension and now use the `require` directive rather than the `include` directive. The previous prohibition against using `require_tree .` and `require_self` directives also no longer applies. For more details see the [CHANGELOG.md](CHANGELOG.md) ## Credits & License @@ -91,8 +91,9 @@ This is a joint project by the two German Rails shops [Zweitag](http://zweitag.d 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). -This project rocks and uses MIT-LICENSE. +**Major Contributors** +* @Umofomia -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/zweilove/css_splitter/trend.png)](https://bitdeli.com/free "Bitdeli Badge") +This project rocks and uses MIT-LICENSE. diff --git a/lib/css_splitter/version.rb b/lib/css_splitter/version.rb index da541da..1c14b2c 100644 --- a/lib/css_splitter/version.rb +++ b/lib/css_splitter/version.rb @@ -1,3 +1,3 @@ module CssSplitter - VERSION = "0.2.0" + VERSION = "0.4.0" end From b637a42437e4f8aecfbc71e5f1526f59c9b87c95 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Tue, 6 May 2014 10:20:11 +0200 Subject: [PATCH 18/70] links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 38f02d3..8d855ff 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ If you have more questions about how it works, look at the code or contact us. #### Differences from previous versions -Note that if you used versions below `0.4.0` of this gem, the naming and contents of the split files have changed. Split files no longer need to have the `.split2` extension and now use the `require` directive rather than the `include` directive. The previous prohibition against using `require_tree .` and `require_self` directives also no longer applies. For more details see the [CHANGELOG.md](CHANGELOG.md) +Note that if you used versions below `0.4.0` of this gem, the naming and contents of the split files have changed. Split files no longer need to have the `.split2` extension and now use the `require` directive rather than the `include` directive. The previous prohibition against using `require_tree .` and `require_self` directives also no longer applies. For more details see the [CHANGELOG.md](CHANGELOG.md#040) ## Credits & License @@ -93,7 +93,7 @@ The original code was written by [Christian Peters](mailto:christian.peters@zwei **Major Contributors** -* @Umofomia +* [@Umofomia](@Umofomia) This project rocks and uses MIT-LICENSE. From 102d8a3acee68fa44b952a98bcb1f626cb205875 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Tue, 6 May 2014 10:22:59 +0200 Subject: [PATCH 19/70] formatting --- CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4f3764..a551b57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,11 @@ * **Breaking changes!** * The `CssSplitter::SprocketsEngine` is now registered as a bundle_processor to avoid issues with sprockets directives #29 -** `.split2` extension is no longer necessary/supported, now we rely on `_splitN` at the end of the filename -** Now you need to use the `require` rather than the `include` directive in the split stylesheet -** Prohibition against using `require_tree .` and `require_self` directives no longer applies -** Better tests -** Thanks a lot to @Umofomia + * `.split2` extension is no longer necessary/supported, now we rely on `_splitN` at the end of the filename + * Now you need to use the `require` rather than the `include` directive in the split stylesheet + * Prohibition against using `require_tree .` and `require_self` directives no longer applies + * Better tests + * Thanks a lot to [@Umofomia](https://github.com/Umofomia) # 0.2.0 @@ -31,4 +31,4 @@ # 0.0.1 -Initial commit \ No newline at end of file +Initial commit From c097b3b15326c0a0c38601db148cd3c435e39d3c Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Tue, 6 May 2014 10:23:25 +0200 Subject: [PATCH 20/70] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d855ff..a847dfe 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ The original code was written by [Christian Peters](mailto:christian.peters@zwei **Major Contributors** -* [@Umofomia](@Umofomia) +* [@Umofomia](https://github.com/Umofomia) This project rocks and uses MIT-LICENSE. From 62039bcb8b1eac963df02f058f7e7ca987358408 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Tue, 6 May 2014 19:29:54 +0200 Subject: [PATCH 21/70] only load engine integration if Rails is actually defined --- lib/css_splitter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/css_splitter.rb b/lib/css_splitter.rb index 7a19c44..a5b2457 100644 --- a/lib/css_splitter.rb +++ b/lib/css_splitter.rb @@ -1,4 +1,4 @@ -require "css_splitter/engine" +require "css_splitter/engine" if defined?(Rails) require "css_splitter/sprockets_engine" require "css_splitter/splitter" From 99d5af9736da7c4463dc1dc2fe71df24a8c34db6 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Tue, 6 May 2014 20:13:09 +0200 Subject: [PATCH 22/70] loosen dependency on rails. #31 --- CHANGELOG.md | 1 + Gemfile | 1 + css_splitter.gemspec | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a551b57..e81b980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Prohibition against using `require_tree .` and `require_self` directives no longer applies * Better tests * Thanks a lot to [@Umofomia](https://github.com/Umofomia) +* loosen dependency on `rails` (depend on `sprockets` instead), to make gem compatible to other frameworks like `middleman` # 0.2.0 diff --git a/Gemfile b/Gemfile index 4042fd6..6052be3 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ gemspec group :development do gem "pry-debugger" end + gem "sass-rails" gem "jquery-rails" gem "uglifier" diff --git a/css_splitter.gemspec b/css_splitter.gemspec index b6b6a6e..4a19196 100644 --- a/css_splitter.gemspec +++ b/css_splitter.gemspec @@ -17,5 +17,7 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"] s.test_files = Dir["test/**/*"] - s.add_dependency "rails", ">= 3.1" + s.add_dependency "sprockets", ">= 2.0.0" + + s.add_development_dependency "rails", ">= 3.1" end From 354d60de57b91242d8cfc1d950ec3b1e9b156094 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Tue, 6 May 2014 20:33:53 +0200 Subject: [PATCH 23/70] add rails to Gemfile so that it will be installed on Travis CI --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 6052be3..37f9103 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ group :development do gem "pry-debugger" end +gem "rails" gem "sass-rails" gem "jquery-rails" gem "uglifier" From 979cb22cc8d79a1d061c6cbce6862efdd0bc60e2 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Tue, 13 May 2014 20:40:50 +0200 Subject: [PATCH 24/70] run travis on ruby 2.x as well --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 33fb9e8..f21f396 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: ruby bundler_args: --without development rvm: - - "1.9.3" \ No newline at end of file + - "1.9.3" + - "2.1.1" \ No newline at end of file From 735f50703220e37f9b334f3d86d2bfd4608fde18 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Thu, 15 May 2014 08:52:53 -0700 Subject: [PATCH 25/70] Fix anchors in media query regex Fixes #34 --- lib/css_splitter/splitter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/css_splitter/splitter.rb b/lib/css_splitter/splitter.rb index eda1d4c..fdb0f7c 100644 --- a/lib/css_splitter/splitter.rb +++ b/lib/css_splitter/splitter.rb @@ -39,7 +39,7 @@ def self.extract_part(rules, part = 1, max_selectors = MAX_SELECTORS_DEFAULT) rule_selectors_count = count_selectors_of_rule rule selectors_count += rule_selectors_count - if rule =~ /^\s*}$/ + if rule =~ /\A\s*}\z$/ current_media = nil # skip the line if the close bracket is the first rule for the new file next if first_hit From af2ba579f4c5f69ab4742dbe9f4fc21e73fa340e Mon Sep 17 00:00:00 2001 From: Bartek Kruszczynski Date: Sun, 12 Oct 2014 22:39:41 +0200 Subject: [PATCH 26/70] Modify to install correct debugger for development. --- Gemfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 37f9103..a6b7a19 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,8 @@ source "http://rubygems.org" gemspec group :development do - gem "pry-debugger" + gem "pry-debugger", platforms: :ruby_19 + gem 'pry-byebug', platforms: [:ruby_20, :ruby_21] end gem "rails" From 6a7546b2e4ec1b275545fed55aea03576a726f74 Mon Sep 17 00:00:00 2001 From: Bartek Kruszczynski Date: Mon, 13 Oct 2014 10:30:42 +0200 Subject: [PATCH 27/70] Remove debugger completely --- Gemfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index a6b7a19..8a91985 100644 --- a/Gemfile +++ b/Gemfile @@ -6,8 +6,7 @@ source "http://rubygems.org" gemspec group :development do - gem "pry-debugger", platforms: :ruby_19 - gem 'pry-byebug', platforms: [:ruby_20, :ruby_21] + gem 'pry-byebug' end gem "rails" From ca0e18e6774b3d1b87353fcdd429f1b5332a6b9c Mon Sep 17 00:00:00 2001 From: Larry Botha Date: Thu, 23 Oct 2014 01:12:17 +0200 Subject: [PATCH 28/70] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index a847dfe..f1ac2c4 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,16 @@ If you have more questions about how it works, look at the code or contact us. Note that if you used versions below `0.4.0` of this gem, the naming and contents of the split files have changed. Split files no longer need to have the `.split2` extension and now use the `require` directive rather than the `include` directive. The previous prohibition against using `require_tree .` and `require_self` directives also no longer applies. For more details see the [CHANGELOG.md](CHANGELOG.md#040) +#### Empty *_split2.css file + +In development the `?body=1` parameter tells Sprockets to retrieve the non-precompiled version of the file for debugging. If your `*_split2.css` file is empty, open the file in a new tab, and remove the `?body=1` parameter. If your generated CSS is showing, you can temporarily disable debugging (and thus serve the compiled versions) for your split file: + +``` +<%= split_stylesheet_link_tag "application", debug: false %> +``` + +Note that it's probably a good idea not to set `debug: false` on your assets indefinitely. Discussion at [issue #37](https://github.com/zweilove/css_splitter/issues/37). + ## 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". From e39735a369bf6b67a3901281e47a020d6c1ec20e Mon Sep 17 00:00:00 2001 From: Bartek Kruszczynski Date: Mon, 24 Nov 2014 00:56:24 +0100 Subject: [PATCH 29/70] Add default debug: false for development. Triigger travis build. --- app/helpers/css_splitter/application_helper.rb | 8 ++++++-- test/dummy/app/views/layouts/application.html.erb | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/helpers/css_splitter/application_helper.rb b/app/helpers/css_splitter/application_helper.rb index af5061d..ecfd2ef 100644 --- a/app/helpers/css_splitter/application_helper.rb +++ b/app/helpers/css_splitter/application_helper.rb @@ -6,7 +6,11 @@ def split_stylesheet_link_tag(*sources) sources.map do |source| split_sources = (2..split_count).map { |index| "#{source}_split#{index}" } - split_sources << options + split_options = options.dup + if Rails.env == 'development' && !split_options.key?(:debug) + split_options[:debug] = false + end + split_sources << split_options [ stylesheet_link_tag(source, options), @@ -17,4 +21,4 @@ def split_stylesheet_link_tag(*sources) end.flatten.join("\n").html_safe end end -end \ No newline at end of file +end diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/dummy/app/views/layouts/application.html.erb index 9fa37cd..f9e8544 100644 --- a/test/dummy/app/views/layouts/application.html.erb +++ b/test/dummy/app/views/layouts/application.html.erb @@ -5,7 +5,7 @@ <%= stylesheet_link_tag "application", :media => "all" %> - <%= split_stylesheet_link_tag "too_big_stylesheet", :media => "all" %> + <%= split_stylesheet_link_tag "too_big_stylesheet", :media => "all", :debug => true %> <%= csrf_meta_tags %> From 7f2bd956590f6434835d2cc993a6480905cb11d6 Mon Sep 17 00:00:00 2001 From: Bartek Kruszczynski Date: Thu, 27 Nov 2014 00:21:40 +0100 Subject: [PATCH 30/70] Test new conditional debug. --- .../css_splitter/application_helper_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/unit/helpers/css_splitter/application_helper_test.rb b/test/unit/helpers/css_splitter/application_helper_test.rb index e42a401..421980a 100644 --- a/test/unit/helpers/css_splitter/application_helper_test.rb +++ b/test/unit/helpers/css_splitter/application_helper_test.rb @@ -18,5 +18,24 @@ class ApplicationHelperTest < ActionView::TestCase assert_equal "\n", output end + test "should default to false on splits" do + Rails.env = 'development' + output = split_stylesheet_link_tag("too_big_stylesheet") + Rails.env = 'test' + assert_equal "\n", output + end + + test "should respect the debug=true option" do + Rails.env = 'development' + output = split_stylesheet_link_tag("too_big_stylesheet", debug: true) + Rails.env = 'test' + assert_equal "\n", output + end + test "should respect the debug=false option" do + Rails.env = 'development' + output = split_stylesheet_link_tag("too_big_stylesheet", debug: false) + Rails.env = 'test' + assert_equal "\n", output + end end end From e12a836a574d45e9aa8f1447a57d320b767150cc Mon Sep 17 00:00:00 2001 From: Bartek Kruszczynski Date: Thu, 27 Nov 2014 00:27:26 +0100 Subject: [PATCH 31/70] Change README and CHANGELOG to reflect changes. --- CHANGELOG.md | 4 ++++ README.md | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e81b980..97ad6ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.4.1 + +* [Improvement] All `*_splitN.css` files default to `debug: false` in development to prevent empty file bug. + # 0.4.0 * **Breaking changes!** diff --git a/README.md b/README.md index f1ac2c4..fef27db 100644 --- a/README.md +++ b/README.md @@ -87,14 +87,12 @@ Note that if you used versions below `0.4.0` of this gem, the naming and content #### Empty *_split2.css file -In development the `?body=1` parameter tells Sprockets to retrieve the non-precompiled version of the file for debugging. If your `*_split2.css` file is empty, open the file in a new tab, and remove the `?body=1` parameter. If your generated CSS is showing, you can temporarily disable debugging (and thus serve the compiled versions) for your split file: +Since 0.4.1 in development split stylesheets have `debug: false` option by default. This prevents the empty `*_split2.css` file issue. You can always explicitly go one way or the other setting `debug` option directly in the `split_stylesheet_link_tag` like this: ``` <%= split_stylesheet_link_tag "application", debug: false %> ``` -Note that it's probably a good idea not to set `debug: false` on your assets indefinitely. Discussion at [issue #37](https://github.com/zweilove/css_splitter/issues/37). - ## 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". From 0d4651eb530e8559d4097c142110e96e7b45ebf8 Mon Sep 17 00:00:00 2001 From: Bartek Kruszczynski Date: Thu, 27 Nov 2014 10:46:50 +0100 Subject: [PATCH 32/70] Group tests for better readability. --- .../css_splitter/application_helper_test.rb | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/test/unit/helpers/css_splitter/application_helper_test.rb b/test/unit/helpers/css_splitter/application_helper_test.rb index 421980a..2d2a75c 100644 --- a/test/unit/helpers/css_splitter/application_helper_test.rb +++ b/test/unit/helpers/css_splitter/application_helper_test.rb @@ -18,24 +18,28 @@ class ApplicationHelperTest < ActionView::TestCase assert_equal "\n", output end - test "should default to false on splits" do - Rails.env = 'development' - output = split_stylesheet_link_tag("too_big_stylesheet") - Rails.env = 'test' - assert_equal "\n", output - end + class RailsEnvDefault < ActionView::TestCase + setup do + Rails.env = 'development' + end - test "should respect the debug=true option" do - Rails.env = 'development' - output = split_stylesheet_link_tag("too_big_stylesheet", debug: true) - Rails.env = 'test' - assert_equal "\n", output - end - test "should respect the debug=false option" do - Rails.env = 'development' - output = split_stylesheet_link_tag("too_big_stylesheet", debug: false) - Rails.env = 'test' - assert_equal "\n", output + teardown do + Rails.env = 'test' + end + + test "should default to false on splits" do + output = split_stylesheet_link_tag("too_big_stylesheet") + assert_equal "\n", output + end + + test "should respect the debug=true option" do + output = split_stylesheet_link_tag("too_big_stylesheet", debug: true) + assert_equal "\n", output + end + test "should respect the debug=false option" do + output = split_stylesheet_link_tag("too_big_stylesheet", debug: false) + assert_equal "\n", output + end end end end From bdc6008766b8e3250a568aa4e6ab7bff23511900 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Thu, 5 Mar 2015 19:02:36 +0100 Subject: [PATCH 33/70] bump version --- lib/css_splitter/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/css_splitter/version.rb b/lib/css_splitter/version.rb index 1c14b2c..18e0de4 100644 --- a/lib/css_splitter/version.rb +++ b/lib/css_splitter/version.rb @@ -1,3 +1,3 @@ module CssSplitter - VERSION = "0.4.0" + VERSION = "0.4.1" end From 8f142c27f8573c2d657eb1ce4ff2bc410baef6df Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Thu, 5 Mar 2015 19:04:06 +0100 Subject: [PATCH 34/70] update contributors --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fef27db..0a86631 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ The original code was written by [Christian Peters](mailto:christian.peters@zwei **Major Contributors** * [@Umofomia](https://github.com/Umofomia) +* [@kruszczynski](https://github.com/kruszczynski) This project rocks and uses MIT-LICENSE. From 30a23e3ac5ab530f78d3d57113e269ff539f857b Mon Sep 17 00:00:00 2001 From: Bartek Kruszczynski Date: Sun, 12 Apr 2015 17:03:22 +0200 Subject: [PATCH 35/70] Fix ApplicationHelper test to play well with rails 4.2 --- .../helpers/css_splitter/application_helper_test.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unit/helpers/css_splitter/application_helper_test.rb b/test/unit/helpers/css_splitter/application_helper_test.rb index 2d2a75c..4dc8d39 100644 --- a/test/unit/helpers/css_splitter/application_helper_test.rb +++ b/test/unit/helpers/css_splitter/application_helper_test.rb @@ -5,17 +5,17 @@ class ApplicationHelperTest < ActionView::TestCase test "should work w/out options" do output = split_stylesheet_link_tag("too_big_stylesheet") - assert_equal "\n", output + assert_equal "\n", output end test "should work with options and multiple stylesheets" do output = split_stylesheet_link_tag("too_big_stylesheet", "foo", media: "print") - assert_equal "\n\n\n", output + assert_equal "\n\n\n", output end test "should work with split_count option" do output = split_stylesheet_link_tag("too_big_stylesheet", split_count: 3) - assert_equal "\n", output + assert_equal "\n", output end class RailsEnvDefault < ActionView::TestCase @@ -29,16 +29,16 @@ class RailsEnvDefault < ActionView::TestCase test "should default to false on splits" do output = split_stylesheet_link_tag("too_big_stylesheet") - assert_equal "\n", output + assert_equal "\n", output end test "should respect the debug=true option" do output = split_stylesheet_link_tag("too_big_stylesheet", debug: true) - assert_equal "\n", output + assert_equal "\n", output end test "should respect the debug=false option" do output = split_stylesheet_link_tag("too_big_stylesheet", debug: false) - assert_equal "\n", output + assert_equal "\n", output end end end From 166ac592b0728647d8d2a262f22ccbb579396718 Mon Sep 17 00:00:00 2001 From: Steven van der Vegt Date: Fri, 28 Aug 2015 20:57:36 +0200 Subject: [PATCH 36/70] Add failing test for css with keyframes --- test/unit/keyframes.css | 16 ++++++++++++++++ test/unit/splitter_test.rb | 4 ++++ 2 files changed, 20 insertions(+) create mode 100644 test/unit/keyframes.css diff --git a/test/unit/keyframes.css b/test/unit/keyframes.css new file mode 100644 index 0000000..deeb3e3 --- /dev/null +++ b/test/unit/keyframes.css @@ -0,0 +1,16 @@ +.red { + color: red; +} + +@keyframes my-animation { + 0% { top: 0px; } + 20% { top: 20px; } + 40% { top: 40px; } + 60% { top: 60px; } + 80% { top: 80px; } + 100% { top: 100px; } +} + +.blue { + background-color: blue; +} diff --git a/test/unit/splitter_test.rb b/test/unit/splitter_test.rb index b5c4b59..26b1abb 100644 --- a/test/unit/splitter_test.rb +++ b/test/unit/splitter_test.rb @@ -40,6 +40,10 @@ class CssSplitterTest < ActiveSupport::TestCase assert_equal ["a{foo:bar;}", "@media print{b{baz:qux;}", "c{quux:corge;}", "}", "d{grault:garply;}"], CssSplitter::Splitter.split_string_into_rules(has_media) end + test "#split_string_into_rules containing @keyframes" do + assert_equal 3, CssSplitter::Splitter.count_selectors('test/unit/keyframes.css') + end + # --- extract_charset --- test '#extract_charset with no charset' do From c2ea8f3e84cca52215e3e686095b0505cd414ae8 Mon Sep 17 00:00:00 2001 From: Ruben Swieringa Date: Fri, 28 Aug 2015 22:05:03 +0200 Subject: [PATCH 37/70] Prevent CssSplitter::Splitter.split_string_into_rules from breaking up @keyframes & @media blocks --- lib/css_splitter/splitter.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/css_splitter/splitter.rb b/lib/css_splitter/splitter.rb index fdb0f7c..dcf73ef 100644 --- a/lib/css_splitter/splitter.rb +++ b/lib/css_splitter/splitter.rb @@ -12,7 +12,21 @@ def self.split_string(css_string, split = 1, max_selectors = MAX_SELECTORS_DEFAU # splits string into array of rules (also strips comments) def self.split_string_into_rules(css_string) - strip_comments(css_string).chomp.scan /[^}]*}/ + partial_rules = strip_comments(css_string).chomp.scan /[^}]*}/ + whole_rules = [] + bracket_balance = 0 + + partial_rules.each do |rule| + if bracket_balance == 0 + whole_rules << rule + else + whole_rules.last << rule + end + + bracket_balance += get_rule_bracket_balance rule + end + + whole_rules end # extracts the specified part of an overlong CSS string @@ -107,6 +121,10 @@ def self.strip_comments(s) s.gsub(/\/\*.*?\*\//m, "") end + def self.get_rule_bracket_balance ( rule ) + rule.scan( /}/ ).size - rule.scan( /{/ ).size + end + end end From 8418978262bd803788966b0df67730de9029303e Mon Sep 17 00:00:00 2001 From: Ruben Swieringa Date: Sat, 29 Aug 2015 12:20:35 +0200 Subject: [PATCH 38/70] Allow for @media blocks to be split up Conform to tests. --- lib/css_splitter/splitter.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/css_splitter/splitter.rb b/lib/css_splitter/splitter.rb index dcf73ef..1cf7a10 100644 --- a/lib/css_splitter/splitter.rb +++ b/lib/css_splitter/splitter.rb @@ -15,9 +15,16 @@ def self.split_string_into_rules(css_string) partial_rules = strip_comments(css_string).chomp.scan /[^}]*}/ whole_rules = [] bracket_balance = 0 + in_media_query = false partial_rules.each do |rule| - if bracket_balance == 0 + if rule =~ /^@media/ + in_media_query = true + elsif bracket_balance == 0 + in_media_query = false + end + + if bracket_balance == 0 || in_media_query whole_rules << rule else whole_rules.last << rule From 0b319d09bea60346085980a97550ddd3c58d9af0 Mon Sep 17 00:00:00 2001 From: Ruben Swieringa Date: Sat, 29 Aug 2015 12:44:09 +0200 Subject: [PATCH 39/70] Set config.active_support.test_order to get rid of deprecation warning for Rails 5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “DEPRECATION WARNING: You did not specify a value for the configuration option ‘active_support.test_order’. In Rails 5, the default value of this option will change from ‘:sorted’ to ‘:random’. To disable this warning and keep the current behavior, you can add the following line to your ‘config/environments/test.rb’:” --- test/dummy/config/environments/test.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 284daa5..7d5d219 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -29,6 +29,9 @@ # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # run tests in a random order + config.active_support.test_order = :random + # Raise exception on mass assignment protection for Active Record models # config.active_record.mass_assignment_sanitizer = :strict From 8ea6dcc8e7eb4e7453ce1555d3b2e06b59656308 Mon Sep 17 00:00:00 2001 From: Ruben Swieringa Date: Mon, 31 Aug 2015 19:45:09 +0200 Subject: [PATCH 40/70] Rename deprecated config.serve_static_assets to config.serve_static_files --- test/dummy/config/environments/test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 7d5d219..3171e7c 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -8,7 +8,7 @@ config.cache_classes = true # Configure static asset server for tests with Cache-Control for performance - config.serve_static_assets = true + config.serve_static_files = true config.static_cache_control = "public, max-age=3600" # Log error messages when you accidentally call methods on nil From 3911379daa1058f0c9a5bebbd3d49643a023a9ae Mon Sep 17 00:00:00 2001 From: Ruben Swieringa Date: Mon, 31 Aug 2015 19:48:45 +0200 Subject: [PATCH 41/70] Rewrite split_string_into_rules() test to compare actual array-contents returned from @keyframes stylesheet ...rather than just the array length --- test/unit/keyframes.css | 16 ---------------- test/unit/splitter_test.rb | 5 +++-- 2 files changed, 3 insertions(+), 18 deletions(-) delete mode 100644 test/unit/keyframes.css diff --git a/test/unit/keyframes.css b/test/unit/keyframes.css deleted file mode 100644 index deeb3e3..0000000 --- a/test/unit/keyframes.css +++ /dev/null @@ -1,16 +0,0 @@ -.red { - color: red; -} - -@keyframes my-animation { - 0% { top: 0px; } - 20% { top: 20px; } - 40% { top: 40px; } - 60% { top: 60px; } - 80% { top: 80px; } - 100% { top: 100px; } -} - -.blue { - background-color: blue; -} diff --git a/test/unit/splitter_test.rb b/test/unit/splitter_test.rb index 26b1abb..bcbb8e7 100644 --- a/test/unit/splitter_test.rb +++ b/test/unit/splitter_test.rb @@ -40,8 +40,9 @@ class CssSplitterTest < ActiveSupport::TestCase assert_equal ["a{foo:bar;}", "@media print{b{baz:qux;}", "c{quux:corge;}", "}", "d{grault:garply;}"], CssSplitter::Splitter.split_string_into_rules(has_media) end - test "#split_string_into_rules containing @keyframes" do - assert_equal 3, CssSplitter::Splitter.count_selectors('test/unit/keyframes.css') + test "#split_string_into_rules containing keyframes" do + has_keyframes = "a{foo:bar;}@keyframes rubes{from{baz:qux;}50%{quux:corge;}}d{grault:garply;}" + assert_equal ["a{foo:bar;}", "@keyframes rubes{from{baz:qux;}50%{quux:corge;}}", "d{grault:garply;}"], CssSplitter::Splitter.split_string_into_rules(has_keyframes) end # --- extract_charset --- From 5f9cfbd085703d745d9c0f126a9f6f72cc5afe58 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Tue, 1 Sep 2015 18:57:35 +0200 Subject: [PATCH 42/70] prevent deprecation warnings inside dummy app --- test/dummy/config/environments/production.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb index 5f2d7d7..7ad11fe 100644 --- a/test/dummy/config/environments/production.rb +++ b/test/dummy/config/environments/production.rb @@ -9,7 +9,7 @@ config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_assets = false + config.serve_static_files = false # Compress JavaScripts and CSS config.assets.compress = true @@ -31,7 +31,7 @@ # config.force_ssl = true # See everything in the log (default is :info) - # config.log_level = :debug + config.log_level = :debug # Prepend all log lines with the following tags # config.log_tags = [ :subdomain, :uuid ] From f7459364677353e48cbed39898df567bd4eeeba5 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Thu, 3 Sep 2015 19:52:58 +0200 Subject: [PATCH 43/70] version 0.4.2 --- CHANGELOG.md | 4 ++++ lib/css_splitter/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97ad6ee..9aff500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.4.2 + +* [bugfix] correctly split stylesheets even if @keyframes are directly on the rule limit #55 by [@rubenswieringa](https://github.com/rubenswieringa) + # 0.4.1 * [Improvement] All `*_splitN.css` files default to `debug: false` in development to prevent empty file bug. diff --git a/lib/css_splitter/version.rb b/lib/css_splitter/version.rb index 18e0de4..22c192c 100644 --- a/lib/css_splitter/version.rb +++ b/lib/css_splitter/version.rb @@ -1,3 +1,3 @@ module CssSplitter - VERSION = "0.4.1" + VERSION = "0.4.2" end From 87ab0fbb8ae48e79778272d3d861c70b39fd3bf4 Mon Sep 17 00:00:00 2001 From: Ernesto Acevedo Date: Thu, 8 Oct 2015 12:36:59 -0300 Subject: [PATCH 44/70] Fix regex comparison for media queries --- lib/css_splitter/splitter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/css_splitter/splitter.rb b/lib/css_splitter/splitter.rb index 1cf7a10..f5f6a25 100644 --- a/lib/css_splitter/splitter.rb +++ b/lib/css_splitter/splitter.rb @@ -18,7 +18,7 @@ def self.split_string_into_rules(css_string) in_media_query = false partial_rules.each do |rule| - if rule =~ /^@media/ + if rule =~ /^\s*@media/ in_media_query = true elsif bracket_balance == 0 in_media_query = false From bf64b9d6c192c06793864780fd8bc50c52ccbee7 Mon Sep 17 00:00:00 2001 From: Gareth Adams Date: Mon, 7 Dec 2015 22:26:54 +0000 Subject: [PATCH 45/70] Add a secret_key_base to the test app config Avoids a deprecation warning with Rails 4 --- test/dummy/config/secrets.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test/dummy/config/secrets.yml diff --git a/test/dummy/config/secrets.yml b/test/dummy/config/secrets.yml new file mode 100644 index 0000000..7eb2e7e --- /dev/null +++ b/test/dummy/config/secrets.yml @@ -0,0 +1,2 @@ +test: + secret_key_base: c2a98602cc1537b2e38d4f279f20d24db66ff86fe523ab5197529f2ea907b6d70e2dca2fa3da50dcc9cad7bb1b861f0c45b6920fc576cc3e170d8c1ded61887f From 579cdca79370b1602b2e5ea43ef960309fc301b0 Mon Sep 17 00:00:00 2001 From: Gareth Adams Date: Tue, 8 Dec 2015 01:09:42 +0000 Subject: [PATCH 46/70] Allow debugger in test environment too --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 8a91985..866d014 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ source "http://rubygems.org" # development dependencies will be added by default to the :development group. gemspec -group :development do +group :development, :test do gem 'pry-byebug' end From 10ce82e23ccc95838e7d4c6b40df12ccb65f4cdf Mon Sep 17 00:00:00 2001 From: Gareth Adams Date: Tue, 8 Dec 2015 08:39:27 +0000 Subject: [PATCH 47/70] Add a test for media query with leading whitespace --- test/unit/splitter_test.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/unit/splitter_test.rb b/test/unit/splitter_test.rb index bcbb8e7..f9713ea 100644 --- a/test/unit/splitter_test.rb +++ b/test/unit/splitter_test.rb @@ -40,6 +40,11 @@ class CssSplitterTest < ActiveSupport::TestCase assert_equal ["a{foo:bar;}", "@media print{b{baz:qux;}", "c{quux:corge;}", "}", "d{grault:garply;}"], CssSplitter::Splitter.split_string_into_rules(has_media) end + test '#split_string_into_rules containing media queries with leading whitespace' do + has_media = "a{foo:bar;}\n @media print{b{baz:qux;}c{quux:corge;}}d{grault:garply;}" + assert_equal ["a{foo:bar;}", "\n @media print{b{baz:qux;}", "c{quux:corge;}", "}", "d{grault:garply;}"], CssSplitter::Splitter.split_string_into_rules(has_media) + end + test "#split_string_into_rules containing keyframes" do has_keyframes = "a{foo:bar;}@keyframes rubes{from{baz:qux;}50%{quux:corge;}}d{grault:garply;}" assert_equal ["a{foo:bar;}", "@keyframes rubes{from{baz:qux;}50%{quux:corge;}}", "d{grault:garply;}"], CssSplitter::Splitter.split_string_into_rules(has_keyframes) From c2a5b42714ace4d63ecd00fe6ca3742a25102360 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Fri, 11 Dec 2015 09:51:04 +0100 Subject: [PATCH 48/70] version 0.4.3 --- CHANGELOG.md | 4 ++++ lib/css_splitter/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aff500..7c63865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.4.3 + +* [bugfix] for media queries with whitespace in front of them #57 + # 0.4.2 * [bugfix] correctly split stylesheets even if @keyframes are directly on the rule limit #55 by [@rubenswieringa](https://github.com/rubenswieringa) diff --git a/lib/css_splitter/version.rb b/lib/css_splitter/version.rb index 22c192c..ae6eecc 100644 --- a/lib/css_splitter/version.rb +++ b/lib/css_splitter/version.rb @@ -1,3 +1,3 @@ module CssSplitter - VERSION = "0.4.2" + VERSION = "0.4.3" end From 4ffc2d4814c2b87d6641cd6787b0ebf0ccc8321d Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Mon, 21 Dec 2015 10:26:57 +0100 Subject: [PATCH 49/70] limited maintenance mode --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 0a86631..c8348c9 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ Gem for splitting up stylesheets that go beyond the IE limit of 4096 selectors, for Rails 3.1+ apps using the Asset Pipeline. You can read this [blogpost](http://railslove.com/blog/2013/03/08/overcoming-ies-4096-selector-limit-using-the-css-splitter-gem) for an explanation of this gem's background story. +### 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 able to help out maintaining it, it would be greatly appreciated. ## Installation From fb677509c97456bb5f7b4a2ce2f02b000faa490b Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Mon, 21 Dec 2015 10:27:51 +0100 Subject: [PATCH 50/70] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c8348c9..77af792 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Gem for splitting up stylesheets that go beyond the IE limit of 4096 selectors, 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 able to help out maintaining it, it would be greatly appreciated. +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. ## Installation From 8b5e2025045e9a0009e5c1ff961036f0b7116a4d Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Wed, 23 Dec 2015 12:26:33 -0500 Subject: [PATCH 51/70] use recent ruby version --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f21f396..344b67b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ +sudo: false language: ruby bundler_args: --without development rvm: - "1.9.3" - - "2.1.1" \ No newline at end of file + - "2.2" From c5e37a8141c628a9eaddb55bfce5b96cb615f191 Mon Sep 17 00:00:00 2001 From: Stephen Eckenrode Date: Mon, 28 Dec 2015 14:03:45 -0500 Subject: [PATCH 52/70] Gracefully handle when assets are not configured In sprockets-rails v3, app.assets is now only set when assets.compile is set to true. This is currently causing an error when upgrading to Rails 4.2.5. This change will cause CSS Splitter to only be registered when assets themselves are configured. Fixes #60 --- lib/css_splitter/engine.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/css_splitter/engine.rb b/lib/css_splitter/engine.rb index c51574e..335a5b1 100644 --- a/lib/css_splitter/engine.rb +++ b/lib/css_splitter/engine.rb @@ -3,7 +3,9 @@ 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 + app.config.assets.configure do |assets| + assets.register_bundle_processor 'text/css', CssSplitter::SprocketsEngine + end end initializer 'css_splitter.action_controller' do |app| From 632ee76ae907469455780d60d253b5b64f218695 Mon Sep 17 00:00:00 2001 From: Stephen Eckenrode Date: Mon, 28 Dec 2015 14:12:11 -0500 Subject: [PATCH 53/70] Upgrade bundler before running Travis tests --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f21f396..7ae037c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,6 @@ language: ruby bundler_args: --without development rvm: - "1.9.3" - - "2.1.1" \ No newline at end of file + - "2.1.1" +before_install: + - gem update bundler From 9a813e780cfd10034b9ecd00f0f191ac903596e6 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Mon, 4 Jan 2016 15:05:10 +0100 Subject: [PATCH 54/70] installing byebug in test environment will break on travis + ruby 1.9.x --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 866d014..8a91985 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ source "http://rubygems.org" # development dependencies will be added by default to the :development group. gemspec -group :development, :test do +group :development do gem 'pry-byebug' end From e10be4daaefde2bbde12145c93371af74e2e8820 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Mon, 4 Jan 2016 15:09:04 +0100 Subject: [PATCH 55/70] test against multiple rails versions --- .travis.yml | 2 ++ Gemfile | 8 -------- Gemfile.rails3 | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 Gemfile.rails3 diff --git a/.travis.yml b/.travis.yml index 2839d69..2f483a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,5 @@ rvm: - "1.9.3" - "2.1.1" - "2.2" +gemfile: + - "Gemfile.rails3" \ No newline at end of file diff --git a/Gemfile b/Gemfile index 8a91985..74fab5c 100644 --- a/Gemfile +++ b/Gemfile @@ -13,11 +13,3 @@ gem "rails" gem "sass-rails" gem "jquery-rails" gem "uglifier" - -# Declare any dependencies that are still in development here instead of in -# your gemspec. These might include edge Rails or gems from your path or -# Git. Remember to move these dependencies to your gemspec before releasing -# your gem to rubygems.org. - -# To use debugger -# gem 'debugger' diff --git a/Gemfile.rails3 b/Gemfile.rails3 new file mode 100644 index 0000000..f511920 --- /dev/null +++ b/Gemfile.rails3 @@ -0,0 +1,15 @@ +source "http://rubygems.org" + +# Declare your gem's dependencies in css_splitter.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec + +group :development do + gem 'pry-byebug' +end + +gem "rails", '~> 3.1' +gem "sass-rails" +gem "jquery-rails" +gem "uglifier" From 01f3adf265a8de0545817266ffbe06f12fa44d89 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Mon, 4 Jan 2016 15:12:50 +0100 Subject: [PATCH 56/70] test both Gemfiles --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2f483a7..eabf7de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ language: ruby bundler_args: --without development rvm: - "1.9.3" - - "2.1.1" + - "2.1" - "2.2" gemfile: + - "Gemfile" - "Gemfile.rails3" \ No newline at end of file From b8bf7e8d1583591a08cbf115dfd9a58ca4398859 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Mon, 4 Jan 2016 15:21:41 +0100 Subject: [PATCH 57/70] don't install byebug for rails3 because travis is failing --- .gitignore | 1 + Gemfile.rails3 | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index a9ecfb8..8757807 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .bundle/ Gemfile.lock +Gemfile.rails3.lock log/*.log pkg/ test/dummy/db/*.sqlite3 diff --git a/Gemfile.rails3 b/Gemfile.rails3 index f511920..a744df7 100644 --- a/Gemfile.rails3 +++ b/Gemfile.rails3 @@ -5,10 +5,6 @@ source "http://rubygems.org" # development dependencies will be added by default to the :development group. gemspec -group :development do - gem 'pry-byebug' -end - gem "rails", '~> 3.1' gem "sass-rails" gem "jquery-rails" From 5eee3181099ca2cfb824d9fa62cff8245b96ce63 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Mon, 4 Jan 2016 15:29:00 +0100 Subject: [PATCH 58/70] remove 2nd rails 3 gemfile again --- .gitignore | 1 - .travis.yml | 3 +-- Gemfile.rails3 | 11 ----------- 3 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 Gemfile.rails3 diff --git a/.gitignore b/.gitignore index 8757807..a9ecfb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .bundle/ Gemfile.lock -Gemfile.rails3.lock log/*.log pkg/ test/dummy/db/*.sqlite3 diff --git a/.travis.yml b/.travis.yml index eabf7de..f09ded4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,4 @@ rvm: - "2.1" - "2.2" gemfile: - - "Gemfile" - - "Gemfile.rails3" \ No newline at end of file + - "Gemfile" \ No newline at end of file diff --git a/Gemfile.rails3 b/Gemfile.rails3 deleted file mode 100644 index a744df7..0000000 --- a/Gemfile.rails3 +++ /dev/null @@ -1,11 +0,0 @@ -source "http://rubygems.org" - -# Declare your gem's dependencies in css_splitter.gemspec. -# Bundler will treat runtime dependencies like base dependencies, and -# development dependencies will be added by default to the :development group. -gemspec - -gem "rails", '~> 3.1' -gem "sass-rails" -gem "jquery-rails" -gem "uglifier" From 0235df33c75e8154859fa40d4d0c1a816c44f36e Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Mon, 4 Jan 2016 15:42:10 +0100 Subject: [PATCH 59/70] fix up dummy app --- test/dummy/config/initializers/assets.rb | 8 ++++++++ test/dummy/config/secrets.yml | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 test/dummy/config/initializers/assets.rb diff --git a/test/dummy/config/initializers/assets.rb b/test/dummy/config/initializers/assets.rb new file mode 100644 index 0000000..b4de740 --- /dev/null +++ b/test/dummy/config/initializers/assets.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +Rails.application.config.assets.precompile += %w( too_big_stylesheet.css too_big_stylesheet_split2.css ) \ No newline at end of file diff --git a/test/dummy/config/secrets.yml b/test/dummy/config/secrets.yml index 7eb2e7e..5dc368e 100644 --- a/test/dummy/config/secrets.yml +++ b/test/dummy/config/secrets.yml @@ -1,2 +1,4 @@ test: secret_key_base: c2a98602cc1537b2e38d4f279f20d24db66ff86fe523ab5197529f2ea907b6d70e2dca2fa3da50dcc9cad7bb1b861f0c45b6920fc576cc3e170d8c1ded61887f +development: + secret_key_base: c2a98602cc1537b2e38d4f279f20d24db66ff86fe523ab5197529f2ea907b6d70e2dca2fa3da50dcc9cad7bb1b861f0c45b6920fc576cc3e170d8c1ded61887f \ No newline at end of file From 3a953b285a3e03a02061e5072239f1756e4f15c0 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Mon, 4 Jan 2016 15:46:54 +0100 Subject: [PATCH 60/70] move some options in the config file --- test/dummy/config/application.rb | 3 --- test/dummy/config/environments/production.rb | 3 --- test/dummy/config/initializers/assets.rb | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 6a0af91..4e42755 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -55,9 +55,6 @@ class Application < Rails::Application # Enable the asset pipeline config.assets.enabled = true - - # Version of your assets, change this if you want to expire all your assets - config.assets.version = '1.0' end end diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb index 7ad11fe..d92c150 100644 --- a/test/dummy/config/environments/production.rb +++ b/test/dummy/config/environments/production.rb @@ -45,9 +45,6 @@ # Enable serving of images, stylesheets, and JavaScripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" - # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) - config.assets.precompile += %w( too_big_stylesheet.css too_big_stylesheet_split2.css test_stylesheet_with_media_queries.css test_stylesheet_with_media_queries_split2.css ) - # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false diff --git a/test/dummy/config/initializers/assets.rb b/test/dummy/config/initializers/assets.rb index b4de740..91073da 100644 --- a/test/dummy/config/initializers/assets.rb +++ b/test/dummy/config/initializers/assets.rb @@ -5,4 +5,4 @@ # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -Rails.application.config.assets.precompile += %w( too_big_stylesheet.css too_big_stylesheet_split2.css ) \ No newline at end of file +Rails.application.config.assets.precompile += %w( too_big_stylesheet.css too_big_stylesheet_split2.css test_stylesheet_with_media_queries.css test_stylesheet_with_media_queries_split2.css ) \ No newline at end of file From c4b6e78e406a4c3145ac9265298c631471f3a4ff Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Mon, 4 Jan 2016 15:50:00 +0100 Subject: [PATCH 61/70] bump version to 0.4.4 --- CHANGELOG.md | 4 ++++ lib/css_splitter/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c63865..bf1f58c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.4.4 + +* [bugfix] fix compatibility with with sprockts-rails version 3.x, see #62 + # 0.4.3 * [bugfix] for media queries with whitespace in front of them #57 diff --git a/lib/css_splitter/version.rb b/lib/css_splitter/version.rb index ae6eecc..06e4f4e 100644 --- a/lib/css_splitter/version.rb +++ b/lib/css_splitter/version.rb @@ -1,3 +1,3 @@ module CssSplitter - VERSION = "0.4.3" + VERSION = "0.4.4" end From 5e805e110b84e1b44a01e86832c44ac5b5ae1890 Mon Sep 17 00:00:00 2001 From: Scott Ringwelski Date: Thu, 21 Jan 2016 21:41:24 -0800 Subject: [PATCH 62/70] Fix issue with ActionController::API:Class Fix an issue where helper is not a defined method --- lib/css_splitter/engine.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/css_splitter/engine.rb b/lib/css_splitter/engine.rb index 335a5b1..4cdaba0 100644 --- a/lib/css_splitter/engine.rb +++ b/lib/css_splitter/engine.rb @@ -10,7 +10,8 @@ class Engine < ::Rails::Engine 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 From 8ba82ab7918ee06a8f1e0ce4af406fd371831dce Mon Sep 17 00:00:00 2001 From: Brad Pardee Date: Mon, 4 Apr 2016 11:34:03 -0400 Subject: [PATCH 63/70] Remove isolate_namespace to fix unresolved split_stylesheet_link_tag --- lib/css_splitter/engine.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/css_splitter/engine.rb b/lib/css_splitter/engine.rb index 335a5b1..2f50392 100644 --- a/lib/css_splitter/engine.rb +++ b/lib/css_splitter/engine.rb @@ -1,7 +1,5 @@ module CssSplitter class Engine < ::Rails::Engine - isolate_namespace CssSplitter - 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 From 45cb5bcf460afd0ed4ded6570e1b6d2a470312a1 Mon Sep 17 00:00:00 2001 From: achernyshev Date: Thu, 14 Apr 2016 17:58:16 +0300 Subject: [PATCH 64/70] fix sprockets engine registering for older sprocket-rails versions --- lib/css_splitter/engine.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/css_splitter/engine.rb b/lib/css_splitter/engine.rb index 2f50392..17122f3 100644 --- a/lib/css_splitter/engine.rb +++ b/lib/css_splitter/engine.rb @@ -1,8 +1,12 @@ 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 From 2a240553362fafa799f96b6bf6a5f343104df0df Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Wed, 25 May 2016 11:19:33 +0200 Subject: [PATCH 65/70] version 0.4.5 --- CHANGELOG.md | 4 ++++ lib/css_splitter/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf1f58c..44ba31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 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/lib/css_splitter/version.rb b/lib/css_splitter/version.rb index 06e4f4e..c6d5586 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.5" end From db0fe7575012e9650c271259e75eb299976ae9f1 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Wed, 1 Jun 2016 15:08:33 +0200 Subject: [PATCH 66/70] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44ba31a..fc25e31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.4.6 (unreleased) + +* [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 From 24017c19c60739d2d1038e985687117839054150 Mon Sep 17 00:00:00 2001 From: Nick Donald Date: Mon, 22 Aug 2016 06:13:32 -0400 Subject: [PATCH 67/70] Follow sproket engine interface guidelines (#70) * Follow sproket engine interface guidelines * Clarify syntax, add comments --- lib/css_splitter/sprockets_engine.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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+)$/ From 5010809517f4ed4fc2379af1c2b2573b5ae8a3f2 Mon Sep 17 00:00:00 2001 From: Jakob Hilden Date: Sat, 27 Aug 2016 16:31:53 +0200 Subject: [PATCH 68/70] bump version to 0.4.6 --- CHANGELOG.md | 3 ++- lib/css_splitter/version.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc25e31..cd411e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -# 0.4.6 (unreleased) +# 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 diff --git a/lib/css_splitter/version.rb b/lib/css_splitter/version.rb index c6d5586..57859d1 100644 --- a/lib/css_splitter/version.rb +++ b/lib/css_splitter/version.rb @@ -1,3 +1,3 @@ module CssSplitter - VERSION = "0.4.5" + VERSION = "0.4.6" end From 749e5410ea67a585b65d75aefbd8c5a0bf1467fd Mon Sep 17 00:00:00 2001 From: khiav reoy Date: Sat, 22 Oct 2016 17:43:12 +0800 Subject: [PATCH 69/70] fix test in different gem version --- test/css_splitter_test.rb | 11 +++++------ test/dummy/config/application.rb | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) 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 From 6cc4244fdbe6599548bef790dc80c008dca1647e Mon Sep 17 00:00:00 2001 From: Christian Peters Date: Wed, 22 Feb 2023 13:36:45 +0100 Subject: [PATCH 70/70] Clarify that this gem is dead --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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.