Juicer
Juicer copied to clipboard
无法解析占位符含有%的模板
因为页面使用 Velocity 模板,所以Juicer变量占位符会与其冲突,改为如下配置:
<textarea id="tpl">
{{wd}} - {{=wd}}
{%if success%}
OK
{%else%}
ERROR
{%/if%}
</textarea>
<script type="text/javascript">
juicer.set({
'tag::operationOpen': '{%',
'tag::operationClose': '%}',
'tag::interpolateOpen': '{{',
'tag::interpolateClose': '}}',
'tag::noneencodeOpen': '{{=',
'tag::noneencodeClose': '}}',
'tag::commentOpen': '{#',
'tag::commentClose': '}',
'errorhandling': false,
'strip': false
});
var tpl = document.getElementById('tpl').value;
var result = juicer(tpl, {
success: 1,
wd: '<em>测试</em>'
});
document.write(result);
</script>
跑出异常:
Juicer Compile Exception: Unexpected token else
经过排查L443 将%转义处理了,导致如下这样的配置不能正常处理 else 分支:
replace(/[+-/
%
!?|^&~<>=,()[]]\s([A-Za-z_]+)/igm, variableAnalyze);
@PaulGuo 是不是可以考虑去掉对%的转义,另外juicer的构造函数中有这样的一行代码:
if(typeof(document) !== 'undefined' && document.body) {
juicer.compile.call(juicer, document.body.innerHTML);
}
是否会带来性能问题