rapper 0.3.0 → 0.4.0

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 CHANGED
@@ -7,5 +7,5 @@ group :development do
7
7
  gem "bundler", "~> 1.0.0"
8
8
  gem "jeweler", "~> 1.5.2"
9
9
  gem "rake", "~> 0.8.7"
10
- gem "closure-compiler", "~> 1.0.0"
10
+ gem "yui-compressor", "~> 0.9.4"
11
11
  end
@@ -1,16 +1,22 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ POpen4 (0.1.4)
5
+ Platform (>= 0.4.0)
6
+ open4
7
+ Platform (0.4.0)
4
8
  bluecloth (2.0.10)
5
- closure-compiler (1.0.0)
6
9
  git (1.2.5)
7
10
  jeweler (1.5.2)
8
11
  bundler (~> 1.0.0)
9
12
  git (>= 1.2.5)
10
13
  rake
14
+ open4 (1.0.1)
11
15
  rake (0.8.7)
12
16
  rspec (1.3.1)
13
17
  yard (0.6.4)
18
+ yui-compressor (0.9.6)
19
+ POpen4 (>= 0.1.4)
14
20
 
15
21
  PLATFORMS
16
22
  ruby
@@ -18,8 +24,8 @@ PLATFORMS
18
24
  DEPENDENCIES
19
25
  bluecloth (~> 2.0.10)
20
26
  bundler (~> 1.0.0)
21
- closure-compiler (~> 1.0.0)
22
27
  jeweler (~> 1.5.2)
23
28
  rake (~> 0.8.7)
24
29
  rspec (~> 1.3.1)
25
30
  yard (~> 0.6.4)
31
+ yui-compressor (~> 0.9.4)
@@ -39,9 +39,11 @@ Rapper is configured using a YAML file that defines the settings to be used in v
39
39
  compress: true
40
40
  version: true
41
41
  # optional, passed to Google Closure Compiler
42
- closure_compiler:
43
- # default: SIMPLE_OPTIMIZATIONS
44
- compilation_level: ADVANCED_OPTIMIZATIONS
42
+ yui_compressor:
43
+ line_break: 2000 # default: 2000
44
+ munge: false # default: false
45
+ optimize: true # default: true
46
+ preserve_semicolons: false # default: false
45
47
 
