-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tag attributes value must be "string forced" #3
Comments
This is possible! Even more complex functions can be called. $ echo "%div{ class: @item.name }" > test.hamlc
$ ./bin/haml-coffee -i test.hamlc
[Haml Coffee] Compiling file test.hamlc to test.jst
$ cat test.jst
(function() {
var _base, _ref;
if ((_ref = window.HAML) == null) window.HAML = {};
(_base = window.HAML).htmlEscape || (_base.htmlEscape = function(text) {
return ("" + text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, ''').replace(/"/g, '"');
});
window.HAML['test'] = function(context) {
var fn;
fn = function(context) {
var e, o;
o = [];
e = window.HAML.htmlEscape;
o.push("<div class='" + (e(this.item.name)) + "'></div>");
return o.join("\n");
};
return fn.call(context);
};
}).call(this); Is there more context in that template? As you have found out by yourself, enforcing interpolation by quoting the expression enables much robust parsing and is always a handy fallback when something does not work. |
The previous test was with haml-coffe. To also verify haml_coffee_assets, I took the example from #2 and modified it a bit: #cart
%h2= I18n.t('js.cart.title')
- if @cart.length == 0
%p.empty= I18n.t('js.cart.empty')
- else
%ul
- for item in @cart
%li
.item
= item.name
%a{ href: item.id }
= I18n.t('js.cart.item.remove') Also in this case I got a template: function (context) {
var fn;
fn = function(context) {
var e, item, o, _i, _len, _ref2;
o = [];
e = HAML.escape;
o.push("<div id='cart'>");
o.push(" <h2>" + (e(I18n.t('js.cart.title'))) + "</h2>");
if (this.cart.length === 0) {
o.push(" <p class='empty'>" + (e(I18n.t('js.cart.empty'))) + "</p>");
} else {
o.push(" <ul>");
_ref2 = this.cart;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
item = _ref2[_i];
o.push(" <li>");
o.push(" <div class='item'>");
o.push(e(" " + item.name));
o.push(" <a href='" + (e(item.id)) + "'>");
o.push(e(" " + I18n.t('js.cart.item.remove')));
o.push(" </a>");
o.push(" </div>");
o.push(" </li>");
}
o.push(" </ul>");
}
o.push("</div>");
return o.join("\n");
};
return fn.call(App.application.globalTemplateContext(context));
} And item.id works fine as attribute: o.push(" <a href='" + (e(item.id)) + "'>"); |
Ok, I'll give it a try again. |
Make sure to use the |
Ok so with
it brokes, with something like:
it's fine. Normal? :) |
This is a bug and has been fixed with the 0.2.3 release. The lexer handles attributes in different ways:
I really like such feedback, it helps tweak the lexer regular expressions for things I have forgotten. |
Works like a charm now. Thanks Micheal! |
This should be possible:
but to make it work, I must done:
Otherwise, it works super great. Thanks a lot!
The text was updated successfully, but these errors were encountered: