1 |
|
2 |
|
3 | (function(global, factory) {
|
4 | if (typeof exports === 'object' && typeof module !== 'undefined') {
|
5 | factory(exports, typeof Snakeskin === 'undefined' ? require('snakeskin') : Snakeskin);
|
6 | return;
|
7 | }
|
8 | if (typeof define === 'function' && define.amd) {
|
9 | define('tpls', ['exports', 'Snakeskin' ], factory);
|
10 | return;
|
11 | }
|
12 | factory(global, Snakeskin);
|
13 | })(this, function(exports, Snakeskin /*#__SNAKESKIN_MODULES__*/ ) {
|
14 | 'use strict';
|
15 | var GLOBAL = new Function('return this')(),
|
16 | __FILTERS__ = Snakeskin.Filters,
|
17 | __VARS__ = Snakeskin.Vars,
|
18 | __LOCAL__ = Snakeskin.LocalVars,
|
19 | __REQUIRE__;
|
20 |
|
21 | function __LENGTH__(val) {
|
22 | if (val[0] instanceof Snakeskin.Node) {
|
23 | return val[0].length();
|
24 | }
|
25 | if (typeof val === 'string' || Array.isArray(val)) {
|
26 | return val.length;
|
27 | }
|
28 | return 1;
|
29 | }
|
30 |
|
31 | function __JOIN__(arr) {
|
32 | var str = '';
|
33 | for (var i = 0; i < arr.length; i++) {
|
34 | str += arr[i];
|
35 | }
|
36 | return str;
|
37 | }
|
38 |
|
39 | function __ESCAPE_D_Q__(str) {
|
40 | return str.replace(/"/g, """)
|
41 | }
|
42 | var TRUE = new Boolean(true),
|
43 | FALSE = new Boolean(false);
|
44 |
|
45 | function Raw(val) {
|
46 | if (!this || this.constructor !== Raw) {
|
47 | return new Raw(val);
|
48 | }
|
49 | this.value = val;
|
50 | }
|
51 | Raw.prototype.push = function(val) {
|
52 | this.value += val;
|
53 | };
|
54 |
|
55 | function Unsafe(val) {
|
56 | if (!this || this.constructor !== Unsafe) {
|
57 | if (typeof val === 'string') {
|
58 | return new Unsafe(val);
|
59 | }
|
60 | return val;
|
61 | }
|
62 | this.value = val;
|
63 | }
|
64 | Unsafe.prototype.toString = function() {
|
65 | return this.value;
|
66 | };
|
67 | __LOCAL__.$__0_0_24d5b = undefined;
|
68 | if (exports.demo instanceof Object === false) {
|
69 | exports.demo = {};
|
70 | }
|
71 | var demo = exports.demo;
|
72 | exports.demo.helloWorld = Snakeskin.decorate([], function helloWorld(name) {
|
73 | var __THIS__ = this;
|
74 | var callee = exports.demo.helloWorld,
|
75 | self = callee.Blocks = {};
|
76 | var __INLINE_TAGS__ = Snakeskin.inlineTags['undefined'] || Snakeskin.inlineTags['html'],
|
77 | __INLINE_TAG__;
|
78 | var __STRING_RESULT__;
|
79 | var __RESULT__ = '';
|
80 |
|
81 | function getTplResult(opt_clear) {
|
82 | var res = __RESULT__ instanceof Raw ? __RESULT__.value : __RESULT__;
|
83 | if (opt_clear) {
|
84 | __RESULT__ = '';
|
85 | }
|
86 | return res;
|
87 | }
|
88 |
|
89 | function clearTplResult() {
|
90 | __RESULT__ = '';
|
91 | }
|
92 | var $0 = undefined,
|
93 | $class = '';
|
94 | var __ATTR_STR__, __ATTR_TYPE__, __ATTR_CACHE__, __ATTR_CONCAT_MAP__ = {
|
95 | 'class': true
|
96 | };
|
97 |
|
98 | function __GET_XML_ATTR_KEY_DECL__(val, cache, empty) {
|
99 | if (val != null && val !== '') {
|
100 | if (!__ATTR_CONCAT_MAP__[val] || !cache[val] || cache[val][0] === TRUE) {
|
101 | cache[val] = [];
|
102 | }
|
103 | cache[val].push(empty ? TRUE : __ATTR_STR__);
|
104 | }
|
105 | __ATTR_STR__ = __ATTR_TYPE__ = undefined;
|
106 | }
|
107 |
|
108 | function __APPEND_XML_ATTR_VAL__(val) {
|
109 | __ATTR_STR__ = __ATTR_STR__ + (__ATTR_STR__ ? ' ' : '') + (val != null ? val : '');
|
110 | }
|
111 |
|
112 | function __GET_XML_ATTRS_DECL_START__(res, link, renderMode, isDOMRenderMode, stringResult) {
|
113 | var __RESULT__ = res;
|
114 | if (!stringResult && isDOMRenderMode) {
|
115 | if (link !== '?') {
|
116 | $0 = new Snakeskin.Element(link, renderMode);
|
117 | }
|
118 | } else {
|
119 | if (link !== '?') {
|
120 | if (stringResult) {
|
121 | __STRING_RESULT__ += '<' + link;
|
122 | } else {
|
123 | __RESULT__ += '<' + link;
|
124 | }
|
125 | }
|
126 | }
|
127 | return __RESULT__;
|
128 | }
|
129 |
|
130 | function __GET_XML_ATTRS_DECL_END__(res, link, cache, isDOMRenderMode, stringResult, isXMLDoctype) {
|
131 | var __RESULT__ = res;
|
132 | if (typeof link === 'undefined' || link !== '?') {
|
133 | var base = true;
|
134 | var set = function(el, key) {
|
135 | if (!base && {
|
136 | 'class': true,
|
137 | 'id': true
|
138 | }[key]) {
|
139 | return;
|
140 | }
|
141 | var attr = el[0] === TRUE ? isDOMRenderMode || isXMLDoctype ? key : TRUE : el.join(' ');
|
142 | if (stringResult) {
|
143 | __STRING_RESULT__ += ' ' + key + (attr === TRUE ? '' : '="' + __ESCAPE_D_Q__(attr) + '"');
|
144 | } else if (isDOMRenderMode) {
|
145 | Snakeskin.setAttribute($0, key, attr);
|
146 | } else {
|
147 | __RESULT__ += ' ' + key + (attr === TRUE ? '' : '="' + __ESCAPE_D_Q__(attr) + '"');
|
148 | }
|
149 | };
|
150 | if (cache['id']) {
|
151 | set(cache['id'], 'id');
|
152 | }
|
153 | if (cache['class']) {
|
154 | set(cache['class'], 'class');
|
155 | }
|
156 | base = false;
|
157 | Snakeskin.forEach(cache, set);
|
158 | }
|
159 | return __RESULT__;
|
160 | }
|
161 |
|
162 | function __GET_XML_TAG_DECL_END__(res, link, inline, inlineTag, isDOMRenderMode, stringResult, isXMLDoctype) {
|
163 | var __RESULT__ = res;
|
164 | if (isDOMRenderMode) {
|
165 | if (link !== '?') {
|
166 | __RESULT__ += $0;
|
167 | if (inline && (!inlineTag || inlineTag === true)) {
|
168 | $0 = __RESULT__[__RESULT__.length - 1];
|
169 | } else if (inlineTag && inlineTag !== true) {
|
170 | __RESULT__ = '';
|
171 | $0 = __RESULT__[__RESULT__.length - 1];
|
172 | } else {
|
173 | __RESULT__.push($0);
|
174 | }
|
175 | }
|
176 | } else {
|
177 | if (link !== '?') {
|
178 | if (inline && (!inlineTag || inlineTag === true)) {
|
179 | if (stringResult) {
|
180 | __STRING_RESULT__ += (isXMLDoctype ? '/' : '') + '>';
|
181 | } else {
|
182 | __RESULT__ += (isXMLDoctype ? '/' : '') + '>';
|
183 | }
|
184 | } else if (inlineTag && inlineTag !== true) {
|
185 | __RESULT__ = '';
|
186 | } else {
|
187 | if (stringResult) {
|
188 | __STRING_RESULT__ += '>';
|
189 | } else {
|
190 | __RESULT__ += '>';
|
191 | }
|
192 | }
|
193 | }
|
194 | }
|
195 | return __RESULT__;
|
196 | }
|
197 |
|
198 | function __GET_END_XML_TAG_DECL__(res, link, inline, inlineTag, attrCache, callCache, callTmp, isDOMRenderMode, stringResult, isXMLDoctype, node) {
|
199 | var __RESULT__ = res;
|
200 | if (isDOMRenderMode) {
|
201 | if (link !== '?') {
|
202 | if (inlineTag) {
|
203 | if (inlineTag !== true) {
|
204 | __RESULT__ = callCache;
|
205 | if (inlineTag in attrCache === false) {
|
206 | Snakeskin.setAttribute(node, inlineTag, callTmp);
|
207 | }
|
208 | }
|
209 | } else if (!inline) {
|
210 | __RESULT__.pop();
|
211 | $0 = __RESULT__[__RESULT__.length - 1];
|
212 | }
|
213 | }
|
214 | } else {
|
215 | if (link !== '?') {
|
216 | if (inlineTag) {
|
217 | if (inlineTag !== true) {
|
218 | __RESULT__ = callCache;
|
219 | if (inlineTag in attrCache === false) {
|
220 | if (stringResult) {
|
221 | __STRING_RESULT__ += ' ' + inlineTag + '="' + callTmp + '"';
|
222 | } else {
|
223 | __RESULT__ += ' ' + inlineTag + '="' + callTmp + '"';
|
224 | }
|
225 | }
|
226 | if (stringResult) {
|
227 | __STRING_RESULT__ += (isXMLDoctype ? '/' : '') + '>';
|
228 | } else {
|
229 | __RESULT__ += (isXMLDoctype ? '/' : '') + '>';
|
230 | }
|
231 | }
|
232 | } else if (!inline) {
|
233 | if (stringResult) {
|
234 | __STRING_RESULT__ += '</' + link + '>';
|
235 | } else {
|
236 | __RESULT__ += '</' + link + '>';
|
237 | }
|
238 | }
|
239 | }
|
240 | }
|
241 | return __RESULT__;
|
242 | }
|
243 |
|
244 | function __TARGET_END__(res, stack, ref) {
|
245 | var __RESULT__ = res;
|
246 | if (__LENGTH__(__RESULT__)) {
|
247 | stack.push({
|
248 | key: undefined,
|
249 | value: Unsafe(__RESULT__ instanceof Raw ? __RESULT__.value : __RESULT__)
|
250 | });
|
251 | }
|
252 | Snakeskin.forEach(stack, function(el) {
|
253 | ref[el.key || ref.length] = el.value;
|
254 | });
|
255 | return __RESULT__;
|
256 | }
|
257 |
|
258 | function __PUTIN_CALL__(res, pos, stack) {
|
259 | var __RESULT__ = res;
|
260 | if (pos === true || !pos && __LENGTH__(__RESULT__)) {
|
261 | stack.push(Unsafe(__RESULT__ instanceof Raw ? __RESULT__.value : __RESULT__));
|
262 | __RESULT__ = '';
|
263 | }
|
264 | return __RESULT__;
|
265 | }
|
266 |
|
267 | function __PUTIN_TARGET__(res, pos, stack, key) {
|
268 | var __RESULT__ = res;
|
269 | if (pos === true || !pos && __LENGTH__(__RESULT__)) {
|
270 | stack.push({
|
271 | key: key,
|
272 | value: Unsafe(__RESULT__ instanceof Raw ? __RESULT__.value : __RESULT__)
|
273 | });
|
274 | __RESULT__ = '';
|
275 | }
|
276 | return __RESULT__;
|
277 | }
|
278 | var __RETURN__ = false,
|
279 | __RETURN_VAL__;
|
280 | var TPL_NAME = "demo.helloWorld",
|
281 | PARENT_TPL_NAME;
|
282 | name = name != null ? name : 'world';
|
283 | $class = 'hello';
|
284 | var ____TAG___tag_254 = ('div').trim() || 'div';
|
285 | __RESULT__ = __GET_XML_ATTRS_DECL_START__(__RESULT__, ____TAG___tag_254, 'stringConcat', false, false);
|
286 | var ____ATTR_CACHE___tag_254 = {};
|
287 | ____ATTR_CACHE___tag_254['class'] = ['hello'].concat(____ATTR_CACHE___tag_254['class'] || []);
|
288 | __RESULT__ = __GET_XML_ATTRS_DECL_END__(__RESULT__, ____TAG___tag_254, ____ATTR_CACHE___tag_254, false, false, false);
|
289 | var ____CALL_CACHE___tag_254 = __RESULT__;
|
290 | __RESULT__ = __GET_XML_TAG_DECL_END__(__RESULT__, ____TAG___tag_254, false, __INLINE_TAGS__[____TAG___tag_254], false, false, false);
|
291 | __RESULT__ += 'Hello ';
|
292 | __RESULT__ += __FILTERS__['htmlObject'](__FILTERS__['undef'].call(this, __FILTERS__['html'].call(this, (__FILTERS__['undef'](name)), Unsafe, __ATTR_TYPE__, __ATTR_CACHE__, TRUE)));
|
293 | __RESULT__ += '!';
|
294 | $class = '';
|
295 | var ____CALL_TMP___tag_307 = __RESULT__ instanceof Raw ? __RESULT__.value : __RESULT__;
|
296 | __RESULT__ = __GET_END_XML_TAG_DECL__(__RESULT__, ____TAG___tag_254, false, __INLINE_TAGS__[____TAG___tag_254], ____ATTR_CACHE___tag_254, ____CALL_CACHE___tag_254, ____CALL_TMP___tag_307, false, false, false);
|
297 | return __RESULT__ instanceof Raw ? __RESULT__.value : __RESULT__;
|
298 | });
|
299 | Snakeskin.cache["demo.helloWorld"] = exports.demo.helloWorld;
|
300 | });
|