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

New doctypes, attribute ordering and attribute escaping #63

Merged
merged 8 commits into from
Mar 13, 2017

Conversation

rowanseymour
Copy link
Member

@rowanseymour rowanseymour commented Mar 13, 2017

I implemented a test runner for https://github.com/nyaruka/haml-spec/tree/django-hamlpy and these are some fixes to bring us closer to consistency with their spec:

  • Adds support for newer doctypes already supported by main Haml project
  • Adds format (html4/html5/xhtml) option same as main Haml project
  • Don't use < /> syntax if not using xhtml format
  • Only use last id from an element, e.g. id of %p#id1#id2 should be just id2
  • Tweak ordering of CSS classes (classes in attribute dict take priority)
  • Tweak ordering of element attributes (other > classes > id)


@property
def html(self):
return self.html4 or self.html5
Copy link
Member Author

Choose a reason for hiding this comment

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

This pattern of using properties lets us follow the Ruby Haml code a bit more closely

@@ -56,12 +56,12 @@ def read_element(stream):

id_or_class = read_word(stream, DOM_OBJECT_EXTRA_CHARS)
if is_id:
ids.append(id_or_class)
_id = id_or_class
Copy link
Member Author

@rowanseymour rowanseymour Mar 13, 2017

Choose a reason for hiding this comment

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

Only the last id value is supposed to be used (https://github.com/nyaruka/haml-spec/blob/django-hamlpy/tests.json#L172)

parts = doctype.split()
if parts and parts[0] == "XML":
attr_wrapper = self.compiler.options['attr_wrapper']
def get_header(self, doctype, options):
Copy link
Member Author

Choose a reason for hiding this comment

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

<img src='/static/imgs/ibl_logo{{id}}.gif' alt='IBL Logo' />
<br />
<img src='/static/imgs/ibl_logo.gif' alt='IBL Logo{{id}}' />
<img src='/static/imgs/ibl_logo{{id}}.gif' alt='IBL Logo'>
Copy link
Member Author

Choose a reason for hiding this comment

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

The default format is html5 - /> syntax only use for xhtml.

@@ -107,7 +107,7 @@ def test_django_variables(self):

# they can be escaped
self._test("%a{'b': '\\\\#{greeting} test', title: \"It can't be removed\"} blah",
"<a b='#{greeting} test' title='It can\\'t be removed'>blah</a>")
"<a b='#{greeting} test' title='It can&#39;t be removed'>blah</a>")
Copy link
Member Author

Choose a reason for hiding this comment

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

HTML special chars now escaped by default in attribute values

@@ -209,12 +209,51 @@ def test_invalid_filter(self):
self._test_error(":nosuchfilter\n", "No such filter: nosuchfilter")

def test_doctypes(self):
self._test('!!!', '<!DOCTYPE html>',
Copy link
Member Author

Choose a reason for hiding this comment

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

These tests are copied from the Ruby project

@rowanseymour rowanseymour changed the title Doctypes and escaping New doctypes and attribute escaping Mar 13, 2017
@rowanseymour rowanseymour changed the title New doctypes and attribute escaping New doctypes, attribute ordering and attribute escaping Mar 13, 2017
@rowanseymour rowanseymour merged commit 541c5b6 into master Mar 13, 2017
@rowanseymour rowanseymour deleted the doctypes_and_escaping branch March 13, 2017 14:01
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.

2 participants