smurf 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ gem "rails", "3.0.3"
4
+
5
+ group :test do
6
+ gem "riot", "0.12.0"
7
+ end
8
+
data/README.markdown CHANGED
@@ -12,7 +12,7 @@ Some cool things about Smurf, which also allude to the reasons I wrote it:
12
12
  * Other than installing it, you don't need to do anything
13
13
  * It just gets out of your way
14
14
 
15
- Smurf will work with any version of Rails `2.x`; including Rails `2.3.4` and `2.1.2`.
15
+ Smurf will work with most versions of Rails `2.3.x` and above; including Rails `3.0.0`.
16
16
 
17
17
  ### JSmin
18
18
 
@@ -29,30 +29,23 @@ The following are the rules I applied, gathered from various perusals around the
29
29
  5. Remove comments between `/* ... */` - this could be a problem (esp. for CSS hacks)
30
30
  6. Remove spaces around `;`, `:`, and `,` characters
31
31
  7. Ensure whitespace between closing brackets and periods
32
+ 8. Preserves [conditional comments](http://msdn.microsoft.com/en-us/library/121hztk3(VS.94).aspx) in IE (ex: /*@cc_on document.write("this will only write in IE") @*/)
32
33
 
33
34
  ## Installation
34
35
 
35
- I like gems. So, I suggest you install Smurf as gem. It's pretty simple, assuming you have added Gem Cutter to your list of gem sources. If you have not, do this:
36
+ You install Smurf as a gem:
36
37
 
37
- sudo gem sources -a http://gemcutter.org
38
+ sudo gem install smurf
38
39
 
39
- Then, install Smurf as a gem:
40
+ Because this latest version is intended to work with Rails 3 and above, you'll need to update your Gemfile ad add:
40
41
 
41
- sudo gem install smurf
42
+ gem 'smurf'
42
43
 
43
44
  Then, wherever you define `javascript_include_tag` or `stylesheet_link_tag`, make sure to add the standard `:cache => true` or `:cache => 'some_bundle'` options.
44
45
 
45
46
  Also make sure to at least have this setting in your production.rb:
46
47
 
47
- config.action_controller.perform_caching = true
48
-
49
- #### As a plugin
50
-
51
- If you really feel like it, go ahead and install Smurf as a plugin. This should do it:
52
-
53
- ./script/plugin install git://github.com/thumblemonks/smurf.git
54
-
55
- Then do the other stuff for setting up Smurf in your Rails environment.
48
+ config.perform_caching = true
56
49
 
57
50
  ### Small suggestion
58
51
 
@@ -64,18 +57,16 @@ Then do the other stuff for setting up Smurf in your Rails environment.
64
57
 
65
58
  ## Testing
66
59
 
67
- If you want to test Smurf and you don't want to test with the latest version of Rails, then do something like the following (using 2.3.4 as an example):
68
-
69
- rake RAILS_GEM_VERSION=2.3.4
60
+ Simple:
70
61
 
71
- This is the mechanism I used for testing that Smurf works for all versions:
62
+ rake
72
63
 
73
- rake && rake RAILS_GEM_VERSION=2.2.2 && rake RAILS_GEM_VERSION=2.1.2
64
+ If you want to play around with different versions, you'll need to update the Gemfile version of rails. While Smurf itself should work as is with Rails 3 and Rails 2.3.x, the test setup is different enough between 3 and 2.3.x that I can't make guarantees. If you need a previous version, look for the appropriate tag in the source code.
74
65
 
75
66
  ## Meta
76
67
 
77
68
  Author: Justin Knowlden <gus@thumblemonks.com>
78
69
 
79
- Contributions from: Lance Ivy, Scott White, Daniel Schierbeck
70
+ Contributions from: Lance Ivy, Scott White, Daniel Schierbeck, Paul Hepworth
80
71
 
81
72
  See MIT-LICENSE for licensing information
data/Rakefile CHANGED
@@ -29,4 +29,4 @@ begin
29
29
  Jeweler::GemcutterTasks.new
30
30
  rescue LoadError
31
31
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
32
- end
32
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 1.0.5
data/lib/smurf.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  require 'smurf/javascript'
2
2
  require 'smurf/stylesheet'
3
+ require 'smurf/noop'
3
4
 
4
5
  module ActionView::Helpers::AssetTagHelper
5
6
  private
6
- def join_asset_file_contents_with_minification(files)
7
- content = join_asset_file_contents_without_minification(files)
8
- if !files.grep(/javascripts.+\.js/).empty?
9
- content = Smurf::Javascript.new(content).minified
10
- elsif !files.grep(/stylesheets.+\.css/).empty?
11
- content = Smurf::Stylesheet.new(content).minified
12
- end
13
- content
7
+ def minifiers
8
+ @@minifiers ||= [Smurf::Javascript, Smurf::Stylesheet, Smurf::Noop]
9
+ end
10
+
11
+ def join_asset_file_contents_with_minification(paths)
12
+ content = join_asset_file_contents_without_minification(paths)
13
+ minifiers.detect { |minifier| minifier.minifies?(paths) }.new(content).minified
14
14
  end
15
15
  alias_method_chain :join_asset_file_contents, :minification
16
16
  end # ActionView::Helpers::AssetTagHelper
@@ -38,6 +38,8 @@ require 'stringio'
38
38
 
39
39
  module Smurf
40
40
  class Javascript
41
+ def self.minifies?(paths) !paths.grep(%r[\.js(\?\d+)?$]).empty?; end
42
+
41
43
  EOF = -1
42
44
 
43
45
  @theA = ""
@@ -75,13 +77,14 @@ module Smurf
75
77
  end
76
78
 
77
79
  # Get the next character without getting it.
78
- def peek()
79
- lookaheadChar = @input.getc
80
- @input.ungetc(lookaheadChar)
81
- return lookaheadChar.chr
80
+ def peek(aheadCount=1)
81
+ history = []
82
+ aheadCount.times { history << @input.getc }
83
+ history.reverse.each { |chr| @input.ungetc(chr) }
84
+ return history.last.chr
82
85
  end
83
86
 
84
- # mynext -- get the next character, excluding comments.
87
+ # mynext -- get the next character, excluding legitimate comments.
85
88
  # peek() is used to see if a '/' is followed by a '/' or '*'.
86
89
  def mynext()
87
90
  c = get
@@ -94,7 +97,7 @@ module Smurf
94
97
  end
95
98
  end
96
99
  end
97
- if(peek == "*")
100
+ if(peek == "*" && peek(2) != "@") # not conditional comments
98
101
  get
99
102
  while(true)
100
103
  case get
@@ -149,7 +152,8 @@ module Smurf
149
152
  @theA == "&" || @theA == "|" || @theA == "?" ||
150
153
  @theA == "{" || @theA == "}" || @theA == ";" ||
151
154
  @theA == "\n"))
