Skip to content

Commit

Permalink
Merge pull request #300 from epoberezkin/master
Browse files Browse the repository at this point in the history
v2 ES6
  • Loading branch information
epoberezkin committed Jul 25, 2020
2 parents 88a6e6a + 2ded735 commit 9bf25af
Show file tree
Hide file tree
Showing 33 changed files with 678 additions and 1,919 deletions.
58 changes: 40 additions & 18 deletions .eslintrc.yml
@@ -1,24 +1,46 @@
env:
node: true
extends: 'eslint:recommended'
globals:
define: false
es6: true
extends:
- "eslint:recommended"
- prettier
parserOptions:
ecmaVersion: 5
ecmaVersion: 2018
rules:
no-trailing-spaces: 2
linebreak-style: [ 2, unix ]
semi: [ 2, always ]
valid-jsdoc: [ 2, { requireReturn: false } ]
no-unused-vars: [ 2, { args: none } ]
block-scoped-var: error
dot-location: [error, property]
dot-notation: error
eqeqeq: [error, smart]
id-match: error
linebreak-style: [error, unix]
no-bitwise: error
no-cond-assign: error
no-console: 0
block-scoped-var: 2
dot-location: [ 2, property ]
dot-notation: 2
no-else-return: 2
no-eq-null: 2
no-fallthrough: 2
no-return-assign: 2
no-use-before-define: [ 2, nofunc ]
no-path-concat: 2
no-debugger: error
no-duplicate-case: error
no-duplicate-imports: error
no-else-return: error
no-empty: error
no-eval: error
no-invalid-this: error
no-eq-null: error
no-fallthrough: error
no-new-wrappers: error
no-path-concat: error
no-redeclare: error
no-return-assign: error
no-sequences: error
no-template-curly-in-string: error
no-trailing-spaces: error
no-undef-init: error
no-unsafe-finally: error
no-unused-vars: [error, args: none]
no-use-before-define: [error, nofunc]
no-useless-escape: 0
no-var: error
no-void: error
prefer-arrow-callback: error
prefer-const: error
radix: error
use-isnan: error
valid-jsdoc: [error, requireReturn: false]
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -34,3 +34,6 @@ node_modules
doT.min.js

package-lock.json

# Minified bundle
doT.min.js
4 changes: 4 additions & 0 deletions .prettierignore
@@ -0,0 +1,4 @@
bin
coverage
examples
.nyc_output
5 changes: 5 additions & 0 deletions .prettierrc.json
@@ -0,0 +1,5 @@
{
"bracketSpacing": false,
"semi": false,
"printWidth": 100
}
3 changes: 1 addition & 2 deletions .travis.yml
@@ -1,8 +1,7 @@
language: node_js
node_js:
- "8"
- "10"
- "12"
- "13"
- "14"
after_script:
- coveralls < coverage/lcov.info
67 changes: 27 additions & 40 deletions README.md
Expand Up @@ -8,7 +8,6 @@ doT.js is fast, small and has no dependencies.
[![npm version](https://badge.fury.io/js/dot.svg)](https://www.npmjs.com/package/dot)
[![Coverage Status](http://coveralls.io/repos/github/olado/doT/badge.svg?branch=master)](https://coveralls.io/github/olado/doT?branch=master)


## Note from the maintainer

doT is a really solid piece of software engineering (I didn’t create it) that is rarely updated exactly for this reason.
Expand All @@ -19,16 +18,14 @@ I used it in my other projects (e.g. [ajv](https://github.com/epoberezkin/ajv))

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).


## Features
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
Expand All @@ -43,58 +40,46 @@ http://olado.github.com/doT (todo: update docs with new features added in versio

```html
{{##def.macro:param:
<div>{{=param.foo}}</div>
#}}

{{#def.macro:myvariable}}
<div>{{=param.foo}}</div>
#}} {{#def.macro:myvariable}}
```

#### Node module now supports auto-compilation of dot templates from specified path

```js
var dots = require("dot").process({ path: "./views"});
var dots = require("dot").process({path: "./views"})
```

This will compile .def, .dot, .jst files found under the specified path.
Details
* It ignores sub-directories.
* Template files can have multiple extensions at the same time.
* Files with .def extension can be included in other files via {{#def.name}}
* Files with .dot extension are compiled into functions with the same name and
can be accessed as renderer.filename
* Files with .jst extension are compiled into .js files. Produced .js file can be
loaded as a commonJS, AMD module, or just installed into a global variable (default is set to window.render)
* All inline defines defined in the .jst file are
compiled into separate functions and are available via _render.filename.definename

Basic usage:
```js
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

#### CLI tool to compile dot templates into js files

./bin/dot-packer -s examples/views -d out/views
- It ignores sub-directories.
- Template files can have multiple extensions at the same time.
- Files with .def extension can be included in other files via {{#def.name}}
- Files with .dot extension are compiled into functions with the same name and
can be accessed as renderer.filename
- Files with .jst extension are compiled into .js files. Produced .js file can be
loaded as a commonJS, AMD module, or just installed into a global variable (default is set to window.render)
- All inline defines defined in the .jst file are
compiled into separate functions and are available via \_render.filename.definename

## Example for express
Many people are using doT with express. I added an example of the best way of doing it examples/express:
Basic usage:

[doT with express](examples/express)
```js
var dots = require("dot").process({path: "./views"})
dots.mytemplate({foo: "hello world"})
```

## Notes
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.
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

## Security considerations

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.
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:

Expand All @@ -105,9 +90,11 @@ It is strongly recommended to compile all templates to JS code as early as possi
Please report any found vulnerabilities to npm, not via issue tracker.

## Author

Laura Doktorova [@olado](http://twitter.com/olado)

## License

doT is licensed under the MIT License. (See LICENSE-DOT)

<p align="center">
Expand Down
110 changes: 0 additions & 110 deletions benchmarks/compileBench.js

This file was deleted.

22 changes: 0 additions & 22 deletions benchmarks/genspeed.html

This file was deleted.

22 changes: 0 additions & 22 deletions benchmarks/index.html

This file was deleted.

0 comments on commit 9bf25af

Please sign in to comment.