 mkdirp = require "mkdirp"
 compressor = require './utils/compressor'
 
-###*
- * compile jade templates into JS functions for use on the client-side, and
-   save it to a specified file
-###
+# compile jade templates into JS functions for use on the client-side, and
+# save it to a specified file
+
 module.exports = ->
   global.options.debug.log 'precompiling templates', 'yellow'
   return false if not global.options.templates?

    buf.push '})();'
    return buf.join ''

  ###*
   * compile individual templates
   * @param {String} template the full filename & path of the template to be compiled
   * @return {String} source of the template function
   * @private
  ###
  compileTemplate: (template) ->
    templateNamespace = path.basename(template, '.jade').replace(/\//g, '.') # Replaces '/' with '.'
    data = fs.readFileSync(template, 'utf8')
    data = jade.compile(data, { compileDebug: @debug || false, inline: @inline || false, client: true })
    return "#{@namespace}.#{templateNamespace} = #{data};\n"

  ###*
   * Gets Jade's helpers and combines them into string
   * @return {String} source of Jade's helpers
   * @private
  ###
  helpers: ->
    buf = [
      jade.runtime.attrs.toString().replace(/exports\./g,''),
      jade.runtime.escape.toString()
    ]

    if @debug
      buf.push jade.runtime.rethrow.toString()

    buf.push """
    var jade = {

  buf = precompiler.compile()
  buf = compressor buf, 'js'

  # TODO: make output path configurable
  output_path = path.normalize('public/js/templates.js')
  mkdirp.sync path.dirname(output_path)
  fs.writeFileSync output_path, buf


class Precompiler
  
  # deals with setting up the variables for options
  # @param {Object} options = {} an object holding all the options to be
  # passed to the compiler. 'templates' must be specified.
  # @constructor
  
  constructor: (options = {}) ->
    defaults =
      include_helpers: true
