Skip to content

Instantly share code, notes, and snippets.

@al-the-x
Created January 3, 2013 17:24
Show Gist options
  • Save al-the-x/4445122 to your computer and use it in GitHub Desktop.
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!
- 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.
<%! 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>
Traceback (most recent call last):
. . .
mako.exceptions.SyntaxException: Expected %> at line: 18 char: 53
@mikeboers
Copy link

It has been released to PyPI as v0.1.9.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment