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

Commit

Permalink
Re-adding support for inline comments, this was lost in the change th…
Browse files Browse the repository at this point in the history
…at rebuild the ruleset from scratch.
  • Loading branch information
kgn committed Apr 24, 2011
1 parent 3032889 commit 594c6b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cssprefixer/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def magic(ruleset, debug, minify):
ruleset.style = cssutils.css.CSSStyleDeclaration()#clear out the styles that were there
rules = list()
for rule in children:
if not hasattr(rule, 'name'):#comments don't have name
rules.append(rule)
continue
rule.name = prefixRegex.sub('', rule.name)
if rule.name in ruleSet:
continue
Expand All @@ -36,6 +39,9 @@ def magic(ruleset, debug, minify):
rules.reverse()#now that we have unique rules flip the order back to what it was
ruleset.style.seq._readonly = False
for rule in rules:
if not hasattr(rule, 'name'):
ruleset.style.seq.append(rule, 'Comment')
continue
processor = None
if rule.name in tr_rules:
processor = tr_rules[rule.name](rule)
Expand Down
17 changes: 17 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ def test_comment(self):
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
display: block
}''')

def test_inline_comment(self):
#TODO: it would be nice if comments on the same line remained there, but this may not be possible because
#cssutils tears everything apart into objects and then we rebuild it.
self.assertEqual(cssprefixer.process('''article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
display: block;/* HTML5 display-role reset for older browsers */
}''', minify=False), '''article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
display: block;
/* HTML5 display-role reset for older browsers */
}''')
self.assertEqual(cssprefixer.process('''article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
/* HTML5 display-role reset for older browsers */
display: block;
}''', minify=False), '''article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
/* HTML5 display-role reset for older browsers */
display: block
}''')

class WebkitPrefixerTestCase(unittest.TestCase):
def test_common(self):
Expand Down

0 comments on commit 594c6b0

Please sign in to comment.