module HamlCoffeeAssets::Compiler

Handles compilation of Haml Coffee templates to JavaScript.

Public Class Methods

compile(name, source, jst = true) click to toggle source

Compile a Haml Coffee template.

@param [String] name the template name @param [String] source the template source code @param [Boolean] jst if a JST template should be generated @return [String] the compiled template in JavaScript

# File lib/haml_coffee_assets/compiler.rb, line 21
def compile(name, source, jst = true)
  config = HamlCoffeeAssets.config

  runtime.call('HamlCoffeeAssets.compile', name, source, jst,
               config.namespace, config.format, config.uglify, config.basename,
               config.escapeHtml, config.escapeAttributes, config.cleanValue, config.placement, config.dependencies,
               config.customHtmlEscape, config.customCleanValue,
               config.customPreserve, config.customFindAndPreserve,
               config.customSurround, config.customSucceed, config.customPrecede, config.customReference,
               config.preserveTags, config.selfCloseTags,
               config.context, false)
end

Private Class Methods

coffeescript() click to toggle source

Get the CoffeeScript source code.

@return [String] the source

# File lib/haml_coffee_assets/compiler.rb, line 72
def coffeescript
  File.read CoffeeScript::Source.path
end
haml_coffee() click to toggle source

Get the Haml CoffeeScript source code.

@return [String] the source

# File lib/haml_coffee_assets/compiler.rb, line 64
def haml_coffee
  read_js 'hamlcoffee.js'
end
haml_coffee_assets() click to toggle source

Get the Haml CoffeeScript Assets source code.

@return [String] the source

# File lib/haml_coffee_assets/compiler.rb, line 56
def haml_coffee_assets
  read_js 'haml_coffee_assets.js'
end
read_js(filename) click to toggle source

Read a JavaScript file from the ‘js` dir.

@param [String] filename the javascript filename @return [String] the source

# File lib/haml_coffee_assets/compiler.rb, line 81
def read_js(filename)
  Pathname.new(__FILE__).dirname.join('..', 'js', filename).read
end
runtime() click to toggle source

Get the context to compile Haml CoffeeScript templates.

@return [Runtime] the JS runtime

# File lib/haml_coffee_assets/compiler.rb, line 40
def runtime
  @runtime ||= ExecJS.compile(source)
end
source() click to toggle source

Get the combined source of haml-coffee and CoffeeScript.

@return [String] the source code

# File lib/haml_coffee_assets/compiler.rb, line 48
def source
  coffeescript + ';' + haml_coffee + ';' + haml_coffee_assets
end