From 534bcaf7191c8455d391c3e628f42a944ef72761 Mon Sep 17 00:00:00 2001 From: "German M. Bravo" Date: Tue, 13 Aug 2013 17:10:09 -0500 Subject: Gradients _position() optimizations and default positions --- scss/functions/compass/gradients.py | 4 ++-- scss/functions/compass/helpers.py | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/scss/functions/compass/gradients.py b/scss/functions/compass/gradients.py index 5119b39..20646f1 100644 --- a/scss/functions/compass/gradients.py +++ b/scss/functions/compass/gradients.py @@ -314,8 +314,8 @@ def linear_gradient(*args): def to__owg(): args = [ 'linear', - position(position_and_angle or ['center', 'top']), - opposite_position(position_and_angle or ['center', 'top']), + position(position_and_angle or None), + opposite_position(position_and_angle or None), ] args.extend('color-stop(%s, %s)' % (to_str(s), c) for s, c in color_stops) ret = '-webkit-gradient(' + ', '.join(to_str(a) for a in args or [] if a is not None) + ')' diff --git a/scss/functions/compass/helpers.py b/scss/functions/compass/helpers.py index bde12ef..3300df9 100644 --- a/scss/functions/compass/helpers.py +++ b/scss/functions/compass/helpers.py @@ -364,29 +364,31 @@ def range_(frm, through=None): # ------------------------------------------------------------------------------ # Working with CSS constants -OPPOSITE_POSITIONS = dict( - top='bottom', - bottom='top', - left='right', - right='left', - center='center', -) +OPPOSITE_POSITIONS = { + 'top': StringValue('bottom', quotes=None), + 'bottom': StringValue('top', quotes=None), + 'left': StringValue('right', quotes=None), + 'right': StringValue('left', quotes=None), + 'center': StringValue('center', quotes=None), +} +DEFAULT_POSITION = [StringValue('center', quotes=None), StringValue('top', quotes=None)] def _position(opposite, positions): - positions = List.from_maybe(positions) + if positions is None: + positions = DEFAULT_POSITION + else: + positions = List.from_maybe(positions) ret = [] for pos in positions: if isinstance(pos, (StringValue, six.string_types)): - _pos = getattr(pos, 'value', pos) - if _pos in OPPOSITE_POSITIONS: + pos_value = getattr(pos, 'value', pos) + if pos_value in OPPOSITE_POSITIONS: if opposite: - opp = OPPOSITE_POSITIONS[pos] - ret.append(StringValue(opp, quotes=None)) + ret.append(OPPOSITE_POSITIONS[pos_value]) else: ret.append(pos) - continue elif isinstance(pos, NumberValue): -- cgit v1.2.1