cmstyle 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/app/assets/images/novartis-micro.png +0 -0
- data/lib/app/assets/images/novartis-small.png +0 -0
- data/lib/app/assets/javascripts/application.js +16 -0
- data/lib/app/assets/stylesheets/application.css +96 -0
- data/lib/app/views/{cmstyle → layouts}/_footer.slim +0 -0
- data/lib/app/views/layouts/_header.slim +34 -0
- data/lib/app/views/layouts/_modals.slim +66 -0
- data/lib/app/views/layouts/application.slim +35 -0
- data/lib/assets/images/8020select.png +0 -0
- data/lib/assets/images/adoptahydrant.png +0 -0
- data/lib/assets/images/apple-touch-icon-114-precomposed.png +0 -0
- data/lib/assets/images/apple-touch-icon-144-precomposed.png +0 -0
- data/lib/assets/images/apple-touch-icon-57-precomposed.png +0 -0
- data/lib/assets/images/apple-touch-icon-72-precomposed.png +0 -0
- data/lib/assets/images/bootstrap-example-carousel.png +0 -0
- data/lib/assets/images/bootstrap-example-fluid.jpg +0 -0
- data/lib/assets/images/bootstrap-example-hero.jpg +0 -0
- data/lib/assets/images/bootstrap-example-marketing-narrow.png +0 -0
- data/lib/assets/images/bootstrap-example-signin.png +0 -0
- data/lib/assets/images/bootstrap-example-starter.jpg +0 -0
- data/lib/assets/images/bootstrap-example-sticky-footer.png +0 -0
- data/lib/assets/images/bootstrap-mdo-sfmoma-01.jpg +0 -0
- data/lib/assets/images/bootstrap-mdo-sfmoma-02.jpg +0 -0
- data/lib/assets/images/bootstrap-mdo-sfmoma-03.jpg +0 -0
- data/lib/assets/images/breakingnews.png +0 -0
- data/lib/assets/images/browser-icon-chrome.png +0 -0
- data/lib/assets/images/browser-icon-firefox.png +0 -0
- data/lib/assets/images/browser-icon-safari.png +0 -0
- data/lib/assets/images/bs-docs-bootstrap-features.png +0 -0
- data/lib/assets/images/bs-docs-masthead-pattern.png +0 -0
- data/lib/assets/images/bs-docs-responsive-illustrations.png +0 -0
- data/lib/assets/images/bs-docs-twitter-github.png +0 -0
- data/lib/assets/images/fleetio.png +0 -0
- data/lib/assets/images/gathercontent.png +0 -0
- data/lib/assets/images/glyphicons-halflings-white.png +0 -0
- data/lib/assets/images/glyphicons-halflings.png +0 -0
- data/lib/assets/images/grid-baseline-20px.png +0 -0
- data/lib/assets/images/jshint.png +0 -0
- data/lib/assets/images/kippt.png +0 -0
- data/lib/assets/images/less-logo-large.png +0 -0
- data/lib/assets/images/logo.png +0 -0
- data/lib/assets/images/noise.png +0 -0
- data/lib/assets/images/responsive-illustrations.png +0 -0
- data/lib/assets/images/slide-01.jpg +0 -0
- data/lib/assets/images/slide-02.jpg +0 -0
- data/lib/assets/images/slide-03.jpg +0 -0
- data/lib/assets/images/small-hogan-icon.png +0 -0
- data/lib/assets/images/soundready.png +0 -0
- data/lib/assets/images/stripes.png +0 -0
- data/lib/assets/javascripts/application.js +154 -0
- data/lib/assets/javascripts/bootstrap-affix.js +19 -0
- data/lib/assets/javascripts/bootstrap-alert.js +56 -0
- data/lib/assets/javascripts/bootstrap-button.js +96 -0
- data/lib/assets/javascripts/bootstrap-carousel.js +63 -0
- data/lib/assets/javascripts/bootstrap-collapse.js +88 -0
- data/lib/assets/javascripts/bootstrap-dropdown.js +145 -0
- data/lib/assets/javascripts/bootstrap-modal.js +114 -0
- data/lib/assets/javascripts/bootstrap-phantom.js +21 -0
- data/lib/assets/javascripts/bootstrap-popover.js +107 -0
- data/lib/assets/javascripts/bootstrap-scrollspy.js +31 -0
- data/lib/assets/javascripts/bootstrap-tab.js +80 -0
- data/lib/assets/javascripts/bootstrap-tooltip.js +153 -0
- data/lib/assets/javascripts/bootstrap-transition.js +13 -0
- data/lib/assets/javascripts/bootstrap-typeahead.js +199 -0
- data/lib/assets/javascripts/compiler.js +348 -0
- data/lib/assets/javascripts/hogan-1.0.5.amd.js +576 -0
- data/lib/assets/javascripts/hogan-1.0.5.common.js +576 -0
- data/lib/assets/javascripts/hogan-1.0.5.js +572 -0
- data/lib/assets/javascripts/hogan-1.0.5.mustache.js +619 -0
- data/lib/assets/javascripts/hogan.js +545 -0
- data/lib/assets/javascripts/index.js +848 -0
- data/lib/assets/javascripts/jquery.js +2 -0
- data/lib/assets/javascripts/mustache.js +90 -0
- data/lib/assets/javascripts/phantom.js +63 -0
- data/lib/assets/javascripts/prettify.js +0 -0
- data/lib/assets/javascripts/qunit.js +1510 -0
- data/lib/assets/javascripts/release.js +74 -0
- data/lib/assets/javascripts/server.js +14 -0
- data/lib/assets/javascripts/spec.js +77 -0
- data/lib/assets/javascripts/template-1.0.5.js +233 -0
- data/lib/assets/javascripts/template.js +233 -0
- data/lib/assets/javascripts/web_templates.js +32 -0
- data/lib/assets/stylesheets/bootstrap.css +2 -2
- data/lib/assets/stylesheets/css-tests.css +139 -0
- data/lib/assets/stylesheets/docs.css +1015 -0
- data/lib/assets/stylesheets/layout.css +206 -0
- data/lib/assets/stylesheets/prettify.css +0 -0
- data/lib/assets/stylesheets/qunit.css +232 -0
- data/lib/assets/stylesheets/skeleton.css +236 -0
- data/lib/cmstyle/railtie.rb +7 -0
- data/lib/cmstyle/version.rb +1 -1
- data/lib/cmstyle.rb +2 -1
- data/lib/tasks/cleanup.rake +52 -0
- data/lib/tasks/setup.rake +32 -0
- metadata +90 -6
- data/lib/app/views/cmstyle/_header.slim +0 -40
- data/lib/app/views/cmstyle/_modals.slim +0 -62
@@ -0,0 +1,619 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2011 Twitter, Inc.
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
* you may not use this file except in compliance with the License.
|
5
|
+
* You may obtain a copy of the License at
|
6
|
+
*
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
*
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
* See the License for the specific language governing permissions and
|
13
|
+
* limitations under the License.
|
14
|
+
*/
|
15
|
+
|
16
|
+
// A wrapper for compatibility with Mustache.js, quirks and all
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
var Hogan = {};
|
21
|
+
|
22
|
+
(function (Hogan) {
|
23
|
+
Hogan.Template = function constructor(renderFunc, text, compiler) {
|
24
|
+
if (renderFunc) {
|
25
|
+
this.r = renderFunc;
|
26
|
+
}
|
27
|
+
this.c = compiler;
|
28
|
+
this.text = text || '';
|
29
|
+
}
|
30
|
+
|
31
|
+
Hogan.Template.prototype = {
|
32
|
+
// render: replaced by generated code.
|
33
|
+
r: function (context, partials, indent) { return ''; },
|
34
|
+
|
35
|
+
// variable escaping
|
36
|
+
v: hoganEscape,
|
37
|
+
|
38
|
+
render: function render(context, partials, indent) {
|
39
|
+
return this.ri([context], partials || {}, indent);
|
40
|
+
},
|
41
|
+
|
42
|
+
// render internal -- a hook for overrides that catches partials too
|
43
|
+
ri: function (context, partials, indent) {
|
44
|
+
return this.r(context, partials, indent);
|
45
|
+
},
|
46
|
+
|
47
|
+
// tries to find a partial in the curent scope and render it
|
48
|
+
rp: function(name, context, partials, indent) {
|
49
|
+
var partial = partials[name];
|
50
|
+
|
51
|
+
if (!partial) {
|
52
|
+
return '';
|
53
|
+
}
|
54
|
+
|
55
|
+
if (this.c && typeof partial == 'string') {
|
56
|
+
partial = this.c.compile(partial);
|
57
|
+
}
|
58
|
+
|
59
|
+
return partial.ri(context, partials, indent);
|
60
|
+
},
|
61
|
+
|
62
|
+
// render a section
|
63
|
+
rs: function(context, partials, section) {
|
64
|
+
var buf = '',
|
65
|
+
tail = context[context.length - 1];
|
66
|
+
|
67
|
+
if (!isArray(tail)) {
|
68
|
+
return buf = section(context, partials);
|
69
|
+
}
|
70
|
+
|
71
|
+
for (var i = 0; i < tail.length; i++) {
|
72
|
+
context.push(tail[i]);
|
73
|
+
buf += section(context, partials);
|
74
|
+
context.pop();
|
75
|
+
}
|
76
|
+
|
77
|
+
return buf;
|
78
|
+
},
|
79
|
+
|
80
|
+
// maybe start a section
|
81
|
+
s: function(val, ctx, partials, inverted, start, end, tags) {
|
82
|
+
var pass;
|
83
|
+
|
84
|
+
if (isArray(val) && val.length === 0) {
|
85
|
+
return false;
|
86
|
+
}
|
87
|
+
|
88
|
+
if (typeof val == 'function') {
|
89
|
+
val = this.ls(val, ctx, partials, inverted, start, end, tags);
|
90
|
+
}
|
91
|
+
|
92
|
+
pass = (val === '') || !!val;
|
93
|
+
|
94
|
+
if (!inverted && pass && ctx) {
|
95
|
+
ctx.push((typeof val == 'object') ? val : ctx[ctx.length - 1]);
|
96
|
+
}
|
97
|
+
|
98
|
+
return pass;
|
99
|
+
},
|
100
|
+
|
101
|
+
// find values with dotted names
|
102
|
+
d: function(key, ctx, partials, returnFound) {
|
103
|
+
var names = key.split('.'),
|
104
|
+
val = this.f(names[0], ctx, partials, returnFound),
|
105
|
+
cx = null;
|
106
|
+
|
107
|
+
if (key === '.' && isArray(ctx[ctx.length - 2])) {
|
108
|
+
return ctx[ctx.length - 1];
|
109
|
+
}
|
110
|
+
|
111
|
+
for (var i = 1; i < names.length; i++) {
|
112
|
+
if (val && typeof val == 'object' && names[i] in val) {
|
113
|
+
cx = val;
|
114
|
+
val = val[names[i]];
|
115
|
+
} else {
|
116
|
+
val = '';
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
if (returnFound && !val) {
|
121
|
+
return false;
|
122
|
+
}
|
123
|
+
|
124
|
+
if (!returnFound && typeof val == 'function') {
|
125
|
+
ctx.push(cx);
|
126
|
+
val = this.lv(val, ctx, partials);
|
127
|
+
ctx.pop();
|
128
|
+
}
|
129
|
+
|
130
|
+
return val;
|
131
|
+
},
|
132
|
+
|
133
|
+
// find values with normal names
|
134
|
+
f: function(key, ctx, partials, returnFound) {
|
135
|
+
var val = false,
|
136
|
+
v = null,
|
137
|
+
found = false;
|
138
|
+
|
139
|
+
for (var i = ctx.length - 1; i >= 0; i--) {
|
140
|
+
v = ctx[i];
|
141
|
+
if (v && typeof v == 'object' && key in v) {
|
142
|
+
val = v[key];
|
143
|
+
found = true;
|
144
|
+
break;
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
if (!found) {
|
149
|
+
return (returnFound) ? false : "";
|
150
|
+
}
|
151
|
+
|
152
|
+
if (!returnFound && typeof val == 'function') {
|
153
|
+
val = this.lv(val, ctx, partials);
|
154
|
+
}
|
155
|
+
|
156
|
+
return val;
|
157
|
+
},
|
158
|
+
|
159
|
+
// higher order templates
|
160
|
+
ho: function(val, cx, partials, text, tags) {
|
161
|
+
var compiler = this.c;
|
162
|
+
var t = val.call(cx, text, function(t) {
|
163
|
+
return compiler.compile(t, {delimiters: tags}).render(cx, partials);
|
164
|
+
});
|
165
|
+
var s = compiler.compile(t.toString(), {delimiters: tags}).render(cx, partials);
|
166
|
+
this.b = s;
|
167
|
+
return false;
|
168
|
+
},
|
169
|
+
|
170
|
+
// higher order template result buffer
|
171
|
+
b: '',
|
172
|
+
|
173
|
+
// lambda replace section
|
174
|
+
ls: function(val, ctx, partials, inverted, start, end, tags) {
|
175
|
+
var cx = ctx[ctx.length - 1],
|
176
|
+
t = null;
|
177
|
+
|
178
|
+
if (!inverted && this.c && val.length > 0) {
|
179
|
+
return this.ho(val, cx, partials, this.text.substring(start, end), tags);
|
180
|
+
}
|
181
|
+
|
182
|
+
t = val.call(cx);
|
183
|
+
|
184
|
+
if (typeof t == 'function') {
|
185
|
+
if (inverted) {
|
186
|
+
return true;
|
187
|
+
} else if (this.c) {
|
188
|
+
return this.ho(t, cx, partials, this.text.substring(start, end), tags);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
return t;
|
193
|
+
},
|
194
|
+
|
195
|
+
// lambda replace variable
|
196
|
+
lv: function(val, ctx, partials) {
|
197
|
+
var cx = ctx[ctx.length - 1];
|
198
|
+
var result = val.call(cx);
|
199
|
+
if (typeof result == 'function') {
|
200
|
+
result = result.call(cx);
|
201
|
+
}
|
202
|
+
result = result.toString();
|
203
|
+
|
204
|
+
if (this.c && ~result.indexOf("{{")) {
|
205
|
+
return this.c.compile(result).render(cx, partials);
|
206
|
+
}
|
207
|
+
|
208
|
+
return result;
|
209
|
+
}
|
210
|
+
|
211
|
+
};
|
212
|
+
|
213
|
+
var rAmp = /&/g,
|
214
|
+
rLt = /</g,
|
215
|
+
rGt = />/g,
|
216
|
+
rApos =/\'/g,
|
217
|
+
rQuot = /\"/g,
|
218
|
+
hChars =/[&<>\"\']/;
|
219
|
+
|
220
|
+
function hoganEscape(str) {
|
221
|
+
str = String((str === null || str === undefined) ? '' : str);
|
222
|
+
return hChars.test(str) ?
|
223
|
+
str
|
224
|
+
.replace(rAmp,'&')
|
225
|
+
.replace(rLt,'<')
|
226
|
+
.replace(rGt,'>')
|
227
|
+
.replace(rApos,''')
|
228
|
+
.replace(rQuot, '"') :
|
229
|
+
str;
|
230
|
+
}
|
231
|
+
|
232
|
+
var isArray = Array.isArray || function(a) {
|
233
|
+
return Object.prototype.toString.call(a) === '[object Array]';
|
234
|
+
};
|
235
|
+
|
236
|
+
})(typeof exports !== 'undefined' ? exports : Hogan);
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
(function (Hogan) {
|
242
|
+
// Setup regex assignments
|
243
|
+
// remove whitespace according to Mustache spec
|
244
|
+
var rIsWhitespace = /\S/,
|
245
|
+
rQuot = /\"/g,
|
246
|
+
rNewline = /\n/g,
|
247
|
+
rCr = /\r/g,
|
248
|
+
rSlash = /\\/g,
|
249
|
+
tagTypes = {
|
250
|
+
'#': 1, '^': 2, '/': 3, '!': 4, '>': 5,
|
251
|
+
'<': 6, '=': 7, '_v': 8, '{': 9, '&': 10
|
252
|
+
};
|
253
|
+
|
254
|
+
Hogan.scan = function scan(text, delimiters) {
|
255
|
+
var len = text.length,
|
256
|
+
IN_TEXT = 0,
|
257
|
+
IN_TAG_TYPE = 1,
|
258
|
+
IN_TAG = 2,
|
259
|
+
state = IN_TEXT,
|
260
|
+
tagType = null,
|
261
|
+
tag = null,
|
262
|
+
buf = '',
|
263
|
+
tokens = [],
|
264
|
+
seenTag = false,
|
265
|
+
i = 0,
|
266
|
+
lineStart = 0,
|
267
|
+
otag = '{{',
|
268
|
+
ctag = '}}';
|
269
|
+
|
270
|
+
function addBuf() {
|
271
|
+
if (buf.length > 0) {
|
272
|
+
tokens.push(new String(buf));
|
273
|
+
buf = '';
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
function lineIsWhitespace() {
|
278
|
+
var isAllWhitespace = true;
|
279
|
+
for (var j = lineStart; j < tokens.length; j++) {
|
280
|
+
isAllWhitespace =
|
281
|
+
(tokens[j].tag && tagTypes[tokens[j].tag] < tagTypes['_v']) ||
|
282
|
+
(!tokens[j].tag && tokens[j].match(rIsWhitespace) === null);
|
283
|
+
if (!isAllWhitespace) {
|
284
|
+
return false;
|
285
|
+
}
|
286
|
+
}
|
287
|
+
|
288
|
+
return isAllWhitespace;
|
289
|
+
}
|
290
|
+
|
291
|
+
function filterLine(haveSeenTag, noNewLine) {
|
292
|
+
addBuf();
|
293
|
+
|
294
|
+
if (haveSeenTag && lineIsWhitespace()) {
|
295
|
+
for (var j = lineStart, next; j < tokens.length; j++) {
|
296
|
+
if (!tokens[j].tag) {
|
297
|
+
if ((next = tokens[j+1]) && next.tag == '>') {
|
298
|
+
// set indent to token value
|
299
|
+
next.indent = tokens[j].toString()
|
300
|
+
}
|
301
|
+
tokens.splice(j, 1);
|
302
|
+
}
|
303
|
+
}
|
304
|
+
} else if (!noNewLine) {
|
305
|
+
tokens.push({tag:'\n'});
|
306
|
+
}
|
307
|
+
|
308
|
+
seenTag = false;
|
309
|
+
lineStart = tokens.length;
|
310
|
+
}
|
311
|
+
|
312
|
+
function changeDelimiters(text, index) {
|
313
|
+
var close = '=' + ctag,
|
314
|
+
closeIndex = text.indexOf(close, index),
|
315
|
+
delimiters = trim(
|
316
|
+
text.substring(text.indexOf('=', index) + 1, closeIndex)
|
317
|
+
).split(' ');
|
318
|
+
|
319
|
+
otag = delimiters[0];
|
320
|
+
ctag = delimiters[1];
|
321
|
+
|
322
|
+
return closeIndex + close.length - 1;
|
323
|
+
}
|
324
|
+
|
325
|
+
if (delimiters) {
|
326
|
+
delimiters = delimiters.split(' ');
|
327
|
+
otag = delimiters[0];
|
328
|
+
ctag = delimiters[1];
|
329
|
+
}
|
330
|
+
|
331
|
+
for (i = 0; i < len; i++) {
|
332
|
+
if (state == IN_TEXT) {
|
333
|
+
if (tagChange(otag, text, i)) {
|
334
|
+
--i;
|
335
|
+
addBuf();
|
336
|
+
state = IN_TAG_TYPE;
|
337
|
+
} else {
|
338
|
+
if (text.charAt(i) == '\n') {
|
339
|
+
filterLine(seenTag);
|
340
|
+
} else {
|
341
|
+
buf += text.charAt(i);
|
342
|
+
}
|
343
|
+
}
|
344
|
+
} else if (state == IN_TAG_TYPE) {
|
345
|
+
i += otag.length - 1;
|
346
|
+
tag = tagTypes[text.charAt(i + 1)];
|
347
|
+
tagType = tag ? text.charAt(i + 1) : '_v';
|
348
|
+
if (tagType == '=') {
|
349
|
+
i = changeDelimiters(text, i);
|
350
|
+
state = IN_TEXT;
|
351
|
+
} else {
|
352
|
+
if (tag) {
|
353
|
+
i++;
|
354
|
+
}
|
355
|
+
state = IN_TAG;
|
356
|
+
}
|
357
|
+
seenTag = i;
|
358
|
+
} else {
|
359
|
+
if (tagChange(ctag, text, i)) {
|
360
|
+
tokens.push({tag: tagType, n: trim(buf), otag: otag, ctag: ctag,
|
361
|
+
i: (tagType == '/') ? seenTag - ctag.length : i + otag.length});
|
362
|
+
buf = '';
|
363
|
+
i += ctag.length - 1;
|
364
|
+
state = IN_TEXT;
|
365
|
+
if (tagType == '{') {
|
366
|
+
if (ctag == '}}') {
|
367
|
+
i++;
|
368
|
+
} else {
|
369
|
+
cleanTripleStache(tokens[tokens.length - 1]);
|
370
|
+
}
|
371
|
+
}
|
372
|
+
} else {
|
373
|
+
buf += text.charAt(i);
|
374
|
+
}
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
filterLine(seenTag, true);
|
379
|
+
|
380
|
+
return tokens;
|
381
|
+
}
|
382
|
+
|
383
|
+
function cleanTripleStache(token) {
|
384
|
+
if (token.n.substr(token.n.length - 1) === '}') {
|
385
|
+
token.n = token.n.substring(0, token.n.length - 1);
|
386
|
+
}
|
387
|
+
}
|
388
|
+
|
389
|
+
function trim(s) {
|
390
|
+
if (s.trim) {
|
391
|
+
return s.trim();
|
392
|
+
}
|
393
|
+
|
394
|
+
return s.replace(/^\s*|\s*$/g, '');
|
395
|
+
}
|
396
|
+
|
397
|
+
function tagChange(tag, text, index) {
|
398
|
+
if (text.charAt(index) != tag.charAt(0)) {
|
399
|
+
return false;
|
400
|
+
}
|
401
|
+
|
402
|
+
for (var i = 1, l = tag.length; i < l; i++) {
|
403
|
+
if (text.charAt(index + i) != tag.charAt(i)) {
|
404
|
+
return false;
|
405
|
+
}
|
406
|
+
}
|
407
|
+
|
408
|
+
return true;
|
409
|
+
}
|
410
|
+
|
411
|
+
function buildTree(tokens, kind, stack, customTags) {
|
412
|
+
var instructions = [],
|
413
|
+
opener = null,
|
414
|
+
token = null;
|
415
|
+
|
416
|
+
while (tokens.length > 0) {
|
417
|
+
token = tokens.shift();
|
418
|
+
if (token.tag == '#' || token.tag == '^' || isOpener(token, customTags)) {
|
419
|
+
stack.push(token);
|
420
|
+
token.nodes = buildTree(tokens, token.tag, stack, customTags);
|
421
|
+
instructions.push(token);
|
422
|
+
} else if (token.tag == '/') {
|
423
|
+
if (stack.length === 0) {
|
424
|
+
throw new Error('Closing tag without opener: /' + token.n);
|
425
|
+
}
|
426
|
+
opener = stack.pop();
|
427
|
+
if (token.n != opener.n && !isCloser(token.n, opener.n, customTags)) {
|
428
|
+
throw new Error('Nesting error: ' + opener.n + ' vs. ' + token.n);
|
429
|
+
}
|
430
|
+
opener.end = token.i;
|
431
|
+
return instructions;
|
432
|
+
} else {
|
433
|
+
instructions.push(token);
|
434
|
+
}
|
435
|
+
}
|
436
|
+
|
437
|
+
if (stack.length > 0) {
|
438
|
+
throw new Error('missing closing tag: ' + stack.pop().n);
|
439
|
+
}
|
440
|
+
|
441
|
+
return instructions;
|
442
|
+
}
|
443
|
+
|
444
|
+
function isOpener(token, tags) {
|
445
|
+
for (var i = 0, l = tags.length; i < l; i++) {
|
446
|
+
if (tags[i].o == token.n) {
|
447
|
+
token.tag = '#';
|
448
|
+
return true;
|
449
|
+
}
|
450
|
+
}
|
451
|
+
}
|
452
|
+
|
453
|
+
function isCloser(close, open, tags) {
|
454
|
+
for (var i = 0, l = tags.length; i < l; i++) {
|
455
|
+
if (tags[i].c == close && tags[i].o == open) {
|
456
|
+
return true;
|
457
|
+
}
|
458
|
+
}
|
459
|
+
}
|
460
|
+
|
461
|
+
function writeCode(tree) {
|
462
|
+
return 'i = i || "";var b = i + "";var _ = this;' + walk(tree) + 'return b;';
|
463
|
+
}
|
464
|
+
|
465
|
+
Hogan.generate = function (code, text, options) {
|
466
|
+
if (options.asString) {
|
467
|
+
return 'function(c,p,i){' + code + ';}';
|
468
|
+
}
|
469
|
+
|
470
|
+
return new Hogan.Template(new Function('c', 'p', 'i', code), text, Hogan);
|
471
|
+
}
|
472
|
+
|
473
|
+
function esc(s) {
|
474
|
+
return s.replace(rSlash, '\\\\')
|
475
|
+
.replace(rQuot, '\\\"')
|
476
|
+
.replace(rNewline, '\\n')
|
477
|
+
.replace(rCr, '\\r');
|
478
|
+
}
|
479
|
+
|
480
|
+
function chooseMethod(s) {
|
481
|
+
return (~s.indexOf('.')) ? 'd' : 'f';
|
482
|
+
}
|
483
|
+
|
484
|
+
function walk(tree) {
|
485
|
+
var code = '';
|
486
|
+
for (var i = 0, l = tree.length; i < l; i++) {
|
487
|
+
var tag = tree[i].tag;
|
488
|
+
if (tag == '#') {
|
489
|
+
code += section(tree[i].nodes, tree[i].n, chooseMethod(tree[i].n),
|
490
|
+
tree[i].i, tree[i].end, tree[i].otag + " " + tree[i].ctag);
|
491
|
+
} else if (tag == '^') {
|
492
|
+
code += invertedSection(tree[i].nodes, tree[i].n,
|
493
|
+
chooseMethod(tree[i].n));
|
494
|
+
} else if (tag == '<' || tag == '>') {
|
495
|
+
code += partial(tree[i]);
|
496
|
+
} else if (tag == '{' || tag == '&') {
|
497
|
+
code += tripleStache(tree[i].n, chooseMethod(tree[i].n));
|
498
|
+
} else if (tag == '\n') {
|
499
|
+
code += text('"\\n"' + (tree.length-1 == i ? '' : ' + i'));
|
500
|
+
} else if (tag == '_v') {
|
501
|
+
code += variable(tree[i].n, chooseMethod(tree[i].n));
|
502
|
+
} else if (tag === undefined) {
|
503
|
+
code += text('"' + esc(tree[i]) + '"');
|
504
|
+
}
|
505
|
+
}
|
506
|
+
return code;
|
507
|
+
}
|
508
|
+
|
509
|
+
function section(nodes, id, method, start, end, tags) {
|
510
|
+
return 'if(_.s(_.' + method + '("' + esc(id) + '",c,p,1),' +
|
511
|
+
'c,p,0,' + start + ',' + end + ', "' + tags + '")){' +
|
512
|
+
'b += _.rs(c,p,' +
|
513
|
+
'function(c,p){ var b = "";' +
|
514
|
+
walk(nodes) +
|
515
|
+
'return b;});c.pop();}' +
|
516
|
+
'else{b += _.b; _.b = ""};';
|
517
|
+
}
|
518
|
+
|
519
|
+
function invertedSection(nodes, id, method) {
|
520
|
+
return 'if (!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' +
|
521
|
+
walk(nodes) +
|
522
|
+
'};';
|
523
|
+
}
|
524
|
+
|
525
|
+
function partial(tok) {
|
526
|
+
return 'b += _.rp("' + esc(tok.n) + '",c,p,"' + (tok.indent || '') + '");';
|
527
|
+
}
|
528
|
+
|
529
|
+
function tripleStache(id, method) {
|
530
|
+
return 'b += (_.' + method + '("' + esc(id) + '",c,p,0));';
|
531
|
+
}
|
532
|
+
|
533
|
+
function variable(id, method) {
|
534
|
+
return 'b += (_.v(_.' + method + '("' + esc(id) + '",c,p,0)));';
|
535
|
+
}
|
536
|
+
|
537
|
+
function text(id) {
|
538
|
+
return 'b += ' + id + ';';
|
539
|
+
}
|
540
|
+
|
541
|
+
Hogan.parse = function(tokens, options) {
|
542
|
+
options = options || {};
|
543
|
+
return buildTree(tokens, '', [], options.sectionTags || []);
|
544
|
+
},
|
545
|
+
|
546
|
+
Hogan.cache = {};
|
547
|
+
|
548
|
+
Hogan.compile = function(text, options) {
|
549
|
+
// options
|
550
|
+
//
|
551
|
+
// asString: false (default)
|
552
|
+
//
|
553
|
+
// sectionTags: [{o: '_foo', c: 'foo'}]
|
554
|
+
// An array of object with o and c fields that indicate names for custom
|
555
|
+
// section tags. The example above allows parsing of {{_foo}}{{/foo}}.
|
556
|
+
//
|
557
|
+
// delimiters: A string that overrides the default delimiters.
|
558
|
+
// Example: "<% %>"
|
559
|
+
//
|
560
|
+
options = options || {};
|
561
|
+
|
562
|
+
var key = text + '||' + !!options.asString;
|
563
|
+
|
564
|
+
var t = this.cache[key];
|
565
|
+
|
566
|
+
if (t) {
|
567
|
+
return t;
|
568
|
+
}
|
569
|
+
|
570
|
+
t = this.generate(writeCode(this.parse(this.scan(text, options.delimiters), options)), text, options);
|
571
|
+
return this.cache[key] = t;
|
572
|
+
};
|
573
|
+
})(typeof exports !== 'undefined' ? exports : Hogan);
|
574
|
+
|
575
|
+
|
576
|
+
var Mustache = (function (Hogan) {
|
577
|
+
|
578
|
+
// Mustache.js has non-spec partial context behavior
|
579
|
+
function mustachePartial(name, context, partials, indent) {
|
580
|
+
var partialScope = this.f(name, context, partials, 0);
|
581
|
+
var cx = context;
|
582
|
+
if (partialScope) {
|
583
|
+
cx = cx.concat(partialScope);
|
584
|
+
}
|
585
|
+
|
586
|
+
return Hogan.Template.prototype.rp.call(this, name, cx, partials, indent);
|
587
|
+
}
|
588
|
+
|
589
|
+
var HoganTemplateWrapper = function(renderFunc, text, compiler){
|
590
|
+
this.rp = mustachePartial;
|
591
|
+
Hogan.Template.call(this, renderFunc, text, compiler);
|
592
|
+
};
|
593
|
+
HoganTemplateWrapper.prototype = Hogan.Template.prototype;
|
594
|
+
|
595
|
+
// Add a wrapper for Hogan's generate method. Mustache and Hogan keep
|
596
|
+
// separate caches, and Mustache returns wrapped templates.
|
597
|
+
var wrapper;
|
598
|
+
var HoganWrapper = function(){
|
599
|
+
this.cache = {};
|
600
|
+
this.generate = function(code, text, options) {
|
601
|
+
return new HoganTemplateWrapper(new Function('c', 'p', 'i', code), text, wrapper);
|
602
|
+
}
|
603
|
+
};
|
604
|
+
HoganWrapper.prototype = Hogan;
|
605
|
+
wrapper = new HoganWrapper();
|
606
|
+
|
607
|
+
return {
|
608
|
+
to_html: function(text, data, partials, sendFun) {
|
609
|
+
var template = wrapper.compile(text);
|
610
|
+
var result = template.render(data, partials);
|
611
|
+
if (!sendFun) {
|
612
|
+
return result;
|
613
|
+
}
|
614
|
+
|
615
|
+
sendFun(result);
|
616
|
+
}
|
617
|
+
}
|
618
|
+
|
619
|
+
})(Hogan);
|