rake-pipeline-web-filters 0.5.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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -cfs -r spec_helper.rb
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --readme README.yard
2
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rake-pipeline-web-filters.gemspec
4
+ gemspec
5
+
6
+ gem "rake-pipeline", :git => "git://github.com/livingsocial/rake-pipeline.git"
data/README.markdown ADDED
@@ -0,0 +1,4 @@
1
+ # Rake::Pipeline::Web::Filters
2
+
3
+ Documentation for Rake::Pipeline::Web::Filters is hosted at
4
+ <a href="http://rubydoc.info/github/wycats/rake-pipeline-web-filters/master/file/README.yard">rubydoc.info</a>
data/README.yard ADDED
@@ -0,0 +1,32 @@
1
+ = Rake::Pipeline::Web::Filters
2
+
3
+ Rake::Pipeline::Web::Filters is a collection of filters for Rake::Pipeline
4
+ for creating pipelines to generate web content.
5
+
6
+ = Usage
7
+
8
+ In your +Assetfile+:
9
+
10
+ !!!ruby
11
+ require "rake-pipeline-web-filters"
12
+
13
+ input "assets"
14
+ output "public"
15
+
16
+ # Take all JS inputs and wrap each of them in code to
17
+ # register them with the Minispade module loader.
18
+ match "*.js" do
19
+ filter Rake::Pipeline::Web::Filters::MinispadeFilter
20
+ end
21
+
22
+ # Take all SCSS inputs and compile them with Sass
23
+ match "*.scss" do
24
+ filter Rake::Pipeline::Web::Filters::SassCompiler
25
+ end
26
+
27
+ = Available Filters
28
+
29
+ * {Rake::Pipeline::Web::Filters::MinispadeFilter}: Wraps JS code for use with Minispade
30
+ * {Rake::Pipeline::Web::Filters::SassCompiler}: Compiles SCSS or Sass to CSS
31
+ * {Rake::Pipeline::Web::Filters::TiltFilter}: Compiles templates with the Tilt template interface
32
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ require "rake-pipeline"
2
+
3
+ module Rake
4
+ class Pipeline
5
+ module Web
6
+ module Filters
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ require "rake-pipeline-web-filters/version"
13
+ require "rake-pipeline-web-filters/tilt_filter"
14
+ require "rake-pipeline-web-filters/sass_compiler"
15
+ require "rake-pipeline-web-filters/minispade_filter"
16
+ require "rake-pipeline-web-filters/ordering_concat_filter"
@@ -0,0 +1,50 @@
1
+ module Rake::Pipeline::Web::Filters
2
+ # Extends the Rake::Pipeline DSL to include shortcuts
3
+ # for adding filters to the pipeline.
4
+ #
5
+ # Instead of:
6
+ # !!!ruby
7
+ # match("*.scss") do
8
+ # filter Rake::Pipeline::Web::Filters::SassCompiler, :syntax => :sass
9
+ # end
10
+ #
11
+ # You can do:
12
+ # !!!ruby
13
+ # match("*.scss") do
14
+ # sass :syntax => :sass
15
+ # end
16
+ module Helpers
17
+ # If the first argument is an Array, add a new {OrderingConcatFilter}
18
+ # to the pipeline. Otherwise add a new {Rake::Pipeline::ConcatFilter}.
19
+ # @see OrderingConcatFilter#initialize
20
+ # @see Rake::Pipeline::ConcatFilter#initialize
21
+ def concat(*args, &block)
22
+ if args.first.kind_of?(Array)
23
+ filter(Rake::Pipeline::Web::Filters::OrderingConcatFilter, *args, &block)
24
+ else
25
+ filter(Rake::Pipeline::ConcatFilter, *args, &block)
26
+ end
27
+ end
28
+
29
+ # Add a new {MinispadeFilter} to the pipeline.
30
+ # @see MinispadeFilter#initialize
31
+ def minispade(*args, &block)
32
+ filter(Rake::Pipeline::Web::Filters::MinispadeFilter, *args, &block)
33
+ end
34
+
35
+ # Add a new {SassCompiler} to the pipeline.
36
+ # @see SassCompiler#initialize
37
+ def sass(*args, &block)
38
+ filter(Rake::Pipeline::Web::Filters::SassCompiler, *args, &block)
39
+ end
40
+ alias_method :scss, :sass
41
+
42
+ # Add a new {TiltFilter} to the pipeline.
43
+ # @see TiltFilter#initialize
44
+ def tilt(*args, &block)
45
+ filter(Rake::Pipeline::Web::Filters::TiltFilter, *args, &block)
46
+ end
47
+ end
48
+ end
49
+
50
+ Rake::Pipeline::DSL.send(:include, Rake::Pipeline::Web::Filters::Helpers)
@@ -0,0 +1,47 @@
1
+ module Rake::Pipeline::Web::Filters
2
+ # A filter that wraps JavaScript files in a minispade.register closure
3
+ # for use in minispade.
4
+ #
5
+ # @example
6
+ # !!!ruby
7
+ # Rake::Pipeline.build do
8
+ # input "app/assets", "**/*.js"
9
+ # output "public"
10
+ #
11
+ # # Wrap each JS file in a minispade.register closure.
12
+ # filter Rake::Pipeleine::Web::Filters::MinispadeFilter
13
+ # end
14
+ class MinispadeFilter < Rake::Pipeline::Filter
15
+
16
+ # @param [Hash] options
17
+ # @option options [Boolean] :use_strict Whether to add "use strict" to
18
+ # each outputted function; defaults to false.
19
+ # @option options [Proc] :module_id_generator a proc to use to generate
20
+ # the minispade module id.
21
+ def initialize(options = {})
22
+ super()
23
+ @use_strict = !!options[:use_strict]
24
+ @module_id_generator = options[:module_id_generator] ||
25
+ proc { |input| input.fullpath.sub(Dir.pwd, '') }
26
+ end
27
+
28
+ # Implement the {#generate_output} method required by
29
+ # the {Filter} API. Wraps each input file in a minispade.register
30
+ # closure.
31
+ #
32
+ # @param [Array<FileWrapper>] inputs an Array of
33
+ # {FileWrapper} objects representing the inputs to
34
+ # this filter.
35
+ # @param [FileWrapper] output a single {FileWrapper}
36
+ # object representing the output.
37
+ def generate_output(inputs, output)
38
+ inputs.each do |input|
39
+ code = input.read
40
+ code = '"use strict"; ' + code if @use_strict
41
+ function = "function() { #{code} }"
42
+ ret = "minispade.register('#{@module_id_generator.call(input)}',#{function});"
43
+ output.write ret
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,53 @@
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
@@ -0,0 +1,57 @@
1
+ require 'tilt'
2
+
3
+ module Rake::Pipeline::Web::Filters
4
+ # A filter that accepts a series of inputs and translates
5
+ # them using the Tilt template interface, which will attempt
6
+ # to guess which template language to use based on the input
7
+ # file extension.
8
+ #
9
+ # @example
10
+ # !!!ruby
11
+ # Rake::Pipeline.build do
12
+ # input "app/assets", "**/*.scss"
13
+ # output "public"
14
+ #
15
+ # # Compile each SCSS file using Tilt, replacing the
16
+ # # scss extension with css.
17
+ # filter(Rake::Pipeline::Web::Filters::TiltFilter) do |input|
18
+ # input.sub(/\.scss$/, 'css')
19
+ # end
20
+ # end
21
+ class TiltFilter < Rake::Pipeline::Filter
22
+ # @return [Hash] a hash of options to pass to Tilt
23
+ # when rendering.
24
+ attr_reader :options
25
+
26
+ # @param [Hash] options options to pass to the Tilt
27
+ # template class constructor.
28
+ # @param [Proc] block a block to use as the Filter's
29
+ # {#output_name_generator}.
30
+ def initialize(options={}, &block)
31
+ super(&block)
32
+ @options = options
33
+ end
34
+
35
+ # Implement the {#generate_output} method required by
36
+ # the {Filter} API. Attempts to compile each input file
37
+ # with Tilt, passing the file through unchanged if Tilt
38
+ # can't find a template class for the file.
39
+ #
40
+ # @param [Array<FileWrapper>] inputs an Array of
41
+ # {FileWrapper} objects representing the inputs to
42
+ # this filter.
43
+ # @param [FileWrapper] output a single {FileWrapper}
44
+ # object representing the output.
45
+ def generate_output(inputs, output)
46
+ inputs.each do |input|
47
+ out = if (template_class = Tilt[input.path])
48
+ template_class.new(nil, 1, options) { |t| input.read }.render
49
+ else
50
+ input.read
51
+ end
52
+
53
+ output.write out
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,9 @@
1
+ module Rake
2
+ class Pipeline
3
+ module Web
4
+ module Filters
5
+ VERSION = "0.5.0"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rake-pipeline-web-filters/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Yehuda Katz"]
6
+ gem.email = ["wycats@gmail.com"]
7
+ gem.description = %q{A collection of web filters for rake-pipeline}
8
+ gem.summary = %q{Contributed filters for use in rake-pipeline that are useful for web projects, like asset management}
9
+ gem.homepage = "http://github.com/wycats/rake-pipeline-web-filters"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "rake-pipeline-web-filters"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Rake::Pipeline::Web::Filters::VERSION
17
+
18
+ gem.add_dependency "rake-pipeline"
19
+
20
+ gem.add_development_dependency "rspec"
21
+ gem.add_development_dependency "tilt"
22
+ gem.add_development_dependency "sass"
23
+ gem.add_development_dependency "compass"
24
+ end
@@ -0,0 +1,50 @@
1
+ require "rake-pipeline-web-filters/helpers"
2
+
3
+ describe "Helpers" do
4
+
5
+ let(:pipeline) { Rake::Pipeline.new }
6
+ let(:dsl) { Rake::Pipeline::DSL.new(pipeline) }
7
+
8
+ before do
9
+ pipeline.input_root = "."
10
+ end
11
+
12
+ def filter
13
+ pipeline.filters.last
14
+ end
15
+
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
+ describe "#minispade" do
31
+ it "creates a MinispadeFilter" do
32
+ dsl.minispade
33
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::MinispadeFilter)
34
+ end
35
+ end
36
+
37
+ describe "#sass" do
38
+ it "creates a SassCompiler" do
39
+ dsl.sass
40
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::SassCompiler)
41
+ end
42
+ end
43
+
44
+ describe "#tilt" do
45
+ it "creates a TiltFilter" do
46
+ dsl.tilt
47
+ filter.should be_kind_of(Rake::Pipeline::Web::Filters::TiltFilter)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,47 @@
1
+ describe "MinispadeFilter" do
2
+ MemoryFileWrapper = Rake::Pipeline::SpecHelpers::MemoryFileWrapper
3
+
4
+ let(:input_files) {
5
+ [
6
+ MemoryFileWrapper.new("/path/to/input", "foo.js", "UTF-8", "var foo = 'bar';")
7
+ ]
8
+ }
9
+
10
+ let(:output_files) {
11
+ [
12
+ MemoryFileWrapper.new("/path/to/output", "foo.js", "UTF-8")
13
+ ]
14
+ }
15
+
16
+ let(:output_file) {
17
+ MemoryFileWrapper.files["/path/to/output/foo.js"]
18
+ }
19
+
20
+ def make_filter(*args)
21
+ filter = Rake::Pipeline::Web::Filters::MinispadeFilter.new(*args)
22
+ filter.file_wrapper_class = MemoryFileWrapper
23
+ filter.input_files = input_files
24
+ filter.output_root = "/path/to/output"
25
+ filter.rake_application = Rake::Application.new
26
+ filter.generate_rake_tasks.each(&:invoke)
27
+ filter
28
+ end
29
+
30
+ it "generates output" do
31
+ filter = make_filter
32
+
33
+ filter.output_files.should == output_files
34
+ output_file.body.should == "minispade.register('/path/to/input/foo.js',function() { var foo = 'bar'; });"
35
+ output_file.encoding.should == "UTF-8"
36
+ end
37
+
38
+ it "uses strict if asked" do
39
+ filter = make_filter(:use_strict => true)
40
+ output_file.body.should == "minispade.register('/path/to/input/foo.js',function() { \"use strict\"; var foo = 'bar'; });"
41
+ end
42
+
43
+ it "takes a proc to name the module" do
44
+ filter = make_filter(:module_id_generator => proc { |input| "octopus" })
45
+ output_file.body.should == "minispade.register('octopus',function() { var foo = 'bar'; });"
46
+ end
47
+ end
@@ -0,0 +1,39 @@
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
@@ -0,0 +1,89 @@
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
@@ -0,0 +1,95 @@
1
+ require "rake-pipeline"
2
+ require "rake-pipeline-web-filters"
3
+
4
+ class Rake::Pipeline
5
+ module SpecHelpers
6
+
7
+ class MemoryFileWrapper < Struct.new(:root, :path, :encoding, :body)
8
+ @@files = {}
9
+
10
+ def self.files
11
+ @@files
12
+ end
13
+
14
+ def with_encoding(new_encoding)
15
+ self.class.new(root, path, new_encoding, body)
16
+ end
17
+
18
+ def fullpath
19
+ File.join(root, path)
20
+ end
21
+
22
+ def create
23
+ @@files[fullpath] = self
24
+ self.body = ""
25
+ yield
26
+ end
27
+
28
+ alias read body
29
+
30
+ def write(contents)
31
+ self.body << contents
32
+ end
33
+ end
34
+
35
+ # TODO: OS agnostic modules
36
+ module FileUtils
37
+ def mkdir_p(dir)
38
+ system "mkdir", "-p", dir
39
+ end
40
+
41
+ def touch(file)
42
+ system "touch", file
43
+ end
44
+
45
+ def rm_rf(dir)
46
+ system "rm", "-rf", dir
47
+ end
48
+
49
+ def touch_p(file)
50
+ dir = File.dirname(file)
51
+ mkdir_p dir
52
+ touch file
53
+ end
54
+
55
+ def age_existing_files
56
+ old_time = Time.now - 10
57
+ Dir[File.join(tmp, "**/*.js")].each do |file|
58
+ File.utime(old_time, old_time, file)
59
+ end
60
+ end
61
+ end
62
+
63
+ module Filters
64
+ ConcatFilter = Rake::Pipeline::ConcatFilter
65
+
66
+ class StripAssertsFilter < Rake::Pipeline::Filter
67
+ def generate_output(inputs, output)
68
+ inputs.each do |input|
69
+ output.write input.read.gsub(%r{^\s*assert\(.*\)\s*;?\s*$}m, '')
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ RSpec.configure do |config|
78
+ original = Dir.pwd
79
+
80
+ config.include Rake::Pipeline::SpecHelpers::FileUtils
81
+
82
+ def tmp
83
+ File.expand_path("../tmp", __FILE__)
84
+ end
85
+
86
+ config.before do
87
+ rm_rf(tmp)
88
+ mkdir_p(tmp)
89
+ Dir.chdir(tmp)
90
+ end
91
+
92
+ config.after do
93
+ Dir.chdir(original)
94
+ end
95
+ end
@@ -0,0 +1,55 @@
1
+ describe "TiltFilter" do
2
+ MemoryFileWrapper = Rake::Pipeline::SpecHelpers::MemoryFileWrapper
3
+
4
+ let(:input_files) {
5
+ [
6
+ MemoryFileWrapper.new("/path/to/input", "foo.erb", "UTF-8", "<%= 'foo' %>\n"),
7
+ MemoryFileWrapper.new("/path/to/input", "bar.str", "UTF-8", '#{ "bar" }')
8
+ ]
9
+ }
10
+
11
+ let(:output_files) {
12
+ [
13
+ MemoryFileWrapper.new("/path/to/output", "foo.txt", "UTF-8"),
14
+ MemoryFileWrapper.new("/path/to/output", "bar.txt", "UTF-8")
15
+ ]
16
+ }
17
+
18
+ def make_filter(*args)
19
+ filter = Rake::Pipeline::Web::Filters::TiltFilter.new(*args) do |input|
20
+ input.sub(/\.(erb|str)$/, '.txt')
21
+ end
22
+ filter.file_wrapper_class = MemoryFileWrapper
23
+ filter.input_files = input_files
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 = make_filter
31
+
32
+ filter.output_files.should == output_files
33
+
34
+ tasks = filter.generate_rake_tasks
35
+ tasks.each(&:invoke)
36
+
37
+ file = MemoryFileWrapper.files["/path/to/output/foo.txt"]
38
+ file.body.should == "foo"
39
+ file.encoding.should == "UTF-8"
40
+
41
+ file = MemoryFileWrapper.files["/path/to/output/bar.txt"]
42
+ file.body.should == "bar"
43
+ file.encoding.should == "UTF-8"
44
+ end
45
+
46
+ it "accepts options to pass to the template class" do
47
+ # :trim => '' should tell ERB not to trim newlines
48
+ filter = make_filter(:trim => '')
49
+
50
+ tasks = filter.generate_rake_tasks
51
+ tasks.each(&:invoke)
52
+ file = MemoryFileWrapper.files["/path/to/output/foo.txt"]
53
+ file.body.should == "foo\n"
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-pipeline-web-filters
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yehuda Katz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake-pipeline
16
+ requirement: &70215098662080 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70215098662080
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70215098661660 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70215098661660
36
+ - !ruby/object:Gem::Dependency
37
+ name: tilt
38
+ requirement: &70215098661240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70215098661240
47
+ - !ruby/object:Gem::Dependency
48
+ name: sass
49
+ requirement: &70215094750840 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70215094750840
58
+ - !ruby/object:Gem::Dependency
59
+ name: compass
60
+ requirement: &70215094748140 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70215094748140
69
+ description: A collection of web filters for rake-pipeline
70
+ email:
71
+ - wycats@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .yardopts
79
+ - Gemfile
80
+ - README.markdown
81
+ - README.yard
82
+ - Rakefile
83
+ - lib/rake-pipeline-web-filters.rb
84
+ - lib/rake-pipeline-web-filters/helpers.rb
85
+ - lib/rake-pipeline-web-filters/minispade_filter.rb
86
+ - lib/rake-pipeline-web-filters/ordering_concat_filter.rb
87
+ - lib/rake-pipeline-web-filters/sass_compiler.rb
88
+ - lib/rake-pipeline-web-filters/tilt_filter.rb
89
+ - lib/rake-pipeline-web-filters/version.rb
90
+ - rake-pipeline-web-filters.gemspec
91
+ - spec/helpers_spec.rb
92
+ - spec/minispade_filter_spec.rb
93
+ - spec/ordering_concat_filter_spec.rb
94
+ - spec/sass_compiler_spec.rb
95
+ - spec/spec_helper.rb
96
+ - spec/tilt_filter_spec.rb
97
+ homepage: http://github.com/wycats/rake-pipeline-web-filters
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.10
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Contributed filters for use in rake-pipeline that are useful for web projects,
121
+ like asset management
122
+ test_files:
123
+ - spec/helpers_spec.rb
124
+ - spec/minispade_filter_spec.rb
125
+ - spec/ordering_concat_filter_spec.rb
126
+ - spec/sass_compiler_spec.rb
127
+ - spec/spec_helper.rb
128
+ - spec/tilt_filter_spec.rb