Пример #1
0
    def load_from_templates(self):
        # Using the Django loader
        bundles = DjangoLoader().load_bundles()

        # Using the Jinja loader, if available
        try:
            import jinja2
        except ImportError:
            pass
        else:
            from webassets.ext.jinja2 import Jinja2Loader, AssetsExtension

            jinja2_envs = []
            # Prepare a Jinja2 environment we can later use for parsing.
            # If not specified by the user, put in there at least our own
            # extension, which we will need most definitely to achieve anything.
            _jinja2_extensions = getattr(settings, 'ASSETS_JINJA2_EXTENSIONS',
                                         False)
            if not _jinja2_extensions:
                _jinja2_extensions = [AssetsExtension.identifier]
            jinja2_envs.append(
                jinja2.Environment(extensions=_jinja2_extensions))

            try:
                from coffin.common import get_env as get_coffin_env
            except ImportError:
                pass
            else:
                jinja2_envs.append(get_coffin_env())

            bundles.extend(
                Jinja2Loader(get_env(), get_django_template_dirs(),
                             jinja2_envs).load_bundles())

        return bundles
Пример #2
0
    def load_from_templates(self):
        # Using the Django loader
        bundles = DjangoLoader().load_bundles()

        # Using the Jinja loader, if available
        try:
            import jinja2
        except ImportError:
            pass
        else:
            from webassets.ext.jinja2 import Jinja2Loader, AssetsExtension

            jinja2_envs = []
            # Prepare a Jinja2 environment we can later use for parsing.
            # If not specified by the user, put in there at least our own
            # extension, which we will need most definitely to achieve anything.
            _jinja2_extensions = getattr(settings, 'ASSETS_JINJA2_EXTENSIONS', False)
            if not _jinja2_extensions:
                _jinja2_extensions = [AssetsExtension.identifier]
            jinja2_envs.append(jinja2.Environment(extensions=_jinja2_extensions))

            try:
                from coffin.common import get_env as get_coffin_env
            except ImportError:
                pass
            else:
                jinja2_envs.append(get_coffin_env())

            bundles.extend(Jinja2Loader(get_env(),
                                        get_django_template_dirs(),
                                        jinja2_envs).load_bundles())

        return bundles
Пример #3
0
    jinja2_envs = []
    from django_assets.jinja2.extension import AssetsExtension
    # Prepare a Jinja2 environment we can later use for parsing.
    # If not specified by the user, put in there at least our own
    # extension, which we will need most definitely to achieve anything.
    _jinja2_extensions = getattr(settings, 'ASSETS_JINJA2_EXTENSIONS')
    if not _jinja2_extensions:
        _jinja2_extensions = [AssetsExtension.identifier]
    jinja2_envs.append(jinja2.Environment(extensions=_jinja2_extensions))

    try:
        from coffin.common import get_env as get_coffin_env
    except:
        pass
    else:
        jinja2_envs.append(get_coffin_env())


def _shortpath(abspath):
    """Make an absolute path relative to the project's settings module,
    which would usually be the project directory."""
    b = os.path.dirname(os.path.normpath(sys.modules[settings.SETTINGS_MODULE].__file__))
    p = os.path.normpath(abspath)
    return p[len(os.path.commonprefix([b, p])):]


class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--parse-templates', action='store_true',
            help='Rebuild assets found by parsing project templates '
                 'instead of using the tracking database.'),
Пример #4
0
    jinja2_envs = []
    from django_assets.jinja2.extension import AssetsExtension
    # Prepare a Jinja2 environment we can later use for parsing.
    # If not specified by the user, put in there at least our own
    # extension, which we will need most definitely to achieve anything.
    _jinja2_extensions = getattr(settings, 'ASSETS_JINJA2_EXTENSIONS')
    if not _jinja2_extensions:
        _jinja2_extensions = [AssetsExtension.identifier]
    jinja2_envs.append(jinja2.Environment(extensions=_jinja2_extensions))

    try:
        from coffin.common import get_env as get_coffin_env
    except:
        pass
    else:
        jinja2_envs.append(get_coffin_env())


def _shortpath(abspath):
    """Make an absolute path relative to the project's settings module,
    which would usually be the project directory."""
    b = os.path.dirname(os.path.normpath(sys.modules[settings.SETTINGS_MODULE].__file__))
    p = os.path.normpath(abspath)
    return p[len(os.path.commonprefix([b, p])):]


class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--parse-templates', action='store_true',
            help='Rebuild assets found by parsing project templates '
                 'instead of using the tracking database.'),