def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs=''):
    bundle = webpack_loader_utils._get_bundle(bundle_name, extension, config)
    tags = []
    for chunk in bundle:
        chunk['url'] += f'?v={settings.REVISION}'
        if chunk['name'].endswith(('.js', '.js.gz')):
            tags.append((
                '<script type="text/javascript" src="{0}" {1}></script>'
            ).format(chunk['url'], attrs))
        elif chunk['name'].endswith(('.css', '.css.gz')):
            tags.append((
                '<link type="text/css" href="{0}" rel="stylesheet" {1}/>'
            ).format(chunk['url'], attrs))
    return tags
Beispiel #2
0
def custom_static(bundle_name, extension=None, config="DEFAULT", attrs=""):
    if settings.DEBUG:
        return render_bundle(bundle_name,
                             extension=extension,
                             config=config,
                             attrs=attrs)

    bundle = _get_bundle(bundle_name, extension, config)
    tags = []
    for chunk in bundle:
        if chunk["name"].endswith((".js", ".js.gz")):
            tags.append(
                ('<script type="text/javascript" src="{0}" {1}></script>'
                 ).format(staticfiles_storage.url(chunk["name"]), attrs))
        elif chunk["name"].endswith((".css", ".css.gz")):
            tags.append(
                ('<link type="text/css" href="{0}" rel="stylesheet" {1}/>'
                 ).format(staticfiles_storage.url(chunk["name"]), attrs))
    return mark_safe("\n".join(tags))
Beispiel #3
0
def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs=''):
    '''
    Get a list of formatted <script> & <link> tags for the assets in the
    named bundle.

    :param bundle_name: The name of the bundle
    :param extension: (optional) filter by extension, eg. 'js' or 'css'
    :param config: (optional) the name of the configuration
    :return: a list of formatted tags as strings
    '''

    bundle = _get_bundle(bundle_name, extension, config)
    tags = []
    for chunk in bundle:
        if chunk['name'].endswith(('.js', '.js.gz')):
            tags.append(('<script src="{0}" {1}></script>').format(
                chunk['url'], attrs))
        elif chunk['name'].endswith(('.css', '.css.gz')):
            tags.append(
                ('<link type="text/css" href="{0}" rel="stylesheet" {1}/>'
                 ).format(chunk['url'], attrs))
    return tags
Beispiel #4
0
def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs=''):
    '''
    Get a list of formatted <script> & <link> tags for the assets in the
    named bundle.

    :param bundle_name: The name of the bundle
    :param extension: (optional) filter by extension, eg. 'js' or 'css'
    :param config: (optional) the name of the configuration
    :return: a list of formatted tags as strings
    '''

    bundle = _get_bundle(bundle_name, extension, config)
    tags = []
    for chunk in bundle:
        if chunk['name'].endswith(('.js', '.js.gz')):
            tags.append((
                '<script src="{0}" {1}></script>'
            ).format(chunk['url'], attrs))
        elif chunk['name'].endswith(('.css', '.css.gz')):
            tags.append((
                '<link type="text/css" href="{0}" rel="stylesheet" {1}/>'
            ).format(chunk['url'], attrs))
    return tags