当前位置: 首页>>代码示例>>Python>>正文


Python Packager.compile方法代码示例

本文整理汇总了Python中pipeline.packager.Packager.compile方法的典型用法代码示例。如果您正苦于以下问题:Python Packager.compile方法的具体用法?Python Packager.compile怎么用?Python Packager.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pipeline.packager.Packager的用法示例。


在下文中一共展示了Packager.compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PipelineManifest

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
class PipelineManifest(Manifest):
    def __init__(self):
        self.packager = Packager()
        self.packages = self.collect_packages()
        self.finders = get_finders()
        self.package_files = self.get_package_files()

    def get_package_files(self):
        files = list()
        for package in self.packages:
            files.append(package.output_filename)
            for path in self.packager.compile(package.paths):
                files.append(path)

        return files     

    def collect_packages(self):
        packages = []
        for package_name in self.packager.packages['css']:
            package = self.packager.package_for('css', package_name)
            if package.manifest:
                packages.append(package)
        for package_name in self.packager.packages['js']:
            package = self.packager.package_for('js', package_name)
            if package.manifest:
                packages.append(package)
        return packages

    def cache(self):
        ignore_patterns = getattr(settings, "STATICFILES_IGNORE_PATTERNS", None)
        
        if PIPELINE:
            for package in self.packages:
                yield str(self.packager.individual_url(package.output_filename))
        else:
            for package in self.packages:
                for path in self.packager.compile(package.paths):
                    yield str(self.packager.individual_url(path))

        for finder in self.finders:
            for path, storage in finder.list(ignore_patterns):
                # Prefix the relative path if the source storage contains it
                if getattr(storage, 'prefix', None):
                    prefixed_path = os.path.join(storage.prefix, path)
                else:
                    prefixed_path = path

                # Dont add any doubles
                if prefixed_path not in self.package_files:
                    yield str(self.packager.individual_url(prefixed_path))
开发者ID:reshift,项目名称:django-pipeline,代码行数:52,代码来源:manifest.py

示例2: CompressedCSSNode

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
class CompressedCSSNode(template.Node):
    def __init__(self, name):
        self.name = name
        self.packager = Packager()

    def render(self, context):
        package_name = template.Variable(self.name).resolve(context)
        try:
            package = self.packager.package_for('css', package_name)
        except PackageNotFound:
            return ''  # fail silently, do not return anything if an invalid group is specified

        if settings.PIPELINE:
            compressed_path = self.packager.pack_stylesheets(package)
            return self.render_css(package, compressed_path)
        else:
            package['paths'] = self.packager.compile(package['paths'])
            return self.render_individual(package)

    def render_css(self, package, path):
        context = {}
        if not 'template' in package:
            package['template'] = "pipeline/css.html"
        if not 'context' in package:
            context = package['context']
        context.update({
            'url': self.packager.individual_url(path)
        })
        return render_to_string(package['template'], context)

    def render_individual(self, package):
        tags = [self.render_css(package, path) for path in package['paths']]
        return '\n'.join(tags)
开发者ID:foonnnnn,项目名称:django-pipeline,代码行数:35,代码来源:compressed.py

示例3: CompressedCSSNode

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
class CompressedCSSNode(template.Node):
    def __init__(self, name):
        self.name = name

    def render(self, context):
        package_name = template.Variable(self.name).resolve(context)
        package = settings.PIPELINE_CSS.get(package_name, {})
        if package:
            package = {package_name: package}
        self.packager = Packager(css_packages=package, js_packages={})

        try:
            package = self.packager.package_for('css', package_name)
        except PackageNotFound:
            return ''  # fail silently, do not return anything if an invalid group is specified

        if settings.PIPELINE:
            return self.render_css(package, package.output_filename)
        else:
            paths = self.packager.compile(package.paths)
            return self.render_individual(package, paths)

    def render_css(self, package, path):
        template_name = package.template_name or "pipeline/css.html"
        context = package.extra_context
        context.update({
            'url': staticfiles_storage.url(path)
        })
        return render_to_string(template_name, context)

    def render_individual(self, package, paths):
        tags = [self.render_css(package, path) for path in paths]
        return '\n'.join(tags)
