diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-07-30 18:42:52 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-07-30 18:42:52 -0700 |
commit | 70b9f8d8907259d2d79bacca6474a794057b49b0 (patch) | |
tree | f0e3ca0d7e8904d50533cadc94b95048a2eb0d42 | |
parent | b52e8efe4ef7c050ab4c92ccc6db4383629e5fbe (diff) | |
download | pyscss-70b9f8d8907259d2d79bacca6474a794057b49b0.tar.gz |
Fix position() and opposite-position(), I think.
-rw-r--r-- | scss/functions/compass/helpers.py | 75 | ||||
-rw-r--r-- | scss/tests/functions/compass/test_helpers.py | 62 |
2 files changed, 105 insertions, 32 deletions
diff --git a/scss/functions/compass/helpers.py b/scss/functions/compass/helpers.py index 98789cc..5f56b6d 100644 --- a/scss/functions/compass/helpers.py +++ b/scss/functions/compass/helpers.py @@ -13,6 +13,7 @@ import math import mimetypes import os.path import time +import warnings from scss import config from scss.functions.library import FunctionLibrary @@ -383,37 +384,47 @@ def range_(frm, through=None): # ------------------------------------------------------------------------------ # Working with CSS constants -def _position(opposite, p): - pos = [] - hrz = vrt = None - nums = [v for v in p if isinstance(v, NumberValue)] - - if 'left' in p: - hrz = 'right' if opposite else 'left' - elif 'right' in p: - hrz = 'left' if opposite else 'right' - elif 'center' in p: - hrz = 'center' - - if 'top' in p: - vrt = 'bottom' if opposite else 'top' - elif 'bottom' in p: - vrt = 'top' if opposite else 'bottom' - elif 'center' in p: - hrz = 'center' - - if hrz == vrt: - vrt = None - - if hrz is not None: - pos.append(hrz) - elif len(nums): - pos.append(nums.pop(0)) - if vrt is not None: - pos.append(vrt) - elif len(nums): - pos.append(nums.pop(0)) - return ListValue(pos + nums) +OPPOSITE_POSITIONS = dict( + top='bottom', + bottom='top', + left='right', + right='left', + center='center', +) + +def _position(opposite, positions): + if isinstance(positions, ListValue): + positions = positions.values() + else: + positions = [positions] + + ret = [] + for pos in positions: + if isinstance(pos, StringValue): + if pos.value in OPPOSITE_POSITIONS: + if opposite: + opp = OPPOSITE_POSITIONS[pos.value] + ret.append(StringValue(opp, quotes=None)) + else: + ret.append(pos) + + continue + + elif isinstance(pos, NumberValue): + if pos.unit == '%': + if opposite: + ret.append(NumberValue(100 - pos.value, '%')) + else: + ret.append(pos) + continue + + warnings.warn("Can't find opposite for position %r" % (pos,)) + ret.append(pos) + + if len(ret) == 1: + return ret[0] + else: + return ListValue(ret, separator='') @register('position') @@ -534,7 +545,7 @@ def inline_font_files(*args): # ------------------------------------------------------------------------------ -# Fonts +# External stylesheets @register('stylesheet-url', 1) @register('stylesheet-url', 2) diff --git a/scss/tests/functions/compass/test_helpers.py b/scss/tests/functions/compass/test_helpers.py index e571c94..7e8b40a 100644 --- a/scss/tests/functions/compass/test_helpers.py +++ b/scss/tests/functions/compass/test_helpers.py @@ -52,8 +52,70 @@ def test_first_value_of(calc): assert calc('first-value-of(a b c d)') == calc('a') assert calc('first-value-of("a b c d")') == calc('"a"') +# -compass-list +# -compass-space-list +# -compass-slice + + +## Property prefixing + +# prefixed + +# prefix + +# -moz... + + +## Selector generation + +# append-selector + +# elements-of-type def test_enumerate(calc): assert calc('enumerate(foo, 4, 7)') == calc('foo-4, foo-5, foo-6, foo-7') + +# headers/headings + +# nest + +# range + + +## Working with CSS constants + +# position + +def test_opposite_position(calc): + assert calc('opposite-position(left)') == calc('right') + assert calc('opposite-position(top)') == calc('bottom') + assert calc('opposite-position(center)') == calc('center') + assert calc('opposite-position(top left)') == calc('bottom right') + assert calc('opposite-position(center right)') == calc('center left') + + +## Math + +# pi + +# sin + +# cos + +# tan + + +## Fonts + +# font-url + +# font-files + +# inline-font-files + + +## External stylesheets + +# stylesheet-url |