smurf 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
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.2.2`.
15
+ Smurf will work with any version of Rails `2.x`; including Rails `2.3.4` and `2.1.2`.
16
16
 
17
17
  ### JSmin
18
18
 
@@ -32,7 +32,13 @@ The following are the rules I applied, gathered from various perusals around the
32
32
 
33
33
  ## Installation
34
34
 
35
- ./script/plugin install git://github.com/thumblemonks/smurf.git
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
+
37
+ sudo gem sources -a http://gemcutter.org
38
+
39
+ Then, install Smurf as a gem:
40
+
41
+ sudo gem install smurf
36
42
 
37
43
  Then, wherever you define `javascript_include_tag` or `stylesheet_link_tag`, make sure to add the standard `:cache => true` or `:cache => 'some_bundle'` options.
38
44
 
@@ -40,6 +46,14 @@ Also make sure to at least have this setting in your production.rb:
40
46
 
41
47
  config.action_controller.perform_caching = true
42
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.
56
+
43
57
  ### Small suggestion
44
58
 
45
59
  [bcarpenter](http://github.com/bcarpenter) reminded all of us that Rails will generate real files if you set `config.action_controller.perform_caching` to `true`. If you happen to do this while developing your fantastic Rails app you may also accidentally commit them to your development repository. This is not what you want as it can send you and your awesome developer friends down the wrong rabbit hole ... and then when you figure out the problem you may be understandably and misguidedly pissed at Smurf :)
@@ -50,13 +64,13 @@ Also make sure to at least have this setting in your production.rb:
50
64
 
51
65
  ## Testing
52
66
 
53
- 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.2.2 as an example):
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):
54
68
 
55
- rake RAILS_GEM_VERSION=2.2.2
69
+ rake RAILS_GEM_VERSION=2.3.4
56
70
 
57
71
  This is the mechanism I used for testing that Smurf works for all versions:
58
72
 
59
- rake && rake RAILS_GEM_VERSION=2.2.2
73
+ rake && rake RAILS_GEM_VERSION=2.2.2 && rake RAILS_GEM_VERSION=2.1.2
60
74
 
61
75
  ## Meta
62
76
 
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ task :default => :test
7
7
 
8
8
  desc 'Test the load_model plugin.'
9
9
  Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
10
+ t.libs += ['lib', 'test']
11
11
  t.pattern = 'test/**/*_test.rb'
12
12
  t.verbose = true
13
13
  end
data/lib/smurf.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'smurf/javascript'
2
2
  require 'smurf/stylesheet'
3
3
 
4
- if Rails.version =~ /^2\.2\./
4
+ if Rails.respond_to?(:version) && Rails.version =~ /^2\.2\./
5
5
  # Support for Rails >= 2.2.x
6
6
  module Smurf
7
7
 
@@ -16,10 +16,8 @@ if Rails.version =~ /^2\.2\./
16
16
  end # StylesheetSources
17
17
 
18
18
  end # ActionView::Helpers::AssetTagHelper::AssetTag
19
- ActionView::Helpers::AssetTagHelper::JavaScriptSources.send(
20
- :include, Smurf::JavaScriptSources)
21
- ActionView::Helpers::AssetTagHelper::StylesheetSources.send(
22
- :include, Smurf::StylesheetSources)
19
+ ActionView::Helpers::AssetTagHelper::JavaScriptSources.send(:include, Smurf::JavaScriptSources)
20
+ ActionView::Helpers::AssetTagHelper::StylesheetSources.send(:include, Smurf::StylesheetSources)
23
21
  else
24
22
  # Support for Rails <= 2.1.x
25
23
  module ActionView::Helpers::AssetTagHelper
data/smurf.gemspec CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
2
2
  s.name = "smurf"
3
3
  s.summary = "Rails plugin to automatically minify JS and CSS when their bundles get cached"
4
4
  s.description = "Rails plugin to automatically minify JS and CSS when their bundles get cached. Send in those patches!"
5
- s.version = "1.0.0"
5
+ s.version = "1.0.1"
6
6
  s.authors = ["Justin Knowlden"]
7
7
  s.email = %w[gus@thumblemonks.com]
8
8
  s.homepage = "http://github.com/thumblemonks/smurf"
@@ -27,7 +27,6 @@ Gem::Specification.new do |s|
27
27
  s.test_files = %w[
28
28
  test/rails/app/controllers/application.rb
29
29
  test/rails/config/boot.rb
30
- test/rails/config/database.yml
31
30
  test/rails/config/environment.rb
32
31
  test/rails/config/environments/test.rb
33
32
  test/rails/config/routes.rb
@@ -1,21 +1,15 @@
1
- # Be sure to restart your server when you modify this file
2
-
3
- # Uncomment below to force Rails into production mode when
4
- # you don't control web/app server and can't set it the proper way
5
- # ENV['RAILS_ENV'] ||= 'production'
6
-
7
1
  # Specifies gem version of Rails to use when vendor/rails is not present
8
2
  unless defined? RAILS_GEM_VERSION
9
- RAILS_GEM_VERSION = (ENV['RAILS_GEM_VERSION'] || '2.3.2')
3
+ RAILS_GEM_VERSION = (ENV['RAILS_GEM_VERSION'] || '2.3.4')
4
+ STDOUT.puts "TESTING with RAILS_GEM_VERSION = #{RAILS_GEM_VERSION}"
10
5
  end
11
6
 
12
7
  # Bootstrap the Rails environment, frameworks, and default configuration
13
8
  require File.join(File.dirname(__FILE__), 'boot')
14
9
 
15
10
  Rails::Initializer.run do |config|
16
- config.gem 'thoughtbot-shoulda', :lib => 'shoulda/rails',
17
- :source => 'http://gems.github.com'
18
- config.gem 'sqlite3-ruby', :lib => 'sqlite3'
11
+ # Don't need 'em
12
+ config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
19
13
 
20
14
  config.action_controller.session = {
21
15
  :session_key => '_smurf_session',
@@ -1,19 +1,7 @@
1
- # Settings specified here will take precedence over those in config/environment.rb
2
-
3
- # The test environment is used exclusively to run your application's
4
- # test suite. You never need to work with it otherwise. Remember that
5
- # your test database is "scratch space" for the test suite and is wiped
6
- # and recreated between test runs. Don't rely on the data there!
7
1
  config.cache_classes = true
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
2
  config.whiny_nils = true
11
3
 
12
- # Show full error reports and disable caching
13
4
  config.action_controller.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
5
+ config.action_controller.perform_caching = true # THIS IS IMPORTANT FOR THE TESTS
15
6
 
16
- # Tell ActionMailer not to deliver emails to the real world.
17
- # The :test delivery method accumulates sent emails in the
18
- # ActionMailer::Base.deliveries array.
19
7
  config.action_mailer.delivery_method = :test
data/test/smurf_test.rb CHANGED
@@ -1,82 +1,56 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
1
+ require 'test_helper'
2
2
 
3
- class SmurfTest < Test::Unit::TestCase
4
- include ActionView::Helpers::TagHelper
5
- include ActionView::Helpers::AssetTagHelper
3
+ # Javascript
6
4
 
7
- # Javascript
8
-
9
- context "when caching on for javascript" do
10
- setup do
11
- ActionController::Base.stubs(:perform_caching).returns(true)
12
- javascript_include_tag('testing.js', :cache => 'cache/actual')
13
- end
14
-
15
- should_have_same_contents('javascripts/cache/expected.js',
16
- 'javascripts/cache/actual.js')
17
- end # when caching on for javascript
18
-
19
- context "minifying multi-line strings in javascript" do
20
- setup do
21
- input = StringIO.new()
22
- input.puts("var foo='bar \\")
23
- input.puts(" bar \\")
24
- input.puts(" baz';")
25
- input.rewind
26
- @content = input.read
27
- end
28
-
29
- should "not affect the string" do
30
- expected = "\n" + @content.gsub(/\\?\r?\n/, '')
31
- assert_equal expected, Smurf::Javascript.new(@content).minified
32
- end
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', :cache => 'cache/actual')
33
9
  end
34
10
 
35
- # Stylesheet
36
-
37
- context "when caching on for stylesheets" do
38
- setup do
39
- ActionController::Base.stubs(:perform_caching).returns(true)
40
- stylesheet_link_tag('foo', 'bar', :cache => 'cache/actual')
41
- end
42
-
43
- should_have_same_contents('stylesheets/cache/expected.css',
44
- 'stylesheets/cache/actual.css')
45
- end # when caching on for stylesheets
46
-
47
- context "minifying a non-existent pattern in a stylesheet" do
48
- setup {@himom = "hi{mom:super-awesome}"}
49
-
50
- # Thanks to someone named Niko for finding this
51
- should "succeed for removing comments" do
52
- actual = "hi { mom: super-awesome; } "
53
- assert_equal @himom, Smurf::Stylesheet.new(actual).minified
54
- end
55
-
56
- should "succeed when no spaces to compress" do
57
- actual = @himom
58
- assert_equal @himom, Smurf::Stylesheet.new(actual).minified
59
- end
60
-
61
- should "succeed when no outside or inside blocks" do
62
- # nothing outside, means nothing inside. they are complementary
63
- actual = "how-did: this-happen; typo: maybe;}"
64
- expected = "how-did: this-happen; typo: maybe}"
65
- assert_equal expected, Smurf::Stylesheet.new(actual).minified
66
- end
67
-
68
- should "succeed when no last semi-colon in block" do
69
- actual = "hi { mom: super-awesome } "
70
- assert_equal @himom, Smurf::Stylesheet.new(actual).minified
71
- end
72
-
73
- should "succeed across all parsers when no content provided" do
74
- actual = ""
75
- assert_equal "", Smurf::Stylesheet.new(actual).minified
76
- end
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
77
24
 
78
- should "succeed if nil provided" do
79
- assert_nil Smurf::Stylesheet.new(nil).minified
80
- end
81
- end # minifying a non-existent pattern
25
+ should "not affect the string" do
26
+ Smurf::Javascript.new(topic).minified
27
+ end.equals("\nvar foo='bar bar baz';")
82
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/test/test_helper.rb CHANGED
@@ -3,30 +3,32 @@ ENV["RAILS_ROOT"] = File.expand_path(File.join(File.dirname(__FILE__), 'rails'))
3
3
  require File.expand_path(File.join(ENV["RAILS_ROOT"], 'config', 'environment'))
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'init'))
5
5
 
6
- require 'test_help'
7
- require 'ruby-debug'
6
+ require 'riot'
8
7
 
9
- class Test::Unit::TestCase
10
-
11
- def teardown
12
- artifacts = Dir.glob(File.join(asset_path, '**', 'cache', 'actual.*'))
13
- FileUtils.rm(artifacts)
14
- end
15
-
16
- def self.should_have_same_contents(expected_path, actual_path)
17
- should "have the same file contents as #{expected_path}" do
18
- expected = read_asset_file(expected_path)
19
- actual = read_asset_file(actual_path)
20
- assert_equal expected, actual
21
- end
8
+ class AssetFile
9
+ def self.base_path
10
+ @path ||= File.join(File.join(ENV["RAILS_ROOT"], 'public'))
22
11
  end
23
12
 
24
- private
25
- def asset_path
26
- File.join(File.join(ENV["RAILS_ROOT"], 'public'))
13
+ def self.read(relative_path)
14
+ File.read(File.join(base_path, relative_path))
27
15
  end
16
+ end
28
17
 
29
- def read_asset_file(relative_path)
30
- File.read(File.join(asset_path, relative_path))
18
+ class Riot::Context
19
+ def should_have_same_contents(expected_path, actual_path)
20
+ asserts "#{actual_path} has the same file contents as #{expected_path}" do
21
+ AssetFile.read(actual_path)
22
+ end.equals(AssetFile.read(expected_path))
31
23
  end
32
24
  end
25
+
26
+ Riot::Situation.instance_eval do
27
+ include ActionView::Helpers::TagHelper
28
+ include ActionView::Helpers::AssetTagHelper
29
+ end
30
+
31
+ at_exit do
32
+ artifacts = Dir.glob(File.join(AssetFile.base_path, '**', 'cache', 'actual.*'))
33
+ FileUtils.rm(artifacts)
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smurf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Knowlden
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-02 00:00:00 -05:00
12
+ date: 2009-10-10 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -66,7 +66,6 @@ summary: Rails plugin to automatically minify JS and CSS when their bundles get
66
66
  test_files:
67
67
  - test/rails/app/controllers/application.rb
68
68
  - test/rails/config/boot.rb
69
- - test/rails/config/database.yml
70
69
  - test/rails/config/environment.rb
71
70
  - test/rails/config/environments/test.rb
72
71
  - test/rails/config/routes.rb
@@ -1,3 +0,0 @@
1
- test:
2
- adapter: sqlite3
3
- dbfile: ":memory:" # db/test.db