rake-pipeline-web-filters-fork 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +11 -0
  4. data/.yardopts +2 -0
  5. data/Gemfile +6 -0
  6. data/README.markdown +58 -0
  7. data/README.yard +25 -0
  8. data/Rakefile +10 -0
  9. data/lib/rake-pipeline-web-filters.rb +31 -0
  10. data/lib/rake-pipeline-web-filters/cache_buster_filter.rb +42 -0
  11. data/lib/rake-pipeline-web-filters/chained_filter.rb +116 -0
  12. data/lib/rake-pipeline-web-filters/coffee_script_filter.rb +41 -0
  13. data/lib/rake-pipeline-web-filters/filter_with_dependencies.rb +27 -0
  14. data/lib/rake-pipeline-web-filters/gzip_filter.rb +59 -0
  15. data/lib/rake-pipeline-web-filters/handlebars_filter.rb +62 -0
  16. data/lib/rake-pipeline-web-filters/helpers.rb +138 -0
  17. data/lib/rake-pipeline-web-filters/iife_filter.rb +38 -0
  18. data/lib/rake-pipeline-web-filters/jade_filter.rb +61 -0
  19. data/lib/rake-pipeline-web-filters/less_filter.rb +55 -0
  20. data/lib/rake-pipeline-web-filters/markdown_filter.rb +70 -0
  21. data/lib/rake-pipeline-web-filters/minispade_filter.rb +63 -0
  22. data/lib/rake-pipeline-web-filters/neuter_filter.rb +110 -0
  23. data/lib/rake-pipeline-web-filters/sass_filter.rb +87 -0
  24. data/lib/rake-pipeline-web-filters/stylus_filter.rb +59 -0
  25. data/lib/rake-pipeline-web-filters/tilt_filter.rb +70 -0
  26. data/lib/rake-pipeline-web-filters/uglify_filter.rb +82 -0
  27. data/lib/rake-pipeline-web-filters/version.rb +9 -0
  28. data/lib/rake-pipeline-web-filters/yui_css_filter.rb +70 -0
  29. data/lib/rake-pipeline-web-filters/yui_javascript_filter.rb +59 -0
  30. data/rake-pipeline-web-filters.gemspec +33 -0
  31. data/spec/cache_buster_filter_spec.rb +108 -0
  32. data/spec/chained_filter_spec.rb +79 -0
  33. data/spec/coffee_script_filter_spec.rb +113 -0
  34. data/spec/gzip_filter_spec.rb +52 -0
  35. data/spec/handlebars_filter_spec.rb +73 -0
  36. data/spec/helpers_spec.rb +146 -0
  37. data/spec/iife_filter_spec.rb +58 -0
  38. data/spec/jade_filter_spec.rb +92 -0
  39. data/spec/less_filter_spec.rb +62 -0
  40. data/spec/markdown_filter_spec.rb +89 -0
  41. data/spec/minispade_filter_spec.rb +82 -0
  42. data/spec/neuter_filter_spec.rb +216 -0
  43. data/spec/sass_filter_spec.rb +152 -0
  44. data/spec/spec_helper.rb +28 -0
  45. data/spec/stylus_filter_spec.rb +72 -0
  46. data/spec/support/spec_helpers/file_utils.rb +33 -0
  47. data/spec/support/spec_helpers/filters.rb +37 -0
  48. data/spec/support/spec_helpers/input_helpers.rb +23 -0
  49. data/spec/support/spec_helpers/memory_file_wrapper.rb +38 -0
  50. data/spec/support/spec_helpers/memory_manifest.rb +19 -0
  51. data/spec/tilt_filter_spec.rb +82 -0
  52. data/spec/uglify_filter_spec.rb +128 -0
  53. data/spec/yui_css_filter_spec.rb +91 -0
  54. data/spec/yui_javascript_filter_spec.rb +71 -0
  55. metadata +308 -0