152
- @output.write @theA
155
+
156
+ @output.write(@theA) unless peek(2) == '@'
153
157
  @output.write @theB
154
158
  while (true)
155
159
  @theA = get
data/lib/smurf/noop.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Smurf
2
+ # This is a no-op; essentially a NullObject pattern implementation. Saves from implementing logic elsewhere
3
+ class Noop
4
+ def self.minifies?(paths) true; end
5
+ def initialize(content) @content = content; end
6
+ def minified; @content; end
7
+ end # Noop
8
+ end # Smurf
@@ -1,5 +1,7 @@
1
1
  module Smurf
2
2
  class Stylesheet
3
+ def self.minifies?(paths) !paths.grep(%r[\.css(\?\d+)?$]).empty?; end
4
+
3
5
  def initialize(content)
4
6
  @content = content.nil? ? nil : minify(content)
5
7
  end
data/smurf.gemspec CHANGED
@@ -1,73 +1,78 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{smurf}
8
- s.version = "1.0.4"
8
+ s.version = "1.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin 'Gus' Knowlden"]
12
- s.date = %q{2010-06-03}
12
+ s.date = %q{2010-11-17}
13
13
  s.description = %q{Rails plugin to automatically minify JS and CSS when their bundles get cached. Send in those patches!}
14
14
  s.email = %q{gus@thumblemonks.com}
