Skip to content

Commit

Permalink
Allow rendering from stdin, fixes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Aug 22, 2014
1 parent 3b1d8c9 commit 1d8c20c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ exports.render = (input, options, done) ->

# Render from/to files
exports.renderFile = (inputFile, outputFile, options, done) ->
fs.readFile inputFile, encoding: 'utf-8', (err, input) ->
if err then return done(err)

exports.render input.toString(), options, (err, html, warnings) ->
render = (input) ->
exports.render input, options, (err, html, warnings) ->
if err then return done(err)

if outputFile isnt '-'
Expand All @@ -108,3 +106,12 @@ exports.renderFile = (inputFile, outputFile, options, done) ->
else
console.log html
done null, warnings

if inputFile isnt '-'
fs.readFile inputFile, encoding: 'utf-8', (err, input) ->
if err then return done(err)
render input.toString()
else
process.stdin.setEncoding 'utf-8'
process.stdin.on 'readable', ->
render process.stdin.read()

0 comments on commit 1d8c20c

Please sign in to comment.