Skip to content
This repository
Browse code

add mustache/handlebars inline attribute support

  • Loading branch information...
commit 1a46656a9de18bc7af358e5d6450c1b2d7ffe249 1 parent 1bb7ace
Lance Pollard lancejpollard authored
181 lib/coffeecup.js
... ... @@ -1,7 +1,8 @@
  1 +// Generated by CoffeeScript 1.3.1
1 2 var cache, coffee, coffeecup, coffeescript_helpers, compiler, elements, merge_elements, skeleton,
2   - __slice = Array.prototype.slice,
3   - __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
4   - __hasProp = Object.prototype.hasOwnProperty,
  3 + __slice = [].slice,
  4 + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
  5 + __hasProp = {}.hasOwnProperty,
5 6 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
6 7
7 8 if (typeof window !== "undefined" && window !== null) {
@@ -59,15 +60,17 @@ elements = {
59 60 };
60 61
61 62 merge_elements = function() {
62   - var a, args, element, result, _i, _j, _len, _len2, _ref;
  63 + var a, args, element, result, _i, _j, _len, _len1, _ref;
63 64 args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
64 65 result = [];
65 66 for (_i = 0, _len = args.length; _i < _len; _i++) {
66 67 a = args[_i];
67 68 _ref = elements[a].split(' ');
68   - for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) {
  69 + for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
69 70 element = _ref[_j];
70   - if (__indexOf.call(result, element) < 0) result.push(element);
  71 + if (__indexOf.call(result, element) < 0) {
  72 + result.push(element);
  73 + }
71 74 }
72 75 }
73 76 return result;
@@ -79,9 +82,15 @@ coffeecup.self_closing = merge_elements('void', 'obsolete_void');
79 82
80 83 skeleton = function(data) {
81 84 var cede, coffeescript, comment, doctype, h, ie, stylus, tag, text, __cc;
82   - if (data == null) data = {};
83   - if (data.format == null) data.format = false;
84   - if (data.autoescape == null) data.autoescape = false;
  85 + if (data == null) {
  86 + data = {};
  87 + }
  88 + if (data.format == null) {
  89 + data.format = false;
  90 + }
  91 + if (data.autoescape == null) {
  92 + data.autoescape = false;
  93 + }
85 94 __cc = {
86 95 buffer: [],
87 96 esc: function(txt) {
@@ -96,7 +105,9 @@ skeleton = function(data) {
96 105 return Array(count + 1).join(string);
97 106 },
98 107 indent: function() {
99   - if (data.format) return text(this.repeat(' ', this.tabs));
  108 + if (data.format) {
  109 + return text(this.repeat(' ', this.tabs));
  110 + }
100 111 },
101 112 tag: function(name, args) {
102 113 var combo, i, _i, _len;
@@ -108,7 +119,7 @@ skeleton = function(data) {
108 119 return tag.apply(data, combo);
109 120 },
110 121 render_idclass: function(str) {
111   - var c, classes, i, id, _i, _j, _len, _len2, _ref;
  122 + var c, classes, i, id, _i, _j, _len, _len1, _ref;
112 123 classes = [];
113 124 _ref = str.split('.');
114 125 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -116,15 +127,21 @@ skeleton = function(data) {
116 127 if (__indexOf.call(i, '#') >= 0) {
117 128 id = i.replace('#', '');
118 129 } else {
119   - if (i !== '') classes.push(i);
  130 + if (i !== '') {
  131 + classes.push(i);
  132 + }
120 133 }
121 134 }
122   - if (id) text(" id=\"" + id + "\"");
  135 + if (id) {
  136 + text(" id=\"" + id + "\"");
  137 + }
123 138 if (classes.length > 0) {
124 139 text(" class=\"");
125   - for (_j = 0, _len2 = classes.length; _j < _len2; _j++) {
  140 + for (_j = 0, _len1 = classes.length; _j < _len1; _j++) {
126 141 c = classes[_j];
127   - if (c !== classes[0]) text(' ');
  142 + if (c !== classes[0]) {
  143 + text(' ');
  144 + }
128 145 text(c);
129 146 }
130 147 return text('"');
@@ -132,12 +149,18 @@ skeleton = function(data) {
132 149 },
133 150 render_attrs: function(obj, prefix) {
134 151 var k, v, _results;
135   - if (prefix == null) prefix = '';
  152 + if (prefix == null) {
  153 + prefix = '';
  154 + }
136 155 _results = [];
137 156 for (k in obj) {
138 157 v = obj[k];
139   - if (typeof v === 'boolean' && v) v = k;
140   - if (typeof v === 'function') v = "(" + v + ").call(this);";
  158 + if (typeof v === 'boolean' && v) {
  159 + v = k;
  160 + }
  161 + if (typeof v === 'function') {
  162 + v = "(" + v + ").call(this);";
  163 + }
141 164 if (typeof v === 'object' && !(v instanceof Array)) {
142 165 _results.push(this.render_attrs(v, prefix + k + '-'));
143 166 } else if (v) {
@@ -150,44 +173,61 @@ skeleton = function(data) {
150 173 },
151 174 render_contents: function(contents, safe) {
152 175 var result;
153   - if (safe == null) safe = false;
  176 + if (safe == null) {
  177 + safe = false;
  178 + }
154 179 switch (typeof contents) {
155 180 case 'string':
156 181 case 'number':
157 182 case 'boolean':
158 183 return text(safe ? contents : this.esc(contents));
159 184 case 'function':
160   - if (data.format) text('\n');
  185 + if (data.format) {
  186 + text('\n');
  187 + }
161 188 this.tabs++;
162 189 result = contents.call(data);
163 190 if (typeof result === 'string') {
164 191 this.indent();
165 192 text(safe ? result : this.esc(result));
166   - if (data.format) text('\n');
  193 + if (data.format) {
  194 + text('\n');
  195 + }
167 196 }
168 197 this.tabs--;
169 198 return this.indent();
170 199 }
171 200 },
172   - render_tag: function(name, idclass, attrs, contents) {
  201 + render_tag: function(name, idclass, attrs, inline, contents) {
173 202 this.indent();
174 203 text("<" + name);
175   - if (idclass) this.render_idclass(idclass);
176   - if (attrs) this.render_attrs(attrs);
  204 + if (idclass) {
  205 + this.render_idclass(idclass);
  206 + }
  207 + if (attrs) {
  208 + this.render_attrs(attrs);
  209 + }
  210 + if (inline) {
  211 + text(" " + inline);
  212 + }
177 213 if (__indexOf.call(this.self_closing, name) >= 0) {
178 214 text(' />');
179   - if (data.format) text('\n');
  215 + if (data.format) {
  216 + text('\n');
  217 + }
180 218 } else {
181 219 text('>');
182 220 this.render_contents(contents);
183 221 text("</" + name + ">");
184   - if (data.format) text('\n');
  222 + if (data.format) {
  223 + text('\n');
  224 + }
185 225 }
186 226 return null;
187 227 }
188 228 };
189 229 tag = function() {
190   - var a, args, attrs, contents, idclass, name, _i, _len;
  230 + var a, args, attrs, contents, first, idclass, inline, name, _i, _len;
191 231 name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
192 232 for (_i = 0, _len = args.length; _i < _len; _i++) {
193 233 a = args[_i];
@@ -207,14 +247,27 @@ skeleton = function(data) {
207 247 contents = a;
208 248 } else {
209 249 if (a === args[0]) {
210   - idclass = a;
  250 + first = a.charAt(0);
  251 + if (first === '#' || first === '.') {
  252 + idclass = a.substr(0, a.indexOf(' '));
  253 + inline = a.substr(a.indexOf(' ') + 1);
  254 + if (idclass === '') {
  255 + idclass = inline;
  256 + inline = void 0;
  257 + }
  258 + } else {
  259 + inline = a;
  260 + if (inline === '') {
  261 + inline = void 0;
  262 + }
  263 + }
211 264 } else {
212 265 contents = a;
213 266 }
214 267 }
215 268 }
216 269 }
217   - return __cc.render_tag(name, idclass, attrs, contents);
  270 + return __cc.render_tag(name, idclass, attrs, inline, contents);
218 271 };
219 272 cede = function(f) {
220 273 var old_buffer, temp_buffer;
@@ -229,9 +282,13 @@ skeleton = function(data) {
229 282 return txt.toString().replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
230 283 };
231 284 doctype = function(type) {
232   - if (type == null) type = 'default';
  285 + if (type == null) {
  286 + type = 'default';
  287 + }
233 288 text(__cc.doctypes[type]);
234   - if (data.format) return text('\n');
  289 + if (data.format) {
  290 + return text('\n');
  291 + }
235 292 };
236 293 text = function(txt) {
237 294 __cc.buffer.push(txt.toString());
@@ -239,7 +296,9 @@ skeleton = function(data) {
239 296 };
240 297 comment = function(cmt) {
241 298 text("<!--" + cmt + "-->");
242   - if (data.format) return text('\n');
  299 + if (data.format) {
  300 + return text('\n');
  301 + }
243 302 };
244 303 coffeescript = function(param) {
245 304 switch (typeof param) {
@@ -258,22 +317,30 @@ skeleton = function(data) {
258 317 };
259 318 stylus = function(s) {
260 319 text('<style>');
261   - if (data.format) text('\n');
  320 + if (data.format) {
  321 + text('\n');
  322 + }
262 323 data.stylus.render(s, {
263 324 compress: !data.format
264 325 }, function(err, css) {
265   - if (err) throw err;
  326 + if (err) {
  327 + throw err;
  328 + }
266 329 return text(css);
267 330 });
268 331 text('</style>');
269   - if (data.format) return text('\n');
  332 + if (data.format) {
  333 + return text('\n');
  334 + }
270 335 };
271 336 ie = function(condition, contents) {
272 337 __cc.indent();
273 338 text("<!--[if " + condition + "]>");
274 339 __cc.render_contents(contents);
275 340 text("<![endif]-->");
276   - if (data.format) return text('\n');
  341 + if (data.format) {
  342 + return text('\n');
  343 + }
277 344 };
278 345 return null;
279 346 };
@@ -283,8 +350,10 @@ skeleton = skeleton.toString().replace(/function\s*\(.*\)\s*\{/, '').replace(/re
283 350 skeleton = coffeescript_helpers + skeleton;
284 351
285 352 coffeecup.compile = function(template, options) {
286   - var code, hardcoded_locals, k, t, tag_functions, tags_used, v, _i, _j, _len, _len2, _ref, _ref2;
287   - if (options == null) options = {};
  353 + var code, hardcoded_locals, k, t, tag_functions, tags_used, v, _i, _j, _len, _len1, _ref, _ref1;
  354 + if (options == null) {
  355 + options = {};
  356 + }
288 357 if (typeof template === 'function') {
289 358 template = template.toString();
290 359 } else if (typeof template === 'string' && (coffee != null)) {
@@ -310,15 +379,15 @@ coffeecup.compile = function(template, options) {
310 379 }
311 380 tag_functions = '';
312 381 tags_used = [];
313   - _ref2 = coffeecup.tags;
314   - for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
315   - t = _ref2[_i];
  382 + _ref1 = coffeecup.tags;
  383 + for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  384 + t = _ref1[_i];
316 385 if (template.indexOf(t) > -1 || hardcoded_locals.indexOf(t) > -1) {
317 386 tags_used.push(t);
318 387 }
319 388 }
320 389 tag_functions += "var " + (tags_used.join(',')) + ";";
321   - for (_j = 0, _len2 = tags_used.length; _j < _len2; _j++) {
  390 + for (_j = 0, _len1 = tags_used.length; _j < _len1; _j++) {
322 391 t = tags_used[_j];
323 392 tag_functions += "" + t + " = function(){return __cc.tag('" + t + "', arguments);};";
324 393 }
@@ -326,9 +395,13 @@ coffeecup.compile = function(template, options) {
326 395 code += "__cc.doctypes = " + (JSON.stringify(coffeecup.doctypes)) + ";";
327 396 code += "__cc.coffeescript_helpers = " + (JSON.stringify(coffeescript_helpers)) + ";";
328 397 code += "__cc.self_closing = " + (JSON.stringify(coffeecup.self_closing)) + ";";
329   - if (options.locals) code += 'with(data.locals){';
  398 + if (options.locals) {
  399 + code += 'with(data.locals){';
  400 + }
330 401 code += "(" + template + ").call(data);";
331   - if (options.locals) code += '}';
  402 + if (options.locals) {
  403 + code += '}';
  404 + }
332 405 code += "return __cc.buffer.join('');";
333 406 return new Function('data', code);
334 407 };
@@ -337,15 +410,23 @@ cache = {};
337 410
338 411 coffeecup.render = function(template, data, options) {
339 412 var k, tpl, v;
340   - if (data == null) data = {};
341   - if (options == null) options = {};
  413 + if (data == null) {
  414 + data = {};
  415 + }
  416 + if (options == null) {
  417 + options = {};
  418 + }
342 419 for (k in options) {
343 420 v = options[k];
344 421 data[k] = v;
345 422 }
346   - if (data.cache == null) data.cache = false;
  423 + if (data.cache == null) {
  424 + data.cache = false;
  425 + }
347 426 data.stylus = require('stylus');
348   - if (data.optimize && !data.cache) data.optimize = false;
  427 + if (data.optimize && !data.cache) {
  428 + data.optimize = false;
  429 + }
349 430 if (data.cache && (cache[template] != null)) {
350 431 tpl = cache[template];
351 432 } else if (data.cache) {
@@ -378,7 +459,9 @@ if (typeof window === "undefined" || window === null) {
378 459 })(Error),
379 460 compile: function(template, data) {
380 461 var TemplateError, tpl;
381   - if (data.hardcode == null) data.hardcode = {};
  462 + if (data.hardcode == null) {
  463 + data.hardcode = {};
  464 + }
382 465 data.hardcode.partial = function() {
383 466 return text(this.partial.apply(this, arguments));
384 467 };
69 lib/compiler.js
... ... @@ -1,5 +1,6 @@
  1 +// Generated by CoffeeScript 1.3.1
1 2 var Code, call_bound_func, coffee, coffeecup, parser, skeleton, uglify, _ref,
2   - __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
  3 + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
3 4
4 5 coffee = require('coffee-script');
5 6
@@ -19,6 +20,8 @@ call_bound_func = function(func) {
19 20
20 21 Code = (function() {
21 22
  23 + Code.name = 'Code';
  24 +
22 25 function Code(parent) {
23 26 this.parent = parent;
24 27 this.nodes = [];
@@ -76,7 +79,7 @@ Code = (function() {
76 79 };
77 80
78 81 Code.prototype.merge_text = function(arg) {
79   - var l, ok, oldArg, prev, _ref2, _ref3;
  82 + var l, ok, oldArg, prev, _ref1, _ref2;
80 83 if (arg[0] === 'binary' && arg[1] === '+') {
81 84 this.merge_text(arg[2]);
82 85 arg = arg[3];
@@ -86,7 +89,7 @@ Code = (function() {
86 89 if (prev[0] === 'stat' && prev[1][0] === 'call' && prev[1][1][0] === 'name' && prev[1][1][1] === 'text') {
87 90 oldArg = prev[1][2][0];
88 91 ok = ['string', 'num'];
89   - if ((_ref2 = oldArg[0], __indexOf.call(ok, _ref2) >= 0) && (_ref3 = arg[0], __indexOf.call(ok, _ref3) >= 0)) {
  92 + if ((_ref1 = oldArg[0], __indexOf.call(ok, _ref1) >= 0) && (_ref2 = arg[0], __indexOf.call(ok, _ref2) >= 0)) {
90 93 prev[1][2][0] = ['string', oldArg[1] + arg[1]];
91 94 return;
92 95 }
@@ -97,7 +100,9 @@ Code = (function() {
97 100
98 101 Code.prototype.get_nodes = function() {
99 102 this.flush();
100   - if (this.parent[0] === 'stat') return ['splice', this.nodes];
  103 + if (this.parent[0] === 'stat') {
  104 + return ['splice', this.nodes];
  105 + }
101 106 return call_bound_func(['function', null, [], this.nodes]);
102 107 };
103 108
@@ -108,14 +113,16 @@ Code = (function() {
108 113 exports.compile = function(source, hardcoded_locals, options) {
109 114 var ast, code, compiled, escape, w;
110 115 escape = function(node) {
111   - if (options.autoescape) return ['call', ['name', 'h'], [node]];
  116 + if (options.autoescape) {
  117 + return ['call', ['name', 'h'], [node]];
  118 + }
112 119 return node;
113 120 };
114 121 ast = parser.parse(hardcoded_locals + ("(" + source + ").call(data);"));
115 122 w = uglify.ast_walker();
116 123 ast = w.with_walkers({
117 124 call: function(expr, args) {
118   - var arg, classes, code, comment, condition, contents, doctype, escape_all, func, i, id, idx, name, node, render_attrs, _i, _j, _k, _len, _len2, _len3, _len4, _ref2, _ref3, _ref4;
  125 + var arg, classes, code, comment, condition, contents, doctype, escape_all, func, i, id, idx, name, node, render_attrs, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref1, _ref2, _ref3;
119 126 name = expr[1];
120 127 if (name === 'doctype') {
121 128 code = new Code(w.parent());
@@ -155,12 +162,14 @@ exports.compile = function(source, hardcoded_locals, options) {
155 162 code.append('<![endif]-->');
156 163 return code.get_nodes();
157 164 } else if (__indexOf.call(coffeecup.tags, name) >= 0 || (name === 'tag' || name === 'coffeescript')) {
158   - if (name === 'tag') name = args.shift()[1];
  165 + if (name === 'tag') {
  166 + name = args.shift()[1];
  167 + }
159 168 if (name === 'coffeescript') {
160 169 name = 'script';
161 170 for (_i = 0, _len = args.length; _i < _len; _i++) {
162 171 arg = args[_i];
163   - if ((_ref2 = arg[0]) !== 'string' && _ref2 !== 'object' && _ref2 !== 'function') {
  172 + if ((_ref1 = arg[0]) !== 'string' && _ref1 !== 'object' && _ref1 !== 'function') {
164 173 throw new Error('Invalid argument to coffeescript function');
165 174 }
166 175 if (arg[0] === 'string' && (args.length === 1 || arg !== args[0])) {
@@ -172,7 +181,7 @@ exports.compile = function(source, hardcoded_locals, options) {
172 181 }
173 182 code = new Code(w.parent());
174 183 code.append("<" + name);
175   - for (_j = 0, _len2 = args.length; _j < _len2; _j++) {
  184 + for (_j = 0, _len1 = args.length; _j < _len1; _j++) {
176 185 arg = args[_j];
177 186 switch (arg[0]) {
178 187 case 'function':
@@ -184,9 +193,9 @@ exports.compile = function(source, hardcoded_locals, options) {
184 193 contents = ['string', "" + func + ".call(this);"];
185 194 } else {
186 195 func = w.walk(arg);
187   - _ref3 = func[3];
188   - for (idx = 0, _len3 = _ref3.length; idx < _len3; idx++) {
189   - node = _ref3[idx];
  196 + _ref2 = func[3];
  197 + for (idx = _k = 0, _len2 = _ref2.length; _k < _len2; idx = ++_k) {
  198 + node = _ref2[idx];
190 199 if (node[0] === 'return' && (node[1] != null) && node[1][0] !== 'string') {
191 200 func[3][idx][1] = escape(node[1]);
192 201 }
@@ -196,18 +205,20 @@ exports.compile = function(source, hardcoded_locals, options) {
196 205 break;
197 206 case 'object':
198 207 render_attrs = function(obj, prefix) {
199   - var attr, key, value, varname, _k, _len4, _ref4, _ref5, _results;
200   - if (prefix == null) prefix = '';
  208 + var attr, key, value, varname, _l, _len3, _ref3, _ref4, _results;
  209 + if (prefix == null) {
  210 + prefix = '';
  211 + }
201 212 _results = [];
202   - for (_k = 0, _len4 = obj.length; _k < _len4; _k++) {
203   - attr = obj[_k];
  213 + for (_l = 0, _len3 = obj.length; _l < _len3; _l++) {
  214 + attr = obj[_l];
204 215 key = attr[0];
205 216 value = attr[1];
206 217 if (value[0] === 'name' && value[1] === 'true') {
207 218 _results.push(code.append(" " + key + "=\"" + key + "\""));
208   - } else if (value[0] === 'name' && ((_ref4 = value[1]) === 'undefined' || _ref4 === 'null' || _ref4 === 'false')) {
  219 + } else if (value[0] === 'name' && ((_ref3 = value[1]) === 'undefined' || _ref3 === 'null' || _ref3 === 'false')) {
209 220 continue;
210   - } else if ((_ref5 = value[0]) === 'name' || _ref5 === 'dot') {
  221 + } else if ((_ref4 = value[0]) === 'name' || _ref4 === 'dot') {
211 222 varname = uglify.gen_code(value);
212 223 condition = "typeof " + varname + " !== 'undefined' && " + varname + " !== null && " + varname + " !== false";
213 224 code.open_if(parser.parse(condition)[1][0][1]);
@@ -235,16 +246,20 @@ exports.compile = function(source, hardcoded_locals, options) {
235 246 case 'string':
236 247 if (args.length > 1 && arg === args[0]) {
237 248 classes = [];
238   - _ref4 = arg[1].split('.');
239   - for (_k = 0, _len4 = _ref4.length; _k < _len4; _k++) {
240   - i = _ref4[_k];
  249 + _ref3 = arg[1].split('.');
  250 + for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
  251 + i = _ref3[_l];
241 252 if (__indexOf.call(i, '#') >= 0) {
242 253 id = i.replace('#', '');
243 254 } else {
244   - if (i !== '') classes.push(i);
  255 + if (i !== '') {
  256 + classes.push(i);
  257 + }
245 258 }
246 259 }
247   - if (id) code.append(" id=\"" + id + "\"");
  260 + if (id) {
  261 + code.append(" id=\"" + id + "\"");
  262 + }
248 263 if (classes.length > 0) {
249 264 code.append(" class=\"" + (classes.join(' ')) + "\"");
250 265 }
@@ -282,7 +297,9 @@ exports.compile = function(source, hardcoded_locals, options) {
282 297 } else {
283 298 code.append('>');
284 299 }
285   - if (contents != null) code.push(contents);
  300 + if (contents != null) {
  301 + code.push(contents);
  302 + }
286 303 if (!(__indexOf.call(coffeecup.self_closing, name) >= 0)) {
287 304 code.append("</" + name + ">");
288 305 }
@@ -297,7 +314,9 @@ exports.compile = function(source, hardcoded_locals, options) {
297 314 beautify: true,
298 315 indent_level: 2
299 316 });
300   - if (options.locals) compiled = "with(data.locals){" + compiled + "}";
  317 + if (options.locals) {
  318 + compiled = "with(data.locals){" + compiled + "}";
  319 + }
301 320 code = skeleton + compiled + "return __cc.buffer;";
302 321 return new Function('data', code);
303 322 };
1  lib/skeleton.js
... ... @@ -1,3 +1,4 @@
  1 +// Generated by CoffeeScript 1.3.1
1 2 var cede, h, text, __cc;
2 3
3 4 __cc = {
17 src/coffeecup.coffee
@@ -189,12 +189,14 @@ skeleton = (data = {}) ->
189 189 @tabs--
190 190 @indent()
191 191
192   - render_tag: (name, idclass, attrs, contents) ->
  192 + render_tag: (name, idclass, attrs, inline, contents) ->
193 193 @indent()
194 194
195 195 text "<#{name}"
196 196 @render_idclass(idclass) if idclass
197 197 @render_attrs(attrs) if attrs
  198 +
  199 + text " #{inline}" if inline
198 200
199 201 if name in @self_closing
200 202 text ' />'
@@ -223,11 +225,20 @@ skeleton = (data = {}) ->
223 225 contents = a
224 226 else
225 227 if a is args[0]
226   - idclass = a
  228 + first = a.charAt(0)
  229 + if first == '#' || first == '.'
  230 + idclass = a.substr(0, a.indexOf(' '))
  231 + inline = a.substr(a.indexOf(' ') + 1)
  232 + if idclass == ''
  233 + idclass = inline
  234 + inline = undefined
  235 + else
  236 + inline = a
  237 + inline = undefined if inline == ''
227 238 else
228 239 contents = a
229 240
230   - __cc.render_tag(name, idclass, attrs, contents)
  241 + __cc.render_tag(name, idclass, attrs, inline, contents)
231 242
232 243 cede = (f) ->
233 244 temp_buffer = []
9 test/attributes.coffee
@@ -11,6 +11,15 @@ describe 'Attribute values', ->
11 11 it 'should render <br vrai="vrai" str="str" num="42" arr="1,2,3" obj-foo="bar" func="(function () {}).call(this);" />', ->
12 12 a = -> br vrai: yes, faux: no, undef: @foo, nil: null, str: 'str', num: 42, arr: [1, 2, 3], obj: {foo: 'bar'}, func: ->
13 13 cc.render(a).should.equal '<br vrai="vrai" str="str" num="42" arr="1,2,3" obj-foo="bar" func="(function () {}).call(this);" />'
  14 +
  15 +describe 'Inline attributes', ->
  16 + describe "p '#foo {{bindAttr class=isSelected}}, 'Bar'", ->
  17 + a = -> p '#foo {{bindAttr class="isSelected"}}', 'Bar'
  18 + cc.render(a).should.equal '<p id="foo" {{bindAttr class="isSelected"}}>Bar</p>'
  19 +
  20 + describe "p '{{bindAttr class=isActive target=App}}, 'Bar'", ->
  21 + a = -> p '{{bindAttr class="isActive" target="App"}}', 'Bar'
  22 + cc.render(a).should.equal '<p {{bindAttr class="isActive" target="App"}}>Bar</p>'
14 23
15 24 describe 'Attributes optimized', ->
16 25 describe "a href: '/', title: 'Home'", ->

0 comments on commit 1a46656

Please sign in to comment.
Something went wrong with that request. Please try again.