15
15
  s.extra_rdoc_files = [
16
16
  "README.markdown"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
- "MIT-LICENSE",
21
- "README.markdown",
22
- "Rakefile",
23
- "VERSION",
24
- "init.rb",
25
- "install.rb",
26
- "lib/smurf.rb",
27
- "lib/smurf/javascript.rb",
28
- "lib/smurf/stylesheet.rb",
29
- "rails/init.rb",
30
- "smurf.gemspec",
31
- "test/rails/app/controllers/application.rb",
32
- "test/rails/config/boot.rb",
33
- "test/rails/config/environment.rb",
34
- "test/rails/config/environments/test.rb",
35
- "test/rails/config/routes.rb",
36
- "test/rails/public/javascripts/cache/expected.js",
37
- "test/rails/public/javascripts/projwcss/jscss.css",
38
- "test/rails/public/javascripts/testing.js",
39
- "test/rails/public/stylesheets/bar.css",
40
- "test/rails/public/stylesheets/cache/expected.css",
41
- "test/rails/public/stylesheets/foo.css",
42
- "test/smurf_test.rb",
43
- "test/test_helper.rb",
44
- "uninstall.rb"
19
+ "Gemfile",
20
+ "MIT-LICENSE",
21
+ "README.markdown",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "lib/smurf.rb",
25
+ "lib/smurf/javascript.rb",
26
+ "lib/smurf/noop.rb",
27
+ "lib/smurf/stylesheet.rb",
28
+ "smurf.gemspec",
29
+ "test/integration_test.rb",
30
+ "test/javascript_test.rb",
31
+ "test/rails/app/controllers/application.rb",
32
+ "test/rails/config/application.rb",
33
+ "test/rails/config/boot.rb",
34
+ "test/rails/config/environment.rb",
35
+ "test/rails/config/environments/test.rb",
36
+ "test/rails/config/routes.rb",
37
+ "test/rails/public/javascripts/cache/expected.js",
38
+ "test/rails/public/javascripts/projwcss/jscss.css",
39
+ "test/rails/public/javascripts/testing.js",
40
+ "test/rails/public/stylesheets/bar.css",
41
+ "test/rails/public/stylesheets/cache/expected-basic.css",
42
+ "test/rails/public/stylesheets/foo.css",
43
+ "test/stylesheet_test.rb",
44
+ "test/test_helper.rb"
45
45
  ]
