コード例 #1
0
def assets(request, *args, **kwargs):
    env = get_webassets_env_from_request(request)

    result = []

    for f in args:
        try:
            result.append(env[f])
        except KeyError:
            result.append(f)

    bundle = Bundle(*result, **kwargs)
    if USING_WEBASSETS_CONTEXT:
        with bundle.bind(env):
            urls = bundle.urls()
    else:
        urls = bundle.urls(env=env)

    return urls
コード例 #2
0
def assets(request, *args, **kwargs):
    env = get_webassets_env_from_request(request)

    result = []

    for f in args:
        try:
            result.append(env[f])
        except KeyError:
            result.append(f)

    bundle = Bundle(*result, **kwargs)
    if USING_WEBASSETS_CONTEXT:
        with bundle.bind(env):
            urls = bundle.urls()
    else:  # pragma: no cover
        urls = bundle.urls(env=env)

    return urls
コード例 #3
0
 def _get_assets(request, *args, **kwargs):
     bundle = Bundle(*args, **kwargs)
     with bundle.bind(env):
         urls = bundle.urls()
     return urls
コード例 #4
0
def _render_assets(tokens, env):
    #pylint:disable=too-many-locals
    # Construct a bundle with the given options
    output = None
    filters = None
    depends = None
    bundle_kwargs = {
        'output': output,
        'filters': filters,
        'debug': False,  # because of `Bundle.iterbuild`, this is useless.
        'depends': depends,
    }

    # Resolve bundle names.
    files = []
    state = None
    buffered_tokens = []
    for token in tokens:
        if state is None:
            if token[1] == 'block_begin':
                state = STATE_BLOCK_BEGIN
        elif state == STATE_BLOCK_BEGIN:
            if token[1] == 'name':
                # nothing to be done?
                pass
            elif token[1] == 'string':
                files = [token[2][1:-1]] # removes '"'.
            if token[1] == 'block_end':
                state = STATE_BLOCK_CONTENT
        elif state == STATE_BLOCK_CONTENT:
            if token[1] == 'block_begin':
                state = None
            else:
                buffered_tokens += [token]

    content = ''.join([token[2] for token in buffered_tokens]).strip()

    urls = []
    bundle_names = []
    for fname in files:
        try:
            bundle = env[fname]
            debug = bundle.config.get('debug')
            bundle.config.update({'debug': False})
            with bundle.bind(env):
                urls += bundle.urls()
            bundle.config.update({'debug': debug})
        except KeyError:
            bundle_names.append(fname)

    if bundle_names:
        bundle = Bundle(*bundle_names, **bundle_kwargs)
        # Retrieve urls (this may or may not cause a build)
        with bundle.bind(env):
            urls += bundle.urls()

    # For each url, execute the content of this template tag (represented
    # by the macro ```caller`` given to use by Jinja2).
    result = content
    for url in urls:
        look = re.match(r'(.*)({{\s*ASSET_URL.*}})(.*)', content)
        if look:
            parts = urlparse(url)
            url = urlunparse((parts.scheme, parts.netloc, parts.path,
                None, None, None))
            result = look.group(1) + url + look.group(3)
        else:
            result = content
    return result
コード例 #5
0
def _render_assets(tokens, env):
    #pylint:disable=too-many-locals
    # Construct a bundle with the given options
    output = None
    filters = None
    depends = None
    bundle_kwargs = {
        'output': output,
        'filters': filters,
        'debug': False,  # because of `Bundle.iterbuild`, this is useless.
        'depends': depends,
    }

    # Resolve bundle names.
    files = []
    state = None
    buffered_tokens = []
    for token in tokens:
        if state is None:
            if token[1] == 'block_begin':
                state = STATE_BLOCK_BEGIN
        elif state == STATE_BLOCK_BEGIN:
            if token[1] == 'name':
                # nothing to be done?
                pass
            elif token[1] == 'string':
                files = [token[2][1:-1]] # removes '"'.
            if token[1] == 'block_end':
                state = STATE_BLOCK_CONTENT
        elif state == STATE_BLOCK_CONTENT:
            if token[1] == 'block_begin':
                state = None
            else:
                buffered_tokens += [token]

    content = ''.join([token[2] for token in buffered_tokens]).strip()

    urls = []
    bundle_names = []
    for fname in files:
        try:
            bundle = env[fname]
            debug = bundle.config.get('debug')
            bundle.config.update({'debug': False})
            with bundle.bind(env):
                urls += bundle.urls()
            bundle.config.update({'debug': debug})
        except KeyError:
            bundle_names.append(fname)

    if bundle_names:
        bundle = Bundle(*bundle_names, **bundle_kwargs)
        # Retrieve urls (this may or may not cause a build)
        with bundle.bind(env):
            urls += bundle.urls()

    # For each url, execute the content of this template tag (represented
    # by the macro ```caller`` given to use by Jinja2).
    result = content
    for url in urls:
        look = re.match(r'(.*)({{\s*ASSET_URL.*}})(.*)', content)
        if look:
            parts = urlparse(url)
            url = urlunparse((parts.scheme, parts.netloc, parts.path,
                None, None, None))
            result = look.group(1) + url + look.group(3)
        else:
            result = content
    return result