Exemplo n.º 1
0
def _type_of(obj, **kwargs):
    if isinstance(obj, BooleanValue):
        return StringValue('bool')
    if isinstance(obj, NumberValue):
        return StringValue('number')
    if isinstance(obj, QuotedStringValue):
        return StringValue('string')
    if isinstance(obj, ColorValue):
        return StringValue('color')
    if isinstance(obj, dict):
        return StringValue('list')
    return 'unknown'
Exemplo n.º 2
0
def _inline_image(image, mimetype=None, **kwargs):
    root = kwargs.get('root')
    path = os.path.abspath(
        os.path.join(root.get_opt('path'),
                     StringValue(image).value))
    if os.path.exists(path):
        mimetype = StringValue(mimetype).value or mimetypes.guess_type(path)[0]
        f = open(path, 'rb')
        url = 'data:' + mimetype + ';base64,' + base64.b64encode(f.read())
    else:
        if root and root.get_opt('warn'):
            warn("Not found image: %s" % path)
        url = '%s?_=NA' % QuotedStringValue(image).value
    inline = 'url("%s")' % url
    return StringValue(inline)
Exemplo n.º 3
0
def _image_height(image, **kwargs):
    root = kwargs.get('root')
    path = os.path.abspath(
        os.path.join(root.get_opt('path'),
                     StringValue(image).value))
    size = __get_size(path, root=root)
    return NumberValue([size[1], 'px'])
Exemplo n.º 4
0
def _headings(a=None, b=None, **kwargs):
    h = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
    if not a or StringValue(a).value == 'all':
        a, b = 1, 6
    elif b is None:
        b, a = a.value + 1, 1
    return ', '.join(h[int(float(a) - 1):int(float(b))])
Exemplo n.º 5
0
class Variable(Value, ParseNode):

    def_value = StringValue('none')

    @classmethod
    def _do_op(cls, self, other, op):
        return self.value._do_op(self.value, other, op)

    @classmethod
    def _do_cmps(cls, self, other, op):
        return self.value._do_cmps(self.value, other, op)

    def __nonzero__(self):
        return True

    @property
    def value(self):
        name = self.data[0].strip('-$')
        minus = self.data[0][0] == '-'
        value = self.ctx.get(name) or self.root.ctx.get(name, self.def_value)
        return (0 - value) if minus else value
Exemplo n.º 6
0
def _minmax(n1, n2, **kwargs):
    return StringValue('minmax({0},{1})'.format(n1, n2))
Exemplo n.º 7
0
def _nest(*args, **kwargs):
    return ', '.join(' '.join(
        s.strip()
        for s in p) if not '&' in p[1] else p[1].replace('&', p[0].strip())
                     for p in product(*(StringValue(sel).value.split(',')
                                        for sel in args)))
Exemplo n.º 8
0
def _enumerate(s, b, e, **kwargs):
    return ', '.join("%s%d" % (StringValue(s).value, x)
                     for x in xrange(int(b.value), int(e.value + 1)))
Exemplo n.º 9
0
def _elements_of_type(display, **kwargs):
    return StringValue(ELEMENTS_OF_TYPE.get(StringValue(display).value, ''))
Exemplo n.º 10
0
def _unquote(*args, **kwargs):
    return StringValue(' '.join(str(s).strip("\"'") for s in args))
Exemplo n.º 11
0
 def __str__(self):
     """ Write to output.
     """
     return ''.join(StringValue(n).value for n in self.data)