diff options
| author | Sean Brant | 2013-03-14 23:20:21 -0500 |
|---|---|---|
| committer | Sean Brant | 2013-03-14 23:20:25 -0500 |
| commit | e65552efafe3d64b8bafecc6b94c7c3d5583b02d (patch) | |
| tree | 91ce147b8bd8aa6d3ed956f349a56293a4b5f283 | |
| parent | 4e128a2fe118494356e2d9bfdea0c9b537fa2578 (diff) | |
| download | pykss-e65552efafe3d64b8bafecc6b94c7c3d5583b02d.tar.bz2 | |
Adds optional syntax to example blocks
This is helpful when you need to add a modifier call to template that
might not otherwise have a class. Instead of displaying class="" you
can wrap wrap the class []? which will strip it out of the section
example but leave it in the modifier examples.
<a href="#"[ class="$modifier_class]?>Link</a>
| -rw-r--r-- | pykss/section.py | 7 | ||||
| -rw-r--r-- | tests/test_section.py | 5 |
2 files changed, 7 insertions, 5 deletions
diff --git a/pykss/section.py b/pykss/section.py index 8f3ed1a..edbfb45 100644 --- a/pykss/section.py +++ b/pykss/section.py @@ -9,7 +9,8 @@ MODIFIER_DESCRIPTION_SEPARATOR = ' - ' EXAMPLE_START = 'Example:' REFERENCE_START = 'Styleguide' -reference_re = re.compile('%s ([\d\.]+)' % REFERENCE_START) +reference_re = re.compile(r'%s ([\d\.]+)' % REFERENCE_START) +optional_re = re.compile(r'\[(.*)\]\?') class Section(object): @@ -76,6 +77,6 @@ class Section(object): return self._reference def add_example(self, example): - self._example = example.replace('$modifier_class', '') + self._example = optional_re.sub('', example).replace('$modifier_class', '') for modifier in self._modifiers: - modifier.add_example(example) + modifier.add_example(optional_re.sub(r'\1', example)) diff --git a/tests/test_section.py b/tests/test_section.py index 6ece110..200e65e 100644 --- a/tests/test_section.py +++ b/tests/test_section.py @@ -17,7 +17,7 @@ Your standard form button. .smaller - A smaller button Example: - <a href="button$modifier_class">Button</a> + <a href="#" class="button$modifier_class">Button</a><a href="#"[ class="$modifier_class"]?>Button</a> Styleguide 2.1.1. """ @@ -36,7 +36,8 @@ Styleguide 2.1.1. self.assertEqual(self.section.modifiers[0].description, 'Highlights when hovering.') def test_parses_the_example(self): - self.assertEqual(self.section.example, '<a href="button">Button</a>') + expected = '<a href="#" class="button">Button</a><a href="#">Button</a>' + self.assertEqual(self.section.example, expected) def test_parses_the_styleguide_reference(self): self.assertEqual(self.section.section, '2.1.1') |
