def append(lst, val, separator=None): separator = separator and StringValue(separator).value ret = ListValue(lst, separator) val = ListValue(val) for v in val: ret.value[len(ret)] = v return ret
def linear_gradient(*args): if len(args) == 1 and isinstance(args[0], (list, tuple, ListValue)): args = ListValue(args[0]).values() position_and_angle = _get_gradient_position_and_angle(args) color_stops = _get_gradient_color_stops(args) if color_stops is None: raise Exception('No color stops provided to linear-gradient function') color_stops = __color_stops(False, *color_stops) args = [ position(position_and_angle) if position_and_angle is not None else None, ] args.extend('%s %s' % (c, to_str(s)) for s, c in color_stops) to__s = 'linear-gradient(' + ', '.join(to_str(a) for a in args or [] if a is not None) + ')' ret = StringValue(to__s) def to__css2(): return StringValue('') ret.to__css2 = to__css2 def to__moz(): return StringValue('-moz-' + to__s) ret.to__moz = to__moz def to__pie(): return StringValue('-pie-' + to__s) ret.to__pie = to__pie def to__ms(): return StringValue('-ms-' + to__s) ret.to__ms = to__ms def to__o(): return StringValue('-o-' + to__s) ret.to__o = to__o def to__webkit(): return StringValue('-webkit-' + to__s) ret.to__webkit = to__webkit def to__owg(): args = [ 'linear', position(position_and_angle or 'center top'), opposite_position(position_and_angle or 'center top'), ] 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) + ')' return StringValue(ret) ret.to__owg = to__owg def to__svg(): return linear_svg_gradient(color_stops, position_and_angle or 'top') ret.to__svg = to__svg return ret
def join(lst1, lst2, separator=None): ret = ListValue(lst1) lst2 = ListValue(lst2).value lst_len = len(ret.value) ret.value.update((k + lst_len if isinstance(k, int) else k, v) for k, v in lst2.items()) separator = __parse_separator(separator) if separator is not None: ret.value['_'] = separator return ret
def dash_compass_list(*args): separator = None if len(args) == 1 and isinstance(args[0], (list, tuple, ListValue)): args = ListValue(args[0]).values() else: separator = ',' ret = ListValue(args) if separator: ret.value['_'] = separator return ret
def radial_gradient(*args): if len(args) == 1 and isinstance(args[0], (list, tuple, ListValue)): args = ListValue(args[0]).values() position_and_angle = _get_gradient_position_and_angle(args) shape_and_size = _get_gradient_shape_and_size(args) color_stops = _get_gradient_color_stops(args) if color_stops is None: raise Exception('No color stops provided to radial-gradient function') color_stops = __color_stops(False, *color_stops) args = [ position(position_and_angle) if position_and_angle is not None else None, shape_and_size if shape_and_size is not None else None, ] args.extend('%s %s' % (c, to_str(s)) for s, c in color_stops) to__s = 'radial-gradient(' + ', '.join(to_str(a) for a in args or [] if a is not None) + ')' ret = StringValue(to__s) def to__css2(): return StringValue('') ret.to__css2 = to__css2 def to__moz(): return StringValue('-moz-' + to__s) ret.to__moz = to__moz def to__pie(): log.warn("PIE does not support radial-gradient.") return StringValue('-pie-radial-gradient(unsupported)') ret.to__pie = to__pie def to__webkit(): return StringValue('-webkit-' + to__s) ret.to__webkit = to__webkit def to__owg(): args = [ 'radial', grad_point(position_and_angle) if position_and_angle is not None else 'center', '0', grad_point(position_and_angle) if position_and_angle is not None else 'center', __grad_end_position(True, color_stops), ] 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) + ')' return StringValue(ret) ret.to__owg = to__owg def to__svg(): return radial_svg_gradient(color_stops, position_and_angle or 'center') ret.to__svg = to__svg return ret
def dash_compass_slice(lst, start_index, end_index=None): start_index = NumberValue(start_index).value end_index = NumberValue(end_index).value if end_index is not None else None ret = {} lst = ListValue(lst).value for i, item in lst.items(): if not isinstance(i, int): if i == '_': ret[i] = item elif i > start_index and end_index is None or i <= end_index: ret[i] = item return ListValue(ret)
def reject(lst, *values): """Removes the given values from the list""" ret = {} if not isinstance(lst, ListValue): lst = ListValue(lst) lst = lst.value if len(values) == 1: values = values[0] if isinstance(values, ListValue): values = values.value.values() for i, item in lst.items(): if item not in values: ret[i] = item separator = lst.get('_', None) if separator is not None: ret['_'] = separator return ListValue(ret)
def nth(lst, n): """ Return the Nth item in the string """ n = NumberValue(n).value lst = ListValue(lst).value try: n = int(float(n)) - 1 n = n % len(lst) except: if n.lower() == 'first': n = 0 elif n.lower() == 'last': n = -1 try: ret = lst[n] except KeyError: lst = [v for k, v in sorted(lst.items()) if isinstance(k, int)] try: ret = lst[n] except: ret = '' return ret.__class__(ret)
def first_value_of(*lst): if len(lst) == 1 and isinstance(lst[0], (list, tuple, ListValue)): lst = ListValue(lst[0]) ret = ListValue(lst).first() return ret.__class__(ret)
def append(lst, val, separator=None): separator = __parse_separator(separator) ret = ListValue(lst, separator) ret.value[len(ret)] = val return ret
def max_(*lst): if len(lst) == 1 and isinstance(lst[0], (list, tuple, ListValue)): lst = ListValue(lst[0]).values() lst = ListValue(lst).value return max(lst.values())
def evaluate(self, calculator, divide=False): items = [ item.evaluate(calculator, divide=divide) for item in self.items ] return ListValue(items, separator="," if self.comma else "")