     escape = jade.runtime.escape.toString()
     rethrow = jade.runtime.rethrow.toString()
 
-    if @settings.compileDebug
-      obj = """
+    if @debug
+      obj = '
         var jade = {
           attrs: attrs,
           escape: escape,
           rethrow: rethrow
         };\n
-      """
+      '
       [attrs, escape, rethrow, obj].join('\n')
     else
-      obj = """
+      obj = '
         var jade = {
           attrs: attrs,
           escape: escape
         };\n
-      """
+      '
       [attrs, escape, obj].join('\n')
-
-
-extend = (main, sub) ->
-  for prop of sub
-    main[prop] = sub[prop] if sub[prop]?
-  main
-
-# Global settings
-globalSettings = {}
-
-###
-precompile(settings, dir)
-Description: Main precompile function
-
-Params:
-  settings(object): Global settings object for tmpl-precompile
-    "verbose": Boolean(default:false), if should output compile info on console
-    "relative": Boolean(default:true), if paths to each template is relative to settings file
-  dir(string): Main execution directory
-###
-precompile = (settings,dir) ->
-  globalSettings = settings
-  globalSettings.dir = dir
-
-  precompiler = new Precompiler(settings)
-  precompiler.compile()
-

path = require "path"
_ = require "underscore"
mkdirp = require "mkdirp"
async = require 'async'
compressor = require './utils/compressor'

# @api private

  root = path.join(global.options.templates, "/")
  output_path = path.normalize("public/js/templates.js")
  mkdirp.sync path.dirname(output_path)

  precompiler = new Precompiler(
    source: path.normalize(process.cwd() + '/' + root)
    output: output_path
    templates: _.map(fs.readdirSync(
      path.join(process.cwd(), root)),
      (f) -> path.basename f, ".jade"
    )
  )
  buf = precompiler.compile()
  buf = compressor buf, 'js'
  fs.writeFileSync output_path, buf


class Precompiler
  constructor: (options = {}) ->
    defaults =
      inline: false
      debug: false
      namespace: "templates"
      source: ''
      output: ''
      templates: undefined

    _.extend @, defaults, options

  ###
  compile()
  Description: Flow control and execution for the compilation
  ###
  compile: ->
    buf = []
    buf.push """
    (function(){
      window.#{@namespace} = window.#{@namespace} || {};
      #{@helpers() if @helpers isnt false and @inline isnt true}
    """

    for template in @templates
      buf.push @compileTemplate(template).toString()

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

  ###
  compileTemplate()
  Description: Compiles individual templates and returns them to compile()
  ###
  compileTemplate : (template) ->
    templateNamespace = template.replace(/\//g, '.') # Replaces '/' with '.'
    sourceFile = @source + template + '.jade'
    data = fs.readFileSync(sourceFile, 'utf8')

    "#{@namespace}.#{templateNamespace} = #{jade.compile(data, { compileDebug: @debug || false, inline: @inline || false, client: true })};\n"

  ###
  helpers()
