Class: Rake::Pipeline::Web::Filters::OrderingConcatFilter

Inherits:
ConcatFilter
  • Object
show all
Defined in:
lib/rake-pipeline-web-filters/ordering_concat_filter.rb

Overview

A filter that concats files in a specified order

Examples:

Rake::Pipeline.build do
  input "app/assets", "**/*.js"
  output "public"

  # Concat each file into libs.js but make sure
  # that jQuery and SproutCore come first
  filter Rake::Pipeline::Web::Filters::OrderingConcatFilter, ["jquery.js", "sproutcore.js"], "libs.js"
end

Instance Method Summary collapse

Constructor Details

#initialize(ordering, string = nil, &block) ⇒ OrderingConcatFilter

Returns a new instance of OrderingConcatFilter.

Parameters:

  • ordering (Array<String>)

    an Array of Strings of file names that should come in the specified order

  • string (String) (defaults to: nil)

    the name of the output file to concatenate inputs to.

  • block (Proc)

    a block to use as the Filter’s #output_name_generator.



22
23
24
25
# File 'lib/rake-pipeline-web-filters/ordering_concat_filter.rb', line 22

def initialize(ordering, string=nil, &block)
  @ordering = ordering
  super(string, &block)
end

Instance Method Details

#generate_output(inputs, output) ⇒ Object

Extend the #generate_output method supplied by ConcatFilter. Re-orders the inputs such that the specified files come first. If a file is not in the list it will come after the specified files.



30
31
32
33
34
35
36
# File 'lib/rake-pipeline-web-filters/ordering_concat_filter.rb', line 30

def generate_output(inputs, output)
  @ordering.reverse.each do |name|
    file = inputs.find{|i| i.path == name }
    inputs.unshift(inputs.delete(file)) if file
  end
  super
end