Class: Rake::Pipeline::ConcatFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/rake-pipeline/filters/concat_filter.rb

Overview

A built-in filter that simply accepts a series of inputs and concatenates them into output files based on the output file name generator.

Examples:

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

  # create a concatenated output file for each
  # directory of inputs.
  filter(Rake::Pipeline::ConcatFilter) do |input|
    # input files will look something like:
    #   javascripts/admin/main.js
    #   javascripts/admin/app.js
    #   javascripts/users/main.js
    #
    # and the outputs will look like:
    #   javascripts/admin.js
    #   javascripts/users.js
    directory = File.dirname(input)
    ext = File.extname(input)

    "#{directory}#{ext}"
  end
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 Filter

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

Constructor Details

#initialize(string = nil, &block) ⇒ ConcatFilter


35
36
37
38
# File 'lib/rake-pipeline/filters/concat_filter.rb', line 35

def initialize(string=nil, &block)
  block = proc { string } if string
  super(&block)
end

Instance Method Details

#encodingString


42
# File 'lib/rake-pipeline/filters/concat_filter.rb', line 42

processes_binary_files

#generate_output(inputs, output) ⇒ Object

implement the #generate_output method required by the Filter API. In this case, simply loop through the inputs and write their contents to the output.

Recall that this method will be called once for each unique output file.


56
57
58
59
60
# File 'lib/rake-pipeline/filters/concat_filter.rb', line 56

def generate_output(inputs, output)
  inputs.each do |input|
    output.write input.read
  end
end