smurf 1.0.3 → 1.0.4.rails3.beta2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ log/*
2
+ *.gem
3
+ test/rails/log/*
4
+ test/rails/db/*
5
+ test/rails/public/*/cache/*
6
+ pkg/*
7
+ .bundle
8
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ gem "rails", "3.0.0.beta2"
2
+
3
+ group :test do
4
+ gem "ruby-debug"
5
+ gem "riot", "0.11.0"
6
+ end
7
+
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.beta1`.
16
16
 
17
17
  ### JSmin
18
18
 
@@ -32,27 +32,19 @@ The following are the rules I applied, gathered from various perusals around the
32
32
 
33
33
  ## Installation
34
34
 
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:
35
+ You install Smurf as a gem:
36
36
 
37
- sudo gem sources -a http://gemcutter.org
37
+ sudo gem install smurf
38
38
 
39
- Then, install Smurf as a gem:
39
+ Because this latest version is intended to work with Rails 3 and above, you'll need to update your Gemfile ad add:
40
40
 
41
- sudo gem install smurf
41
+ gem 'smurf'
42
42
 
43
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.
44
44
 
45
45
  Also make sure to at least have this setting in your production.rb:
46
46
 
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.
47
+ config.perform_caching = true
56
48
 
57
49
  ### Small suggestion
58
50
 
@@ -64,13 +56,11 @@ Then do the other stuff for setting up Smurf in your Rails environment.
64
56
 
65
57
  ## Testing
66
58
 
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
59
+ Simple:
70
60
 
71
- This is the mechanism I used for testing that Smurf works for all versions:
61
+ rake
72
62
 
73
- rake && rake RAILS_GEM_VERSION=2.2.2 && rake RAILS_GEM_VERSION=2.1.2
63
+ 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
64
 
75
65
  ## Meta
76
66
 
data/Rakefile CHANGED
@@ -5,18 +5,28 @@ require 'rake/rdoctask'
5
5
  desc 'Default: run unit tests.'
6
6
  task :default => :test
7
7
 
8
- desc 'Test the load_model plugin.'
8
+ desc 'Test the smurf plugin.'
9
9
  Rake::TestTask.new(:test) do |t|
10
10
  t.libs += ['test']
11
11
  t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
12
+ t.verbose = false # Verbose is just dumb
13
13
  end
14
14
 
15
- desc 'Generate documentation for the smurf plugin.'
16
- Rake::RDocTask.new(:rdoc) do |rdoc|
17
- rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = 'Smurf'
19
- rdoc.options << '--line-numbers' << '--inline-source'
20
- rdoc.rdoc_files.include('README')
21
- rdoc.rdoc_files.include('lib/**/*.rb')
15
+ #
16
+ # Some monks like diamonds. I like gems.
17
+
18
+ begin
19
+ require 'jeweler'
20
+ Jeweler::Tasks.new do |gem|
21
+ gem.name = "smurf"
22
+ gem.summary = "Rails plugin to automatically minify JS and CSS when their bundles get cached"
23
+ gem.description = "Rails plugin to automatically minify JS and CSS when their bundles get cached. Send in those patches!"
24
+ gem.email = "gus@thumblemonks.com"
25
+ gem.homepage = "http://github.com/thumblemonks/smurf"
26
+ gem.authors = ["Justin 'Gus' Knowlden"]
27
+ gem.add_development_dependency "riot"
28
+ end
29
+ Jeweler::GemcutterTasks.new
30
+ rescue LoadError
31
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
32
  end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.4.rails3.beta2
@@ -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 = ""
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/lib/smurf.rb CHANGED
@@ -3,14 +3,13 @@ require 'smurf/stylesheet'
3
3
 
4
4
  module ActionView::Helpers::AssetTagHelper
5
5
  private
