smurf 1.0.4.rails3.beta3 → 1.0.4

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/.gitignore CHANGED
@@ -4,5 +4,3 @@ test/rails/log/*
4
4
  test/rails/db/*
5
5
  test/rails/public/*/cache/*
6
6
  pkg/*
7
- .bundle
8
- Gemfile.lock
@@ -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 most versions of Rails `2.3.x` and above; including Rails `3.0.0.beta1`.
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,19 +32,27 @@ The following are the rules I applied, gathered from various perusals around the
32
32
 
33
33
  ## Installation
34
34
 
35
- You install Smurf as a gem:
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
36
 
37
- sudo gem install smurf
37
+ sudo gem sources -a http://gemcutter.org
38
38
 
39
- Because this latest version is intended to work with Rails 3 and above, you'll need to update your Gemfile ad add:
39
+ Then, install Smurf as a gem:
40
40
 
41
- gem 'smurf'
41
+ sudo gem install 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.perform_caching = true
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
56
 
49
57
  ### Small suggestion
50
58
 
@@ -56,11 +64,13 @@ Also make sure to at least have this setting in your production.rb:
56
64
 
57
65
  ## Testing
58
66
 
59
- Simple:
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
70
 
61
- rake
71
+ This is the mechanism I used for testing that Smurf works for all versions:
62
72
 
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.
73
+ rake && rake RAILS_GEM_VERSION=2.2.2 && rake RAILS_GEM_VERSION=2.1.2
64
74
 
65
75
  ## Meta
66
76
 
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.rails3.beta3
1
+ 1.0.4
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'smurf'
File without changes
@@ -1,16 +1,16 @@
1
1
  require 'smurf/javascript'
2
2
  require 'smurf/stylesheet'
3
- require 'smurf/noop'
4
3
 
5
4
  module ActionView::Helpers::AssetTagHelper
6
5
  private
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
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
14
14
  end
15
15
  alias_method_chain :join_asset_file_contents, :minification
16
16
  end # ActionView::Helpers::AssetTagHelper
@@ -38,8 +38,6 @@ 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
-
43
41
  EOF = -1
44
42
 
45
43
  @theA = ""
@@ -1,7 +1,5 @@
1
1
  module Smurf
2
2
  class Stylesheet
3
- def self.minifies?(paths) !paths.grep(%r[\.css(\?\d+)?$]).empty?; end
4
-
5
3
  def initialize(content)
6
4
  @content = content.nil? ? nil : minify(content)
7
5
  end
@@ -0,0 +1 @@
1
+ require 'smurf'
@@ -5,9 +5,9 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{smurf}
8
- s.version = "1.0.4.rails3.beta3"
8
+ s.version = "1.0.4"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin 'Gus' Knowlden"]
12
12
  s.date = %q{2010-06-03}
13
13
  s.description = %q{Rails plugin to automatically minify JS and CSS when their bundles get cached. Send in those patches!}
@@ -17,20 +17,18 @@ Gem::Specification.new do |s|
17
17
  ]
18
18
  s.files = [
19
19
  ".gitignore",
20
- "Gemfile",
21
20
  "MIT-LICENSE",
22
21
  "README.markdown",
23
22
  "Rakefile",
24
23
  "VERSION",
24
+ "init.rb",
25
+ "install.rb",
25
26
  "lib/smurf.rb",
26
27
  "lib/smurf/javascript.rb",
27
- "lib/smurf/noop.rb",
28
28
  "lib/smurf/stylesheet.rb",
29
+ "rails/init.rb",
29
30
  "smurf.gemspec",
30
- "test/integration_test.rb",
31
- "test/javascript_test.rb",
32
31
  "test/rails/app/controllers/application.rb",
33
- "test/rails/config/application.rb",
34
32
  "test/rails/config/boot.rb",
35
33
  "test/rails/config/environment.rb",
36
34
  "test/rails/config/environments/test.rb",
@@ -39,10 +37,11 @@ Gem::Specification.new do |s|
39
37
  "test/rails/public/javascripts/projwcss/jscss.css",
40
38
  "test/rails/public/javascripts/testing.js",
41
39
  "test/rails/public/stylesheets/bar.css",
42
- "test/rails/public/stylesheets/cache/expected-basic.css",
40
+ "test/rails/public/stylesheets/cache/expected.css",
43
41
  "test/rails/public/stylesheets/foo.css",
44
- "test/stylesheet_test.rb",
45
- "test/test_helper.rb"
42
+ "test/smurf_test.rb",
43
+ "test/test_helper.rb",
44
+ "uninstall.rb"
46
45
  ]
47
46
  s.homepage = %q{http://github.com/thumblemonks/smurf}
48
47
  s.rdoc_options = ["--charset=UTF-8"]
@@ -50,15 +49,12 @@ Gem::Specification.new do |s|
50
49
  s.rubygems_version = %q{1.3.6}
51
50
  s.summary = %q{Rails plugin to automatically minify JS and CSS when their bundles get cached}
52
51
  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",
52
+ "test/rails/app/controllers/application.rb",
57
53
  "test/rails/config/boot.rb",
58
54
  "test/rails/config/environment.rb",
59
55
  "test/rails/config/environments/test.rb",
60
56
  "test/rails/config/routes.rb",
61
- "test/stylesheet_test.rb",
57
+ "test/smurf_test.rb",
62
58
  "test/test_helper.rb"
63
59
  ]
64
60
 
@@ -1,9 +1,109 @@
1
- begin
2
- require File.expand_path("../../../../.bundle/environment", __FILE__)
3
- rescue LoadError
4
- require 'rubygems'
5
- require 'bundler'
6
- Bundler.setup :default
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
7
106
  end
8
107
 
9
- $:.unshift File.expand_path('../../../../lib', __FILE__)
108
+ # All that for this:
109
+ Rails.boot!
@@ -1,5 +1,18 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
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
3
6
 
4
- # Initialize the rails application
5
- Smurf::Application.initialize!
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
@@ -1,7 +1,7 @@
1
- Smurf::Application.configure do
2
- config.cache_classes = true
3
- config.whiny_nils = true
1
+ config.cache_classes = true
2
+ config.whiny_nils = true
4
3
 
5
- config.action_controller.consider_all_requests_local = true
6
- config.action_controller.perform_caching = true # THIS IS IMPORTANT FOR THE TESTS
7
- end
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
@@ -1,4 +1,4 @@
1
- Smurf::Application.routes.draw do |map|
1
+ ActionController::Routing::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,56 @@
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
@@ -1,20 +1,17 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
- require ::File.expand_path('../rails/config/environment', __FILE__)
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'))
3
5
 
4
- # Rails.public_path = Rails.root + "test" + "rails" + "public"
5
6
  require 'riot'
6
- require 'ostruct'
7
-
8
- # require 'smurf'
9
- require ::File.expand_path('../../lib/smurf', __FILE__)
10
7
 
11
8
  class AssetFile
12
9
  def self.base_path
13
- @path ||= Rails.public_path
10
+ @path ||= File.join(File.join(ENV["RAILS_ROOT"], 'public'))
14
11
  end
15
12
 
16
13
  def self.read(relative_path)
17
- File.read(base_path + relative_path)
14
+ File.read(File.join(base_path, relative_path))
18
15
  end
19
16
  end
20
17
 
@@ -26,23 +23,12 @@ class Riot::Context
26
23
  end
27
24
  end
28
25
 
29
- class Riot::Situation
26
+ Riot::Situation.instance_eval do
30
27
  include ActionView::Helpers::TagHelper
31
28
  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
43
29
  end
44
30
 
45
31
  at_exit do
46
- artifacts = Dir.glob(File.join(AssetFile.base_path, '**', 'cache', 'actual*.*'))
32
+ artifacts = Dir.glob(File.join(AssetFile.base_path, '**', 'cache', 'actual.*'))
47
33
  FileUtils.rm(artifacts)
48
34
  end
File without changes
metadata CHANGED
@@ -1,14 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smurf
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
8
  - 4
9
- - rails3
10
- - beta3
11
- version: 1.0.4.rails3.beta3
9
+ version: 1.0.4
12
10
  platform: ruby
13
11
  authors:
14
12
  - Justin 'Gus' Knowlden
@@ -41,20 +39,18 @@ extra_rdoc_files:
41
39
  - README.markdown
42
40
  files:
43
41
  - .gitignore
44
- - Gemfile
45
42
  - MIT-LICENSE
46
43
  - README.markdown
47
44
  - Rakefile
48
45
  - VERSION
46
+ - init.rb
47
+ - install.rb
49
48
  - lib/smurf.rb
50
49
  - lib/smurf/javascript.rb
51
- - lib/smurf/noop.rb
52
50
  - lib/smurf/stylesheet.rb
51
+ - rails/init.rb
53
52
  - smurf.gemspec
54
- - test/integration_test.rb
55
- - test/javascript_test.rb
56
53
  - test/rails/app/controllers/application.rb
57
- - test/rails/config/application.rb
58
54
  - test/rails/config/boot.rb
59
55
  - test/rails/config/environment.rb
60
56
  - test/rails/config/environments/test.rb
@@ -63,10 +59,11 @@ files:
63
59
  - test/rails/public/javascripts/projwcss/jscss.css
64
60
  - test/rails/public/javascripts/testing.js
65
61
  - test/rails/public/stylesheets/bar.css
66
- - test/rails/public/stylesheets/cache/expected-basic.css
62
+ - test/rails/public/stylesheets/cache/expected.css
67
63
  - test/rails/public/stylesheets/foo.css
68
- - test/stylesheet_test.rb
64
+ - test/smurf_test.rb
69
65
  - test/test_helper.rb
66
+ - uninstall.rb
70
67
  has_rdoc: true
71
68
  homepage: http://github.com/thumblemonks/smurf
72
69
  licenses: []
@@ -85,13 +82,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
82
  version: "0"
86
83
  required_rubygems_version: !ruby/object:Gem::Requirement
87
84
  requirements:
88
- - - ">"
85
+ - - ">="
89
86
  - !ruby/object:Gem::Version
90
87
  segments:
91
- - 1
92
- - 3
93
- - 1
94
- version: 1.3.1
88
+ - 0
89
+ version: "0"
95
90
  requirements: []
96
91
 
97
92
  rubyforge_project:
@@ -100,13 +95,10 @@ signing_key:
100
95
  specification_version: 3
101
96
  summary: Rails plugin to automatically minify JS and CSS when their bundles get cached
102
97
  test_files:
103
- - test/integration_test.rb
104
- - test/javascript_test.rb
105
98
  - test/rails/app/controllers/application.rb
106
- - test/rails/config/application.rb
107
99
  - test/rails/config/boot.rb
108
100
  - test/rails/config/environment.rb
109
101
  - test/rails/config/environments/test.rb
110
102
  - test/rails/config/routes.rb
111
- - test/stylesheet_test.rb
103
+ - test/smurf_test.rb
112
104
  - test/test_helper.rb
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- gem "rails", "3.0.0.beta3"
2
-
3
- group :test do
4
- gem "ruby-debug"
5
- gem "riot", "0.11.0"
6
- end
7
-
@@ -1,8 +0,0 @@
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,13 +0,0 @@
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
@@ -1,31 +0,0 @@
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
@@ -1,17 +0,0 @@
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.session_store :cookie_store, {:key => "_smurf_session"}
13
- config.secret_token = "i own you." * 3
14
-
15
- config.root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
16
- end
17
- end
@@ -1,41 +0,0 @@
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