开发者ID:trapeze,项目名称:django-pipeline,代码行数:35,代码来源:compressed.py

示例4: PipelineManifest

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
class PipelineManifest(Manifest):
    def __init__(self):
        self.packager = Packager()
        self.packages = self.collect_packages()
        self.finder = DefaultStorageFinder()

    def collect_packages(self):
        packages = []
        for package_name in self.packager.packages["css"]:
            package = self.packager.package_for("css", package_name)
            if package.manifest:
                packages.append(package)
        for package_name in self.packager.packages["js"]:
            package = self.packager.package_for("js", package_name)
            if package.manifest:
                packages.append(package)
        return packages

    def cache(self):
        if settings.PIPELINE:
            for package in self.packages:
                yield str(self.packager.individual_url(package.output_filename))
        else:
            for package in self.packages:
                for path in self.packager.compile(package.paths):
                    yield str(self.packager.individual_url(path))
        for path in self.finder.list():
            yield str(self.packager.individual_url(path))
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:30,代码来源:manifest.py

示例5: compressed_css

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
def compressed_css(ctx, name):
    package = settings.PIPELINE_CSS.get(name, {})
    if package:
        package = {name: package}

    packager = Packager(css_packages=package, js_packages={})

    try:
        package = packager.package_for('css', name)
    except PackageNotFound:
        return ""

    def _render_css(path):
        template_name = package.template_name or "pipeline/css.jinja"

        context = package.extra_context
        context.update({
            'type': guess_type(path, 'text/css'),
            'url': staticfiles_storage.url(path)
        })

        template = ctx.environment.get_template(template_name)
        return template.render(context)

    if settings.PIPELINE_ENABLED:
        return _render_css(package.output_filename)
    else:
        default_collector.collect()
        paths = packager.compile(package.paths)
        tags = [_render_css(path) for path in paths]
        return '\n'.join(tags)
开发者ID:AsymmetricVentures,项目名称:django-jinja,代码行数:33,代码来源:_pipeline.py

示例6: compressed_css

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
def compressed_css(name):
    package = settings.PIPELINE_CSS.get(name, {})
    if package:
        package = {name: package}

    packager = Packager(css_packages=package, js_packages={})

    try:
        package = packager.package_for('css', name)
    except PackageNotFound:
        return ""

    def _render_css(path):
        template_name = package.template_name or "pipeline/css.jinja"

        context = package.extra_context
        context.update({
            'type': guess_type(path, 'text/css'),
            'url': staticfiles_storage.url(path)
        })

        return render_to_string(template_name, context)

    if not settings.DEBUG:
        return _render_css(package.output_filename)

    paths = packager.compile(package.paths)
    tags = [_render_css(path) for path in paths]

    return '\n'.join(tags)
开发者ID:andreif,项目名称:django-jinja,代码行数:32,代码来源:_pipeline.py

示例7: CommonNode

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
class CommonNode(template.Node):
    def __init__(self, name):
        self.name = name

    def render(self, context):
        package_name = template.Variable(self.name).resolve(context)
        package = self.packages.get(package_name, {})
        if package:
            package = {package_name: package}
        self.packager = Packager(css_packages=package, js_packages=package)

        try:
            package = self.packager.package_for(self.type, package_name)
        except PackageNotFound:
            return ''  # fail silently, do not return anything if an invalid group is specified

        if settings.PIPELINE:
            return self.render_type_specific(package, package.output_filename)
        else:
            paths = self.packager.compile(package.paths)
            return self.render_individual(package, paths)

    def render_individual(self, package, paths):
        tags = [self.render_type_specific(package, path) for path in paths]
        return '\n'.join(tags)

    def get_url(self, path):
        if path_is_url(path):
            return path
        return default_storage.url(path)
开发者ID:fahhem,项目名称:django-pipeline,代码行数:32,代码来源:compressed.py

