Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 79 lines (53 sloc) 3.1 kb
a7e339c @paularmstrong replace Node-T references with Swig
authored
1 # Swig
0eac08c @skid Initial Commit
skid authored
2
2370d2b @paularmstrong breaking out the docs and cleaning up the README a bit
authored
3 A fast, Django-like template engine for node.js.
0eac08c @skid Initial Commit
skid authored
4
a7e339c @paularmstrong replace Node-T references with Swig
authored
5 Swig is a template engine inspired by the Django syntax. It has a few extensions and the templates are compiled to native javascript functions which make them really fast. For now it's synchronous, but once a template is read and compiled, it is cached in memory.
0eac08c @skid Initial Commit
skid authored
6
fa1cc2c @paularmstrong started a Features section for the README
authored
7 ## Features
8
9 * Object-Oriented template inheritance: inherit from multiple parent templates.
10 * Apply variable filters and transformations in your templates.
11 * [Express][2] compatible!
12
8fbe0a3 @paularmstrong add install instructions. should probably mention it's on npm... ya know...
authored
13 ## Installation
14
15 npm install swig
16
8a4c46d @paularmstrong add a documentation index and link from the readme
authored
17 ## Documentation
18
2eaef3f @paularmstrong moving docs/index to docs/readme for github prettiness.
authored
19 All documentation can be viewed online. [Documentation Table of Contents](https://github.com/paularmstrong/swig/blob/master/docs)
8a4c46d @paularmstrong add a documentation index and link from the readme
authored
20
2370d2b @paularmstrong breaking out the docs and cleaning up the README a bit
authored
21 ## Basic Example
23ea88f @paularmstrong updating readme for filters
authored
22
2370d2b @paularmstrong breaking out the docs and cleaning up the README a bit
authored
23 ### Template code
0eac08c @skid Initial Commit
skid authored
24
2370d2b @paularmstrong breaking out the docs and cleaning up the README a bit
authored
25 <h1>Example</h1>
26 {% for name in names %}
27 <p>
28 {{ forloop.counter }}
29 {# This is a comment #}
c4795ab @paularmstrong Require using end<tagname> like `endif` and `endfor` for all tags.
authored
30 {{ name }}{% if name == "Django" %} Reinhardt{% endif %}
2370d2b @paularmstrong breaking out the docs and cleaning up the README a bit
authored
31 </p>
c4795ab @paularmstrong Require using end<tagname> like `endif` and `endfor` for all tags.
authored
32 {% endfor %}
2370d2b @paularmstrong breaking out the docs and cleaning up the README a bit
authored
33
34 ### node.js code
0eac08c @skid Initial Commit
skid authored
35
a7e339c @paularmstrong replace Node-T references with Swig
authored
36 var template = require('Swig');
0eac08c @skid Initial Commit
skid authored
37 var tmpl = template.fromFile("/path/to/template.html");
2071180 @paularmstrong code conformity per jslint specifications.
authored
38 console.log(tmpl.render({names: ["Duke", "Django", "Louis"]}));
0eac08c @skid Initial Commit
skid authored
39
2370d2b @paularmstrong breaking out the docs and cleaning up the README a bit
authored
40 ### Output
41
42 <h1>Example</h1>
43 <p>
44 1
45 Duke
46 </p>
47 <p>
48 2
49 Django Reinhardt
50 </p>
51 <p>
52 3
53 Louis
54 </p>
55
56 ## How it works
0eac08c @skid Initial Commit
skid authored
57
a7e339c @paularmstrong replace Node-T references with Swig
authored
58 Swig reads template files and translates them into javascript functions using the Function constructor. When we later render a template we call the evaled function passing a context object as an argument. This makes the rendering very fast. The template tags are defined as strings of Javascript code - which is a bit ugly, but there are helpers that will make writing tags easier for you.
0eac08c @skid Initial Commit
skid authored
59
60 ## Template syntax
61
a7e339c @paularmstrong replace Node-T references with Swig
authored
62 While Swig is inspired by the [Django template syntax][1], there are a few differences:
0eac08c @skid Initial Commit
skid authored
63
2370d2b @paularmstrong breaking out the docs and cleaning up the README a bit
authored
64 - Filters have a different syntaxt.
65 - Some tags are missing or have different syntax.
66 - Some extra tags are available.
72f5ae3 @skid Added Message
skid authored
67
68 ## License
69
3a72f33 @paularmstrong updating license, adding license file
authored
70 Copyright (c) 2010-2011 Paul Armstrong, Dusko Jordanovski
72f5ae3 @skid Added Message
skid authored
71
72 Permission 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:
73
74 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
75
76 THE 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.
77
fa1cc2c @paularmstrong started a Features section for the README
authored
78 [1]: http://djangoproject.com/
79 [2]: http://expressjs.com/
Something went wrong with that request. Please try again.