Skip to content

Commit

Permalink
compile remastered. +haml prefilter dirty fix
Browse files Browse the repository at this point in the history
  • Loading branch information
printercu committed Jan 16, 2013
1 parent 4094588 commit c6c0976
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 97 deletions.
106 changes: 55 additions & 51 deletions compile.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 44 additions & 46 deletions src/compile.coffee
Expand Up @@ -3,63 +3,61 @@ module.exports = (data, finalcb) ->
path = require 'path'
flow = require 'flow'
doT = require './doT.js'
child = require 'child_process'

readItem = ( item, callback ) ->
any_error = (results) ->
for r in results
return r[0] if r[0]
null

readItem = (item, callback) ->
flow.exec(
->
fs.stat item, @
( err, stat ) ->
if err
process.stderr.write err
@ err
else if stat.isDirectory()
cb = @
flow.exec(
->
fs.readdir item, @
( err, files ) ->
if err
process.stderr.write err
@ err
else
files.forEach ( file ) =>
readItem path.join( item, file ), @MULTI()
-> cb null
)
else
readFile item, @
-> callback null
-> fs.stat item, @
(err, stat) ->
return @ err if err
return readFile item, @ unless stat.isDirectory()
item_cb = @
flow.exec(
-> fs.readdir item, @
(err, files) ->
return @MULTI err if err
files.forEach (file) =>
readItem path.join(item, file), @MULTI()
(results) -> item_cb any_error results
)
(err) ->
callback err
)

readFile = ( file, callback ) ->
readFile = (file, callback) ->
flow.exec(
->
fs.readFile file, @
( err, text ) ->
if err
process.stderr.write "Error reading file '#{file}': '#{err}\n"
@ err
if file.match /.haml$/
child.exec "haml '#{file}'", @
file = path.basename file, '.haml'
else
id = path.basename file, path.extname file
if data.base
rel = path.relative(data.base, path.dirname file)
.replace /\//g, '.'
id = "#{rel}.#{id}" if rel
try
f = doT.compile text
doT.addCached id, f
@ null, f
catch e
process.stderr.write "Error compiling file '#{file}': '#{e}'\n"
@ e
-> callback(null)
fs.readFile file, @
(err, text) ->
return @ err if err
id = path.basename file, path.extname file
if data.base
rel = path.relative(data.base, path.dirname file)
.replace /\//g, '.'
id = "#{rel}.#{id}" if rel
f = dot_err = null
try
f = doT.compile text
doT.addCached id, f
catch e
dot_err = e
@ dot_err, f
(err, f) ->
callback err, f
)

flow.exec(
-> data.files.forEach ( val, i ) => readItem val, @MULTI()
(results) ->
return unless finalcb
for r in results
return finalcb r[0], doT.exportCached() if r[0]
finalcb null, doT.exportCached()
finalcb any_error(results), doT.exportCached()
)

0 comments on commit c6c0976

Please sign in to comment.