   register: (name,fn) ->
     @hbs.registerHelper(name,withRoot(fn,{root: @root,hbs: @hbs, compiler: this}))
 
-  # cb(err)
-  compile: (cb) ->
+  # @param {String} input The string to compile as template
+  # @param {Function(Error,String)} Callbacks with the compiled output string.
+  compile: (input,cb) ->
     async.waterfall [
-      @readInput.bind(@)
-      @renderhbs.bind(@)
+      @renderhbs.bind(@,input)
       @renderMarkedDown.bind(@)
       @applyTransforms.bind(@)
-      @writeOutput.bind(@)
     ], cb
 
   # @param content (String)

        highlight(code,lang,@hbs)
      }, cb

  # cb(err,streamData:String)
  readInput: (cb) ->
    chunks = []
    @inStream.on "data", (data) ->
      # assume is a buffer
      # TODO type check
      chunks.push data.toString()
    @inStream.on "end", ->
      cb(null,chunks.join(""))
    @inStream.on "error", (error) ->
      cb(error)

  # @param result (String)
  # cb(err)
  writeOutput: (result,cb) ->
    @outStream.write(result,"utf8",cb)

module.exports = TemplateCompiler

]

class TemplateCompiler
  constructor: (@root) ->
    @hbs = hbs.create()

    # Add utility functions to this instance of handlebars