46
46
  s.homepage = %q{http://github.com/thumblemonks/smurf}
47
- s.rdoc_options = ["--charset=UTF-8"]
48
47
  s.require_paths = ["lib"]
49
- s.rubygems_version = %q{1.3.6}
48
+ s.rubygems_version = %q{1.3.7}
50
49
  s.summary = %q{Rails plugin to automatically minify JS and CSS when their bundles get cached}
51
50
  s.test_files = [
51
+ "test/integration_test.rb",
52
+ "test/javascript_test.rb",
52
53
  "test/rails/app/controllers/application.rb",
53
- "test/rails/config/boot.rb",
54
- "test/rails/config/environment.rb",
55
- "test/rails/config/environments/test.rb",
56
- "test/rails/config/routes.rb",
57
- "test/smurf_test.rb",
58
- "test/test_helper.rb"
54
+ "test/rails/config/application.rb",
55
+ "test/rails/config/boot.rb",
56
+ "test/rails/config/environment.rb",
57
+ "test/rails/config/environments/test.rb",
58
+ "test/rails/config/routes.rb",
59
+ "test/stylesheet_test.rb",
60
+ "test/test_helper.rb"
59
61
  ]
60
62
 
61
63
  if s.respond_to? :specification_version then
62
64
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
65
  s.specification_version = 3
64
66
 
65
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
68
+ s.add_runtime_dependency(%q<rails>, ["= 3.0.3"])
66
69
  s.add_development_dependency(%q<riot>, [">= 0"])
67
70
  else
71
+ s.add_dependency(%q<rails>, ["= 3.0.3"])
68
72
  s.add_dependency(%q<riot>, [">= 0"])
69
73
  end
70
74
  else
75
+ s.add_dependency(%q<rails>, ["= 3.0.3"])
71
76
  s.add_dependency(%q<riot>, [">= 0"])
72
77
  end
73
78
  end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ context "link tags when caching on" do
4
+ setup do
5
+ javascript_include_tag('testing', :cache => 'cache/actual')
6
+ stylesheet_link_tag('foo', 'bar', :cache => 'cache/actual-basic')
7
+ stylesheet_link_tag('foo', 'bar', '/javascripts/projwcss/jscss', :cache => 'cache/actual-plus')
8
+ end
9
+
10
+ should_have_same_contents('/javascripts/cache/expected.js', '/javascripts/cache/actual.js')
11
+ should_have_same_contents('/stylesheets/cache/expected-basic.css', '/stylesheets/cache/actual-basic.css')
12
+ should_have_same_contents('/stylesheets/cache/expected-plus.css', '/stylesheets/cache/actual-plus.css')
13
+ end # link tags when caching on
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ context "Javascript minifier" do
4
+
5
+ should "want to minify files in the javascripts directory" do
6
+ Smurf::Javascript.minifies?(["a/b/javascripts/bar.js", "c/d/javascripts/baz.js"])
7
+ end
8
+
9
+ should "want to minify files in the stylesheets directory" do
10
+ Smurf::Javascript.minifies?(["a/b/stylesheets/bar.js", "c/d/stylesheets/baz.js"])
11
+ end
12
+
13
+ should "want to minify nothing but stylesheets" do
14
+ Smurf::Javascript.minifies?(["a/b/javascripts/bar.css", "c/d/javascripts/baz.css"])
15
+ end.not!
16
+
17
+ context "working with multi-line strings" do
18
+ setup do
19
+ input = StringIO.new()
20
+ input.puts("var foo='bar \\")
21
+ input.puts(" bar \\")
22
+ input.puts(" baz';")
23
+ input.rewind
24
+ input.read
25
+ end
26
+
27
+ should "not affect the string" do
28
+ Smurf::Javascript.new(topic).minified
29
+ end.equals("\nvar foo='bar bar baz';")
30
+ end # working with multi-line strings
31
+
32
+ context "working with conditional compilation on IE" do
33
+ setup do
34
+ input = StringIO.new()
35
+ input.puts("/*@cc_on(function(){document.write('this will write out to IE browsers)});@*/")
36
+ input.rewind
37
+ input.read
38
+ end
39
+
40
+ should "not affect the string" do
41
+ Smurf::Javascript.new(topic).minified
42
+ end.equals("/*@cc_on(function(){document.write('this will write out to IE browsers)});@*/")
43
+ end # working with conditional compilation on IE
44
+
45
+ end # Javascript minifier
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require "action_controller/railtie"
5
+ require "action_view/railtie"
6
+
7
+ # Auto-require default libraries and those for the current Rails environment.
8
+ Bundler.require :default, Rails.env
9
+
10
+ module Smurf
11
+ class Application < Rails::Application
12
+ config.consider_all_requests_local = true
13
+ config.session_store :cookie_store, {:key => "_smurf_session"}
14
+ config.secret_token = "i own you." * 3
15
+
16
+ config.root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
17
+ end
18
+ end
@@ -1,109 +1,9 @@
1
- # Don't change this file!
2
- # Configure your app in config/environment.rb and config/environments/*.rb
3
-
4
- RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
-
6
- module Rails
7
- class << self
8
- def boot!
9
- unless booted?
10
- preinitialize
11
- pick_boot.run
12
- end
13
- end
14
-
15
- def booted?
16
- defined? Rails::Initializer
17
- end
18
-
19
- def pick_boot
20
- (vendor_rails? ? VendorBoot : GemBoot).new
21
- end
22
-
23
- def vendor_rails?
24
- File.exist?("#{RAILS_ROOT}/vendor/rails")
25
- end
26
-
27
- def preinitialize
28
- load(preinitializer_path) if File.exist?(preinitializer_path)
29
- end
30
-
31
- def preinitializer_path
32
- "#{RAILS_ROOT}/config/preinitializer.rb"
33
- end
34
- end
35
-
36
- class Boot
37
- def run
38
- load_initializer
39
- Rails::Initializer.run(:set_load_path)
40
- end
41
- end
42
-
43
- class VendorBoot < Boot
44
- def load_initializer
45
- require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
- Rails::Initializer.run(:install_gem_spec_stubs)
47
- end
48
- end
49
-
50
- class GemBoot < Boot
51
- def load_initializer
52
- self.class.load_rubygems
53
- load_rails_gem
54
- require 'initializer'
55
- end
56
-
57
- def load_rails_gem
58
- if version = self.class.gem_version
59
- gem 'rails', version
60
- else
61
- gem 'rails'
62
- end
63
- rescue Gem::LoadError => load_error
64
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
65
- exit 1
66
- end
67
-
68
- class << self
69
- def rubygems_version
70
- Gem::RubyGemsVersion rescue "0.0.0"
71
- end
72
-
73
- def gem_version
74
- if defined? RAILS_GEM_VERSION
75
- RAILS_GEM_VERSION
76
- elsif ENV.include?('RAILS_GEM_VERSION')
77
- ENV['RAILS_GEM_VERSION']
78
- else
79
- parse_gem_version(read_environment_rb)
80
- end
81
- end
82
-
83
- def load_rubygems
84
- require 'rubygems'
85
- min_version = '1.1.1'
86
- unless rubygems_version >= min_version
87
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
- exit 1
89
- end
90
-
91
- rescue LoadError
92
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
93
- exit 1
94
- end
95
-
96
- def parse_gem_version(text)
97
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
98
- end
99
-
100
- private
101
- def read_environment_rb
102
- File.read("#{RAILS_ROOT}/config/environment.rb")
103
- end
104
- end
105
- end
1
+ begin
2
+ require File.expand_path("../../../../.bundle/environment", __FILE__)
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+ Bundler.setup :default
106
7
  end
107
8
 
108
- # All that for this:
109
- Rails.boot!
9
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,18 +1,5 @@
1
- # Specifies gem version of Rails to use when vendor/rails is not present
2
- unless defined? RAILS_GEM_VERSION
3
- RAILS_GEM_VERSION = (ENV['RAILS_GEM_VERSION'] || '2.3.5')
4
- STDOUT.puts "TESTING with RAILS_GEM_VERSION = #{RAILS_GEM_VERSION}"
5
- end
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
6
3
 
7
- # Bootstrap the Rails environment, frameworks, and default configuration
8
- require File.join(File.dirname(__FILE__), 'boot')
9
-
10
- Rails::Initializer.run do |config|
11
- # Don't need 'em
12
- config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
13
-
14
- config.action_controller.session = {
15
- :session_key => '_smurf_session',
16
- :secret => '731d6426b731d6426b731d6426b731d6426b731d6426b731d6426b731d6426b'
17
- }
18
- end
4
+ # Initialize the rails application
5
+ Smurf::Application.initialize!
@@ -1,7 +1,7 @@
1
- config.cache_classes = true
2
- config.whiny_nils = true
1
+ Smurf::Application.configure do
2
+ config.active_support.deprecation = :stderr
3
+ config.cache_classes = true
4
+ config.whiny_nils = true
3
5
 
4
- config.action_controller.consider_all_requests_local = true
5
- config.action_controller.perform_caching = true # THIS IS IMPORTANT FOR THE TESTS
6
-
7
- config.action_mailer.delivery_method = :test
6
+ config.action_controller.perform_caching = true # THIS IS IMPORTANT FOR THE TESTS
7
+ end
@@ -1,5 +1,3 @@
1
- ActionController::Routing::Routes.draw do |map|
2
- map.connect ':controller/service.wsdl', :action => 'wsdl'
3
- map.connect ':controller/:action/:id.:format'
4
- map.connect ':controller/:action/:id'
1
+ Smurf::Application.routes.draw do
2
+ match '/:controller(/:action(/:id))'
5
3
  end
@@ -0,0 +1,2 @@
1
+
2
+ function foo(){puts"Hello, world"}
@@ -0,0 +1 @@
1
+ html{color:#000;background:#FFF}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal}li{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}q:before,q:after{content:''}abbr,acronym{border:0;font-variant:normal}sup{vertical-align:text-top}sub{vertical-align:text-bottom}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit}input,textarea,select{*font-size:100%}legend{color:#000}del,ins{text-decoration:none}smurf{content:"pa pa"}.smurf :link li{color:blue}smurf #smurf,:smurf .smurf{color:black}smurfdom{papa:smurf}
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ context "Stylesheet minifier" do
4
+ setup { Smurf::Stylesheet }
5
+ helper(:minify) { |content| topic.new(content).minified }
6
+
7
+ should "want to minify files in the stylesheets directory" do
8
+ topic.minifies?(["a/b/stylesheets/bar.css", "c/d/stylesheets/baz.css?12344"])
9
+ end
10
+
11
+ should "want to minify files in the javascripts directory" do
12
+ topic.minifies?(["a/b/javascripts/bar.css?12345", "c/d/javascripts/baz.css"])
13
+ end
14
+
15
+ should "want to minify nothing but javascripts" do
16
+ topic.minifies?(["a/b/stylesheet/foo.js", "c/d/javascripts/baz.js"])
17
+ end.not!
18
+
19
+ context "minifying a non-existent pattern in a stylesheet" do
20
+ should("succeed for removing comments") do
21
+ minify("hi { mom: super-awesome; } ")
22
+ end.equals("hi{mom:super-awesome}")
23
+
24
+ should("succeed when no spaces to compress") do
25
+ minify("hi{mom:super-awesome}")
26
+ end.equals("hi{mom:super-awesome}")
27
+
28
+ # nothing outside, means nothing inside. they are complementary
29
+ should "succeed when no outside or inside blocks" do
30
+ minify("how-did: this-happen; typo: maybe;}")
31
+ end.equals("how-did: this-happen; typo: maybe}")
32
+
33
+ asserts "when no last semi-colon in block" do
34
+ minify("hi { mom: super-awesome } ")
35
+ end.equals("hi{mom:super-awesome}")
36
+
37
+ asserts("empty string when no content provided") { minify("") }.equals("")
38
+
39
+ asserts("nil even if nil provided") { minify(nil) }.nil
40
+ end # minifying a non-existent pattern in a stylesheet
41
+ end # Stylesheet minifier
data/test/test_helper.rb CHANGED
@@ -1,17 +1,20 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
- ENV["RAILS_ROOT"] = File.expand_path(File.join(File.dirname(__FILE__), 'rails'))
3
- require File.expand_path(File.join(ENV["RAILS_ROOT"], 'config', 'environment'))
4
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'init'))
2
+ require ::File.expand_path('../rails/config/environment', __FILE__)
5
3
 
