Inital Commit
[oweals/finalsclub.git] / node_modules / ejs / Readme.md
1
2 # EJS
3
4 Embedded JavaScript templates.
5
6 ## Installation
7
8     $ npm install ejs
9
10 ## Features
11
12   * Complies with the [Express](http://expressjs.com) view system
13   * Static caching of intermediate JavaScript
14   * Unbuffered code for conditionals etc `<% code %>`
15   * Escapes html by default with `<%= code %>`
16   * Unescaped buffering with `<%- code %>`
17   * Supports tag customization
18   * Filter support for designer-friendly templates
19   * Client-side support
20
21 ## Example
22
23     <% if (user) { %>
24             <h2><%= user.name %></h2>
25     <% } %>
26
27 ## Usage
28
29     ejs.compile(str, options);
30     // => Function
31
32     ejs.render(str, options);
33     // => str
34
35 ## Options
36
37   - `locals`          Local variables object
38   - `cache`           Compiled functions are cached, requires `filename`
39   - `filename`        Used by `cache` to key caches
40   - `scope`           Function execution context
41   - `debug`           Output generated function body
42   - `open`            Open tag, defaulting to "<%"
43   - `close`           Closing tag, defaulting to "%>"
44
45 ## Custom Tags
46
47 Custom tags can also be applied globally:
48
49     var ejs = require('ejs');
50     ejs.open = '{{';
51     ejs.close = '}}';
52
53 Which would make the following a valid template:
54
55     <h1>{{= title }}</h1>
56
57 ## Filters
58
59 EJS conditionally supports the concept of "filters". A "filter chain"
60 is a designer friendly api for manipulating data, without writing JavaScript.
61
62 Filters can be applied by supplying the _:_ modifier, so for example if we wish to take the array `[{ name: 'tj' }, { name: 'mape' },  { name: 'guillermo' }]` and output a list of names we can do this simply with filters:
63
64 Template:
65
66     <p><%=: users | map:'name' | join %></p>
67
68 Output:
69
70     <p>Tj, Mape, Guillermo</p>
71
72 Render call:
73
74     ejs.render(str, {
75         locals: {
76             users: [
77                 { name: 'tj' },
78                 { name: 'mape' },
79                 { name: 'guillermo' }
80             ]
81         }
82     });
83
84 Or perhaps capitalize the first user's name for display:
85
86     <p><%=: users | first | capitalize %></p>
87
88 ## Filter List
89
90 Currently these filters are available:
91
92   - first
93   - last
94   - capitalize
95   - downcase
96   - upcase
97   - sort
98   - sort_by:'prop'
99   - size
100   - length
101   - plus:n
102   - minus:n
103   - times:n
104   - divided_by:n
105   - join:'val'
106   - truncate:n
107   - truncate_words:n
108   - replace:pattern,substitution
109   - prepend:val
110   - append:val
111   - map:'prop'
112   - reverse
113   - get:'prop'
114
115 ## client-side support
116
117   include `./ejs.js` or `./ejs.min.js` and `require("ejs").compile(str)`.
118
119 ## License 
120
121 (The MIT License)
122
123 Copyright (c) 2009-2010 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
124
125 Permission is hereby granted, free of charge, to any person obtaining
126 a copy of this software and associated documentation files (the
127 'Software'), to deal in the Software without restriction, including
128 without limitation the rights to use, copy, modify, merge, publish,
129 distribute, sublicense, and/or sell copies of the Software, and to
130 permit persons to whom the Software is furnished to do so, subject to
131 the following conditions:
132
133 The above copyright notice and this permission notice shall be
134 included in all copies or substantial portions of the Software.
135
136 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
137 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
138 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
139 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
140 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
141 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
142 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.