Class: Rake::Pipeline::Web::Filters::CoffeeScriptFilter

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

Overview

A filter that compiles CoffeeScript to JavaScript.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ CoffeeScriptFilter

By default, the CoffeeScriptFilter converts inputs with the extension .coffee to .js.

Parameters:

  • options (Hash) (defaults to: {})

    options to pass to the CoffeeScript compiler.

  • block (Proc)

    the output name generator block



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

def initialize(options = {}, &block)
  block ||= proc { |input| input.sub(/\.coffee$/, '.js') }
  super(&block)
  @options = options
end

Instance Attribute Details

#optionsHash (readonly)

Returns a hash of options to pass to CoffeeScript when rendering.

Returns:

  • (Hash)

    a hash of options to pass to CoffeeScript when rendering.



8
9
10
# File 'lib/rake-pipeline-web-filters/coffee_script_filter.rb', line 8

def options
  @options
end

Instance Method Details

#external_dependenciesObject



37
38
39
# File 'lib/rake-pipeline-web-filters/coffee_script_filter.rb', line 37

def external_dependencies
  [ "coffee-script" ]
end

#generate_output(inputs, output) ⇒ Object

The body of the filter. Compile each input file into a CoffeeScript compiled output file.

Parameters:

  • inputs (Array)

    an Array of FileWrapper objects.

  • output (FileWrapper)

    a FileWrapper object



27
28
29
30
31
32
33
34
35
# File 'lib/rake-pipeline-web-filters/coffee_script_filter.rb', line 27

def generate_output(inputs, output)
  inputs.each do |input|
    begin
      output.write CoffeeScript.compile(input, options)
    rescue ExecJS::Error => error
      raise error, "Error compiling #{input.path}. #{error.message}"
    end
  end
end