https://github.com/nuintun/portal
A micro and fast html template engine
https://github.com/nuintun/portal
javascript javascript-library portal template template-engine
Last synced: 8 months ago
JSON representation
A micro and fast html template engine
- Host: GitHub
- URL: https://github.com/nuintun/portal
- Owner: nuintun
- License: mit
- Created: 2016-12-29T01:56:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-07-20T03:40:11.000Z (almost 4 years ago)
- Last Synced: 2023-04-05T13:38:06.424Z (about 3 years ago)
- Topics: javascript, javascript-library, portal, template, template-engine
- Language: JavaScript
- Homepage:
- Size: 221 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# portal
> A micro and fast html template engine
>
> [![Dependencies][david-image]][david-url]
### API
* new Portal(options: Object)
* params: options { open: string, open: string, debug: boolean, strict: boolean }
* open: template open tag
* close: template close tag
* debug: debug mode
* strict: strict mode
* return: { inject: Function, eject: Function, compile: Function }
* inject(name: string, helper: Function): inject helper
* name: the name of helper
* helper: helper method
* eject(name: string): eject helper
* name: the name of helper
* compile(template: string): compile a template string
* template: template string
* `:` call helper
* `@` read template data property
* `=` output html escape string
* `==` output origin string
* return: { render: Function }
* render(data: Object): render function
* data: the template data
### Example
template:
```html
<% @items.forEach(function(item, index) { %>
<%== :link(item.href, 'download-' + index) %>
<% }) %>
```
usage:
```js
// Create a new instance
var portal = new Portal();
// Inject helper
portal.inject('link', function(href, text) {
return '' + text + '';
});
// Compile template string
var view = portal.compile(template);
// Render view
console.log(
view.render({
items: [
{ src: 'a.jpg', href: '/download/a.jpg' },
{ src: 'b.jpg', href: '/download/b.jpg' },
{ src: 'c.jpg', href: '/download/c.jpg' }
]
})
);
// Eject helper
portal.eject('link');
```
### Benchmark
> [speed](https://nuintun.github.io/portal/tests/speed.html)
>
> [render](https://nuintun.github.io/portal/tests/render.html)
>
> [compile](https://nuintun.github.io/portal/tests/compile.html)
### License
[MIT](LICENSE)
[david-image]: http://img.shields.io/david/dev/nuintun/portal.svg?style=flat-square
[david-url]: https://david-dm.org/nuintun/portal?type=dev