Class: Rake::Pipeline::Web::Filters::NeuterFilter

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

Overview

A filter that takes files with requires and collapses them into a single file without requires.

Examples:

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

  filter Rake::Pipeline::Web::Filters::NeuterFilter, "neutered.js"
end

Instance Method Summary collapse

Constructor Details

#initialize(string = nil, config = {}, &block) ⇒ NeuterFilter

Returns a new instance of NeuterFilter.



85
86
87
88
89
90
91
92
93
94
# File 'lib/rake-pipeline-web-filters/neuter_filter.rb', line 85

def initialize(string=nil, config={}, &block)
  if string.is_a?(Hash)
    config = string
    string = nil
  end

  @config = config

  super(string, &block)
end

Instance Method Details

#additional_dependencies(input) ⇒ Object



105
106
107
108
# File 'lib/rake-pipeline-web-filters/neuter_filter.rb', line 105

def additional_dependencies(input)
  method = @config[:additional_dependencies]
  method ? method.call(input).map{|p| File.expand_path(p, input.root) } : []
end

#generate_output(inputs, output) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/rake-pipeline-web-filters/neuter_filter.rb', line 96

def generate_output(inputs, output)
  inputs.each do |input|
    known_files = [input.fullpath] + additional_dependencies(input)
    batch = NeuterBatch.new(@config, known_files)
    file = batch.file_wrapper(file_wrapper_class, input.root, input.path, input.encoding)
    output.write file.read
  end
end