Created
January 3, 2013 17:24
-
-
Save al-the-x/4445122 to your computer and use it in GitHub Desktop.
While using PyHAML to build an app with AngularJS, I noticed that some of my attributes were being "sanitized" when I use a `def` or `block` tag with HAML syntax (e.g. `%%self:some_def` below). The PyHAML preprocessor expands the attribute name on the tag to `ng-app`, then Mako barfs on the `ng-` prefix of the attribute. Woes!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- attrs={ "ngApp": "something" } | |
%p(**attrs) | |
This element should have an attribute <code>ng-app="something"</code>. | | |
It works just fine. | |
%%(def(name="some_def(**attrs)") | |
= attrs | |
%p(**attrs) | |
= caller.body() or 'Cannot pass a body to a function... :/' | |
${some_def(ngApp="something") | |
I can't pass a body with this invocation, can I...? | |
%%self:some_def(ngApp="something") | |
This element should have an attribute <code>ng-app="something"</code>, too. | | |
But something went wrong. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%! from haml import runtime as __HAML %> | |
<% | |
attrs={ "ngApp": "something" } | |
%> | |
<p<% __M_writer(__HAML.attribute_str(**attrs)) %>> | |
This element should have an attribute <code>ng-app="something"</code>. | |
It works just fine. | |
</p> | |
<%def name="some_def(**attrs)"> | |
${attrs} | |
<p<% __M_writer(__HAML.attribute_str(**attrs)) %>> | |
${caller and caller.body()} | |
</p> | |
</%def> | |
${some_def(ngApp="something")} | |
I can't pass a body with this invocation, can I...? | |
<%self:some_def ng-app="something"> | |
This element should have an attribute <code>ng-app="something"</code>, too. | |
But something went wrong. | |
</%self:some-def> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Traceback (most recent call last): | |
. . . | |
mako.exceptions.SyntaxException: Expected %> at line: 18 char: 53 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It has been released to PyPI as v0.1.9.
Cheers!