4
+ # Rails.public_path = Rails.root + "test" + "rails" + "public"
6
5
  require 'riot'
6
+ require 'ostruct'
7
+
8
+ # require 'smurf'
9
+ require ::File.expand_path('../../lib/smurf', __FILE__)
7
10
 
8
11
  class AssetFile
9
12
  def self.base_path
10
- @path ||= File.join(File.join(ENV["RAILS_ROOT"], 'public'))
13
+ @path ||= Rails.public_path
11
14
  end
12
15
 
13
16
  def self.read(relative_path)
14
- File.read(File.join(base_path, relative_path))
17
+ File.read(base_path + relative_path)
15
18
  end
16
19
  end
17
20
 
@@ -23,12 +26,23 @@ class Riot::Context
23
26
  end
24
27
  end
25
28
 
26
- Riot::Situation.instance_eval do
29
+ class Riot::Situation
27
30
  include ActionView::Helpers::TagHelper
28
31
  include ActionView::Helpers::AssetTagHelper
32
+
33
+ def controller; nil; end
34
+
35
+ def config
36
+ OpenStruct.new({
37
+ :assets_dir => Rails.public_path,
38
+ :javascripts_dir => Rails.public_path + "/javascripts",
39
+ :stylesheets_dir => Rails.public_path + "/stylesheets",
40
+ :perform_caching => true
41
+ })
42
+ end
29
43
  end
