创建的目的是寻找最快和简洁的JavaScript模板函数,重点关注V8和node js的性能。它显示了node js和浏览器的出色性能。
特点:
- 没有依赖,120 loc
- 非常快
- 自定义分隔符
- 运行时评估
- 运行时插值
- 编译时评估
- 部分支持
- 条件支持
- 数组迭代器
- 编码
- 控制空白 - 条纹或保留
- 流媒体友好
- 使用它作为无逻辑或逻辑,取决于你
Node.js和浏览器中最快捷的简洁JavaScript模板引擎。(The fastest + concise javascript template engine for Node.js and browsers.)
创建的目的是寻找最快和简洁的JavaScript模板函数,重点关注V8和node js的性能。它显示了node js和浏览器的出色性能。
名稱與所有者 | olado/doT |
---|---|
主編程語言 | JavaScript |
編程語言 | JavaScript (語言數: 2) |
平台 | |
許可證 | Other |
發布數 | 9 |
最新版本名稱 | v2.0.0-beta.1 (發布於 ) |
第一版名稱 | 0.2.0 (發布於 2012-12-23 20:55:09) |
創建於 | 2011-01-10 20:47:04 |
推送於 | 2023-11-02 13:32:48 |
最后一次提交 | 2020-07-26 13:34:20 |
星數 | 5k |
關注者數 | 167 |
派生數 | 1k |
提交數 | 163 |
已啟用問題? | |
問題數 | 216 |
打開的問題數 | 21 |
拉請求數 | 21 |
打開的拉請求數 | 8 |
關閉的拉請求數 | 74 |
已啟用Wiki? | |
已存檔? | |
是復刻? | |
已鎖定? | |
是鏡像? | |
是私有? |
Created in search of the fastest and concise JavaScript templating function with emphasis on performance under V8 and nodejs. It shows great performance for both nodejs and browsers.
doT.js is fast, small and has no dependencies.
doT is a really solid piece of software engineering (I didn’t create it) that is rarely updated exactly for this reason.
It took me years to grasp how it works even though it’s only 140 lines of code - it looks like magic.
I used it in my other projects (e.g. ajv) as the smallest, the fastest and the most functional (all three!) templating engine ever made, that is particularly useful in all code generation scenarios where manipulating AST is an overkill.
It’s a race car of templating engines - doT lacks bells and whistles that other templating engines have, but it allows to achive more than any other, if you use it right (YMMV).
custom delimiters
runtime evaluation
runtime interpolation
compile-time evaluation
partials support
conditionals support
array iterators
encoding
control whitespace - strip or preserve
streaming friendly
use it as logic-less or with logic, it is up to you
http://olado.github.com/doT (todo: update docs with new features added in version 1.0.0)
{{##def.macro:param:
<div>{{=param.foo}}</div>
#}}
{{#def.macro:myvariable}}
var dots = require("dot").process({ path: "./views"});
This will compile .def, .dot, .jst files found under the specified path.
Details
Basic usage:
var dots = require("dot").process({path: "./views"});
dots.mytemplate({foo:"hello world"});
The above snippet will:
* Compile all templates in views folder (.dot, .def, .jst)
* Place .js files compiled from .jst templates into the same folder
These files can be used with require, i.e. require("./views/mytemplate")
* Return an object with functions compiled from .dot templates as its properties
* Render mytemplate template
./bin/dot-packer -s examples/views -d out/views
Many people are using doT with express. I added an example of the best way of doing it examples/express:
doU.js is here only so that legacy external tests do not break. Use doT.js.
doT.js with doT.templateSettings.append=false provides the same performance as doU.js.
doT allows arbitrary JavaScript code in templates, making it one of the most flexible and powerful templating engines. It means that doT security model assumes that you only use trusted templates and you don't use any user input as any part of the template, as otherwise it can lead to code injection.
It is strongly recommended to compile all templates to JS code as early as possible. Possible options:
Please report any found vulnerabilities to npm, not via issue tracker.
Laura Doktorova @olado
doT is licensed under the MIT License. (See LICENSE-DOT)
Thank you @KevinKirchner for the logo.