Class: Soca::Plugins::CoffeeScript
- Inherits:
-
Soca::Plugin
- Object
- Soca::Plugin
- Soca::Plugins::CoffeeScript
- Defined in:
- lib/soca/plugins/coffeescript.rb
Instance Attribute Summary
Attributes inherited from Soca::Plugin
Instance Method Summary collapse
-
#before_build ⇒ Object
Run the coffeescript plugin.
Methods inherited from Soca::Plugin
#app_dir, #config, #initialize, #logger, name, plugins
Constructor Details
This class inherits a constructor from Soca::Plugin
Instance Method Details
#before_build ⇒ Object
Run the coffeescript plugin. Available options:
-
:files - Run these files through CoffeeScript. Can be an array of patterns
or a single file. The default is '*.coffee'.
-
:vars - Additional variables to interpolate. By default the ‘env` and
`config` are interpolated.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/soca/plugins/coffeescript.rb', line 17 def before_build file_patterns = [:files] || '**/*.coffee' files = Dir[*[file_patterns].flatten] vars = { :env => pusher.env, :config => pusher.config }.merge([:vars] || {}) Soca.logger.debug "CoffeeScript vars: #{vars.inspect}" files.each do |file| Soca.logger.debug "Running #{file} through CoffeeScript." basename = File.basename(file) dir = File.dirname(file) parts = basename.split(/\./) new_file = (parts.length > 2 ? parts[0..-2].join('.') : parts[0]) + ".js" output_dir = [:output_dir] || dir File.open(File.join(output_dir, new_file), 'w') do |f| f << ::CoffeeScript.compile(File.read(file), vars) end Soca.logger.debug "Wrote to #{new_file}" end end |