My favorites
▼
|
Sign in
json-template
Minimal but powerful templating language implemented in multiple languages
Project Home
Downloads
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
22
attachment: prototype.patch
(1.4 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Index: json-template.js
===================================================================
--- json-template.js (revision 267)
+++ json-template.js (working copy)
@@ -509,24 +509,21 @@
function Template(template_str, options) {
+ if(!(this instanceof Template)) // run as `Template()` instead of `new Template()`
+ return new Template(template_str, options);
// options.undefined_str can either be a string or undefined
- options = options || {};
-
- var program = _Compile(template_str, options);
-
- return {
- render: function(data_dict, callback) {
- var context = _ScopedContext(data_dict, options.undefined_str);
- _Execute(program.Statements(), context, callback);
- },
-
- expand: function(data_dict) {
- var tokens = [];
- this.render(data_dict, function(x) { tokens.push(x); });
- return tokens.join('');
- }
- };
+ this._options = options || {};
+ this._program = _Compile(template_str, this._options);
}
+Template.prototype.render = function(data_dict, callback) {
+ var context = _ScopedContext(data_dict, this._options.undefined_str);
+ _Execute(this._program.Statements(), context, callback);
+};
+Template.prototype.expand = function(data_dict) {
+ var tokens = [];
+ this.render(data_dict, function(x) { tokens.push(x); });
+ return tokens.join('');
+};
// We just export one name for now, the Template "class".
Powered by
Google Project Hosting