Skip to content

Commit

Permalink
Merge branch 'pyrotechnick-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricemach committed Feb 11, 2011
2 parents 41674ec + 1f416e8 commit cc45da5
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions bin/coffeekup.coffee
Expand Up @@ -13,20 +13,24 @@ if process.argv[0] is 'node' and process.argv.length >= 2
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:
Expand All @@ -35,6 +39,7 @@ usage = '''

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")']
Expand All @@ -61,5 +66,5 @@ if args.length > 0
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
render file, options.output
else render file, options.output

0 comments on commit cc45da5

Please sign in to comment.