46
48
  The only required setting is `definition_root`. (Of course, you'll still need definition files to define the asset packages that you want build. More on that below.)
47
49
 
@@ -52,7 +54,8 @@ The `definition_root` setting in the rapper config is a path to a folder contain
52
54
  --- !omap
53
55
  - root: public/javascripts
54
56
  - destination_root: public/assets # optional, default: root + "/assets"
55
- - tag_root: /javascripts
57
+ - component_tag_root: /javascripts
58
+ - asset_tag_root: /javascripts/assets
56
59
  - suffix: js
57
60
  - assets: !omap
58
61
  - base: !omap
@@ -126,6 +129,7 @@ Rapper's got a Gemfile. You know what to do.
126
129
 
127
130
  ## Version history
128
131
 
132
+ * **0.4.0** - Switching to YUI Compressor for JavaScript compression due to its better handling of local variable compressing in scopes with eval() usage (I'm looking at you, ExtJS). Adding `component_tag_root` and `asset_tag_root` options to allow better control over URLs.
129
133
  * **0.3.0** - Remove hard Closure Compiler dependency (it will still need to be installed to compress JS), shorter view helper method names.
130
134
  * **0.2.4** - Add tag_paths() to get all file paths for a given asset.
131
135
  * **0.2.2** - Change tag_root behavior to not add `.../assets` path suffix when a `destination_root` is defined.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -1,7 +1,7 @@
1
1
  require File.expand_path( File.dirname( __FILE__ ) + "/../yui/css_compressor.rb" )
2
2
  require 'fileutils'
3
3
  begin
4
- require "closure-compiler"
4
+ require "yui/compressor"
5
5
  rescue LoadError; end
6
6
 
7
7
  module Rapper
@@ -15,7 +15,7 @@ module Rapper
15
15
  def compress( file )
16
16
  opts = {}
17
17
  # TODO: Someday this goes away.
18
- opts = get_config( "closure_compiler" ) if file =~ /\.js/
18
+ opts = get_config( "yui_compressor" ) if file =~ /\.js/
19
19
  Rapper::Compressors::Compressor.compress( file, opts )
20
20
  end
21
21
 
@@ -99,26 +99,26 @@ module Rapper
99
99
  end
100
100
  end
101
101
 
102
- # Uses Google's Closure Compiler (via DocumentCloud's closure-compiler gem)
103
- # to compress JavaScrpt.
102
+ # Uses YUI Compressor (via Sam Stephenson's yui-compressor gem) to compress
103
+ # JavaScrpt.
104
104
  class JSCompressor < Compressor
105
105
  register ".js"
106
106
 
107
107
  def self.do_compress( file_path, opts={} )
108
- return unless closure_available?
108
+ return unless compressor_available?
109
109
 
110
- closure = Closure::Compiler.new( opts )
110
+ compressor = YUI::JavaScriptCompressor.new( opts )
111
111
 
112
112
  js = read_file( file_path )
113
113
  destination = writable_file( file_path )
114
114
 
115
- destination.write( closure.compile( js ) )
115
+ destination.write( compressor.compress( js ) )
116
116
  destination.write "\n"
117
117
  destination.close
118
118
  end
119
119
 
120
- def self.closure_available?
121
- Closure::Compiler.is_a?( Class )
120
+ def self.compressor_available?
121
+ YUI::JavaScriptCompressor.is_a?( Class )
122
122
  rescue NameError
123
123
  false
124
124
  end
@@ -73,8 +73,8 @@ module Rapper
73
73
  "compress" => true,
74
74
  "tag_style" => "html5",
75
75
  "version" => true,
76
- "closure_compiler" => {
77
- "compilation_level" => "SIMPLE_OPTIMIZATIONS"
76
+ "yui_compressor" => {
77
+ "line_break" => 2000
78
78
  }
79
79
  }
80
80
  end
@@ -20,6 +20,8 @@ module Rapper
20
20
  @definition["root"]
21
21
  end
22
22
 
23
+ # @return [String] The root for packaged asset files. Defaults to root +
24
+ # "/assets".
23
25
  def destination_root
24
26
  @default_destination_root ||= @definition["root"].gsub( /\/$/, '' ) + "/assets"
25
27
  @definition["destination_root"] || @default_destination_root
@@ -28,13 +30,12 @@ module Rapper
28
30
  # @return [String] The public url root for the asset component files (used
29
31
  # when bundling is off).
30
32
  def component_tag_root
31
- @definition["tag_root"]
33
+ @definition["component_tag_root"]
32
34
  end
33
35
 
34
36
  # @return [String] The public url root for packaged asset files.
35
37
  def asset_tag_root
36
- @default_asset_tag_root ||= @definition["tag_root"].gsub( /\/$/, '' )
37
- @definition["destination_root"] ? @default_asset_tag_root : @default_asset_tag_root + "/assets"
38
+ @definition["asset_tag_root"]
38
39
  end
39
40
 
40
41
  # @return [String] The suffix of files used in this definition.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rapper}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tyson Tate"]
12
- s.date = %q{2011-04-05}
12
+ s.date = %q{2011-04-08}
13
13
  s.description = %q{Static asset packager and compressor with versioning and built-in view helpers. Compresses files only when they need compressing.}
14
14
  s.email = %q{tyson@tysontate.com}
15
15
  s.extra_rdoc_files = [
@@ -140,7 +140,7 @@ Gem::Specification.new do |s|
140
140
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
141
141
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
142
142
  s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
143
- s.add_development_dependency(%q<closure-compiler>, ["~> 1.0.0"])
143
+ s.add_development_dependency(%q<yui-compressor>, ["~> 0.9.4"])
144
144
  else
145
145
  s.add_dependency(%q<rspec>, ["~> 1.3.1"])
146
146
  s.add_dependency(%q<yard>, ["~> 0.6.4"])
@@ -148,7 +148,7 @@ Gem::Specification.new do |s|
148
148
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
149
149
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
150
150
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
151
- s.add_dependency(%q<closure-compiler>, ["~> 1.0.0"])
151
+ s.add_dependency(%q<yui-compressor>, ["~> 0.9.4"])
152
152
  end
153
153
  else
154
154
  s.add_dependency(%q<rspec>, ["~> 1.3.1"])
@@ -157,7 +157,7 @@ Gem::Specification.new do |s|
157
157
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
158
158
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
159
159
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
160
- s.add_dependency(%q<closure-compiler>, ["~> 1.0.0"])
160
+ s.add_dependency(%q<yui-compressor>, ["~> 0.9.4"])
161
161
  end
162
162
  end
163
163
 
@@ -1,6 +1,7 @@
1
1
  --- !omap
2
2
  - root: spec/fixtures/javascripts
3
- - tag_root: /javascripts
3
+ - asset_tag_root: /javascripts/assets
4
+ - component_tag_root: /javascripts
4
5
  - suffix: js
5
6
  - assets: !omap
6
7
  - single_file: !omap
@@ -1,6 +1,7 @@
1
1
  --- !omap
2
2
  - root: spec/fixtures/stylesheets
3
- - tag_root: /stylesheets
3
+ - asset_tag_root: /stylesheets/assets
4
+ - component_tag_root: /stylesheets
4
5
  - suffix: css
5
6
  - assets: !omap
6
7
  - single_file: !omap
@@ -1,7 +1,8 @@
1
1
  --- !omap
2
2
  - root: spec/fixtures/javascripts
3
3
  - destination_root: tmp/custom_destination
4
- - tag_root: /javascripts
4
+ - component_tag_root: /javascripts/components
5
+ - asset_tag_root: /javascripts/compiled
5
6
  - suffix: js
6
7
  - assets: !omap
7
8
  - multiple_files: !omap
@@ -1,6 +1,7 @@
1
1
  --- !omap
2
2
  - root: spec/fixtures/stylesheets
3
- - tag_root: /stylesheets
3
+ - asset_tag_root: /stylesheets/assets
4
+ - component_tag_root: /stylesheets
4
5
  - suffix: css
5
6
  - assets: !omap
6
7
  - multiple_files: !omap
@@ -6,9 +6,8 @@ test:
6
6
  compress: true
7
7
  tag_style: html
8
8
  version: false
9
- closure_compiler:
10
- compilation_level: ADVANCED_OPTIMIZATIONS
11
- formatting: pretty_print
9
+ yui_compressor:
10
+ line_break: 0
12
11
  test_empty:
13
12
  <<: *base
14
13
  test_no_definition_root:
@@ -32,6 +31,11 @@ test_custom_destination:
32
31
  definition_root: spec/fixtures/config/asset_definitions/custom_destination
33
32
  bundle: true
34
33
  compress: false
34
+ test_custom_destination_no_bundle:
35
+ <<: *base
36
+ definition_root: spec/fixtures/config/asset_definitions/custom_destination
37
+ bundle: false
38
+ compress: false
35
39
  test_missing_file:
36
40
  <<: *base
37
41
  definition_root: spec/fixtures/config/asset_definitions/missing_file
@@ -1,6 +1,7 @@
1
1
  --- !omap
2
2
  - root: spec/fixtures/stylesheets
3
- - tag_root: /stylesheets
3
+ - asset_tag_root: /stylesheets/assets
4
+ - component_tag_root: /stylesheets
4
5
  - suffix: css
5
6
  - assets: !omap
6
7
  - base: !omap
@@ -1,6 +1,7 @@
1
1
  --- !omap
2
2
  - root: spec/fixtures/javascripts
3
- - tag_root: /javascripts
3
+ - asset_tag_root: /javascripts/assets
4
+ - component_tag_root: /javascripts
4
5
  - suffix: js
5
6
  - assets: !omap
6
7
  - base: !omap
@@ -1,2 +1 @@
1
- var x=1,y=2;function a(){return true}a=1;b=2;function b(){return false};
2
-
1
+ var x=1;var y=2;function a(){return true}a=1;b=2;function b(){return false};
@@ -1,2 +1 @@
1
- a=1;b=2;function b(){return false}var x=1,y=2;function a(){return true};
2
-
1
+ a=1;b=2;function b(){return false}var x=1;var y=2;function a(){return true};
@@ -1,6 +1,7 @@
1
1
  --- !omap
2
2
  - root: spec/fixtures/stylesheets
3
- - tag_root: /stylesheets
3
+ - asset_tag_root: /stylesheets/assets
4
+ - component_tag_root: /stylesheets
4
5
  - suffix: css
5
6
  - assets: !omap
6
7
  - base: !omap
@@ -1,6 +1,7 @@
1
1
  --- !omap
2
2
  - root: spec/fixtures/javascripts
3
- - tag_root: /javascripts
3
+ - asset_tag_root: /javascripts/assets
4
+ - component_tag_root: /javascripts
4
5
  - suffix: js
5
6
  - assets: !omap
6
7
  - base: !omap
@@ -41,8 +41,8 @@ describe Rapper do
41
41
  rapper.send( :get_config, "bundle" ).should be_true
42
42
  rapper.send( :get_config, "compress" ).should be_true
43
43
  rapper.send( :get_config, "version" ).should be_true
44
- rapper.send( :get_config, "closure_compiler" ).should == {
45
- "compilation_level" => "SIMPLE_OPTIMIZATIONS"
44
+ rapper.send( :get_config, "yui_compressor" ).should == {
45
+ "line_break" => 2000
46
46
  }
47
47
  end
48
48
 
@@ -137,9 +137,25 @@ describe Rapper do
137
137
  Dir[ "tmp/custom_destination/*" ].should == ["tmp/custom_destination/multiple_files.js"]
138
138
  end
139
139
 
140
+ it "uses the asset tag root" do
141
+ @rapper.js_tag( "javascripts", "multiple_files" ).should ==
142
+ "<script src=\"/javascripts/compiled/multiple_files.js?v=f3d9\"></script>"
143
+ end
144
+ end
145
+
146
+ describe "custom definition destination, without bundling" do
147
+ before :each do
148
+ @rapper = Rapper::Engine.new( "spec/fixtures/config/assets.yml", "test_custom_destination_no_bundle" )
149
+ @rapper.package
150
+ end
151
+
152
+ it "works" do
153
+ Dir[ "tmp/custom_destination/*" ].should == ["tmp/custom_destination/multiple_files.js"]
154
+ end
155
+
140
156
  it "doesn't use the defaut '/assets' tag root" do
141
157
  @rapper.js_tag( "javascripts", "multiple_files" ).should ==
142
- "<script src=\"/javascripts/multiple_files.js?v=f3d9\"></script>"
158
+ "<script src=\"/javascripts/components/simple_1.js?v=f3d9\"></script>\n<script src=\"/javascripts/components/simple_2.js?v=f3d9\"></script>"
143
159
  end
144
160
  end
145
161
 
@@ -1,23 +1,10 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe Closure::Compiler do
3
+ describe YUI::JavaScriptCompressor do
4
4
  it "shoud be available" do
5
- closure = Closure::Compiler.new
6
- closure.compile( "var x = 1; var y = 2;" ).should == "var x=1,y=2;\n"
5
+ closure = YUI::JavaScriptCompressor.new
6
+ closure.compress( "var x = 1; var y = 2;" ).should == "var x=1;var y=2;"
7
7
  end
8
-
9
- it "provides whitespace-only, simple, and advanced compression" do
10
- # https://github.com/documentcloud/closure-compiler/blob/master/test/unit/test_closure_compiler.rb
11
-
12
- original = "window.hello = function(name) { return console.log('hello ' + name ); }; hello.squared = function(num) { return num * num; }; hello('world');"
13
- compiled_whitespace = "window.hello=function(name){return console.log(\"hello \"+name)};hello.squared=function(num){return num*num};hello(\"world\");\n"
14
- compiled_simple = "window.hello=function(a){return console.log(\"hello \"+a)};hello.squared=function(a){return a*a};hello(\"world\");\n"
15
- compiled_advanced = "window.a=function(b){return console.log(\"hello \"+b)};hello.b=function(b){return b*b};hello(\"world\");\n"
16
-
17
- Closure::Compiler.new( :compilation_level => "WHITESPACE_ONLY" ).compile(original).should == compiled_whitespace
18
- Closure::Compiler.new.compile(original).should == compiled_simple
19
- Closure::Compiler.new( :compilation_level => "ADVANCED_OPTIMIZATIONS" ).compile(original).should == compiled_advanced
20
- end
21
8
  end
22
9
 
23
10
  describe YUI::CSS do
@@ -33,4 +20,4 @@ describe YUI::CSS do
33
20
  YUI::CSS.compress( test_css ).should == expected_css
34
21
  end
35
22
  end
36
- end
23
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tyson Tate
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-05 00:00:00 -07:00
18
+ date: 2011-04-08 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -121,15 +121,15 @@ dependencies:
121
121
  requirements:
122
122
  - - ~>
123
123
  - !ruby/object:Gem::Version
124
- hash: 23
124
+ hash: 51
125
125
  segments:
126
- - 1
127
- - 0
128
126
  - 0
129
- version: 1.0.0
127
+ - 9
128
+ - 4
129
+ version: 0.9.4
130
130
  type: :development
131
131
  requirement: *id007
132
- name: closure-compiler
132
+ name: yui-compressor
133
133
  description: Static asset packager and compressor with versioning and built-in view helpers. Compresses files only when they need compressing.
134
134
  email: tyson@tysontate.com
135
135
  executables: []