crush 0.2.0 → 0.3.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/.travis.yml +4 -0
- data/README.md +75 -39
- data/crush.gemspec +7 -4
- data/lib/crush.rb +43 -97
- data/lib/crush/all.rb +3 -0
- data/lib/crush/closure.rb +11 -6
- data/lib/crush/css.rb +3 -0
- data/lib/crush/cssmin.rb +13 -5
- data/lib/crush/engine.rb +49 -85
- data/lib/crush/js.rb +3 -0
- data/lib/crush/jsmin.rb +13 -5
- data/lib/crush/packr.rb +14 -2
- data/lib/crush/rainpress.rb +14 -2
- data/lib/crush/uglifier.rb +11 -2
- data/lib/crush/version.rb +1 -1
- data/lib/crush/yui.rb +20 -12
- data/spec/crush/closure_spec.rb +11 -8
- data/spec/crush/cssmin_spec.rb +7 -6
- data/spec/crush/engine_spec.rb +40 -84
- data/spec/crush/jsmin_spec.rb +7 -6
- data/spec/crush/packr_spec.rb +7 -11
- data/spec/crush/rainpress_spec.rb +9 -8
- data/spec/crush/uglifier_spec.rb +11 -8
- data/spec/crush/yui_spec.rb +22 -15
- data/spec/crush_spec.rb +36 -132
- data/spec/spec_helper.rb +3 -6
- metadata +44 -56
data/lib/crush/js.rb
ADDED
data/lib/crush/jsmin.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
require "crush/engine"
|
2
|
+
|
1
3
|
module Crush
|
4
|
+
# Engine implementation of Douglas Crockford's
|
5
|
+
# JSMin JavaScript minifier. See:
|
6
|
+
#
|
7
|
+
# https://rubygems.org/gems/jsmin
|
2
8
|
class JSMin < Engine
|
3
|
-
|
4
|
-
"jsmin"
|
5
|
-
end
|
9
|
+
self.default_mime_type = "application/javascript"
|
6
10
|
|
7
11
|
def self.engine_initialized?
|
8
12
|
!!(defined? ::JSMin)
|
@@ -12,8 +16,12 @@ module Crush
|
|
12
16
|
require_template_library "jsmin"
|
13
17
|
end
|
14
18
|
|
15
|
-
def
|
16
|
-
|
19
|
+
def prepare
|
20
|
+
@output = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def evaluate(scope, locals, &block)
|
24
|
+
@output ||= ::JSMin.minify(data)
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
data/lib/crush/packr.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
|
+
require "crush/engine"
|
2
|
+
|
1
3
|
module Crush
|
4
|
+
# Engine implementation of Dean Edwards'
|
5
|
+
# JavaScript compressor, Packr. See:
|
6
|
+
#
|
7
|
+
# https://rubygems.org/gems/packr
|
2
8
|
class Packr < Engine
|
9
|
+
self.default_mime_type = "application/javascript"
|
10
|
+
|
3
11
|
def self.engine_initialized?
|
4
12
|
!!(defined? ::Packr)
|
5
13
|
end
|
@@ -8,8 +16,12 @@ module Crush
|
|
8
16
|
require_template_library "packr"
|
9
17
|
end
|
10
18
|
|
11
|
-
def
|
12
|
-
|
19
|
+
def prepare
|
20
|
+
@output = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def evaluate(scope, locals, &block)
|
24
|
+
@output ||= ::Packr.pack(data, options)
|
13
25
|
end
|
14
26
|
end
|
15
27
|
end
|
data/lib/crush/rainpress.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
|
+
require "crush/engine"
|
2
|
+
|
1
3
|
module Crush
|
4
|
+
# Engine implementation of the CSS compressor,
|
5
|
+
# Rainpress. See:
|
6
|
+
#
|
7
|
+
# https://rubygems.org/gems/rainpress
|
2
8
|
class Rainpress < Engine
|
9
|
+
self.default_mime_type = "text/css"
|
10
|
+
|
3
11
|
def self.engine_initialized?
|
4
12
|
!!(defined? ::Rainpress)
|
5
13
|
end
|
@@ -8,8 +16,12 @@ module Crush
|
|
8
16
|
require_template_library "rainpress"
|
9
17
|
end
|
10
18
|
|
11
|
-
def
|
12
|
-
|
19
|
+
def prepare
|
20
|
+
@output = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def evaluate(scope, locals, &block)
|
24
|
+
@output ||= ::Rainpress.compress(data, options)
|
13
25
|
end
|
14
26
|
end
|
15
27
|
end
|
data/lib/crush/uglifier.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
|
+
require "crush/engine"
|
2
|
+
|
1
3
|
module Crush
|
4
|
+
# Engine implementation of the UglifyJS
|
5
|
+
# JavaScript compressor. See:
|
6
|
+
#
|
7
|
+
# https://rubygems.org/gems/rainpress
|
2
8
|
class Uglifier < Engine
|
9
|
+
self.default_mime_type = "application/javascript"
|
10
|
+
|
3
11
|
def self.engine_initialized?
|
4
12
|
!!(defined? ::Uglifier)
|
5
13
|
end
|
@@ -10,10 +18,11 @@ module Crush
|
|
10
18
|
|
11
19
|
def prepare
|
12
20
|
@engine = ::Uglifier.new(options)
|
21
|
+
@output = nil
|
13
22
|
end
|
14
23
|
|
15
|
-
def evaluate
|
16
|
-
@engine.compile(data)
|
24
|
+
def evaluate(scope, locals, &block)
|
25
|
+
@output ||= @engine.compile(data)
|
17
26
|
end
|
18
27
|
end
|
19
28
|
end
|
data/lib/crush/version.rb
CHANGED
data/lib/crush/yui.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
+
require "crush/engine"
|
2
|
+
|
1
3
|
module Crush
|
2
4
|
module YUI
|
5
|
+
# Engine implementation the YUI JavaScript
|
6
|
+
# compressor. See:
|
7
|
+
#
|
8
|
+
# https://rubygems.org/gems/yui-compressor
|
3
9
|
class JavaScriptCompressor < Crush::Engine
|
4
|
-
|
5
|
-
"yui_js"
|
6
|
-
end
|
10
|
+
self.default_mime_type = "application/javascript"
|
7
11
|
|
8
12
|
def self.engine_initialized?
|
9
|
-
!!(defined? ::YUI
|
13
|
+
!!(defined? ::YUI && defined? ::YUI::JavaScriptCompressor)
|
10
14
|
end
|
11
15
|
|
12
16
|
def initialize_engine
|
@@ -15,20 +19,23 @@ module Crush
|
|
15
19
|
|
16
20
|
def prepare
|
17
21
|
@engine = ::YUI::JavaScriptCompressor.new(options)
|
22
|
+
@output = nil
|
18
23
|
end
|
19
24
|
|
20
|
-
def evaluate
|
21
|
-
@engine.compress(data)
|
25
|
+
def evaluate(scope, locals, &block)
|
26
|
+
@output ||= @engine.compress(data)
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
30
|
+
# Engine implementation the YUI CSS
|
31
|
+
# compressor. See:
|
32
|
+
#
|
33
|
+
# https://rubygems.org/gems/yui-compressor
|
25
34
|
class CssCompressor < Crush::Engine
|
26
|
-
|
27
|
-
"yui_css"
|
28
|
-
end
|
35
|
+
self.default_mime_type = "text/css"
|
29
36
|
|
30
37
|
def self.engine_initialized?
|
31
|
-
!!(defined? ::YUI
|
38
|
+
!!(defined? ::YUI && defined? ::YUI::CssCompressor)
|
32
39
|
end
|
33
40
|
|
34
41
|
def initialize_engine
|
@@ -37,10 +44,11 @@ module Crush
|
|
37
44
|
|
38
45
|
def prepare
|
39
46
|
@engine = ::YUI::CssCompressor.new(options)
|
47
|
+
@output = nil
|
40
48
|
end
|
41
49
|
|
42
|
-
def evaluate
|
43
|
-
@engine.compress(data)
|
50
|
+
def evaluate(scope, locals, &block)
|
51
|
+
@output ||= @engine.compress(data)
|
44
52
|
end
|
45
53
|
end
|
46
54
|
end
|
data/spec/crush/closure_spec.rb
CHANGED
@@ -1,18 +1,13 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
require "closure-compiler"
|
3
2
|
|
4
3
|
describe Crush::Closure::Compiler do
|
5
|
-
specify { Crush::Closure::Compiler.
|
4
|
+
specify { Crush::Closure::Compiler.default_mime_type.should == "application/javascript" }
|
6
5
|
|
7
|
-
it "
|
8
|
-
Crush.mappings["js"].should include(Crush::Closure::Compiler)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "minifies using Closure::Compiler" do
|
6
|
+
it "compresses using Closure::Compiler" do
|
12
7
|
compressor = mock(:compressor)
|
13
8
|
::Closure::Compiler.should_receive(:new).with({}).and_return(compressor)
|
14
9
|
compressor.should_receive(:compile).with("hello").and_return("world")
|
15
|
-
Crush::Closure::Compiler.
|
10
|
+
Crush::Closure::Compiler.compress("hello").should == "world"
|
16
11
|
end
|
17
12
|
|
18
13
|
it "sends options to Closure::Compiler" do
|
@@ -21,4 +16,12 @@ describe Crush::Closure::Compiler do
|
|
21
16
|
compressor.should_receive(:compile).with("hello").and_return("world")
|
22
17
|
Crush::Closure::Compiler.new(:foo => "bar").compress("hello")
|
23
18
|
end
|
19
|
+
|
20
|
+
it "is registered with Tilt" do
|
21
|
+
compressor = mock(:compressor)
|
22
|
+
::Closure::Compiler.should_receive(:new).with({}).and_return(compressor)
|
23
|
+
compressor.should_receive(:compile).with("hello").and_return("world")
|
24
|
+
Tilt.register Crush::Closure::Compiler, "js"
|
25
|
+
Tilt.new("application.js").compress("hello").should == "world"
|
26
|
+
end
|
24
27
|
end
|
data/spec/crush/cssmin_spec.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
require "cssmin"
|
3
2
|
|
4
3
|
describe Crush::CSSMin do
|
5
|
-
specify { Crush::CSSMin.
|
4
|
+
specify { Crush::CSSMin.default_mime_type.should == "text/css" }
|
6
5
|
|
7
|
-
it "
|
8
|
-
|
6
|
+
it "minifies using CSSMin" do
|
7
|
+
::CSSMin.should_receive(:minify).with("hello").and_return("world")
|
8
|
+
Crush::CSSMin.compress("hello").should == "world"
|
9
9
|
end
|
10
10
|
|
11
|
-
it "
|
11
|
+
it "is registered with Tilt" do
|
12
12
|
::CSSMin.should_receive(:minify).with("hello").and_return("world")
|
13
|
-
Crush::CSSMin
|
13
|
+
Tilt.register Crush::CSSMin, "css"
|
14
|
+
Tilt.new("application.css").compress("hello").should == "world"
|
14
15
|
end
|
15
16
|
end
|
data/spec/crush/engine_spec.rb
CHANGED
@@ -1,110 +1,66 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Crush::Engine do
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
class Stripper < Crush::Engine
|
5
|
+
def evaluate(*args)
|
6
|
+
case options[:direction]
|
7
|
+
when :left
|
8
|
+
data.lstrip
|
9
|
+
when :right
|
10
|
+
data.rstrip
|
11
|
+
else
|
12
|
+
data.strip
|
13
|
+
end
|
10
14
|
end
|
11
15
|
end
|
12
16
|
|
13
|
-
describe "
|
14
|
-
it "
|
15
|
-
|
16
|
-
engine.file.should == "application.js"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#options" do
|
21
|
-
it "returns the options passed to the engine" do
|
22
|
-
engine = MockEngine.new(nil, :foo => "bar") {}
|
23
|
-
engine.options[:foo].should == "bar"
|
24
|
-
engine = MockEngine.new(:bar => "foo") {}
|
25
|
-
engine.options[:bar].should == "foo"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#data" do
|
30
|
-
it "returns the data from the file" do
|
31
|
-
File.stub(:binread => "Hello", :read => "Hello")
|
32
|
-
engine = MockEngine.new("application.js")
|
33
|
-
engine.data.should == "Hello"
|
17
|
+
describe ".compress" do
|
18
|
+
it "compresses the given data" do
|
19
|
+
Stripper.compress(" data ").should == "data"
|
34
20
|
end
|
35
21
|
|
36
|
-
it "
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class InitializingMockEngine < Crush::Engine
|
43
|
-
class << self
|
44
|
-
attr_accessor :initialized_count
|
22
|
+
it "accepts options" do
|
23
|
+
Stripper.compress(" data ", :direction => :left).should == "data "
|
24
|
+
Stripper.compress(" data ", :direction => :right).should == " data"
|
45
25
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
26
|
+
|
27
|
+
it "is aliased as `compile`" do
|
28
|
+
Stripper.compile(" data ").should == "data"
|
49
29
|
end
|
50
30
|
end
|
51
31
|
|
52
|
-
describe "#
|
53
|
-
it "
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
InitializingMockEngine.new
|
58
|
-
InitializingMockEngine.initialized_count.should == 1
|
32
|
+
describe "#initialize" do
|
33
|
+
it "does not raise errors without a file or block" do
|
34
|
+
expect {
|
35
|
+
Stripper.new
|
36
|
+
}.to_not raise_error(ArgumentError)
|
59
37
|
end
|
60
38
|
end
|
61
39
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
describe ".engine_initialized?" do
|
66
|
-
it "returns false before the engine has been initialized" do
|
67
|
-
InitializedMockEngine.engine_initialized?.should be_false
|
40
|
+
describe "#compress" do
|
41
|
+
it "compresses the given data" do
|
42
|
+
Stripper.new.compress(" data ").should == "data"
|
68
43
|
end
|
69
44
|
|
70
|
-
it "
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class PreparingMockEngine < Crush::Engine
|
77
|
-
class << self
|
78
|
-
attr_accessor :prepared_count
|
45
|
+
it "uses options set when initializing" do
|
46
|
+
Stripper.new(:direction => :left).compress(" data ").should == "data "
|
47
|
+
Stripper.new(:direction => :right).compress(" data ").should == " data"
|
79
48
|
end
|
80
49
|
|
81
|
-
|
82
|
-
|
50
|
+
it "is aliased as `compile`" do
|
51
|
+
Stripper.new.compile(" data ").should == "data"
|
83
52
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
it "is called each time an engine is created" do
|
88
|
-
PreparingMockEngine.prepared_count = 0
|
89
|
-
PreparingMockEngine.new
|
90
|
-
PreparingMockEngine.prepared_count.should == 1
|
91
|
-
PreparingMockEngine.new
|
92
|
-
PreparingMockEngine.prepared_count.should == 2
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
class SimpleMockEngine < Crush::Engine
|
97
|
-
def evaluate
|
98
|
-
@data.strip
|
53
|
+
|
54
|
+
it "can be used without an argument" do
|
55
|
+
Stripper.new { " data " }.compress.should == "data"
|
99
56
|
end
|
100
57
|
end
|
101
58
|
|
102
|
-
describe "#
|
103
|
-
it "
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
SimpleMockEngine.new.compress(" hello ").should == "hello"
|
59
|
+
describe "#render" do
|
60
|
+
it "throws an error if used without data" do
|
61
|
+
expect {
|
62
|
+
Stripper.new.render
|
63
|
+
}.to raise_error(ArgumentError)
|
108
64
|
end
|
109
65
|
end
|
110
66
|
end
|
data/spec/crush/jsmin_spec.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
require "jsmin"
|
3
2
|
|
4
3
|
describe Crush::JSMin do
|
5
|
-
specify { Crush::JSMin.
|
4
|
+
specify { Crush::JSMin.default_mime_type.should == "application/javascript" }
|
6
5
|
|
7
|
-
it "
|
8
|
-
|
6
|
+
it "minifies using JSMin" do
|
7
|
+
::JSMin.should_receive(:minify).with("hello").and_return("world")
|
8
|
+
Crush::JSMin.compress("hello").should == "world"
|
9
9
|
end
|
10
10
|
|
11
|
-
it "
|
11
|
+
it "is registered with Tilt" do
|
12
12
|
::JSMin.should_receive(:minify).with("hello").and_return("world")
|
13
|
-
Crush::JSMin
|
13
|
+
Tilt.register Crush::JSMin, "js"
|
14
|
+
Tilt.new("application.js").compress("hello").should == "world"
|
14
15
|
end
|
15
16
|
end
|
data/spec/crush/packr_spec.rb
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
require "packr"
|
3
2
|
|
4
3
|
describe Crush::Packr do
|
5
|
-
specify { Crush::Packr.
|
4
|
+
specify { Crush::Packr.default_mime_type.should == "application/javascript" }
|
6
5
|
|
7
|
-
it "
|
8
|
-
Crush.mappings["js"].should include(Crush::Packr)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "minifies using Packr" do
|
6
|
+
it "compresses using Packr" do
|
12
7
|
::Packr.should_receive(:pack).with("hello", {}).and_return("world")
|
13
|
-
Crush::Packr.
|
8
|
+
Crush::Packr.compress("hello").should == "world"
|
14
9
|
end
|
15
10
|
|
16
|
-
it "
|
17
|
-
::Packr.should_receive(:pack).with("hello",
|
18
|
-
Crush::Packr
|
11
|
+
it "is registered with Tilt" do
|
12
|
+
::Packr.should_receive(:pack).with("hello", {}).and_return("world")
|
13
|
+
Tilt.register Crush::Packr, "js"
|
14
|
+
Tilt.new("application.js").compress("hello").should == "world"
|
19
15
|
end
|
20
16
|
end
|