 else
   argv = process.argv[0..]
 
-render = (input_path) ->
+render = (input_path, output_directory) ->
   fs.readFile input_path, (err, contents) ->
     throw err if err
     html = coffeekup.render String(contents), options
-    write input_path, html
+    write input_path, html, output_directory
 
-write = (input_path, html) ->
+write = (input_path, html, output_directory) ->
   filename = path.basename(input_path, path.extname(input_path)) + '.html'
-  dir = path.dirname input_path
-  output_path = path.join dir, filename
-  html = ' ' if html.length <= 0
-  fs.writeFile output_path, html, (err) ->
-    puts html if options.print
-    puts "Compiled #{input_path}" if options.watch
+  dir = output_directory or path.dirname input_path
+  path.exists dir, (exists) ->
+    unless exists then fs.mkdirSync dir, 0777
+    
+    output_path = path.join dir, filename
+    html = ' ' if html.length <= 0
+    fs.writeFile output_path, html, (err) ->
+      throw err if err
+      puts html if options.print
+      puts "Compiled #{input_path}" if options.watch
 
 usage = '''
   Usage:

  if options.watch
    fs.watchFile file, {persistent: true, interval: 500}, (curr, prev) ->
      return if curr.size is prev.size and curr.mtime.getTime() is prev.mtime.getTime()
      render file
  else render file


switches = [
  ['-w', '--watch', 'Keeps watching the file and recompiling it when it changes']
  ['-o', '--output [DIR]', 'Specifies a directory to compile into.']
  ['-p', '--print', 'Prints the compiled html to stdout']
  ['-f', '--format', 'Applies line breaks to html output']
  ['-u', '--utils', 'Adds helper locals (currently only "render")']
