UNPKG

772 BJavaScriptView Raw
1var metascript = require('metascript');
2
3/**
4 * metascript 编码
5 *
6 * @see https://github.com/dcodeIO/MetaScript
7 * @param {string} content 文本内容
8 * @param {Object} attrs 属性
9 */
10// <example>
11// * @example metascript():base
12// input:
13// <~jdists encoding="metascript" VERSION="1.0"~>
14// MyLibrary.VERSION = "/*?= VERSION */";
15// <~/jdists~>
16// output:
17// <~jdists encoding="metascript" VERSION="1.0"~>
18// MyLibrary.VERSION = "1.0";
19// <~/jdists~>
20// </example>
21module.exports = function processor(content, attrs, scope) {
22 if (!content) {
23 return content;
24 }
25 content = metascript.transform(content, scope.getDirname(), attrs);
26 if (/^(off|false|no)$/.test(attrs.rework)) {
27 return content;
28 } else {
29 return scope.compile(content);
30 }
31};