-fs = require 'fs'
-W = require 'when'
-_ = require 'lodash'
+fs        = require 'fs'
+W         = require 'when'
+_         = require 'lodash'
+nodefn    = require 'when/node'
+readFile  = _.partialRight(nodefn.lift(fs.readFile), 'utf8')
 
 class Adapter
   render: (str, opts = {}) ->

    @_render(str, opts)

  renderFile: (file, opts = {}) ->
    @render(fs.readFileSync(file, 'utf8'), _.extend(opts, {filename: file}))

  compile: (str, opts = {}) ->
    if not @_compile

    @_compileClient(str, opts)

  compileFileClient: (file, opts = {}) ->
    readFile(file).then _.partialRight(@compileClient, _.extend(opts, {filename: file})).bind(@)

module.exports = Adapter
