Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 40 lines (34 sloc) 1.152 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
Compiler = require('./haml-coffee')
CoffeeScript = require('coffee-script')

# Facade to Haml Coffee for easy template function
# compiling and JST template rendering.
#
module.exports =

  # Compile the Haml Coffee template into
  # a JavaScript function.
  #
  # @see {Compiler} for a complete list of the supported
  # compiler options.
  #
  # @param [String] source the Haml Coffee source
  # @param [Object] options the compiler options
  # @return [Function] the template
  #
  compile: (source, options) ->
    compiler = new Compiler(options)
    compiler.parse source

    template = new Function CoffeeScript.compile(compiler.precompile(), bare: true)

    (params) -> template.call params

  # Render a JavaScript Template.
  #
  # @see {Compiler} for a complete list of the supported
  # compiler options.
  #
  # @param [String] source the Haml Coffee source
  # @param [Object] options the compiler options
  # @return [String] the template source code
  #
  template: (source, name, namespace, options) ->
    compiler = new Compiler(options)
    compiler.parse source

    CoffeeScript.compile compiler.render(name, namespace)
Something went wrong with that request. Please try again.