30
44
 
31
45
  at_exit do
32
- artifacts = Dir.glob(File.join(AssetFile.base_path, '**', 'cache', 'actual.*'))
46
+ artifacts = Dir.glob(File.join(AssetFile.base_path, '**', 'cache', 'actual*.*'))
33
47
  FileUtils.rm(artifacts)
34
48
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 4
9
- version: 1.0.4
8
+ - 5
9
+ version: 1.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Justin 'Gus' Knowlden
@@ -14,13 +14,28 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-03 00:00:00 -05:00
17
+ date: 2010-11-17 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: riot
22
- prerelease: false
21
+ name: rails
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 0
30
+ - 3
31
+ version: 3.0.3
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: riot
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
24
39
  requirements:
25
40
  - - ">="
26
41
  - !ruby/object:Gem::Version
@@ -28,7 +43,8 @@ dependencies:
28
43
  - 0
29
44
  version: "0"
30
45
  type: :development
31
- version_requirements: *id001
46
+ prerelease: false
47
+ version_requirements: *id002
32
48
  description: Rails plugin to automatically minify JS and CSS when their bundles get cached. Send in those patches!
33
49
  email: gus@thumblemonks.com
34
50
  executables: []
@@ -38,19 +54,20 @@ extensions: []
38
54
  extra_rdoc_files:
