-
Notifications
You must be signed in to change notification settings - Fork 0
Concise and fast javascript templating compatible with nodejs and other javascript environments
License
bayun/doT
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Created in search of the fast and concise JavaScript templating function with emphasis on performance under V8 and nodejs. doT can be used with nodejs and other javascript environments. doT.js is a blend of jQote2 and underscore.js templating functions with some additions. jQote2 technique provides for fast performance and also enables flushing data to the stream at any point in the generated template function, this is handy when using on server. Features: custom delimiters, runtime evaluation, runtime interpolation, compile-time evaluation, partials support, encoding, control whitespace - strip or preserve, streaming friendly Differences between this version and original: foreach implied - if data given to generated template functions is array, function will output concatenation of templates for each array member: doT.template("[{{=it}}]")([1,2,3,4,5]) will return "[1][2][3][4][5]" sub-template definition and usage. With foreach this allows to do repeating sections in one template. Only one level of sub-templates supported. Example: doT.template("{[f:[{{=it}}]]}==={{=it.header}}==={>f:it.array<}")({header: 'Head', array:[1,2,3,4,5]}) will output "===Head===[1][2][3][4][5]" Benchmarks: jslitmus is used for benchmarking. To run the benchmarks for measuring execution of compiled templates: In the browser: navigate to benchmarks/index.html or go to http://olado.github.com/doT/bench.html With node: node benchmarks/templatesBench.js doT.js vs other engines: http://jsperf.com/dom-vs-innerhtml-based-templating To run the benchmarks for measuring compilation speed: In the browser: navigate to benchmarks/genspeed.html With node: node benchmarks/compileBench.js Install doT: npm install dot // use require('dot') in your code if you installed with npm Usage: Default delimiters: {{= }} for interpolation, {{ }} for evaluation, {{! }} for interpolation with encoding, {{# }} for compile-time evaluation/includes and partials, {{## #}} for compile-time defines {[ ]} for sub-template definition {><} for sub-template use Other delimiters may be configured. To control whitespace use 'strip' option, true - to strip, false - to preserve. Sample: // 1. Compile template function var tempFn = doT.template("<h1>Here is a sample template {{=it.foo}} </h1>"); // 2. Use template function as many times as you like var resultText = tempFn({foo: 'with doT'}); Basic template sample: https://github.com/olado/doT/blob/master/examples/snippet.txt Advanced template sample: https://github.com/olado/doT/blob/master/examples/advancedsnippet.txt Note about doU.js: doU.js is here only so that legacy extrenal tests do not break. Use doT.js. doT.js with doT.templateSettings.append=false provides the same performance as doU.js. License: doT is an open source component of http://bebedo.com doT is licensed under the MIT License. (See LICENSE-DOT)
About
Concise and fast javascript templating compatible with nodejs and other javascript environments
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- JavaScript 100.0%