slinejs
v1.0.0
Published
Single-file ESM build of the Sline template engine.
Maintainers
Readme
slinejs
slinejs 是 Sline 模板引擎的单文件 ESM 发布包。npm 包只暴露根入口 sline.js,适合直接在 Node 或现代浏览器中通过 import 使用。
安装
npm install slinejs使用
Node / Bundler
import Sline from 'slinejs';
const sline = new Sline({ strict: false });
const template = sline.compile(`
<ul>
{{#for product in products}}
<li>{{product.title}} - {{product.price | money("$")}}</li>
{{/for}}
</ul>
`);
const html = template({
products: [
{ title: 'Orange Slice Drops', price: 389 },
{ title: 'Pearl Drop Ring', price: 109 },
],
});浏览器 ESM
<script type="module">
import Sline from './sline.js';
const sline = new Sline();
const html = sline.render('<h1>{{shop.name}}</h1>', {
shop: { name: 'Sline Demo' },
});
document.body.innerHTML = html;
</script>支持的核心能力
compile()/render()模板编译与渲染- 内置 Bottle 风格的 helper / filter
registerHelper()/registerFilter()注册自定义扩展registerPartial()/registerComponent()注册局部模板与组件registerTranslation()/registerTranslations()注入翻译字典- 模板缓存与 strict mode
说明
- 这个 npm 包的业务文件只发布根入口
sline.js和README.md;package.json会由 npm 自动附带。 - 仓库里的
core/、runtime/、demo.html、tests/等文件仍保留在源码仓库中,用于开发和验证,不随 npm 包一起发布。 - 如果你需要源码、示例或完整文档,请查看仓库:maxlee/sline.js
