Class: Rake::Pipeline::Web::Filters::IifeFilter

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

Overview

A filter that wraps input files in an IIFE (immediately invoked functional expression)

Examples:

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

  # Wrap each file in: (function() { ... })();"
  filter Rake::Pipeline::Web::Filters::IifeFilter
end

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ IifeFilter


17
18
19
20
# File 'lib/rake-pipeline-web-filters/iife_filter.rb', line 17

def initialize(&block)
  block ||= proc { |input| input }
  super(&block)
end

Instance Method Details

#generate_output(inputs, output) ⇒ Object

Implement the #generate_output method required by the Filter API. Wraps each input in an IIFE.


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

def generate_output(inputs, output)
  inputs.each do |input|
    output.write "(function() {\n"
    output.write input.read
    output.write "})();"
  end
end