6
- def join_asset_file_contents_with_minification(files)
7
- content = join_asset_file_contents_without_minification(files)
8
- if !files.grep(%r[/javascripts]).empty?
9
- content = Smurf::Javascript.new(content).minified
10
- elsif !files.grep(%r[/stylesheets]).empty?
11
- content = Smurf::Stylesheet.new(content).minified
12
- end
13
- content
6
+ def minifiers
7
+ @@minifiers ||= [Smurf::Javascript, Smurf::Stylesheet, Smurf::Noop]
8
+ end
9
+
10
+ def join_asset_file_contents_with_minification(paths)
11
+ content = join_asset_file_contents_without_minification(paths)
12
+ minifiers.detect { |minifier| minifier.minifies?(paths) }.new(content).minified
14
13
  end
15
14
  alias_method_chain :join_asset_file_contents, :minification
16
15
  end # ActionView::Helpers::AssetTagHelper
data/smurf.gemspec CHANGED
@@ -1,41 +1,78 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
1
6
  Gem::Specification.new do |s|
2
- s.name = "smurf"
3
- s.summary = "Rails plugin to automatically minify JS and CSS when their bundles get cached"
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.3"
6
- s.authors = ["Justin Knowlden"]
7
- s.email = %w[gus@thumblemonks.com]
8
- s.homepage = "http://github.com/thumblemonks/smurf"
9
- s.has_rdoc = true
10
- s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
11
- s.post_install_message = %q{Choosy Gargamels choose Thumble Monks.}
7
+ s.name = %q{smurf}
8
+ s.version = "1.0.4.rails3.beta2"
12
9
 
