Skip to content

Commit 7eaa2af

Browse files
committed
Updated qooxdoo templates.
1 parent 4c3caf8 commit 7eaa2af

File tree

2 files changed

+56
-31
lines changed

2 files changed

+56
-31
lines changed

wrappers/qooxdoo/mustache.js.post

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
// EXPOSE qooxdoo variant
6-
qx.bom.Template.version = Mustache.version;
7-
qx.bom.Template.render = Mustache.render;
6+
qx.bom.Template.version = this.Mustache.version;
7+
qx.bom.Template.render = this.Mustache.render;
88

9-
})();
9+
}).call({});

wrappers/qooxdoo/mustache.js.pre

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
This class contains code based on the following work:
2121

22-
* Mustache.js version 0.5.1-dev
22+
* Mustache.js version 0.7.2
2323

2424
Code:
2525
https://github.com/janl/mustache.js
@@ -56,27 +56,25 @@
5656
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5757

5858
************************************************************************ */
59-
/* ************************************************************************
60-
61-
#ignore(module)
6259

63-
************************************************************************ */
6460
/**
65-
* The is a template class which can be used for HTML templating. In fact,
66-
* this is a wrapper for mustache.js which is a "framework-agnostic way to
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
6763
* render logic-free views".
68-
*
64+
*
6965
* Here is a basic example how to use it:
7066
* Template:
71-
* <pre>
67+
* <pre class="javascript">
7268
* var template = "Hi, my name is {{name}}!";
7369
* var view = {name: "qooxdoo"};
74-
* qx.bom.Template.toHtml(template, view);
70+
* qx.bom.Template.render(template, view);
7571
* // return "Hi, my name is qooxdoo!"
7672
* </pre>
77-
*
73+
*
7874
* For further details, please visit the mustache.js documentation here:
7975
* https://github.com/janl/mustache.js/blob/master/README.md
76+
*
77+
* @ignore(module)
8078
*/
8179
qx.Bootstrap.define("qx.bom.Template", {
8280
statics : {
@@ -95,35 +93,60 @@ qx.Bootstrap.define("qx.bom.Template", {
9593
*/
9694
render: null,
9795

96+
/**
97+
* Combines {@link #render} and {@link #get}. Input is equal to {@link #render}
98+
* and output is equal to {@link #get}. The advantage over {@link #get}
99+
* is that you don't need a HTML template but can use a template
100+
* string and still get a DOM element. Keep in mind that templates
101+
* can only have one root element.
102+
*
103+
* @param template {String} The String containing the template.
104+
* @param view {Object} The object holding the data to render.
105+
* @param partials {Object} Object holding parts of a template.
106+
* @return {Element} A DOM element holding the parsed template data.
107+
*/
108+
renderToNode : function(template, view, partials) {
109+
var renderedTmpl = this.render(template, view, partials);
110+
return this._createNodeFromTemplate(renderedTmpl);
111+
},
98112

99113
/**
100-
* Helper method which provides you with a direct access to templates
101-
* stored as HTML in the DOM. The DOM node with the given ID will be used
102-
* as a template, parsed and a new DOM node will be returned containing the
103-
* parsed data. Keep in mind to have only one root DOM element in the the
114+
* Helper method which provides you with a direct access to templates
115+
* stored as HTML in the DOM. The DOM node with the given ID will be used
116+
* as a template, parsed and a new DOM node will be returned containing the
117+
* parsed data. Keep in mind to have only one root DOM element in the the
104118
* template.
119+
* Additionally, you should not put the template into a regular, hidden
120+
* DOM element because the template may not be valid HTML due to the containing
121+
* mustache tags. We suggest to put it into a script tag with the type
122+
* <code>text/template</code>.
105123
*
106124
* @param id {String} The id of the HTML template in the DOM.
107125
* @param view {Object} The object holding the data to render.
108126
* @param partials {Object} Object holding parts of a template.
109-
* @return {DomNode} A DOM element holding the parsed template data.
127+
* @return {Element} A DOM element holding the parsed template data.
110128
*/
111129
get : function(id, view, partials) {
112130
// get the content stored in the DOM
113131
var template = document.getElementById(id);
114-
var inner = template.innerHTML;
132+
return this.renderToNode(template.innerHTML, view, partials);
133+
},
115134

116-
// apply the view
117-
inner = this.toHtml(inner, view, partials);
118-
119-
// special case for text only conversion
120-
if (inner.search(/<|>/) === -1) {
121-
return inner;
135+
/**
136+
* Accepts a parsed template and returns a (potentially nested) node.
137+
*
138+
* @param template {String} The String containing the template.
139+
* @return {Element} A DOM element holding the parsed template data.
140+
*/
141+
_createNodeFromTemplate : function(template) {
142+
// template is text only (no html elems) so use text node
143+
if (template.search(/<|>/) === -1) {
144+
return document.createTextNode(template);
122145
}
123146

124-
// create a helper to convert the string into DOM nodes
125-
var helper = qx.bom.Element.create("div");
126-
helper.innerHTML = inner;
147+
// template has html elems so convert string into DOM nodes
148+
var helper = qx.dom.Element.create("div");
149+
helper.innerHTML = template;
127150

128151
return helper.children[0];
129152
}
@@ -133,7 +156,9 @@ qx.Bootstrap.define("qx.bom.Template", {
133156
(function() {
134157

135158
/**
136-
* Below is the original mustache.js code. Snapshot date is mentioned in
159+
* Below is the original mustache.js code. Snapshot date is mentioned in
137160
* the head of this file.
138-
* @lint ignoreUndefined(module)
161+
* @ignore(exports)
162+
* @ignore(define.*)
163+
* @ignore(module.*)
139164
*/

0 commit comments

Comments
 (0)