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.
Files changed (47) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +1 -0
  3. data/Rakefile +8 -0
  4. data/lib/rake-pipeline-web-filters.rb +17 -3
  5. data/lib/rake-pipeline-web-filters/cache_buster_filter.rb +42 -0
  6. data/lib/rake-pipeline-web-filters/chained_filter.rb +116 -0
  7. data/lib/rake-pipeline-web-filters/coffee_script_filter.rb +41 -0
  8. data/lib/rake-pipeline-web-filters/filter_with_dependencies.rb +27 -0
  9. data/lib/rake-pipeline-web-filters/gzip_filter.rb +59 -0
  10. data/lib/rake-pipeline-web-filters/handlebars_filter.rb +62 -0
  11. data/lib/rake-pipeline-web-filters/helpers.rb +100 -18
  12. data/lib/rake-pipeline-web-filters/iife_filter.rb +38 -0
  13. data/lib/rake-pipeline-web-filters/less_filter.rb +55 -0
  14. data/lib/rake-pipeline-web-filters/markdown_filter.rb +70 -0
  15. data/lib/rake-pipeline-web-filters/minispade_filter.rb +21 -5
  16. data/lib/rake-pipeline-web-filters/neuter_filter.rb +110 -0
  17. data/lib/rake-pipeline-web-filters/sass_filter.rb +87 -0
  18. data/lib/rake-pipeline-web-filters/stylus_filter.rb +59 -0
  19. data/lib/rake-pipeline-web-filters/tilt_filter.rb +16 -3
  20. data/lib/rake-pipeline-web-filters/uglify_filter.rb +66 -0
  21. data/lib/rake-pipeline-web-filters/version.rb +1 -1
  22. data/lib/rake-pipeline-web-filters/yui_css_filter.rb +70 -0
  23. data/lib/rake-pipeline-web-filters/yui_javascript_filter.rb +59 -0
  24. data/rake-pipeline-web-filters.gemspec +10 -1
  25. data/spec/cache_buster_filter_spec.rb +105 -0
  26. data/spec/chained_filter_spec.rb +76 -0
  27. data/spec/coffee_script_filter_spec.rb +110 -0
  28. data/spec/gzip_filter_spec.rb +49 -0
  29. data/spec/handlebars_filter_spec.rb +70 -0
  30. data/spec/helpers_spec.rb +112 -18
  31. data/spec/iife_filter_spec.rb +55 -0
  32. data/spec/less_filter_spec.rb +59 -0
  33. data/spec/markdown_filter_spec.rb +86 -0
  34. data/spec/minispade_filter_spec.rb +47 -15
  35. data/spec/neuter_filter_spec.rb +204 -0
  36. data/spec/sass_filter_spec.rb +147 -0
  37. data/spec/spec_helper.rb +10 -1
  38. data/spec/stylus_filter_spec.rb +69 -0
  39. data/spec/tilt_filter_spec.rb +25 -1
  40. data/spec/uglify_filter_spec.rb +82 -0
  41. data/spec/yui_css_filter_spec.rb +88 -0
  42. data/spec/yui_javascript_filter_spec.rb +68 -0
  43. metadata +225 -19
  44. data/lib/rake-pipeline-web-filters/ordering_concat_filter.rb +0 -38
  45. data/lib/rake-pipeline-web-filters/sass_compiler.rb +0 -53
  46. data/spec/ordering_concat_filter_spec.rb +0 -39
  47. data/spec/sass_compiler_spec.rb +0 -89