示例8: PipelineManifest

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
class PipelineManifest(Manifest):
    def __init__(self):
        self.packager = Packager()
        self.packages = self.collect_packages()
        self.finder = DefaultStorageFinder()

    def collect_packages(self):
        packages = []
        for package_name in self.packager.packages['css']:
            package = self.packager.package_for('css', package_name)
            if package.manifest:
                packages.append(package)
        for package_name in self.packager.packages['js']:
            package = self.packager.package_for('js', package_name)
            if package.manifest:
                packages.append(package)
        return packages

    def cache(self):
        ignore_patterns = getattr(settings, "STATICFILES_IGNORE_PATTERNS", None)
        
        if settings.PIPELINE:
            for package in self.packages:
                yield str(self.packager.individual_url(package.output_filename))
        else:
            for package in self.packages:
                for path in self.packager.compile(package.paths):
                    yield str(self.packager.individual_url(path))
        for path in self.finder.list(ignore_patterns):
            yield str(self.packager.individual_url(path))
开发者ID:ZibMedia,项目名称:django-pipeline,代码行数:32,代码来源:manifest.py

示例9: CompressedJSNode

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
class CompressedJSNode(template.Node):
    def __init__(self, name):
        self.name = name

    def render(self, context):
        package_name = template.Variable(self.name).resolve(context)
        package = settings.PIPELINE_JS.get(package_name, {})
        if package:
            package = {package_name: package}
        self.packager = Packager(css_packages={}, js_packages=package)

        try:
            package = self.packager.package_for('js', package_name)
        except PackageNotFound:
            return ''  # fail silently, do not return anything if an invalid group is specified

        if 'externals' in package:
            return '\n'.join([self.render_external(package, url) for url in package['externals']])

        if settings.PIPELINE:
            compressed_path = self.packager.pack_javascripts(package)
            return self.render_js(package, compressed_path)
        else:
            package['paths'] = self.packager.compile(package['paths'])
            templates = self.packager.pack_templates(package)
            return self.render_individual(package, templates)

    def render_js(self, package, path):
        context = {}
        if not 'template' in package:
            package['template'] = "pipeline/js.html"
        if 'context' in package:
            context = package['context']
        context.update({
            'url': self.packager.individual_url(path)
        })
        return render_to_string(package['template'], context)

    def render_external(self, package, url):
        if not 'template' in package:
            package['template'] = "pipeline/js.html"
        return render_to_string(package['template'], {
            'url': url
        })

    def render_inline(self, package, js):
        context = {}
        if 'context' in package:
            context = package['context']
        context.update({
            'source': js
        })
        return render_to_string("pipeline/inline_js.html", context)

    def render_individual(self, package, templates=None):
        tags = [self.render_js(package, js) for js in package['paths']]
        if templates:
            tags.append(self.render_inline(package, templates))
        return '\n'.join(tags)
开发者ID:UniIsland,项目名称:django-pipeline,代码行数:61,代码来源:compressed.py

示例10: render_compressed

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
 def render_compressed(self, package, package_type):
     if not settings.DEBUG:
         method = getattr(self, "render_{0}".format(package_type))
         return method(package, package.output_filename)
     else:
         packager = Packager()
         method = getattr(self, "render_individual_{0}".format(package_type))
         paths = packager.compile(package.paths)
         templates = packager.pack_templates(package)
         return method(package, paths, templates=templates)
开发者ID:EDITD,项目名称:django-pipeline,代码行数:12,代码来源:compressed.py

示例11: tabzilla_css_redirect

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
def tabzilla_css_redirect(r):
    packer = Packager()
    tabzilla_package = packer.package_for('css', 'tabzilla')
    if not settings.DEBUG:
        file_path = tabzilla_package.output_filename
    else:
        default_collector.collect()
        paths = packer.compile(tabzilla_package.paths)
        file_path = paths[0]

    return static(file_path)
开发者ID:ckprice,项目名称:bedrock,代码行数:13,代码来源:urls.py