@@ -0,0 +1,73 @@
1
+ describe "HandlebarsFilter" do
2
+ HandlebarsFilter ||= Rake::Pipeline::Web::Filters::HandlebarsFilter
3
+ MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
4
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
5
+
6
+ let(:handlebars_input) {
7
+ '<h1 class="title">{{title}}</h1>'
8
+ }
9
+
10
+ let(:expected_output) {
11
+ "Ember.TEMPLATES['test']=Ember.Handlebars.compile(\"<h1 class=\\\"title\\\">{{title}}</h1>\");"
12
+ }
13
+
14
+ def input_file(name, content)
15
+ MemoryFileWrapper.new("/path/to/input", name, "UTF-8", content)
16
+ end
17
+
18
+ def output_file(name)
19
+ MemoryFileWrapper.new("/path/to/output", name, "UTF-8")
20
+ end
21
+
22
+ def setup_filter(filter, input_filename = "test.handlebars")
23
+ filter.file_wrapper_class = MemoryFileWrapper
24
+ filter.manifest = MemoryManifest.new
25
+ filter.last_manifest = MemoryManifest.new
26
+ filter.input_files = [input_file(input_filename, handlebars_input)]
27
+ filter.output_root = "/path/to/output"
28
+ filter.rake_application = Rake::Application.new
29
+ filter
30
+ end
31
+
32
+ it "generates output" do
33
+ filter = setup_filter HandlebarsFilter.new
34
+
35
+ filter.output_files.should == [output_file("test.js")]
36
+
37
+ tasks = filter.generate_rake_tasks
38
+ tasks.each(&:invoke)
39
+
40
+ file = MemoryFileWrapper.files["/path/to/output/test.js"]
41
+ file.body.should == expected_output
42
+ file.encoding.should == "UTF-8"
43
+ end
44
+
45
+ describe "naming output files" do
46
+ it "translates .handlebars extensions to .js by default" do
47
+ filter = setup_filter HandlebarsFilter.new, "test.handlebars"
48
+ filter.output_files.first.path.should == "test.js"
49
+ end
50
+
51
+ it "translates .hbs extensions to .js by default" do
52
+ filter = setup_filter HandlebarsFilter.new, "test.hbs"
53
+ filter.output_files.first.path.should == "test.js"
54
+ end
55
+
56
+ it "accepts a block to customize output file names" do
57
+ filter = setup_filter(HandlebarsFilter.new { |input| "squid" })
58
+ filter.output_files.first.path.should == "squid"
59
+ end
60
+ end
61
+
62
+ describe "options" do
63
+ it "should allow an option to name the key" do
64
+ filter = setup_filter(HandlebarsFilter.new(:key_name_proc => proc { |input| "new_name_key" }))
65
+
66
+ tasks = filter.generate_rake_tasks
67
+ tasks.each(&:invoke)
68
+
69
+ file = MemoryFileWrapper.files["/path/to/output/test.js"]
70
+ file.body.should =~ /^Ember\.TEMPLATES\['new_name_key'\]/
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,146 @@
1
+ require "rake-pipeline-web-filters/helpers"
2
+
3
+ describe "Helpers" do
4
+ let(:pipeline) { Rake::Pipeline.new }
5
+ let(:dsl) { Rake::Pipeline::DSL::PipelineDSL.new(pipeline) }
6
+
7
+ before do
8
+ pipeline.add_input '.'
9
+ end
10
+
11
+ def filter
12
+ pipeline.filters.last
13
+ end
14
+
15
+ describe "#minispade" do
16
+ it "creates a MinispadeFilter" do
17
+ dsl.minispade
18
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::MinispadeFilter)
19
+ end
20
+ end
21
+
22
+ describe "#sass" do
23
+ it "creates a SassCompiler" do
24
+ dsl.sass
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)
33
+ end
34
+ end
35
+
36
+ describe "#jade" do
37
+ it "creates a JadeCompiler" do
38
+ dsl.jade
39
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::JadeFilter)
40
+ end
41
+ end
42
+
43
+ describe "#tilt" do
44
+ it "creates a TiltFilter" do
45
+ dsl.tilt
46
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::TiltFilter)
47
+ end
48
+ end
49
+
50
+ describe "#markdown" do
51
+ it "creates a MarkdownCompiler" do
52
+ dsl.markdown
53
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::MarkdownFilter)
54
+ end
55
+ end
56
+
57
+ describe "#cache_buster" do
58
+ it "creates a CacheBuster" do
59
+ dsl.cache_buster
60
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::CacheBusterFilter)
61
+ end
62
+ end
63
+
64
+ describe "#coffee_script" do
65
+ it "creates a CoffeeScriptCompiler" do
66
+ dsl.coffee_script
67
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::CoffeeScriptFilter)
68
+ end
69
+ end
70
+
71
+ describe "#yui_javascript" do
72
+ it "creates a YUIJavaScriptCompressor" do
73
+ dsl.yui_javascript
74
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::YUIJavaScriptFilter)
75
+ end
76
+ end
77
+
78
+ describe "#yui_css" do
79
+ it "creates a YUICssCompressor" do
80
+ dsl.yui_css
81
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::YUICssFilter)
82
+ end
83
+ end
84
+
85
+ describe "#uglify" do
86
+ it "creates an UglifyFilter" do
87
+ dsl.uglify
88
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::UglifyFilter)
89
+ end
90
+ end
91
+
92
+ describe "#less" do
93
+ it "creates a LessFilter" do
94
+ dsl.less
95
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::LessFilter)
96
+ end
97
+ end
98
+
99
+ describe "#gzip" do
100
+ it "creates a GzipFilter" do
101
+ dsl.gzip
102
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::GzipFilter)
103
+ end
104
+ end
105
+
106
+ describe "#handlebars" do
107
+ it "creates a HandlebarsFilter" do
108
+ dsl.handlebars
109
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::HandlebarsFilter)
110
+ end
111
+ end
112
+
113
+ describe "#iffe" do
114
+ it "creates a IifeFilter" do
115
+ dsl.iife
116
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::IifeFilter)
117
+ end
118
+ end
119
+ end
120
+
121
+ describe "ProjectHelpers" do
122
+ let(:project) { Rake::Pipeline::Project.new }
123
+ let(:dsl) { Rake::Pipeline::DSL::ProjectDSL.new(project) }
124
+
125
+ describe "register" do
126
+ it "registers filters per file name" do
127
+ dsl.register :coffee, Rake::Pipeline::Web::Filters::CoffeeScriptFilter
128
+ dsl.register :handlebars, Rake::Pipeline::Web::Filters::HandlebarsFilter
129
+
130
+ dsl.input "lib" do
131
+ concat "lib.js"
132
+ end
133
+
134
+ dsl.input "tests" do
135
+ concat "tests.js"
136
+ end
137
+
138
+ project.pipelines.size.should == 2
139
+
140
+ project.pipelines.each do |pipeline|
141
+ pipeline.filters.first.should be_kind_of Rake::Pipeline::Web::Filters::ChainedFilter
142
+ pipeline.filters.first.filters.keys.should == [:coffee, :handlebars]
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,58 @@
1
+ describe "IifeFilter" do
2
+ IifeFilter ||= Rake::Pipeline::Web::Filters::IifeFilter
3
+ MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
4
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
5
+
6
+ let(:js_input) { <<-HERE }
7
+ var name = "Truckasaurus Gates";
8
+ HERE
9
+
10
+ let(:expected_js_output) { <<-HERE }
11
+ (function() {
12
+ var name = "Truckasaurus Gates";
13
+ })();
14
+ HERE
15
+
16
+ def input_file(name, content)
17
+ MemoryFileWrapper.new("/path/to/input", name, "UTF-8", content)
18
+ end
19
+
20
+ def output_file(name)
21
+ MemoryFileWrapper.new("/path/to/output", name, "UTF-8")
22
+ end
23
+
24
+ def setup_filter(filter)
25
+ filter.file_wrapper_class = MemoryFileWrapper
26
+ filter.manifest = MemoryManifest.new
27
+ filter.last_manifest = MemoryManifest.new
28
+ filter.input_files = [input_file("name.js", js_input)]
29
+ filter.output_root = "/path/to/output"
30
+ filter.rake_application = Rake::Application.new
31
+ filter
32
+ end
33
+
34
+ it "generates output" do
35
+ filter = setup_filter IifeFilter.new
36
+
37
+ filter.output_files.should == [output_file("name.js")]
38
+
39
+ tasks = filter.generate_rake_tasks
40
+ tasks.each(&:invoke)
41
+
42
+ file = MemoryFileWrapper.files["/path/to/output/name.js"]
43
+ file.body.should == expected_js_output.chomp
44
+ file.encoding.should == "UTF-8"
45
+ end
46
+
47
+ describe "naming output files" do
48
+ it "translates .js extensions to .min.js by default" do
49
+ filter = setup_filter IifeFilter.new
50
+ filter.output_files.first.path.should == "name.js"
51
+ end
52
+
53
+ it "accepts a block to customize output file names" do
54
+ filter = setup_filter(IifeFilter.new { |input| "octopus" })
55
+ filter.output_files.first.path.should == "octopus"
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,92 @@
1
+ describe "JadeFilter" do
2
+ JadeFilter ||= Rake::Pipeline::Web::Filters::JadeFilter
3
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
4
+
5
+ let(:jade_input) {
6
+ """
7
+ !!! 5
8
+ html
9
+ head
10
+ title Hello
11
+ body
12
+ h1 Hello
13
+ """
14
+ }
15
+
16
+ let(:expected_html_output) {
17
+ """<!DOCTYPE html><html><head><title>Hello</title></head><body><h1>Hello</h1></body></html>"""
18
+ }
19
+
20
+ let(:expected_prettified_html_output) {
21
+ """\
22
+ <!DOCTYPE html>
23
+ <html>
24
+ <head>
25
+ <title>Hello</title>
26
+ </head>
27
+ <body>
28
+ <h1>Hello</h1>
29
+ </body>
30
+ </html>"""
31
+ }
32
+
33
+ let(:input_root) { File.expand_path('./input') }
34
+ let(:input_path) { 'index.jade' }
35
+
36
+ let(:input_file) {
37
+ mkdir_p input_root
38
+ File.open(File.join(input_root, input_path), 'w+:UTF-8') {|file| file << jade_input }
39
+ Rake::Pipeline::FileWrapper.new(input_root, input_path, "UTF-8")
40
+ }
41
+
42
+ let(:output_root) { File.expand_path('./output') }
43
+ let(:output_path) { 'index.html' }
44
+
45
+ let(:output_file) {
46
+ Rake::Pipeline::FileWrapper.new(output_root, output_path, "UTF-8")
47
+ }
48
+
49
+ def setup_filter(filter, input=jade_input)
50
+ filter.manifest = MemoryManifest.new
51
+ filter.last_manifest = MemoryManifest.new
52
+ filter.input_files = [input_file]
53
+ filter.output_root = output_root
54
+ filter.rake_application = Rake::Application.new
55
+ filter
56
+ end
57
+
58
+ it "generates output" do
59
+ filter = setup_filter JadeFilter.new
60
+ filter.output_files.should == [output_file]
61
+
62
+ tasks = filter.generate_rake_tasks
63
+ tasks.each(&:invoke)
64
+
65
+ output_file.read.should == expected_html_output
66
+ output_file.encoding.should == "UTF-8"
67
+ end
68
+
69
+ it "prettifies output" do
70
+ filter = setup_filter JadeFilter.new :pretty => true
71
+
72
+ filter.output_files.should == [output_file]
73
+
74
+ tasks = filter.generate_rake_tasks
75
+ tasks.each(&:invoke)
76
+
77
+ output_file.read.should == expected_prettified_html_output
78
+ output_file.encoding.should == "UTF-8"
79
+ end
80
+
81
+ describe "naming output files" do
82
+ it "translates .jade extensions to .html by default" do
83
+ filter = setup_filter JadeFilter.new
84
+ filter.output_files.first.path.should == "index.html"
85
+ end
86
+
87
+ it "accepts a block to customize output file names" do
88
+ filter = setup_filter(JadeFilter.new { |input| "hbs" })
89
+ filter.output_files.first.path.should == "hbs"
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,62 @@
1
+ describe "LessFilter" do
2
+ LessFilter ||= Rake::Pipeline::Web::Filters::LessFilter
3
+ MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
4
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
5
+
6
+ let(:less_input) { <<-SCSS }
7
+ @blue: #3bbfce;
8
+
9
+ .border {
10
+ border-color: @blue;
11
+ }
12
+ SCSS
13
+
14
+ let(:expected_css_output) { <<-CSS }
15
+ .border {
16
+ border-color: #3bbfce;
17
+ }
18
+ CSS
19
+
20
+ def input_file(name, content)
21
+ MemoryFileWrapper.new("/path/to/input", name, "UTF-8", content)
22
+ end
23
+
24
+ def output_file(name)
25
+ MemoryFileWrapper.new("/path/to/output", name, "UTF-8")
26
+ end
27
+
28
+ def setup_filter(filter)
29
+ filter.file_wrapper_class = MemoryFileWrapper
30
+ filter.manifest = MemoryManifest.new
31
+ filter.last_manifest = MemoryManifest.new
32
+ filter.input_files = [input_file("border.less", less_input)]
33
+ filter.output_root = "/path/to/output"
34
+ filter.rake_application = Rake::Application.new
35
+ filter
36
+ end
37
+
38
+ it "generates output" do
39
+ filter = setup_filter LessFilter.new
40
+
41
+ filter.output_files.should == [output_file("border.css")]
42
+
43
+ tasks = filter.generate_rake_tasks
44
+ tasks.each(&:invoke)
45
+
46
+ file = MemoryFileWrapper.files["/path/to/output/border.css"]
47
+ file.body.should == expected_css_output
48
+ file.encoding.should == "UTF-8"
49
+ end
50
+
51
+ describe "naming output files" do
52
+ it "translates .less extensions to .css by default" do
53
+ filter = setup_filter LessFilter.new
54
+ filter.output_files.first.path.should == "border.css"
55
+ end
56
+
57
+ it "accepts a block to customize output file names" do
58
+ filter = setup_filter(LessFilter.new { |input| "octopus" })
59
+ filter.output_files.first.path.should == "octopus"
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,89 @@
1
+ describe "MarkdownFilter" do
2
+ MarkdownFilter ||= Rake::Pipeline::Web::Filters::MarkdownFilter
3
+ MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
4
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
5
+
6
+ let(:markdown_input) { <<-MARKDOWN }
7
+ ## This is an H2
8
+
9
+ Some *important* text. It might have a link: http://foo.com/
10
+
11
+ Some code
12
+
13
+ That's all.
14
+ MARKDOWN
15
+
16
+ let(:expected_html_output) { <<-HTML }
17
+ <h2>This is an H2</h2>
18
+
19
+ <p>Some <em>important</em> text. It might have a link: http://foo.com/</p>
20
+
21
+ <pre><code>Some code
22
+ </code></pre>
23
+
24
+ <p>That&#39;s all.</p>
25
+ HTML
26
+
27
+ def input_file(name, content)
28
+ MemoryFileWrapper.new("/path/to/input", name, "UTF-8", content)
29
+ end
30
+
31
+ def output_file(name)
32
+ MemoryFileWrapper.new("/path/to/output", name, "UTF-8")
33
+ end
34
+
35
+ def setup_filter(filter)
36
+ filter.file_wrapper_class = MemoryFileWrapper
37
+ filter.manifest = MemoryManifest.new
38
+ filter.last_manifest = MemoryManifest.new
39
+ filter.input_files = [input_file("page.md", markdown_input)]
40
+ filter.output_root = "/path/to/output"
41
+ filter.rake_application = Rake::Application.new
42
+ filter
43
+ end
44
+
45
+ it "generates output" do
46
+ filter = setup_filter MarkdownFilter.new
47
+
48
+ filter.output_files.should == [output_file("page.html")]
49
+
50
+ tasks = filter.generate_rake_tasks
51
+ tasks.each(&:invoke)
52
+
53
+ file = MemoryFileWrapper.files["/path/to/output/page.html"]
54
+ file.body.should == expected_html_output
55
+ file.encoding.should == "UTF-8"
56
+ end
57
+
58
+ describe "naming output files" do
59
+ it "translates .md extensions to .html by default" do
60
+ filter = setup_filter MarkdownFilter.new
61
+ filter.output_files.first.path.should == "page.html"
62
+ end
63
+
64
+ it "accepts a block to customize output file names" do
65
+ filter = setup_filter(MarkdownFilter.new { |input| "octopus" })
66
+ filter.output_files.first.path.should == "octopus"
67
+ end
68
+ end
69
+
70
+ it "passes options to the Markdown compiler" do
71
+ filter = setup_filter(MarkdownFilter.new(:autolink => true))
72
+ filter.input_files = [input_file("page.md", markdown_input)]
73
+ tasks = filter.generate_rake_tasks
74
+ tasks.each(&:invoke)
75
+ file = MemoryFileWrapper.files["/path/to/output/page.html"]
76
+ file.body.should =~ %r{<a href="http://foo\.com/">}
77
+ end
78
+
79
+ it "accepts a :compiler option" do
80
+ filter = setup_filter(MarkdownFilter.new(:compiler => proc { |text, options| text }))
81
+ filter.input_files = [input_file("page.md", markdown_input)]
82
+ tasks = filter.generate_rake_tasks
83
+ tasks.each(&:invoke)
84
+ file = MemoryFileWrapper.files["/path/to/output/page.html"]
85
+ file.body.should == markdown_input
86
+ end
87
+
88
+ end
89
+