@@ -1,38 +0,0 @@
1
- module Rake::Pipeline::Web::Filters
2
- # A filter that concats files in a specified order
3
- #
4
- # @example
5
- # !!!ruby
6
- # Rake::Pipeline.build do
7
- # input "app/assets", "**/*.js"
8
- # output "public"
9
- #
10
- # # Concat each file into libs.js but make sure
11
- # # that jQuery and SproutCore come first
12
- # filter Rake::Pipeline::Web::Filters::OrderingConcatFilter, ["jquery.js", "sproutcore.js"], "libs.js"
13
- # end
14
- class OrderingConcatFilter < Rake::Pipeline::ConcatFilter
15
-
16
- # @param [Array<String>] ordering an Array of Strings
17
- # of file names that should come in the specified order
18
- # @param [String] string the name of the output file to
19
- # concatenate inputs to.
20
- # @param [Proc] block a block to use as the Filter's
21
- # {#output_name_generator}.
22
- def initialize(ordering, string=nil, &block)
23
- @ordering = ordering
24
- super(string, &block)
25
- end
26
-
27
- # Extend the {#generate_output} method supplied by {ConcatFilter}.
28
- # Re-orders the inputs such that the specified files come first.
29
- # If a file is not in the list it will come after the specified files.
30
- def generate_output(inputs, output)
31
- @ordering.reverse.each do |name|
32
- file = inputs.find{|i| i.path == name }
33
- inputs.unshift(inputs.delete(file)) if file
34
- end
35
- super
36
- end
37
- end
38
- end
@@ -1,53 +0,0 @@
1
- require 'sass'
2
- require 'compass'
3
-
4
- module Rake::Pipeline::Web::Filters
5
- # A filter that compiles input files written in SCSS
6
- # to CSS using the Sass compiler and the Compass CSS
7
- # framework.
8
- #
9
- # @example
10
- # !!!ruby
11
- # Rake::Pipeline.build do
12
- # input "app/assets", "**/*.scss"
13
- # output "public"
14
- #
15
- # # Compile each SCSS file under the app/assets
16
- # # directory.
17
- # filter Rake::Pipeline::Web::Filters::SassCompiler
18
- # end
19
- class SassCompiler < Rake::Pipeline::Filter
20
- # @return [Hash] a hash of options to pass to Sass
21
- # when compiling.
22
- attr_reader :options
23
-
24
- # @param [Hash] options options to pass to the Sass
25
- # compiler
26
- # @option options [Array] :additional_load_paths a
27
- # list of paths to append to Sass's :load_path.
28
- # @param [Proc] block a block to use as the Filter's
29
- # {#output_name_generator}.
30
- def initialize(options={}, &block)
31
- block ||= proc { |input| input.sub(/\.(scss|sass)$/, '.css') }
32
- super(&block)
33
- Compass.add_project_configuration
34
- @options = Compass.configuration.to_sass_engine_options
35
- @options[:load_paths].concat(Array(options.delete(:additional_load_paths)))
36
- @options.merge!(options)
37
- end
38
-
39
- # Implement the {#generate_output} method required by
40
- # the {Filter} API. Compiles each input file with Sass.
41
- #
42
- # @param [Array<FileWrapper>] inputs an Array of
43
- # {FileWrapper} objects representing the inputs to
44
- # this filter.
45
- # @param [FileWrapper] output a single {FileWrapper}
46
- # object representing the output.
47
- def generate_output(inputs, output)
48
- inputs.each do |input|
49
- output.write Sass.compile(input.read, options)
50
- end
51
- end
52
- end
53
- end
@@ -1,39 +0,0 @@
1
- describe "OrderingConcatFilter" do
2
- MemoryFileWrapper = Rake::Pipeline::SpecHelpers::MemoryFileWrapper
3
-
4
- let(:input_files) {
5
- [
6
- MemoryFileWrapper.new("/path/to/input", "first.txt", "UTF-8", "FIRST"),
7
- MemoryFileWrapper.new("/path/to/input", "second.txt", "UTF-8", "SECOND"),
8
- MemoryFileWrapper.new("/path/to/input", "last.txt", "UTF-8", "LAST")
9
- ]
10
- }
11
-
12
- let(:output_files) {
13
- [
14
- MemoryFileWrapper.new("/path/to/output", "all.txt", "BINARY")
15
- ]
16
- }
17
-
18
- let(:output_file) {
19
- MemoryFileWrapper.files["/path/to/output/all.txt"]
20
- }
21
-
22
- def make_filter(ordering)
23
- filter = Rake::Pipeline::Web::Filters::OrderingConcatFilter.new(ordering, "all.txt")
24
- filter.file_wrapper_class = MemoryFileWrapper
25
- filter.input_files = input_files
26
- filter.output_root = "/path/to/output"
27
- filter.rake_application = Rake::Application.new
28
- filter.generate_rake_tasks.each(&:invoke)
29
- filter
30
- end
31
-
32
- it "generates output" do
33
- filter = make_filter(["first.txt", "second.txt"])
34
-
35
- filter.output_files.should == output_files
36
- output_file.body.should == "FIRSTSECONDLAST"
37
- output_file.encoding.should == "BINARY"
38
- end
39
- end
@@ -1,89 +0,0 @@
1
- describe "SassCompiler" do
2
- MemoryFileWrapper = Rake::Pipeline::SpecHelpers::MemoryFileWrapper
3
- SassCompiler = Rake::Pipeline::Web::Filters::SassCompiler
4
-
5
- SCSS_INPUT = <<-SCSS
6
- $blue: #3bbfce;
7
-
8
- .border {
9
- border-color: $blue;
10
- }
11
- SCSS
12
-
13
- SASS_INPUT = <<-SASS
14
- $blue: #3bbfce
15
-
16
- .border
17
- border-color: $blue
18
- SASS
19
-
20
- EXPECTED_CSS_OUTPUT = <<-CSS
21
- /* line 3 */
22
- .border {
23
- border-color: #3bbfce;
24
- }
25
- CSS
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.input_files = [input_file("border.scss", SCSS_INPUT)]
38
- filter.output_root = "/path/to/output"
39
- filter.rake_application = Rake::Application.new
40
- filter
41
- end
42
-
43
- it "generates output" do
44
- filter = setup_filter SassCompiler.new
45
-
46
- filter.output_files.should == [output_file("border.css")]
47
-
48
- tasks = filter.generate_rake_tasks
49
- tasks.each(&:invoke)
50
-
51
- file = MemoryFileWrapper.files["/path/to/output/border.css"]
52
- file.body.should == EXPECTED_CSS_OUTPUT
53
- file.encoding.should == "UTF-8"
54
- end
55
-
56
- describe "naming output files" do
57
- it "translates .scss extensions to .css by default" do
58
- filter = setup_filter SassCompiler.new
59
- filter.output_files.first.path.should == "border.css"
60
- end
61
-
62
- it "accepts a block to customize output file names" do
63
- filter = setup_filter(SassCompiler.new { |input| "octopus" })
64
- filter.output_files.first.path.should == "octopus"
65
- end
66
- end
67
-
68
- it "accepts options to pass to the Sass compiler" do
69
- filter = setup_filter(SassCompiler.new(:syntax => :sass))
70
- filter.input_files = [input_file("border.sass", SASS_INPUT)]
71
- tasks = filter.generate_rake_tasks
72
- tasks.each(&:invoke)
73
- file = MemoryFileWrapper.files["/path/to/output/border.css"]
74
- file.body.should == EXPECTED_CSS_OUTPUT
75
- end
76
-
77
- it "passes Compass's options to the Sass compiler" do
78
- Compass.configuration do |c|
79
- c.preferred_syntax = :sass
80
- end
81
-
82
- filter = setup_filter(SassCompiler.new)
83
- filter.input_files = [input_file("border.css", SCSS_INPUT)]
84
- tasks = filter.generate_rake_tasks
85
- tasks.each(&:invoke)
86
- file = MemoryFileWrapper.files["/path/to/output/border.css"]
87
- file.body.should == EXPECTED_CSS_OUTPUT
88
- end
89
- end