Class: Rake::Pipeline::Web::Filters::CoffeeScriptFilter
- Inherits:
-
Filter
- Object
- Filter
- Rake::Pipeline::Web::Filters::CoffeeScriptFilter
- 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
-
#options ⇒ Hash
readonly
A hash of options to pass to CoffeeScript when rendering.
Instance Method Summary collapse
- #external_dependencies ⇒ Object
-
#generate_output(inputs, output) ⇒ Object
The body of the filter.
-
#initialize(options = {}, &block) ⇒ CoffeeScriptFilter
constructor
By default, the CoffeeScriptFilter converts inputs with the extension
.coffee
to.js
.
Constructor Details
#initialize(options = {}, &block) ⇒ CoffeeScriptFilter
By default, the CoffeeScriptFilter converts inputs with the extension .coffee
to .js
.
16 17 18 19 20 |
# File 'lib/rake-pipeline-web-filters/coffee_script_filter.rb', line 16 def initialize( = {}, &block) block ||= proc { |input| input.sub(/\.coffee$/, '.js') } super(&block) @options = end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns 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 end |
Instance Method Details
#external_dependencies ⇒ Object
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.
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, ) rescue ExecJS::Error => error raise error, "Error compiling #{input.path}. #{error.}" end end end |