Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (34 sloc) 1.09 KB
fs = require 'fs'
path = require 'path'
jade = require 'jade'
regex = ///
include\s+ # @import followed by one or more whitespace chars
(.+) # capture any except single or double quote
///gi
exports.findImports = findImports = (imports, file, callback) ->
await fs.readFile file, 'utf8', defer err, contents
return callback err if err
newImports = []
while match = regex.exec contents
item = match[1]
item += '.jade' if path.extname(item) is ''
item = path.resolve path.dirname(file), item
unless item in imports
newImports.push item
imports.push item
for item in newImports
await findImports imports, item, defer err
return callback err if err
callback()
exports.compile = (file, flags, callback) ->
await fs.readFile file, 'utf8', defer err, contents
return callback err if err
try
contents = jade.compileClient contents,
filename: file
client: yes
compileDebug: no
catch err
return callback err
templateName = path.basename file, '.jade'
callback null, "JST['#{templateName}'] = #{contents};\n"