Example #1
0
@register('opposite-position')
def opposite_position(p):
    return _position(True, p)


# ------------------------------------------------------------------------------
# Math


@register('pi', 0)
def pi():
    return NumberValue(math.pi)


COMPASS_HELPERS_LIBRARY.add(NumberValue.wrap_python_function(math.sin), 'sin',
                            1)
COMPASS_HELPERS_LIBRARY.add(NumberValue.wrap_python_function(math.cos), 'cos',
                            1)
COMPASS_HELPERS_LIBRARY.add(NumberValue.wrap_python_function(math.tan), 'tan',
                            1)

# ------------------------------------------------------------------------------
# Fonts


def _font_url(path, only_path=False, cache_buster=True, inline=False):
    filepath = StringValue(path).value
    path = None
    if callable(config.STATIC_ROOT):
        try:
Example #2
0
# ------------------------------------------------------------------------------
# Number functions


@register('percentage', 1)
def percentage(value):
    if not isinstance(value, NumberValue):
        raise TypeError("Expected number, got %r" % (value, ))

    if not value.is_unitless:
        raise TypeError("Expected unitless number, got %r" % (value, ))

    return value * NumberValue(100, unit='%')


CORE_LIBRARY.add(NumberValue.wrap_python_function(abs), 'abs', 1)
CORE_LIBRARY.add(NumberValue.wrap_python_function(round), 'round', 1)
CORE_LIBRARY.add(NumberValue.wrap_python_function(math.ceil), 'ceil', 1)
CORE_LIBRARY.add(NumberValue.wrap_python_function(math.floor), 'floor', 1)


# ------------------------------------------------------------------------------
# List functions
def __parse_separator(separator, default_from=None):
    if separator is None:
        return None
    separator = StringValue(separator).value
    if separator == 'comma':
        return True
    elif separator == 'space':
        return False
Example #3
0

# ------------------------------------------------------------------------------
# Number functions

@register('percentage', 1)
def percentage(value):
    if not isinstance(value, NumberValue):
        raise TypeError("Expected number, got %r" % (value,))

    if not value.is_unitless:
        raise TypeError("Expected unitless number, got %r" % (value,))

    return value * NumberValue(100, unit='%')

CORE_LIBRARY.add(NumberValue.wrap_python_function(abs), 'abs', 1)
CORE_LIBRARY.add(NumberValue.wrap_python_function(round), 'round', 1)
CORE_LIBRARY.add(NumberValue.wrap_python_function(math.ceil), 'ceil', 1)
CORE_LIBRARY.add(NumberValue.wrap_python_function(math.floor), 'floor', 1)


# ------------------------------------------------------------------------------
# List functions
def __parse_separator(separator, default_from=None):
    if separator is None:
        return None
    separator = StringValue(separator).value
    if separator == 'comma':
        return True
    elif separator == 'space':
        return False
Example #4
0
    return _position(False, p)


@register('opposite-position')
def opposite_position(p):
    return _position(True, p)


# ------------------------------------------------------------------------------
# Math

@register('pi', 0)
def pi():
    return NumberValue(math.pi)

COMPASS_HELPERS_LIBRARY.add(NumberValue.wrap_python_function(math.sin), 'sin', 1)
COMPASS_HELPERS_LIBRARY.add(NumberValue.wrap_python_function(math.cos), 'cos', 1)
COMPASS_HELPERS_LIBRARY.add(NumberValue.wrap_python_function(math.tan), 'tan', 1)


# ------------------------------------------------------------------------------
# Fonts

def _font_url(path, only_path=False, cache_buster=True, inline=False):
    filepath = StringValue(path).value
    path = None
    if callable(config.STATIC_ROOT):
        try:
            _file, _storage = list(config.STATIC_ROOT(filepath))[0]
            d_obj = _storage.modified_time(_file)
            filetime = int(time.mktime(d_obj.timetuple()))