UNPKG

2.85 kBMarkdownView Raw
1Swig [![Build Status](https://secure.travis-ci.org/paularmstrong/swig.png)](http://travis-ci.org/paularmstrong/swig)
2====
3
4[Swig](http://paularmstrong.github.com/swig/) is a fast, Django-like template engine for node.js.
5
6Features
7--------
8
9* Incredibly [fast][1]!
10* Available for node.js **and** major web browsers!
11* [Express](http://expressjs.com/) compatible.
12* Object-Oriented template inheritance.
13* Apply filters and transformations to output in your templates.
14* Automatically escapes all output.
15* Lots of iteration and conditionals supported.
16* Extendable and customizable.
17
18Installation
19------------
20
21 npm install swig
22
23Documentation
24-------------
25
26All documentation can be viewed online. [Documentation Table of Contents](https://github.com/paularmstrong/swig/tree/master/docs#readme)
27
28Basic Example
29-------------
30
31### Template code
32
33 <h1>{{ pagename|title }}</h1>
34 <ul>
35 {% for author in authors %}
36 <li{% if loop.index <= 0 %} class="first"{% endif %}>{{ author }}</li>
37 {% else %}
38 <li>There are no authors.</li>
39 {% endfor %}
40 </ul>
41
42### node.js code
43
44 var template = require('swig');
45 var tmpl = template.compileFile('/path/to/template.html');
46 tmpl.render({
47 pagename: 'awesome people',
48 authors: ['Paul', 'Jim', 'Jane']
49 });
50
51### Output
52
53 <h1>Awesome People</h1>
54 <ul>
55 <li class="first">Paul</li>
56 <li>Jim</li>
57 <li>Jane</li>
58 </ul>
59
60How it works
61------------
62
63Swig reads template files and translates them into cached javascript functions. When we later render a template we call the evaluated function, passing a context object as an argument. This makes the rendering [_very fast_][1].
64
65License
66-------
67
68Copyright (c) 2010-2011 Paul Armstrong, Dusko Jordanovski
69
70Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
71
72The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
73
74THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
75
76[1]: http://paularmstrong.github.com/node-templates/
\No newline at end of file