Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Attribute dictionary tweaks #64

Merged
merged 7 commits into from
Mar 14, 2017
Merged

Attribute dictionary tweaks #64

merged 7 commits into from
Mar 14, 2017

Conversation

rowanseymour
Copy link
Member

@rowanseymour rowanseymour commented Mar 13, 2017

  • Interpret an unquoted HTML style attribute value as a variable, e.g. .(foo=bar) is compiled to <div foo="{{ bar }}"></div>
  • Support multiple attribute dictionaries on a single element. The example given in the Haml reference is %a(title=@title){:href => @link.href} Stuff
  • Ensure attribute values which are themselves Haml are parsed with same options as rest of document
  • Interpret .(foo=True) as a boolean attribute, and .(foo=None) as removing attribute foo
  • Render boolean attributes as checked="checked" in XHTML mode

@rowanseymour rowanseymour self-assigned this Mar 13, 2017
self._test('%form(foo=bar id="myform")', "<form foo='{{ bar }}' id='myform'></form>")

# multiple dicts
self._test('%a(a="b"){:c => "d"} Stuff', "<a a='b' c='d'>Stuff</a>")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, do you like this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can think of no good use for it but also no reason to not support it since it's in the spec.. no?

@rowanseymour
Copy link
Member Author

@nicpottier have made few additional changes so please take another look

if value is None:
rendered.append("%s" % name) # boolean attribute
if name in ('id', 'class') or value in (None, False):
# this line isn't recorded in coverage because it gets optimized away (http://bugs.python.org/issue2506)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicpottier @ericnewcomer @norkans7 just in case anyone runs into something similar - a line which is definitely hit, but not included in coverage because CPython optimizes it away.

@rowanseymour rowanseymour merged commit 994eae4 into master Mar 14, 2017
@rowanseymour rowanseymour deleted the html_vars branch March 14, 2017 08:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants