paste 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +20 -36
- data/lib/paste/cache.rb +33 -0
- data/lib/paste/compress.rb +71 -0
- data/lib/paste/erb_renderer.rb +53 -0
- data/lib/paste/glue.rb +46 -3
- data/lib/paste/parser/sprockets.rb +42 -36
- data/lib/paste/rails/helper.rb +27 -16
- data/lib/paste/rails/railtie.rb +7 -7
- data/lib/paste/rails/updater.rb +2 -0
- data/lib/paste/rails.rb +3 -3
- data/lib/paste/resolver.rb +5 -4
- data/lib/paste/tasks/paste.rake +1 -6
- data/lib/paste/version.rb +1 -1
- data/lib/paste.rb +10 -29
- data/spec/paste/cache_spec.rb +41 -0
- data/spec/paste/{js/config_spec.rb → config_spec.rb} +12 -12
- data/spec/paste/erb_spec.rb +88 -0
- data/spec/paste/glue_spec.rb +56 -0
- data/spec/paste/provides_spec.rb +18 -0
- data/spec/paste/rails/helper_spec.rb +45 -26
- data/spec/spec_helper.rb +4 -4
- data/spec/support/helpers.rb +35 -49
- metadata +21 -43
- data/lib/paste/capistrano.rb +0 -32
- data/lib/paste/css/base.rb +0 -6
- data/lib/paste/js/base.rb +0 -26
- data/lib/paste/js/cache.rb +0 -111
- data/lib/paste/js/chain.rb +0 -55
- data/lib/paste/js/compress.rb +0 -46
- data/lib/paste/js/erb_renderer.rb +0 -55
- data/lib/paste/js/unify.rb +0 -38
- data/spec/paste/css/provides_spec.rb +0 -29
- data/spec/paste/js/cache_spec.rb +0 -47
- data/spec/paste/js/chain_spec.rb +0 -133
- data/spec/paste/js/compress_spec.rb +0 -43
- data/spec/paste/js/erb_spec.rb +0 -106
- data/spec/paste/js/unify_spec.rb +0 -90
data/spec/paste/js/erb_spec.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Paste::JS::Base do
|
4
|
-
|
5
|
-
it "should render an erb file into a temporary location" do
|
6
|
-
Paste::JS::Test.write 'foo.js.erb', ''
|
7
|
-
subject.render_all_erb
|
8
|
-
|
9
|
-
subject.erb_path('foo.js').should exist
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should execute the ERB in the file" do
|
13
|
-
Paste::JS::Test.write 'foo.js.erb', '<%= "foo" %><%= "bar" %>'
|
14
|
-
subject.render_all_erb
|
15
|
-
|
16
|
-
subject.erb_path('foo.js').should have_contents('foobar')
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should handle deeply nested erb files alright" do
|
20
|
-
Paste::JS::Test.write 'foo/bar/baz.js.erb', '<%= "foo" %><%= "bar" %>'
|
21
|
-
subject.render_all_erb
|
22
|
-
|
23
|
-
subject.erb_path('foo/bar/baz.js').should have_contents('foobar')
|
24
|
-
end
|
25
|
-
|
26
|
-
it "shouldn't try to render regular js files" do
|
27
|
-
Paste::JS::Test.write 'foo', 'foo()'
|
28
|
-
subject.render_all_erb
|
29
|
-
|
30
|
-
subject.erb_path('foo.js').should_not exist
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should render when being rebuilt" do
|
34
|
-
Paste::JS::Test.write 'foo.js.erb', 'foobar'
|
35
|
-
subject.rebuild!
|
36
|
-
|
37
|
-
subject.erb_path('foo.js').should have_contents('foobar')
|
38
|
-
end
|
39
|
-
|
40
|
-
context "pasting a variety of regular/erb files" do
|
41
|
-
shared_examples_for 'an erb paster' do
|
42
|
-
it "should use the generated ERB file when pasting" do
|
43
|
-
Paste::JS::Test.write 'foo.js.erb', '<%= "foo" %><%= "bar" %>'
|
44
|
-
Paste::JS::Test.write 'bar', "//= require <foo>\nbar()"
|
45
|
-
subject.render_all_erb
|
46
|
-
|
47
|
-
subject.paste('bar')
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should watch for a file to be changed to an ERB file" do
|
51
|
-
Paste::JS::Test.write 'foo', 'foo'
|
52
|
-
result = subject.paste('foo')[:javascript]
|
53
|
-
result.each{ |p| Paste::JS::Test.delete p }
|
54
|
-
Paste::JS::Test.delete_source 'foo'
|
55
|
-
|
56
|
-
Paste::JS::Test.write 'foo.js.erb', '<%= "foo" %><%= "bar" %>'
|
57
|
-
subject.render_all_erb
|
58
|
-
|
59
|
-
subject.paste('foo')
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe Paste::JS::Chain do
|
64
|
-
it_should_behave_like 'an erb paster'
|
65
|
-
end
|
66
|
-
|
67
|
-
describe Paste::JS::Unify do
|
68
|
-
it_should_behave_like 'an erb paster'
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "modifying existing files" do
|
73
|
-
before :each do
|
74
|
-
Paste::JS::Test.write subject.erb_path('foo.js'), 'foo'
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should regenerate the file if the source was modified" do
|
78
|
-
# File is modified after the original one
|
79
|
-
Paste::JS::Test.write 'foo.js.erb', 'foobar', Time.now + 42
|
80
|
-
|
81
|
-
subject.render_all_erb
|
82
|
-
|
83
|
-
subject.erb_path('foo.js').should have_contents('foobar')
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should not regenerate the file if the source was not modified" do
|
87
|
-
Paste::JS::Test.write 'foo.js.erb', 'foobar', Time.now - 42
|
88
|
-
subject.render_all_erb
|
89
|
-
|
90
|
-
subject.erb_path('foo.js').should have_contents('foo')
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "rails" do
|
95
|
-
before :each do
|
96
|
-
Rails = {:foo => 'bar'}
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should allow templates to use Rails instead of ::Rails" do
|
100
|
-
Paste::JS::Test.write 'foo.js.erb', '<%= Rails[:foo] %>'
|
101
|
-
subject.render_all_erb
|
102
|
-
|
103
|
-
subject.erb_path('foo.js').should have_contents('bar')
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
data/spec/paste/js/unify_spec.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Paste::JS::Unify do
|
4
|
-
before :each do
|
5
|
-
Paste::JS::Test.write 'foo', 'foo()'
|
6
|
-
Paste::JS::Test.write 'bar', 'bar()'
|
7
|
-
Paste::JS::Test.write 'foo/baz', 'baz()'
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should generate only one result" do
|
11
|
-
results = subject.paste('foo', 'bar', 'foo/baz')[:javascript]
|
12
|
-
|
13
|
-
results.size.should == 1
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should generate the same results for different forms of the input" do
|
17
|
-
results = subject.paste('foo', 'bar', 'foo/baz')
|
18
|
-
|
19
|
-
results.should == subject.paste('foo', 'foo/baz.js', 'bar.js')
|
20
|
-
results.should == subject.paste('bar', 'foo.js', 'foo/baz')
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should generate the concatenation when the destination doesn't exist" do
|
24
|
-
result = subject.paste('foo', 'bar', 'foo/baz')[:javascript].first
|
25
|
-
|
26
|
-
subject.should have_in_result(result, "foo()\nbar()\nbaz()")
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should rebuild the results after the file has been removed" do
|
30
|
-
result = subject.paste('foo', 'bar', 'foo/baz')[:javascript].first
|
31
|
-
|
32
|
-
Paste::JS::Test.delete result
|
33
|
-
subject.paste('foo', 'bar', 'foo/baz')
|
34
|
-
|
35
|
-
subject.should have_in_result(result, "foo()\nbar()\nbaz()")
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should raise a descriptive exception when the source doesn't exist" do
|
39
|
-
lambda {
|
40
|
-
subject.paste 'random'
|
41
|
-
}.should raise_error(/source random/i)
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "regenerating files" do
|
45
|
-
it "should occur if any file is changed" do
|
46
|
-
result = subject.paste('foo', 'bar')[:javascript].first
|
47
|
-
|
48
|
-
Paste::JS::Test.write 'foo', 'foobar()', Time.now + 42
|
49
|
-
subject.paste('foo', 'bar')
|
50
|
-
|
51
|
-
subject.should have_in_result(result, "foobar()\nbar()")
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should not occur if no files have changed" do
|
55
|
-
result = subject.paste('foo', 'bar')[:javascript].first
|
56
|
-
|
57
|
-
Paste::JS::Test.write 'foo', 'foobar', Time.now - 42
|
58
|
-
subject.paste('foo', 'bar')
|
59
|
-
|
60
|
-
subject.should have_in_result(result, "foo()\nbar()")
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should update the results only if the sources have changed" do
|
64
|
-
subject = described_class.new
|
65
|
-
|
66
|
-
result1 = subject.paste('foo')[:javascript].first
|
67
|
-
result2 = subject.paste('bar', 'foo/baz')[:javascript].first
|
68
|
-
Paste::JS::Test.write 'foo', 'foobar()', Time.now - 42
|
69
|
-
Paste::JS::Test.write 'bar', 'barbar()', Time.now + 42
|
70
|
-
|
71
|
-
subject.rebuild
|
72
|
-
|
73
|
-
subject.should have_in_result(result1, 'foo()')
|
74
|
-
subject.should have_in_result(result2, "barbar()\nbaz()")
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should watch for changes in dependencies as well" do
|
78
|
-
Paste::JS::Test.write 'foo', "//= require <bar>\nfoo"
|
79
|
-
Paste::JS::Test.write 'bar', 'bar'
|
80
|
-
Paste::JS::Test.write 'baz', 'baz'
|
81
|
-
result = subject.paste('foo')[:javascript].first
|
82
|
-
|
83
|
-
Paste::JS::Test.write 'bar', "//= require <baz>\nbar", Time.now + 42
|
84
|
-
|
85
|
-
subject.paste('foo')
|
86
|
-
|
87
|
-
subject.should have_in_result(result, "baz\nbar\nfoo")
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|