示例12: compressed_css

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
def compressed_css(package_name, raw=False):
    package = settings.PIPELINE_CSS.get(package_name, {})
    if package:
        package = {package_name: package}
    packager = Packager(css_packages=package, js_packages={})

    package = packager.package_for('css', package_name)

    if settings.PIPELINE_ENABLED:
        return render_css(package, package.output_filename, raw=raw)
    else:
        paths = packager.compile(package.paths)
        return render_individual_css(package, paths, raw=raw)
开发者ID:28554010,项目名称:edx-platform,代码行数:15,代码来源:__init__.py

示例13: compressed_js

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
def compressed_js(package_name):
    package = settings.PIPELINE_JS.get(package_name, {})
    if package:
        package = {package_name: package}
    packager = Packager(css_packages={}, js_packages=package)

    package = packager.package_for('js', package_name)

    if settings.PIPELINE_ENABLED:
        return render_js(package, package.output_filename)
    else:
        paths = packager.compile(package.paths)
        templates = packager.pack_templates(package)
        return render_individual_js(package, paths, templates)
开发者ID:28554010,项目名称:edx-platform,代码行数:16,代码来源:__init__.py

示例14: compressed_js

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
def compressed_js(ctx, name):
    package = settings.PIPELINE_JS.get(name, {})
    if package:
        package = {name: package}

    packager = Packager(css_packages={}, js_packages=package)
    try:
        package = packager.package_for("js", name)
    except PackageNotFound:
        return ""

    def _render_js(path):
        template_name = package.template_name or "pipeline/js.jinja"
        context = package.extra_context
        context.update({
            'type': guess_type(path, 'text/javascript'),
            'url': staticfiles_storage.url(path),
        })

        template = ctx.environment.get_template(template_name)
        return template.render(context)

    def _render_inline_js(js):
        context = package.extra_context
        context.update({
            'source': js
        })

        template = ctx.environment.get_template("pipeline/inline_js.jinja")

        return template.render(context)

    # Render a optimized one
    if settings.PIPELINE_ENABLED:
        return _render_js(package.output_filename)
    else:
        default_collector.collect()
        paths = packager.compile(package.paths)
        templates = packager.pack_templates(package)
        tags = [_render_js(js) for js in paths]
        if templates:
            tags.append(_render_inline_js(templates))

        return '\n'.join(tags)
开发者ID:AsymmetricVentures,项目名称:django-jinja,代码行数:46,代码来源:_pipeline.py

示例15: CompressedJSNode

# 需要导入模块: from pipeline.packager import Packager [as 别名]
# 或者: from pipeline.packager.Packager import compile [as 别名]
class CompressedJSNode(template.Node):
    def __init__(self, name):
        self.name = name

    def render(self, context):
        package_name = template.Variable(self.name).resolve(context)
        package = settings.PIPELINE_JS.get(package_name, {})
        if package:
            package = {package_name: package}
        self.packager = Packager(css_packages={}, js_packages=package)

        try:
            package = self.packager.package_for('js', package_name)
        except PackageNotFound:
            return ''  # fail silently, do not return anything if an invalid group is specified

        if settings.PIPELINE:
            return self.render_js(package, package.output_filename)
        else:
            paths = self.packager.compile(package.paths)
            templates = self.packager.pack_templates(package)
            return self.render_individual(package, paths, templates)

    def render_js(self, package, path):
        template_name = package.template_name or "pipeline/js.html"
        context = package.extra_context
        context.update({
            'type': guess_type(path, 'text/javascript'),
            'url': staticfiles_storage.url(path)
        })
        return render_to_string(template_name, context)

    def render_inline(self, package, js):
        context = package.extra_context
        context.update({
            'source': js
        })
        return render_to_string("pipeline/inline_js.html", context)

    def render_individual(self, package, paths, templates=None):
        tags = [self.render_js(package, js) for js in paths]
        if templates:
            tags.append(self.render_inline(package, templates))
        return '\n'.join(tags)
开发者ID:fabiosantoscode,项目名称:django-pipeline,代码行数:46,代码来源:compressed.py


注:本文中的pipeline.packager.Packager.compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。