Class: Extruder::OrderingConcatFilter

Inherits:
ConcatFilter show all
Defined in:
lib/extruder/filters/ordering_concat_filter.rb

Overview

A filter that concats files in a specified order.

Examples:

Extruder.build do
  input "app/assets"
  output "public"

  # Concat each file into libs.js but make sure
  # that jQuery and Ember come first.
  match "**/*.js"
    filter Rake::Extruder::OrderingConcatFilter, ["jquery.js", "ember.js"], "libs.js"
  end
end

Instance Attribute Summary

Attributes inherited from Filter

#files, #output_name_generator, #output_root

Instance Method Summary collapse

Methods inherited from ConcatFilter

#encoding

Methods inherited from Filter

#outputs, #process, 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.



31
32
33
34
# File 'lib/extruder/filters/ordering_concat_filter.rb', line 31

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.



42
43
44
45
46
47
48
# File 'lib/extruder/filters/ordering_concat_filter.rb', line 42

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