1
+ /* ************************************************************************
2
+
3
+ qooxdoo - the new era of web development
4
+
5
+ http://qooxdoo.org
6
+
7
+ Copyright:
8
+ 2004-2011 1&1 Internet AG, Germany, http://www.1und1.de
9
+
10
+ License:
11
+ LGPL: http://www.gnu.org/licenses/lgpl.html
12
+ EPL: http://www.eclipse.org/org/documents/epl-v10.php
13
+ See the LICENSE file in the project's top-level directory for details.
14
+
15
+ Authors:
16
+ * Martin Wittemann (martinwittemann)
17
+
18
+ ======================================================================
19
+
20
+ This class contains code based on the following work:
21
+
22
+ * Mustache.js version 0.4.0-dev
23
+
24
+ Code:
25
+ https://github.com/janl/mustache.js
26
+
27
+ Copyright:
28
+ (c) 2009 Chris Wanstrath (Ruby)
29
+ (c) 2010 Jan Lehnardt (JavaScript)
30
+
31
+ License:
32
+ MIT: http://www.opensource.org/licenses/mit-license.php
33
+
34
+ ----------------------------------------------------------------------
35
+
36
+ Copyright (c) 2009 Chris Wanstrath (Ruby)
37
+ Copyright (c) 2010 Jan Lehnardt (JavaScript)
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining
40
+ a copy of this software and associated documentation files (the
41
+ "Software"), to deal in the Software without restriction, including
42
+ without limitation the rights to use, copy, modify, merge, publish,
43
+ distribute, sublicense, and/or sell copies of the Software, and to
44
+ permit persons to whom the Software is furnished to do so, subject to
45
+ the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be
48
+ included in all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
51
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
52
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
53
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
54
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
55
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
56
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57
+
58
+ ************************************************************************ */
59
+
60
+ /**
61
+ * The is a template class which can be used for HTML templating. In fact,
62
+ * this is a wrapper for mustache.js which is a "framework-agnostic way to
63
+ * render logic-free views".
64
+ *
65
+ * Here is a basic example how to use it:
66
+ * Template:
67
+ * <pre>
68
+ * var template = "Hi, my name is {{name}}!";
69
+ * var view = {name: "qooxdoo"};
70
+ * qx.bom.Template.toHtml(template, view);
71
+ * // return "Hi, my name is qooxdoo!"
72
+ * </pre>
73
+ *
74
+ * For further details, please visit the mustache.js documentation here:
75
+ * https://github.com/janl/mustache.js/blob/master/README.md
76
+ */
77
+ qx.Class.define("qx.bom.Template", {
78
+ statics : {
79
+ /** Contains the mustache.js version. */
80
+ version: null,
81
+
82
+ /**
83
+ * Original and only template method of mustache.js. For further
84
+ * documentation, please visit https://github.com/janl/mustache.js
85
+ *
86
+ * @signature function(template, view, partials, send_fun)
87
+ * @param template {String} The String containing the template.
88
+ * @param view {Object} The object holding the data to render.
89
+ * @param partials {Object} Object holding parts of a template.
90
+ * @param send_fun {Function?} Callback function for streaming.
91
+ * @return {String} The parsed template.
92
+ */
93
+ toHtml: null,
94
+
95
+
96
+ /**
97
+ * Helper method which provides you with a direct access to templates
98
+ * stored as HTML in the DOM. The DOM node with the given ID will be reated
99
+ * as a template, parsed and a new DOM node will be returned containing the
100
+ * parsed data.
101
+ *
102
+ * @param id {String} The id of the HTML template in the DOM.
103
+ * @param view {Object} The object holding the data to render.
104
+ * @param partials {Object} Object holding parts of a template.
105
+ * @return {DomNode} A DOM element holding the parsed template data.
106
+ */
107
+ get : function(id, view, partials) {
108
+ var template = document.getElementById(id);
109
+ var inner = template.innerHTML;
110
+
111
+ inner = this.toHtml(inner, view, partials);
112
+
113
+ var helper = qx.bom.Element.create("div");
114
+ helper.innerHTML = inner;
115
+
116
+ return helper.children[0];
117
+ }
118
+ }
119
+ });
120
+
121
+ (function() {
122
+
123
+ /**
124
+ * Below is the original mustache.js code. Snapshot date is mentioned in
125
+ * the head of this file.
126
+ */
127
+
0 commit comments