项目作者: jimczj

项目描述 :
a javascript template engine
高级语言: JavaScript
项目地址: git://github.com/jimczj/jstemp.git
创建时间: 2017-11-08T04:36:00Z
项目社区:https://github.com/jimczj/jstemp

开源协议:MIT License

下载


jstemp

一个javascript模板引擎,词法分析没有使用正则表达式和其他第三方库,纯手写有穷状态机。目前支持变量替换,if\elseif\else表达式,for语句。暂不支持模板继承,过滤器等功能,错误处理也比较暴力,后期将继续完善。此库目前仅供练习使用,本人会将开发本库的过程写成博客记录下来,如果对这方面有兴趣,可以点star或watch。

安装

  1. npm install jstemp --save

使用方法

  1. var jstemp = require('jstemp');
  2. // 渲染变量
  3. jstemp.render('{{value}}', {value: 'hello world'});// hello world
  4. // 渲染if 表达式,目前if 条件表达式不支持复杂的表达式,如>=,||,&&,后期将加强
  5. jstemp.render('{% if value1 %}hello{% elseif value %}world{% else %}byebye{% endif %}', {value: 'hello world'});// world
  6. // 渲染列表
  7. jstemp.render('{%for item : list %}{{item}}{%endfor%}', {list:[1, 2, 3]});// 123

开发笔记

不用正则表达式,用javascript从零写一个模板引擎(一)

License

MIT License

Copyright (c) 2017 jimczj