nornj
Version:
A powerful template engine that can works with React, JSX enhancement or alternative tools.
59 lines (55 loc) • 1.38 kB
JavaScript
import nj from '../core';
import { assign } from '../utils/tools';
import { compileStringTmpl } from '../parser/checkStringElem';
import { createTmplRule } from '../utils/createTmplRule';
export function createTaggedTmpl(opts = {}) {
const {
outputH,
delimiters,
fileName,
isExpression,
isCss
} = opts;
const tmplRule = delimiters ? createTmplRule(delimiters) : nj.tmplRule;
return function (strs, ...args) {
return compileStringTmpl.apply({
tmplRule,
outputH,
fileName,
isExpression,
isCss
}, arguments);
};
}
export function createTaggedTmplH(opts = {}) {
opts.outputH = true;
return createTaggedTmpl(opts);
}
export const taggedTmpl = createTaggedTmpl();
export const taggedTmplH = createTaggedTmplH();
export function template(strs, ...args) {
return (nj.outputH ? taggedTmplH : taggedTmpl).apply(null, arguments)();
}
const _taggedExpressionH = createTaggedTmplH({
isExpression: true
});
export function expression(strs, ...args) {
return _taggedExpressionH.apply(null, arguments)();
}
const _taggedCssH = createTaggedTmplH({
isCss: true
});
export function css(strs, ...args) {
return _taggedCssH.apply(null, arguments)();
}
assign(nj, {
createTaggedTmpl,
createTaggedTmplH,
taggedTmpl,
htmlString: taggedTmpl,
taggedTmplH,
html: taggedTmplH,
template,
expression,
css
});