rake-pipeline-web-filters 0.5.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/Rakefile +8 -0
- data/lib/rake-pipeline-web-filters.rb +17 -3
- data/lib/rake-pipeline-web-filters/cache_buster_filter.rb +42 -0
- data/lib/rake-pipeline-web-filters/chained_filter.rb +116 -0
- data/lib/rake-pipeline-web-filters/coffee_script_filter.rb +41 -0
- data/lib/rake-pipeline-web-filters/filter_with_dependencies.rb +27 -0
- data/lib/rake-pipeline-web-filters/gzip_filter.rb +59 -0
- data/lib/rake-pipeline-web-filters/handlebars_filter.rb +62 -0
- data/lib/rake-pipeline-web-filters/helpers.rb +100 -18
- data/lib/rake-pipeline-web-filters/iife_filter.rb +38 -0
- data/lib/rake-pipeline-web-filters/less_filter.rb +55 -0
- data/lib/rake-pipeline-web-filters/markdown_filter.rb +70 -0
- data/lib/rake-pipeline-web-filters/minispade_filter.rb +21 -5
- data/lib/rake-pipeline-web-filters/neuter_filter.rb +110 -0
- data/lib/rake-pipeline-web-filters/sass_filter.rb +87 -0
- data/lib/rake-pipeline-web-filters/stylus_filter.rb +59 -0
- data/lib/rake-pipeline-web-filters/tilt_filter.rb +16 -3
- data/lib/rake-pipeline-web-filters/uglify_filter.rb +66 -0
- data/lib/rake-pipeline-web-filters/version.rb +1 -1
- data/lib/rake-pipeline-web-filters/yui_css_filter.rb +70 -0
- data/lib/rake-pipeline-web-filters/yui_javascript_filter.rb +59 -0
- data/rake-pipeline-web-filters.gemspec +10 -1
- data/spec/cache_buster_filter_spec.rb +105 -0
- data/spec/chained_filter_spec.rb +76 -0
- data/spec/coffee_script_filter_spec.rb +110 -0
- data/spec/gzip_filter_spec.rb +49 -0
- data/spec/handlebars_filter_spec.rb +70 -0
- data/spec/helpers_spec.rb +112 -18
- data/spec/iife_filter_spec.rb +55 -0
- data/spec/less_filter_spec.rb +59 -0
- data/spec/markdown_filter_spec.rb +86 -0
- data/spec/minispade_filter_spec.rb +47 -15
- data/spec/neuter_filter_spec.rb +204 -0
- data/spec/sass_filter_spec.rb +147 -0
- data/spec/spec_helper.rb +10 -1
- data/spec/stylus_filter_spec.rb +69 -0
- data/spec/tilt_filter_spec.rb +25 -1
- data/spec/uglify_filter_spec.rb +82 -0
- data/spec/yui_css_filter_spec.rb +88 -0
- data/spec/yui_javascript_filter_spec.rb +68 -0
- metadata +225 -19
- data/lib/rake-pipeline-web-filters/ordering_concat_filter.rb +0 -38
- data/lib/rake-pipeline-web-filters/sass_compiler.rb +0 -53
- data/spec/ordering_concat_filter_spec.rb +0 -39
- data/spec/sass_compiler_spec.rb +0 -89
@@ -0,0 +1,110 @@
|
|
1
|
+
describe "CoffeeScriptFilter" do
|
2
|
+
CoffeeScriptFilter ||= Rake::Pipeline::Web::Filters::CoffeeScriptFilter
|
3
|
+
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
|
4
|
+
|
5
|
+
let(:coffee_input) { <<-COFFEE }
|
6
|
+
x = 1;
|
7
|
+
|
8
|
+
y = ->
|
9
|
+
x += 1
|
10
|
+
COFFEE
|
11
|
+
|
12
|
+
let(:expected_coffee_output) { <<-HTML }
|
13
|
+
(function() {
|
14
|
+
var x, y;
|
15
|
+
|
16
|
+
x = 1;
|
17
|
+
|
18
|
+
y = function() {
|
19
|
+
return x += 1;
|
20
|
+
};
|
21
|
+
|
22
|
+
}).call(this);
|
23
|
+
HTML
|
24
|
+
|
25
|
+
let(:expected_unwrapped_coffee_output) { <<-HTML }
|
26
|
+
var x, y;
|
27
|
+
|
28
|
+
x = 1;
|
29
|
+
|
30
|
+
y = function() {
|
31
|
+
return x += 1;
|
32
|
+
};
|
33
|
+
HTML
|
34
|
+
|
35
|
+
def input_file(name, content)
|
36
|
+
MemoryFileWrapper.new("/path/to/input", name, "UTF-8", content)
|
37
|
+
end
|
38
|
+
|
39
|
+
def output_file(name)
|
40
|
+
MemoryFileWrapper.new("/path/to/output", name, "UTF-8")
|
41
|
+
end
|
42
|
+
|
43
|
+
def should_match(expected, output)
|
44
|
+
"#{expected}\n".gsub(/\n+/, "\n").should == "#{output}\n".gsub(/\n+/, "\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup_filter(filter)
|
48
|
+
filter.file_wrapper_class = MemoryFileWrapper
|
49
|
+
filter.input_files = [input_file("input.coffee", coffee_input)]
|
50
|
+
filter.output_root = "/path/to/output"
|
51
|
+
filter.rake_application = Rake::Application.new
|
52
|
+
filter
|
53
|
+
end
|
54
|
+
|
55
|
+
it "generates output" do
|
56
|
+
filter = setup_filter CoffeeScriptFilter.new
|
57
|
+
|
58
|
+
filter.output_files.should == [output_file("input.js")]
|
59
|
+
|
60
|
+
tasks = filter.generate_rake_tasks
|
61
|
+
tasks.each(&:invoke)
|
62
|
+
|
63
|
+
file = MemoryFileWrapper.files["/path/to/output/input.js"]
|
64
|
+
should_match file.body, expected_coffee_output
|
65
|
+
file.encoding.should == "UTF-8"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "generates unwrapped output" do
|
69
|
+
filter = setup_filter CoffeeScriptFilter.new(:no_wrap => true)
|
70
|
+
|
71
|
+
filter.output_files.should == [output_file("input.js")]
|
72
|
+
|
73
|
+
tasks = filter.generate_rake_tasks
|
74
|
+
tasks.each(&:invoke)
|
75
|
+
|
76
|
+
file = MemoryFileWrapper.files["/path/to/output/input.js"]
|
77
|
+
should_match file.body, expected_unwrapped_coffee_output
|
78
|
+
file.encoding.should == "UTF-8"
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "naming output files" do
|
82
|
+
it "translates .coffee extensions to .js by default" do
|
83
|
+
filter = setup_filter CoffeeScriptFilter.new
|
84
|
+
filter.output_files.first.path.should == "input.js"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "accepts a block to customize output file names" do
|
88
|
+
filter = setup_filter(CoffeeScriptFilter.new { |input| "octopus" })
|
89
|
+
filter.output_files.first.path.should == "octopus"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "invalid input" do
|
94
|
+
let(:coffee_input) { <<-COFFEE }
|
95
|
+
y = function(){
|
96
|
+
return "whoops there javascript in here!"
|
97
|
+
}
|
98
|
+
COFFEE
|
99
|
+
|
100
|
+
it "has a useful error message including the input file name" do
|
101
|
+
filter = setup_filter CoffeeScriptFilter.new
|
102
|
+
tasks = filter.generate_rake_tasks
|
103
|
+
lambda {
|
104
|
+
tasks.each(&:invoke)
|
105
|
+
}.should raise_error(ExecJS::RuntimeError, /Error compiling input.coffee.+line 1/i)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'stringio'
|
3
|
+
require 'zlib'
|
4
|
+
|
5
|
+
describe "GzipFilter" do
|
6
|
+
GzipFilter ||= Rake::Pipeline::Web::Filters::GzipFilter
|
7
|
+
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
|
8
|
+
|
9
|
+
let(:input) { "(function(){console.log('gzip me')})();" }
|
10
|
+
|
11
|
+
def input_file(name, content)
|
12
|
+
MemoryFileWrapper.new("/path/to/input", name, "UTF-8", content)
|
13
|
+
end
|
14
|
+
|
15
|
+
def output_file(name)
|
16
|
+
MemoryFileWrapper.new("/path/to/output", name, "BINARY")
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup_filter(filter)
|
20
|
+
filter.file_wrapper_class = MemoryFileWrapper
|
21
|
+
filter.input_files = [input_file("test.js", input)]
|
22
|
+
filter.output_root = "/path/to/output"
|
23
|
+
filter.rake_application = Rake::Application.new
|
24
|
+
filter
|
25
|
+
end
|
26
|
+
|
27
|
+
it "generates output" do
|
28
|
+
filter = setup_filter GzipFilter.new
|
29
|
+
filter.output_files.should == [output_file("test.js.gz")]
|
30
|
+
tasks = filter.generate_rake_tasks
|
31
|
+
tasks.each(&:invoke)
|
32
|
+
file = MemoryFileWrapper.files["/path/to/output/test.js.gz"]
|
33
|
+
Zlib::GzipReader.new(StringIO.new(file.body)).read.should == input
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "naming output files" do
|
37
|
+
it "translates extensions to .*.gz by default" do
|
38
|
+
filter = setup_filter GzipFilter.new
|
39
|
+
filter.output_files.first.path.should == "test.js.gz"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "accepts a block to customize output file names" do
|
43
|
+
filter = setup_filter(GzipFilter.new { |input| "octopus" })
|
44
|
+
filter.output_files.first.path.should == "octopus"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
describe "HandlebarsFilter" do
|
2
|
+
HandlebarsFilter ||= Rake::Pipeline::Web::Filters::HandlebarsFilter
|
3
|
+
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
|
4
|
+
|
5
|
+
let(:handlebars_input) {
|
6
|
+
'<h1 class="title">{{title}}</h1>'
|
7
|
+
}
|
8
|
+
|
9
|
+
let(:expected_output) {
|
10
|
+
"Ember.TEMPLATES['test']=Ember.Handlebars.compile(\"<h1 class=\\\"title\\\">{{title}}</h1>\");"
|
11
|
+
}
|
12
|
+
|
13
|
+
def input_file(name, content)
|
14
|
+
MemoryFileWrapper.new("/path/to/input", name, "UTF-8", content)
|
15
|
+
end
|
16
|
+
|
17
|
+
def output_file(name)
|
18
|
+
MemoryFileWrapper.new("/path/to/output", name, "UTF-8")
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup_filter(filter, input_filename = "test.handlebars")
|
22
|
+
filter.file_wrapper_class = MemoryFileWrapper
|
23
|
+
filter.input_files = [input_file(input_filename, handlebars_input)]
|
24
|
+
filter.output_root = "/path/to/output"
|
25
|
+
filter.rake_application = Rake::Application.new
|
26
|
+
filter
|
27
|
+
end
|
28
|
+
|
29
|
+
it "generates output" do
|
30
|
+
filter = setup_filter HandlebarsFilter.new
|
31
|
+
|
32
|
+
filter.output_files.should == [output_file("test.js")]
|
33
|
+
|
34
|
+
tasks = filter.generate_rake_tasks
|
35
|
+
tasks.each(&:invoke)
|
36
|
+
|
37
|
+
file = MemoryFileWrapper.files["/path/to/output/test.js"]
|
38
|
+
file.body.should == expected_output
|
39
|
+
file.encoding.should == "UTF-8"
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "naming output files" do
|
43
|
+
it "translates .handlebars extensions to .js by default" do
|
44
|
+
filter = setup_filter HandlebarsFilter.new, "test.handlebars"
|
45
|
+
filter.output_files.first.path.should == "test.js"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "translates .hbs extensions to .js by default" do
|
49
|
+
filter = setup_filter HandlebarsFilter.new, "test.hbs"
|
50
|
+
filter.output_files.first.path.should == "test.js"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "accepts a block to customize output file names" do
|
54
|
+
filter = setup_filter(HandlebarsFilter.new { |input| "squid" })
|
55
|
+
filter.output_files.first.path.should == "squid"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "options" do
|
60
|
+
it "should allow an option to name the key" do
|
61
|
+
filter = setup_filter(HandlebarsFilter.new(:key_name_proc => proc { |input| "new_name_key" }))
|
62
|
+
|
63
|
+
tasks = filter.generate_rake_tasks
|
64
|
+
tasks.each(&:invoke)
|
65
|
+
|
66
|
+
file = MemoryFileWrapper.files["/path/to/output/test.js"]
|
67
|
+
file.body.should =~ /^Ember\.TEMPLATES\['new_name_key'\]/
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/helpers_spec.rb
CHANGED
@@ -1,32 +1,17 @@
|
|
1
1
|
require "rake-pipeline-web-filters/helpers"
|
2
2
|
|
3
3
|
describe "Helpers" do
|
4
|
-
|
5
4
|
let(:pipeline) { Rake::Pipeline.new }
|
6
|
-
let(:dsl) { Rake::Pipeline::DSL.new(pipeline) }
|
5
|
+
let(:dsl) { Rake::Pipeline::DSL::PipelineDSL.new(pipeline) }
|
7
6
|
|
8
7
|
before do
|
9
|
-
pipeline.
|
8
|
+
pipeline.add_input '.'
|
10
9
|
end
|
11
10
|
|
12
11
|
def filter
|
13
12
|
pipeline.filters.last
|
14
13
|
end
|
15
14
|
|
16
|
-
describe "#concat" do
|
17
|
-
it "creates a ConcatFilter" do
|
18
|
-
dsl.concat "octopus"
|
19
|
-
filter.should be_kind_of(Rake::Pipeline::ConcatFilter)
|
20
|
-
end
|
21
|
-
|
22
|
-
context "passed an Array first argument" do
|
23
|
-
it "creates an OrderingConcatFilter" do
|
24
|
-
dsl.concat ["octopus"]
|
25
|
-
filter.should be_kind_of(Rake::Pipeline::Web::Filters::OrderingConcatFilter)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
15
|
describe "#minispade" do
|
31
16
|
it "creates a MinispadeFilter" do
|
32
17
|
dsl.minispade
|
@@ -37,7 +22,14 @@ describe "Helpers" do
|
|
37
22
|
describe "#sass" do
|
38
23
|
it "creates a SassCompiler" do
|
39
24
|
dsl.sass
|
40
|
-
filter.should be_kind_of(Rake::Pipeline::Web::Filters::
|
25
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::SassFilter)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#stylus" do
|
30
|
+
it "creates a StylusCompiler" do
|
31
|
+
dsl.stylus
|
32
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::StylusFilter)
|
41
33
|
end
|
42
34
|
end
|
43
35
|
|
@@ -47,4 +39,106 @@ describe "Helpers" do
|
|
47
39
|
filter.should be_kind_of(Rake::Pipeline::Web::Filters::TiltFilter)
|
48
40
|
end
|
49
41
|
end
|
42
|
+
|
43
|
+
describe "#markdown" do
|
44
|
+
it "creates a MarkdownCompiler" do
|
45
|
+
dsl.markdown
|
46
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::MarkdownFilter)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#cache_buster" do
|
51
|
+
it "creates a CacheBuster" do
|
52
|
+
dsl.cache_buster
|
53
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::CacheBusterFilter)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#coffee_script" do
|
58
|
+
it "creates a CoffeeScriptCompiler" do
|
59
|
+
dsl.coffee_script
|
60
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::CoffeeScriptFilter)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#yui_javascript" do
|
65
|
+
it "creates a YUIJavaScriptCompressor" do
|
66
|
+
dsl.yui_javascript
|
67
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::YUIJavaScriptFilter)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#yui_css" do
|
72
|
+
it "creates a YUICssCompressor" do
|
73
|
+
dsl.yui_css
|
74
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::YUICssFilter)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#uglify" do
|
79
|
+
it "creates an UglifyFilter" do
|
80
|
+
dsl.uglify
|
81
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::UglifyFilter)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#less" do
|
86
|
+
it "creates a LessFilter" do
|
87
|
+
dsl.less
|
88
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::LessFilter)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#gzip" do
|
93
|
+
it "creates a GzipFilter" do
|
94
|
+
dsl.gzip
|
95
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::GzipFilter)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#handlebars" do
|
100
|
+
it "creates a HandlebarsFilter" do
|
101
|
+
dsl.handlebars
|
102
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::HandlebarsFilter)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#iffe" do
|
107
|
+
it "creates a IifeFilter" do
|
108
|
+
dsl.iife
|
109
|
+
filter.should be_kind_of(Rake::Pipeline::Web::Filters::IifeFilter)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "ProjectHelpers" do
|
115
|
+
def project
|
116
|
+
@project ||= Rake::Pipeline::Project.new
|
117
|
+
end
|
118
|
+
|
119
|
+
def dsl
|
120
|
+
@dsl ||= Rake::Pipeline::DSL::ProjectDSL.new(project)
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "register" do
|
124
|
+
it "registers filters per file name" do
|
125
|
+
dsl.register :coffee, Rake::Pipeline::Web::Filters::CoffeeScriptFilter
|
126
|
+
dsl.register :handlebars, Rake::Pipeline::Web::Filters::HandlebarsFilter
|
127
|
+
|
128
|
+
dsl.input "lib" do
|
129
|
+
concat "lib.js"
|
130
|
+
end
|
131
|
+
|
132
|
+
dsl.input "tests" do
|
133
|
+
concat "tests.js"
|
134
|
+
end
|
135
|
+
|
136
|
+
project.pipelines.size.should == 2
|
137
|
+
|
138
|
+
project.pipelines.each do |pipeline|
|
139
|
+
pipeline.filters.first.should be_kind_of Rake::Pipeline::Web::Filters::ChainedFilter
|
140
|
+
pipeline.filters.first.filters.keys.should == [:coffee, :handlebars]
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
50
144
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
describe "IifeFilter" do
|
2
|
+
IifeFilter ||= Rake::Pipeline::Web::Filters::IifeFilter
|
3
|
+
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
|
4
|
+
|
5
|
+
let(:js_input) { <<-HERE }
|
6
|
+
var name = "Truckasaurus Gates";
|
7
|
+
HERE
|
8
|
+
|
9
|
+
let(:expected_js_output) { <<-HERE }
|
10
|
+
(function() {
|
11
|
+
var name = "Truckasaurus Gates";
|
12
|
+
})();
|
13
|
+
HERE
|
14
|
+
|
15
|
+
def input_file(name, content)
|
16
|
+
MemoryFileWrapper.new("/path/to/input", name, "UTF-8", content)
|
17
|
+
end
|
18
|
+
|
19
|
+
def output_file(name)
|
20
|
+
MemoryFileWrapper.new("/path/to/output", name, "UTF-8")
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_filter(filter)
|
24
|
+
filter.file_wrapper_class = MemoryFileWrapper
|
25
|
+
filter.input_files = [input_file("name.js", js_input)]
|
26
|
+
filter.output_root = "/path/to/output"
|
27
|
+
filter.rake_application = Rake::Application.new
|
28
|
+
filter
|
29
|
+
end
|
30
|
+
|
31
|
+
it "generates output" do
|
32
|
+
filter = setup_filter IifeFilter.new
|
33
|
+
|
34
|
+
filter.output_files.should == [output_file("name.js")]
|
35
|
+
|
36
|
+
tasks = filter.generate_rake_tasks
|
37
|
+
tasks.each(&:invoke)
|
38
|
+
|
39
|
+
file = MemoryFileWrapper.files["/path/to/output/name.js"]
|
40
|
+
file.body.should == expected_js_output.chomp
|
41
|
+
file.encoding.should == "UTF-8"
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "naming output files" do
|
45
|
+
it "translates .js extensions to .min.js by default" do
|
46
|
+
filter = setup_filter IifeFilter.new
|
47
|
+
filter.output_files.first.path.should == "name.js"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "accepts a block to customize output file names" do
|
51
|
+
filter = setup_filter(IifeFilter.new { |input| "octopus" })
|
52
|
+
filter.output_files.first.path.should == "octopus"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
describe "LessFilter" do
|
2
|
+
LessFilter ||= Rake::Pipeline::Web::Filters::LessFilter
|
3
|
+
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
|
4
|
+
|
5
|
+
let(:less_input) { <<-SCSS }
|
6
|
+
@blue: #3bbfce;
|
7
|
+
|
8
|
+
.border {
|
9
|
+
border-color: @blue;
|
10
|
+
}
|
11
|
+
SCSS
|
12
|
+
|
13
|
+
let(:expected_css_output) { <<-CSS }
|
14
|
+
.border {
|
15
|
+
border-color: #3bbfce;
|
16
|
+
}
|
17
|
+
CSS
|
18
|
+
|
19
|
+
def input_file(name, content)
|
20
|
+
MemoryFileWrapper.new("/path/to/input", name, "UTF-8", content)
|
21
|
+
end
|
22
|
+
|
23
|
+
def output_file(name)
|
24
|
+
MemoryFileWrapper.new("/path/to/output", name, "UTF-8")
|
25
|
+
end
|
26
|
+
|
27
|
+
def setup_filter(filter)
|
28
|
+
filter.file_wrapper_class = MemoryFileWrapper
|
29
|
+
filter.input_files = [input_file("border.less", less_input)]
|
30
|
+
filter.output_root = "/path/to/output"
|
31
|
+
filter.rake_application = Rake::Application.new
|
32
|
+
filter
|
33
|
+
end
|
34
|
+
|
35
|
+
it "generates output" do
|
36
|
+
filter = setup_filter LessFilter.new
|
37
|
+
|
38
|
+
filter.output_files.should == [output_file("border.css")]
|
39
|
+
|
40
|
+
tasks = filter.generate_rake_tasks
|
41
|
+
tasks.each(&:invoke)
|
42
|
+
|
43
|
+
file = MemoryFileWrapper.files["/path/to/output/border.css"]
|
44
|
+
file.body.should == expected_css_output
|
45
|
+
file.encoding.should == "UTF-8"
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "naming output files" do
|
49
|
+
it "translates .less extensions to .css by default" do
|
50
|
+
filter = setup_filter LessFilter.new
|
51
|
+
filter.output_files.first.path.should == "border.css"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "accepts a block to customize output file names" do
|
55
|
+
filter = setup_filter(LessFilter.new { |input| "octopus" })
|
56
|
+
filter.output_files.first.path.should == "octopus"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|