13
- s.files = %w[
14
- MIT-LICENSE
15
- README.markdown
16
- Rakefile
17
- init.rb
18
- install.rb
19
- lib/smurf.rb
20
- lib/smurf/javascript.rb
21
- lib/smurf/stylesheet.rb
22
- rails/init.rb
23
- smurf.gemspec
24
- uninstall.rb
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Justin 'Gus' Knowlden"]
12
+ s.date = %q{2010-06-03}
13
+ s.description = %q{Rails plugin to automatically minify JS and CSS when their bundles get cached. Send in those patches!}
14
+ s.email = %q{gus@thumblemonks.com}
15
+ s.extra_rdoc_files = [
16
+ "README.markdown"
25
17
  ]
26
-
27
- s.test_files = %w[
28
- test/rails/app/controllers/application.rb
29
- test/rails/config/boot.rb
30
- test/rails/config/environment.rb
31
- test/rails/config/environments/test.rb
32
- test/rails/config/routes.rb
33
- test/rails/public/javascripts/cache/expected.js
34
- test/rails/public/javascripts/testing.js
35
- test/rails/public/stylesheets/bar.css
36
- test/rails/public/stylesheets/cache/expected.css
37
- test/rails/public/stylesheets/foo.css
38
- test/smurf_test.rb
39
- test/test_helper.rb
18
+ s.files = [
19
+ ".gitignore",
20
+ "Gemfile",
21
+ "MIT-LICENSE",
22
+ "README.markdown",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/smurf.rb",
26
+ "lib/smurf/javascript.rb",
27
+ "lib/smurf/noop.rb",
28
+ "lib/smurf/stylesheet.rb",
29
+ "smurf.gemspec",
30
+ "test/integration_test.rb",
31
+ "test/javascript_test.rb",
32
+ "test/rails/app/controllers/application.rb",
33
+ "test/rails/config/application.rb",
34
+ "test/rails/config/boot.rb",
35
+ "test/rails/config/environment.rb",
36
+ "test/rails/config/environments/test.rb",
37
+ "test/rails/config/routes.rb",
38
+ "test/rails/public/javascripts/cache/expected.js",
39
+ "test/rails/public/javascripts/projwcss/jscss.css",
40
+ "test/rails/public/javascripts/testing.js",
41
+ "test/rails/public/stylesheets/bar.css",
42
+ "test/rails/public/stylesheets/cache/expected-basic.css",
43
+ "test/rails/public/stylesheets/foo.css",
44
+ "test/stylesheet_test.rb",
45
+ "test/test_helper.rb"
46
+ ]
47
+ s.homepage = %q{http://github.com/thumblemonks/smurf}
48
+ s.rdoc_options = ["--charset=UTF-8"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.3.6}
51
+ s.summary = %q{Rails plugin to automatically minify JS and CSS when their bundles get cached}
52
+ s.test_files = [
53
+ "test/integration_test.rb",
54
+ "test/javascript_test.rb",
55
+ "test/rails/app/controllers/application.rb",
56
+ "test/rails/config/application.rb",
57
+ "test/rails/config/boot.rb",
58
+ "test/rails/config/environment.rb",
59
+ "test/rails/config/environments/test.rb",
60
+ "test/rails/config/routes.rb",
61
+ "test/stylesheet_test.rb",
62
+ "test/test_helper.rb"
40
63
  ]
64
+
65
+ if s.respond_to? :specification_version then
66
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
67
+ s.specification_version = 3
68
+
69
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
70
+ s.add_development_dependency(%q<riot>, [">= 0"])
71
+ else
72
+ s.add_dependency(%q<riot>, [">= 0"])
73
+ end
74
+ else
75
+ s.add_dependency(%q<riot>, [">= 0"])
76
+ end
41
77
  end
78
+
@@ -0,0 +1,23 @@
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
14
+
15
+ # context "link tags when caching on" do
16
+ # setup do
17
+ # javascript_include_tag('testing', "cache" => 'cache/actual')
18
+ # stylesheet_link_tag('foo', 'bar', "cache" => 'cache/actual')
19
+ # end
20
+ #
21
+ # should_have_same_contents('javascripts/cache/expected.js', 'javascripts/cache/actual.js')
22
+ # should_have_same_contents('stylesheets/cache/expected.css', 'stylesheets/cache/actual.css')
23
+ # end # link tags when caching on
@@ -0,0 +1,31 @@
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
+ end # Javascript minifier
@@ -0,0 +1,25 @@
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
+ # Settings in config/environments/* take precedence over those specified here.
13
+ # Application configuration should go into files in config/initializers
14
+ # -- all .rb files in that directory are automatically loaded.
15
+
16
+ # Add additional load paths for your own custom dirs
17
+ # config.load_paths += %W( #{config.root}/... )
18
+
19
+ config.session_store :cookie_store, {:key => "_smurf_session"}
20
+ config.cookie_secret = '731d6426b731d6426b731d6426b731d6426b731d6426b731d6426b731d6426b'
21
+
22
+ # Configure sensitive parameters which will be filtered from the log file.
23
+ config.filter_parameters << :password
24
+ end
25
+ 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 if defined? Gem::RubyGemsVersion
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'
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.4')
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,9 @@
1
- config.cache_classes = true
2
- config.whiny_nils = true
1
+ Smurf::Application.configure do
2
+ config.cache_classes = true
3
+ config.whiny_nils = true
3
4
 
4
- config.action_controller.consider_all_requests_local = true
5
- config.action_controller.perform_caching = true # THIS IS IMPORTANT FOR THE TESTS
5
+ config.action_controller.consider_all_requests_local = true
6
+ config.action_controller.perform_caching = true # THIS IS IMPORTANT FOR THE TESTS
6
7
 
7
- config.action_mailer.delivery_method = :test
8
+ config.action_mailer.delivery_method = :test
9
+ end
@@ -1,4 +1,4 @@
1
- ActionController::Routing::Routes.draw do |map|
1
+ Smurf::Application.routes.draw do |map|
2
2
  map.connect ':controller/service.wsdl', :action => 'wsdl'
3
3
  map.connect ':controller/:action/:id.:format'
4
4
  map.connect ':controller/:action/:id'
@@ -0,0 +1,3 @@
1
+ ul.test li:not(.current) a span {
2
+ display: none;
3
+ }
@@ -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
@@ -1,46 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smurf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ prerelease: true
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 4
9
+ - rails3
10
+ - beta2
11
+ version: 1.0.4.rails3.beta2
5
12
  platform: ruby
6
13
  authors:
7
- - Justin Knowlden
14
+ - Justin 'Gus' Knowlden
8
15
  autorequire:
9
16
  bindir: bin
10
17
  cert_chain: []
11
18
 
12
- date: 2009-10-13 00:00:00 -05:00
19
+ date: 2010-06-03 00:00:00 -05:00
13
20
  default_executable:
14
- dependencies: []
15
-
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: riot
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
16
34
  description: Rails plugin to automatically minify JS and CSS when their bundles get cached. Send in those patches!
17
- email:
18
- - gus@thumblemonks.com
35
+ email: gus@thumblemonks.com
19
36
  executables: []
20
37
 
21
38
  extensions: []
22
39
 
23
- extra_rdoc_files: []
24
-
40
+ extra_rdoc_files:
41
+ - README.markdown
25
42
  files:
43
+ - .gitignore
44
+ - Gemfile
26
45
  - MIT-LICENSE
27
46
  - README.markdown
28
47
  - Rakefile
29
- - init.rb
30
- - install.rb
48
+ - VERSION
31
49
  - lib/smurf.rb
32
50
  - lib/smurf/javascript.rb
51
+ - lib/smurf/noop.rb
33
52
  - lib/smurf/stylesheet.rb
34
- - rails/init.rb
35
53
  - smurf.gemspec
36
- - uninstall.rb
54
+ - test/integration_test.rb
55
+ - test/javascript_test.rb
56
+ - test/rails/app/controllers/application.rb
57
+ - test/rails/config/application.rb
58
+ - test/rails/config/boot.rb
59
+ - test/rails/config/environment.rb
60
+ - test/rails/config/environments/test.rb
61
+ - test/rails/config/routes.rb
62
+ - test/rails/public/javascripts/cache/expected.js
63
+ - test/rails/public/javascripts/projwcss/jscss.css
64
+ - test/rails/public/javascripts/testing.js
65
+ - test/rails/public/stylesheets/bar.css
66
+ - test/rails/public/stylesheets/cache/expected-basic.css
67
+ - test/rails/public/stylesheets/foo.css
68
+ - test/stylesheet_test.rb
69
+ - test/test_helper.rb
37
70
  has_rdoc: true
38
71
  homepage: http://github.com/thumblemonks/smurf
39
72
  licenses: []
40
73
 
41
- post_install_message: Choosy Gargamels choose Thumble Monks.
74
+ post_install_message:
42
75
  rdoc_options:
43
- - --inline-source
44
76
  - --charset=UTF-8
45
77
  require_paths:
46
78
  - lib
@@ -48,31 +80,33 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
80
  requirements:
49
81
  - - ">="
50
82
  - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
51
85
  version: "0"
52
- version:
53
86
  required_rubygems_version: !ruby/object:Gem::Requirement
54
87
  requirements:
55
- - - ">="
88
+ - - ">"
56
89
  - !ruby/object:Gem::Version
57
- version: "0"
58
- version:
90
+ segments:
91
+ - 1
92
+ - 3
93
+ - 1
94
+ version: 1.3.1
59
95
  requirements: []
60
96
 
61
97
  rubyforge_project:
62
- rubygems_version: 1.3.5
98
+ rubygems_version: 1.3.6
63
99
  signing_key:
64
100
  specification_version: 3
65
101
  summary: Rails plugin to automatically minify JS and CSS when their bundles get cached
66
102
  test_files:
103
+ - test/integration_test.rb
104
+ - test/javascript_test.rb
67
105
  - test/rails/app/controllers/application.rb
106
+ - test/rails/config/application.rb
68
107
  - test/rails/config/boot.rb
69
108
  - test/rails/config/environment.rb
70
109
  - test/rails/config/environments/test.rb
71
110
  - test/rails/config/routes.rb
72
- - test/rails/public/javascripts/cache/expected.js
73
- - test/rails/public/javascripts/testing.js
74
- - test/rails/public/stylesheets/bar.css
75
- - test/rails/public/stylesheets/cache/expected.css
76
- - test/rails/public/stylesheets/foo.css
77
- - test/smurf_test.rb
111
+ - test/stylesheet_test.rb
78
112
  - test/test_helper.rb
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', :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