export
render
str, options
options.cache
yes
options.filename
yes
fn
cache[filename]
cache[filename] = compile(str, options)
no
Error: cache need filename
options.__proto__ = options.locals
fn.call(options.scope, options)
compile
str
compileDebug
yes
__stack
parse(str, options)
catch error & rethrow
fn = new Function('locals, filters, escape, rethrow', str)
client
no
fn.call(this, locals, filters, escape, rethrow)
parse
options._with ? with(locals || {}) {function(){}} : ''
str traverse: stri<br>
str.slice(i, open.length + i) === open
i += open.length
i+1
var end = str.indexOf(close, i)
end < 0
throw Error
var js = str.substring(i, end)
'-' == js[js.length-1]
协助删除尾部换行符
include
yes
filename
yes
include = read file
include = parse(include, options)
js.substr(0, 1)
:
js = filtered(js)
%
buf.push('<%" + js.substring(1).replace(/'/g, "\\'") + "%>');<br>
输出 <%
buf += prefix<br>buf += js<br>buf += postfix
renderFile
str = read(path)
fn(null, render(str, options))
filter
require('./filter')
cache
cache = {}
clearCache