Example #1
0
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)
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)
Example #3
0
    def add_css(self):
        # compile assets
        default_collector.collect(self.request)

        # add the files that produce export.css
        pkg = self.package_for('epub', 'css')
        packager = Packager()
        paths = packager.compile(pkg.paths)

        self.stylesheets = []
        for path in paths:
            with codecs.open(staticfiles_storage.path(path), 'r',
                             'utf-8') as f:
                css = f.read()
            self.book.add_item(
                epub.EpubItem(file_name=path,
                              media_type="text/css",
                              content=css))
            self.stylesheets.append(path)

        # now ensure all html items link to the stylesheets
        for item in self.book.items:
            if isinstance(item, (epub.EpubHtml, epub.EpubNav)):
                for stylesheet in self.stylesheets:
                    # relativise path
                    href = '/'.join(['..'] * item.file_name.count('/') +
                                    [stylesheet])
                    item.add_link(href=href, rel='stylesheet', type='text/css')
Example #4
0
def install_media(site):
    """Install static media.

    Args:
        site (reviewboard.cmdline.rbsite.Site):
            The site to install media for.

            This will be the site corresponding to the current working
            directory.
    """
    from pipeline.collector import default_collector
    from pipeline.packager import Packager

    page = ui.page('Setting up static media files')

    media_path = os.path.join('htdocs', 'media')
    uploaded_path = os.path.join(site.install_dir, media_path, 'uploaded')
    ext_media_path = os.path.join(site.install_dir, media_path, 'ext')

    site.mkdir(uploaded_path)
    site.mkdir(os.path.join(uploaded_path, 'images'))
    site.mkdir(ext_media_path)

    # Run Pipeline on all the files, so we can prime the static media
    # directory. This cuts down on the very long initial load times, in
    # exchange for a somewhat long up-front time. Pipeline will at least
    # compile files within each bundle in parallel.
    default_collector.collect()

    packager = Packager()

    package_types = (
        ('css', 'CSS'),
        ('js', 'JavaScript'),
    )

    total_packages = sum(
        len(packager.packages[package_type])
        for package_type, package_type_desc in package_types
    )

    i = 1

    for package_type, package_type_desc in package_types:
        packages = packager.packages[package_type]

        for package_name, package in sorted(six.iteritems(packages),
                                            key=lambda pair: pair[0]):
            ui.step(page,
                    'Compiling %s bundle %s' % (package_type_desc,
                                                package.output_filename),
                    step_num=i,
                    total_steps=total_packages,
                    func=lambda: packager.compile(package.paths))

            i += 1
Example #5
0
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)
Example #6
0
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)
Example #7
0
    def test_delete_file_with_unmodified(self):
        list(default_collector.collect(files=['pipeline/js/first.js']))

        self.assertFalse(
            default_collector.delete_file(
                'js/first.js', 'pipeline/js/first.js',
                FileSystemStorage(local_path('assets'))))
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)
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)
Example #10
0
 def test_collect_with_files(self):
     self.assertEqual(
         set(default_collector.collect(files=[
             'pipeline/js/first.js',
             'pipeline/js/second.js',
         ])),
         set([
             'pipeline/js/first.js',
             'pipeline/js/second.js',
         ]))
Example #11
0
 def test_collect_with_files(self):
     self.assertEqual(
         set(
             default_collector.collect(files=[
                 'pipeline/js/first.js',
                 'pipeline/js/second.js',
             ])), set([
                 'pipeline/js/first.js',
                 'pipeline/js/second.js',
             ]))
Example #12
0
    def test_delete_file_with_modified(self):
        list(default_collector.collect())

        storage = FileSystemStorage(local_path('assets'))
        new_mtime = os.path.getmtime(storage.path('js/first.js')) - 1000
        os.utime(default_collector.storage.path('pipeline/js/first.js'),
                 (new_mtime, new_mtime))

        self.assertTrue(default_collector.delete_file(
            'js/first.js', 'pipeline/js/first.js', storage))
Example #13
0
    def test_delete_file_with_modified(self):
        list(default_collector.collect())

        storage = FileSystemStorage(local_path('assets'))
        new_mtime = os.path.getmtime(storage.path('js/first.js')) - 1000
        os.utime(default_collector.storage.path('pipeline/js/first.js'),
                 (new_mtime, new_mtime))

        self.assertTrue(
            default_collector.delete_file('js/first.js',
                                          'pipeline/js/first.js', storage))
Example #14
0
 def test_compile(self):
         paths = self.compiler.compile([_('pipeline/js/dummy.coffee')])
         default_collector.collect()
         self.assertEqual([_('pipeline/js/dummy.junk')], list(paths))
Example #15
0
 def setUp(self):
     default_collector.collect()
 def test_collect(self):
     self.assertEqual(set(default_collector.collect()), set(self._get_collectable_files()))
 def setUp(self):
     default_collector.collect()
     self.compiler = Compiler()
Example #18
0
 def setUp(self):
     self.maxDiff = None
     self.compressor = Compressor()
     default_collector.collect()
 def setUp(self):
     self.compressor = Compressor()
     default_collector.collect(RequestFactory().get('/'))
 def test_post_process_dry_run(self):
     default_collector.collect()
     processed_files = PipelineStorage().post_process({}, True)
     self.assertEqual(list(processed_files), [])
Example #21
0
    def test_delete_file_with_unmodified(self):
        list(default_collector.collect(files=['pipeline/js/first.js']))

        self.assertFalse(default_collector.delete_file(
            'js/first.js', 'pipeline/js/first.js',
            FileSystemStorage(local_path('assets'))))
Example #22
0
 def test_collect(self):
     self.assertEqual(set(default_collector.collect()),
                      set(self._get_collectable_files()))
Example #23
0
 def setUp(self):
     default_collector.collect()
     self.compiler = Compiler()
 def test_post_process(self):
     default_collector.collect()
     storage = PipelineStorage()
     processed_files = storage.post_process({})
     self.assertTrue(('screen.css', 'screen.css', True) in processed_files)
     self.assertTrue(('scripts.js', 'scripts.js', True) in processed_files)
Example #25
0
 def setUp(self):
     default_collector.collect()
Example #26
0
 def test_post_process_dry_run(self):
     default_collector.collect()
     processed_files = PipelineStorage().post_process({}, True)
     self.assertEqual(list(processed_files), [])
 def setUp(self):
     self.maxDiff = None
     self.compressor = Compressor()
     default_collector.collect()
Example #28
0
 def test_post_process(self):
     default_collector.collect()
     storage = PipelineStorage()
     processed_files = storage.post_process({})
     self.assertTrue(('screen.css', 'screen.css', True) in processed_files)
     self.assertTrue(('scripts.js', 'scripts.js', True) in processed_files)
Example #29
0
 def setUp(self):
     default_collector.collect()
     self.compiler = Compiler()
     self.old_compilers = settings.PIPELINE_COMPILERS
     settings.PIPELINE_COMPILERS = ['tests.tests.test_compiler.DummyCompiler']
 def test_compile(self):
     paths = self.compiler.compile([_('pipeline/js/dummy.coffee')])
     default_collector.collect()
     self.assertEqual([_('pipeline/js/dummy.junk')], list(paths))