39
55
  - README.markdown
40
56
  files:
41
- - .gitignore
57
+ - Gemfile
42
58
  - MIT-LICENSE
43
59
  - README.markdown
44
60
  - Rakefile
45
61
  - VERSION
46
- - init.rb
47
- - install.rb
48
62
  - lib/smurf.rb
49
63
  - lib/smurf/javascript.rb
64
+ - lib/smurf/noop.rb
50
65
  - lib/smurf/stylesheet.rb
51
- - rails/init.rb
52
66
  - smurf.gemspec
67
+ - test/integration_test.rb
68
+ - test/javascript_test.rb
53
69
  - test/rails/app/controllers/application.rb
70
+ - test/rails/config/application.rb
54
71
  - test/rails/config/boot.rb
55
72
  - test/rails/config/environment.rb
56
73
  - test/rails/config/environments/test.rb
@@ -59,21 +76,21 @@ files:
59
76
  - test/rails/public/javascripts/projwcss/jscss.css
60
77
  - test/rails/public/javascripts/testing.js
61
78
  - test/rails/public/stylesheets/bar.css
62
- - test/rails/public/stylesheets/cache/expected.css
79
+ - test/rails/public/stylesheets/cache/expected-basic.css
63
80
  - test/rails/public/stylesheets/foo.css
64
- - test/smurf_test.rb
81
+ - test/stylesheet_test.rb
65
82
  - test/test_helper.rb
66
- - uninstall.rb
67
83
  has_rdoc: true
68
84
  homepage: http://github.com/thumblemonks/smurf
69
85
  licenses: []
70
86
 
71
87
  post_install_message:
72
- rdoc_options:
73
- - --charset=UTF-8
88
+ rdoc_options: []
89
+
74
90
  require_paths:
