Class: Rake::Pipeline::OrderingConcatFilter

Inherits:
ConcatFilter show all
Defined in:
lib/rake-pipeline/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 Ember come first.
  filter Rake::Pipeline::OrderingConcatFilter, ["jquery.js", "ember.js"], "libs.js"
end

Instance Attribute Summary

Attributes inherited from Filter

#file_wrapper_class, #input_files, #last_manifest, #manifest, #output_name_generator, #output_root, #pipeline, #rake_application, #rake_tasks

Instance Method Summary collapse

Methods inherited from ConcatFilter

#encoding

Methods inherited from Filter

#additional_dependencies, #generate_rake_tasks, #output_files, #outputs, processes_binary_files

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 Filter#output_name_generator.


22
23
24
25
# File 'lib/rake-pipeline/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/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