ejs 流程
2020-04-09 17:31:51 0 举报
AI智能生成
ejs 源码逻辑
作者其他创作
大纲/内容
ejs
export
render
str, options
options.cache
yes
options.filename
yes
fn
cache[filename]
cache[filename] = compile(str, options)
no
Error: cache need filename
no
fn
compile(str, options)
options.__proto__ = options.locals
fn.call(options.scope, options)
compile
str
compileDebug
yes
__stack
parse(str, options)
catch error & rethrow
no
parse(str, options)
fn = new Function('locals, filters, escape, rethrow', str)
client
yes
fn
no
fn.call(this, locals, filters, escape, rethrow)
parse
options._with ? with(locals || {}) {function(){}} : ''
str traverse: stri
str.slice(i, open.length + i) === open
i += open.length
switch
=
',escape(( ,
)),'
-
',( ,
),'
default
');
; buf.push('
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
no
throw error
yes
include = read file
include = parse(include, options)
js.substr(0, 1)
:
js = filtered(js)
%
buf.push('<%" + js.substring(1).replace(/'/g, "\\'") + "%>');
输出 <%
#
js = ''
注释
buf += prefix
buf += js
buf += postfix
buf += js
buf += postfix
\\
\\\\
'
\\'
\r
ignore
\n
consumeEOL
yes
consumeEOL = false
no
\\n
lineno++
default
buf += stri
renderFile
str = read(path)
fn(null, render(str, options))
filter
require('./filter')
cache
cache = {}
clearCache
function
filtered
rethrow
resolveInclude
utils
filter
&
<
>
'
"
0 条评论
下一页