75
91
  - lib
76
92
  required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
77
94
  requirements:
78
95
  - - ">="
79
96
  - !ruby/object:Gem::Version
@@ -81,6 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
98
  - 0
82
99
  version: "0"
83
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
84
102
  requirements:
85
103
  - - ">="
86
104
  - !ruby/object:Gem::Version
@@ -90,15 +108,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
108
  requirements: []
91
109
 
92
110
  rubyforge_project:
93
- rubygems_version: 1.3.6
111
+ rubygems_version: 1.3.7
94
112
  signing_key:
95
113
  specification_version: 3
96
114
  summary: Rails plugin to automatically minify JS and CSS when their bundles get cached
97
115
  test_files:
116
+ - test/integration_test.rb
117
+ - test/javascript_test.rb
98
118
  - test/rails/app/controllers/application.rb
119
+ - test/rails/config/application.rb
99
120
  - test/rails/config/boot.rb
100
121
  - test/rails/config/environment.rb
101
122
  - test/rails/config/environments/test.rb
102
123
  - test/rails/config/routes.rb
103
- - test/smurf_test.rb
124
+ - test/stylesheet_test.rb
104
125
  - test/test_helper.rb
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- log/*
2
- *.gem
3
- test/rails/log/*
4
- test/rails/db/*
5
- test/rails/public/*/cache/*
6
- pkg/*
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'smurf'
data/install.rb DELETED
File without changes
data/rails/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'smurf'
data/test/smurf_test.rb DELETED
@@ -1,56 +0,0 @@
1
- require 'test_helper'
2
-
3
- # Javascript
4
-
5
- context "link tags when caching on" do
6
- setup do
7
- javascript_include_tag('testing', :cache => 'cache/actual')
8
- stylesheet_link_tag('foo', 'bar', '/javascripts/projwcss/jscss', :cache => 'cache/actual')
9
- end
10
-
11
- should_have_same_contents('javascripts/cache/expected.js', 'javascripts/cache/actual.js')
12
- should_have_same_contents('stylesheets/cache/expected.css', 'stylesheets/cache/actual.css')
13
- end # link tags when caching on
14
-
15
- context "minifying multi-line strings in javascript" do
16
- setup do
17
- input = StringIO.new()
18
- input.puts("var foo='bar \\")
19
- input.puts(" bar \\")
20
- input.puts(" baz';")
21
- input.rewind
22
- input.read
23
- end
24
-
25
- should "not affect the string" do
26
- Smurf::Javascript.new(topic).minified
27
- end.equals("\nvar foo='bar bar baz';")
28
- end
29
-
30
- context "minifying a non-existent pattern in a stylesheet" do
31
- # Thanks to someone named Niko for finding this
32
- should "succeed for removing comments" do
33
- Smurf::Stylesheet.new("hi { mom: super-awesome; } ").minified
34
- end.equals("hi{mom:super-awesome}")
35
-
36
- should "succeed when no spaces to compress" do
37
- Smurf::Stylesheet.new("hi{mom:super-awesome}").minified
38
- end.equals("hi{mom:super-awesome}")
39
-
40
- # nothing outside, means nothing inside. they are complementary
41
- should "succeed when no outside or inside blocks" do
42
- Smurf::Stylesheet.new("how-did: this-happen; typo: maybe;}").minified
43
- end.equals("how-did: this-happen; typo: maybe}")
44
-
45
- asserts "when no last semi-colon in block" do
46
- Smurf::Stylesheet.new("hi { mom: super-awesome } ").minified
47
- end.equals("hi{mom:super-awesome}")
48
-
49
- asserts "empty string when no content provided" do
50
- Smurf::Stylesheet.new("").minified
51
- end.equals("")
52
-
53
- asserts "nil even if nil provided" do
54
- Smurf::Stylesheet.new(nil).minified
55
- end.nil
56
- end # minifying a non-existent pattern in a stylesheet
data/uninstall.rb DELETED
File without changes