Example #1
0
def _bundle_app_coffee(env, debug=False):
    """Compile the apps coffeescript and bundle it into appname.js"""
    COFFEE_PATH = 'coffee'
    APP_PATH = path.join(COFFEE_PATH, 'appname')
    scripts = (
        path.join(COFFEE_PATH, 'nested.coffee'),
        path.join(COFFEE_PATH, 'app.coffee'),
        path.join(APP_PATH, 'app.coffee'),
        path.join(APP_PATH, 'menu.coffee'),
        path.join(APP_PATH, 'channel.coffee'),
        path.join(APP_PATH, 'contact.coffee'),
        path.join(APP_PATH, 'tag.coffee'),
        path.join(APP_PATH, 'person.coffee'),
        path.join(APP_PATH, 'vendor.coffee'),
        path.join(APP_PATH, 'activity.coffee'),
        path.join(APP_PATH, 'transaction.coffee'),
        path.join(APP_PATH, 'summary.coffee'),
        path.join(APP_PATH, 'router.coffee'),
    )

    all_js = Bundle(
        *scripts,
        filters='coffeescript',
        output=path.join('..', 'static', 'script', 'appname.js')
    )
    env.add(all_js)

    if not debug:
        all_js.filters = 'closure_js'
Example #2
0
def _bundle_3rd_party_js(env, debug=False):
    """Combine thrid party js libs into libs.js.

    For debug, they are left uncompressed.  For production the minified
    versions are used.  We suggest using hte vendor supplied minified version
    of each library.
    """
    JSPATH = path.join('js', 'lib')
    if debug:
        all_js = Bundle(
            path.join(JSPATH, 'json2.js'),
            path.join(JSPATH, 'jquery.js'),
            path.join(JSPATH, 'underscore.js'),
            path.join(JSPATH, 'backbone.js'),
            path.join(JSPATH, 'bootstrap.js'),
            path.join(JSPATH, 'leaflet.js'),
            path.join(JSPATH, 'bootstrap-typeahead-improved.js'),
            output=path.join('..', 'static', 'script', 'libs.js')
        )
    else:
        JSPATH = path.join(JSPATH, 'min')
        all_js = Bundle(
            path.join(JSPATH, 'json2.min.js'),
            path.join(JSPATH, 'jquery-min.js'),
            path.join(JSPATH, 'underscore-min.js'),
            path.join(JSPATH, 'backbone-min.js'),
            path.join(JSPATH, 'bootstrap-min.js'),
            path.join(JSPATH, 'leaflet-min.js'),
            path.join(JSPATH, 'bootstrap-typeahead-improved-min.js'),
            output=path.join('..', 'static', 'script', 'libs.js')
        )

    env.add(all_js)
    if debug:
        all_js.build()
Example #3
0
def _bundle_3rd_party_js(app, env, debug=False):
    """Combine thrid party js libs into libs.js.

    For debug, they are left uncompressed.  For production the minified
    versions are used.  We suggest using hte vendor supplied minified version
    of each library.
    """
    JSPATH = path.join('js', 'lib')

    if debug:
        scripts = ()
        if not scripts:
            return

        all_js = Bundle(
            *scripts,
            output=path.join('..', '..', app, 'static', 'script', 'libs.js')
        )
    else:
        JSPATH = path.join(JSPATH, 'min')

        scripts = ()
        if not scripts:
            return

        all_js = Bundle(
            *scripts,
            output=path.join('..', '..', app, 'static', 'script', 'libs.js')
        )

    env.add(all_js)
    if debug:
        all_js.build()
    def test(self):
        bundle = Bundle("one.css", "two.css", output="styles.css")
        assets_env = create_assets_env(
            source_dir="./tests/fixtures/bundle", build_dir=self.build_dir, static_url="/", bundles={}
        )
        bundle.build(env=assets_env)

        self.assertTrue("styles.css" in os.listdir(self.build_dir))
Example #5
0
            def __init__(self, *a, **kw):
                Bundle.__init__(self, *a, **kw)
                self.env = assets_env

                self.dbg = kw.get('debug', None)

                # Kind of hacky, but gives us access to the last Bundle
                # instance used by the extension.
                test_instance.the_bundle = self
Example #6
0
 def register_tpl_bundle(self, name, *files):
     def noop(_in, out, **kw):
         out.write(_in.read())
     bundle = Bundle(*files, filters=(noop,), output='tpls/{}'.format(name))
     fileName = bundle.resolve_output(self.assets)
     if os.path.isfile(fileName):
         os.remove(fileName)
     bundle.build(self.assets,force=False,disable_cache=True)
     self.assets.register(name, bundle)
Example #7
0
 def test_pass_down_env(self):
     """[Regression] When a root *container* bundle is connected
     to an environment, the child bundles do not have to be.
     """
     child = Bundle('1', '2')
     child.env = None
     root = self.MockBundle(child)
     root.env = self.m
     # Does no longer raise an "unconnected env" exception
     assert root.urls() == ['/1', '/2']
Example #8
0
def _bundle_app_jsts(app, env, debug=False):
    """Compile and bundle JSTs into template.js"""
    all_js = Bundle(
        path.join('templates', '**', '*.jst'), debug=False, filters='jst',
        output=path.join('..', '..', app, 'static', 'script', 'template.js')
    )
    env.add(all_js)

    if not debug:
        all_js.filters = 'closure_js'
Example #9
0
def _bundle_app_less(app, env, debug):
    """Compile and minify demo's less files into demo.css."""
    bundle = Bundle(
        Bundle(path.join('less', '%s.less' % (app.lower(),)), filters='less'),
        output=path.join('..', '..', app, 'static', 'css', '%s.css' % (app.lower(),))
    )

    if not debug:
        bundle.filters = 'cssmin'

    env.add(bundle)
Example #10
0
def _bundle_app_less(env, debug):
    """Compile and minify appname's less files into appname.css."""
    bundle = Bundle(
        Bundle(path.join('less', 'appname.less'), filters='less'),
        output=path.join('..', 'static', 'css', 'appname.css')
    )

    if not debug:
        bundle.filters = 'cssmin'

    env.add(bundle)
    def test_init_extra_kwarg(self):
        """Bundles may be given an ``extra`` dictionary."""
        assert Bundle().extra == {}
        assert Bundle(extra={'foo': 'bar'}).extra == {'foo': 'bar'}

        # Nested extra values
        assert Bundle(Bundle(extra={'foo': 'bar'}),
                      Bundle(extra={'baz': 'qux'})).extra == {
            'foo': 'bar', 'baz': 'qux'}

        # [Regression] None values in child bundles raise no exception
        bundle = Bundle('foo')
        bundle.extra = None
        assert Bundle(bundle).extra == {}
Example #12
0
    def resolve_source_to_url(self, filepath, item):
        request = get_current_request()
        env = self.env

        # Copied from webassets 0.8. Reproduced here for backwards
        # compatibility with the previous webassets release.
        # This ensures files which do not require building are still served
        # with proper versioning of URLs.
        # This can likely be removed once miracle2k/webassets#117 is fixed.

        # Only query the version if we need to for performance
        version = None
        if has_placeholder(filepath) or env.url_expire is not False:
            # If auto-build is enabled, we must not use a cached version
            # value, or we might serve old versions.
            bundle = Bundle(item, output=filepath)
            version = bundle.get_version(env, refresh=env.auto_build)

        url = filepath
        if has_placeholder(url):
            url = url % {'version': version}

        # This part is different from webassets. Try to resolve with an asset
        # spec first, then try the base class source URL resolver.

        resolved = False
        if request is not None:
            # Attempt to resolve the filepath as passed (but after versioning).
            # If this fails, it may be because the static route was registered
            # with an asset spec. In this case, the original item may also be
            # an asset spec contained therein, so try to resolve that.
            for attempt in (url, item):
                try:
                    url = request.static_url(attempt)
                except ValueError:
                    continue
                else:
                    resolved = True
                    break

        if not resolved:
            url = super(PyramidResolver, self).resolve_source_to_url(
                url,
                item
            )

        if env.url_expire or (
                env.url_expire is None and not has_placeholder(filepath)):
            url = "%s?%s" % (url, version)
        return url
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)
    urls = bundle.urls(env=env)

    return urls
    def test_asset_spec_is_resolved(self):
        from webassets import Bundle

        self.create_files({
                'dotted/__init__.py': '',
                'dotted/package/__init__.py': '',
                'dotted/package/name/__init__.py': '',
                'dotted/package/name/static/zing.css':
                '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec, output='gen/zung.css')

        urls = bundle.urls(self.env)
        assert urls == ['/static/gen/zung.css']
        assert file(self.tempdir+urls[0]).read() == '* { text-decoration: underline }'
    def test_asset_spec_missing_file(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': ''})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        fname = self.tempdir+'/dotted/package/name/static/zing.css'
        assert str(cm.exception.message) == ("'%s' does not exist" % (fname,))
    def test_asset_spec_globbing(self):
        from webassets import Bundle

        self.create_files({
            'static/__init__.py': '',
            'static/zing.css':
            '* { text-decoration: underline }',
            'static/zang.css':
            '* { text-decoration: underline }'})
        asset_spec = 'static:z*ng.css'
        bundle = Bundle(asset_spec)

        urls = bundle.urls(self.env)
        assert len(urls) == 2
        assert 'http://example.com/static/zing.css' in urls
        assert 'http://example.com/static/zang.css' in urls
    def test_url(self, base_url, static_view, webasset, expected):
        """
        Test final urls

        Special notes on the parametrized variables:
        - expected file, if it ends in o.css, it setups output in the bundle
        - static_view set to manual changes also the base_dir to /mypkg instead
          of /static
        """
        from webassets import Bundle

        expected = self.format_expected(expected, webasset)
        params = {} if not 'o.css' in expected else {'output': 'o.css'}
        bundle = Bundle(webasset, **params)
        res = bundle.urls(self.build_env(base_url, static_view))
        assert [expected] == res
    def test_asset_spec_passthru_uses_static_url(self):
        from webassets import Bundle

        self.create_files({
                'dotted/__init__.py': '',
                'dotted/package/__init__.py': '',
                'dotted/package/name/__init__.py': '',
                'dotted/package/name/static/zing.css':
                '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)
        self.request.static_url = Mock(return_value='http://example.com/foo/')

        urls = bundle.urls(self.env)
        self.request.static_url.assert_called_with(asset_spec)
        assert urls == ['http://example.com/foo/']
    def test_asset_spec_missing_file(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
                'dotted/__init__.py': '',
                'dotted/package/__init__.py': '',
                'dotted/package/name/__init__.py': ''})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        assert cm.exception.args[0].message == '{0!r} does not exist'.format(
                self.tempdir+'/dotted/package/name/static/zing.css')
    def test_asset_spec_output_is_resolved(self):
        from webassets import Bundle

        self.create_files({
            'static/__init__.py': '',
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec, output='static:zung.css')

        urls = bundle.urls(self.env)
        assert urls == ['http://example.com/static/zung.css']
        urls[0] = urls[0][len(self.request.application_url):]
        assert file(self.tempdir+urls[0]).read() == '* { text-decoration: underline }'
    def test_asset_spec_missing_package(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.rabbits:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        assert cm.exception.args[0].message == 'No module named rabbits'
    def test_asset_spec_load_path_and_mapping(self):
        from webassets import Bundle

        asset_path = self.tempdir + '/dotted/package/name/static/'
        self.env.append_path(asset_path, 'http://static.example.com')

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec, output=asset_spec.replace('zing', 'zung'))

        urls = bundle.urls(self.env)
        assert urls == ['http://static.example.com/zung.css']
    def test_asset_spec_no_static_view(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
                'dotted/__init__.py': '',
                'dotted/package/__init__.py': '',
                'dotted/package/name/__init__.py': '',
                'dotted/package/name/static/zing.css':
                '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        assert cm.exception.args[0].message == 'No static URL definition matching '+asset_spec
Example #24
0
def _bundle_skel(app_path, env, debug=False):
    """Combine thrid party js libs into libs.js.

    For debug, they are left uncompressed.  For production the minified
    versions are used.  We suggest using the vendor supplied minified version
    of each library.
    """

    JS_LIB_PATH = path.join('js', 'lib')
    third_js = Bundle(
        path.join(JS_LIB_PATH, 'json2.js'),
        path.join(JS_LIB_PATH, 'jquery.js'),
        path.join(JS_LIB_PATH, 'underscore.js'),
        path.join(JS_LIB_PATH, 'backbone.js'),
        path.join(JS_LIB_PATH, 'backbone.paginator.js'),
        path.join(JS_LIB_PATH, 'bootstrap.js'),
        path.join(JS_LIB_PATH, 'bootstrap-typeahead-improved.js'),
        path.join(JS_LIB_PATH, 'date.js'),
    )

    #TOOD: add require so we can simplify this
    COFFEE_PATH = 'coffee'
    coffee_js = Bundle(
        path.join(COFFEE_PATH, 'nested.coffee'),
        path.join(COFFEE_PATH, 'app.coffee'),
        path.join(COFFEE_PATH, 'datagrid.coffee'),
        path.join(COFFEE_PATH, 'skel.coffee'),
        path.join(COFFEE_PATH, 'channel.coffee'),
        path.join(COFFEE_PATH, 'utils.coffee'),
        path.join(COFFEE_PATH, 'smartbox.coffee'),
        filters='coffeescript'
    )

    all_js = Bundle(
        third_js,
        Bundle(
            path.join('templates', '**', '*.jst'), filters='jst', debug=False),
        coffee_js,
        output=path.join(app_path, 'script', 'skel.js'))

    env.add(all_js)

    if not debug:
        all_js.filters = 'closure_js'
Example #25
0
def _bundle_app_coffee(app_path, env, debug=False):
    """Compile the apps coffeescript and bundle it into demo.js"""
    COFFEE_PATH = 'coffee'
    scripts = (
        path.join(COFFEE_PATH, 'nested.coffee'),
        path.join(COFFEE_PATH, 'app.coffee'),
        path.join(COFFEE_PATH, 'skel.coffee'),
        path.join(COFFEE_PATH, 'channel.coffee'),
        path.join(COFFEE_PATH, 'utils.coffee'),
    )
    all_js = Bundle(
        *scripts,
        filters='coffeescript',
        output=path.join(app_path, 'script', 'skel.js')
    )
    env.add(all_js)

    if not debug:
        all_js.filters = 'closure_js'
    def test_asset_spec_no_static_view(self):
        from webassets import Bundle

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        # webassets will copy the file into a place that it can generate
        # a url for
        urls = bundle.urls(self.env)
        domain = 'http://example.com/static/webassets-external/'

        assert domain in urls[0]
        assert len(urls) == 1
Example #27
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
Example #28
0
def _bundle_app_coffee(app, env, debug=False):
    """Compile the apps coffeescript and bundle it into demo.js"""
    COFFEE_PATH = 'coffee'
    scripts = (
        path.join(COFFEE_PATH, 'app.coffee'),
        path.join(COFFEE_PATH, 'menu.coffee'),
        path.join(COFFEE_PATH, 'router.coffee'),
    )

    if not scripts:
        return

    all_js = Bundle(
        *scripts,
        filters='coffeescript',
        output=path.join('..', '..', app, 'static', 'script', '%s.js' % (app.lower(),))
    )
    env.add(all_js)

    if not debug:
        all_js.filters = 'closure_js'
Example #29
0
def _bundle_admin_js(env, debug=False):
    """Combine all js libs into sosadmin.js.

    For debug, they are left uncompressed.  For production the minified
    versions are used.  We suggest using the vendor supplied minified version
    of each library.
    """

    all_js = Bundle(
        _bundle_3rd_party_js(debug),
        #this needs to be debug false to handle recurisve templates
        Bundle(
            path.join('templates', '**', '*.jst'), filters='jst', debug=False),
        _bundle_admin_coffee(debug),
        output=path.join(
            '..', '..', APP_NAME, 'static', 'script', 'sosadmin.js')
    )

    env.add(all_js)

    if not debug:
        all_js.filters = 'closure_js'
def create_and_register_bundles(section, filter, DEPLOY):
    environment = Environment('.')
    for option in config.options(section):
        deps = [v.strip() for v in config.get(section, option).split(',')]
        log.info("%s.%s has dependencies: %s", option, section, deps)
        bndl = Bundle(*deps, filters=filter,
                      output=concat_string([DEPLOY, '/', option, '.', section]))
        environment.register(option, bndl)
        bndlgz = Bundle(*deps, filters=concat_string([filter, ', gzip']),
                      output=concat_string([DEPLOY, '/', option, '.', section, '.gz']))
        environment.register(concat_string([option, 'gz']), bndlgz)
        bndl.build()
        bndlgz.build()
Example #31
0
 def test_post_init_set_debug_to_False(self):
     bundle = Bundle()
     bundle.debug = False
     assert bundle.debug is False
Example #32
0
# -*- coding: utf-8 -*-

"""
Deprecated declarations. Will be removed in Baseframe 0.3.0
"""

from __future__ import absolute_import

from webassets import Bundle

# --- Legacy asset declarations below will be dropped in baseframe 0.3 --------

jquery_js = Bundle(
    'baseframe/js/jquery-1.7.1.js',
    filters='closure_js',
    output='js/baseframe-jquery.min.js',
)


bootstrap_js = Bundle(
    'baseframe/js/bootstrap/bootstrap-alert.js',
    'baseframe/js/bootstrap/bootstrap-button.js',
    #                      'baseframe/js/bootstrap/bootstrap-carousel.js',
    #                      'baseframe/js/bootstrap/bootstrap-collapse.js',
    'baseframe/js/bootstrap/bootstrap-dropdown.js',
    'baseframe/js/bootstrap/bootstrap-modal.js',
    'baseframe/js/bootstrap/bootstrap-tooltip.js',
    #                      'baseframe/js/bootstrap/bootstrap-popover.js',
    #                      'baseframe/js/bootstrap/bootstrap-scrollspy.js',
    'baseframe/js/bootstrap/bootstrap-tab.js',
    'baseframe/js/bootstrap/bootstrap-transition.js',
Example #33
0
 def load(self):
     """Mock load entry point."""
     return Bundle(self.name)
Example #34
0
 def __init__(self, app):
     assets = app.extensions['invenio-assets']
     assets.env.register('testbundle', Bundle())
Example #35
0
from webassets import Bundle

from .filters import SimpleClosureJS


# Font Awesome

fontawesome_css = Bundle(
    'http://rawgit.com/FortAwesome/Font-Awesome/v3.2.1/css/font-awesome.css',
    output='css/fontawesome-%(version)s.css')

fontawesome_webfont_eot = Bundle(
    'http://github.com/FortAwesome/Font-Awesome/blob/v3.2.1/font/fontawesome-webfont.eot?raw=true',
    output='font/fontawesome-webfont.eot')

fontawesome_webfont_woff = Bundle(
    'http://github.com/FortAwesome/Font-Awesome/blob/v3.2.1/font/fontawesome-webfont.woff?raw=true',
    output='font/fontawesome-webfont.woff')

fontawesome_webfont_ttf = Bundle(
    'http://github.com/FortAwesome/Font-Awesome/blob/v3.2.1/font/fontawesome-webfont.ttf?raw=true',
    output='font/fontawesome-webfont.ttf')

fontawesome_webfont_svg = Bundle(
    'http://rawgit.com/FortAwesome/Font-Awesome/v3.2.1/font/fontawesome-webfont.svg',
    output='font/fontawesome-webfont.svg')


# Twitter Bootstrap

bootstrap_js = Bundle(
Example #36
0
        self.append_path(os.path.join(plugin_dir, 'htdocs'), url=url_path)


indico_core = Bundle('js/indico/Core/Presentation.js',
                     'js/indico/Core/Data.js',
                     'js/indico/Core/Components.js',
                     'js/indico/Core/Auxiliar.js',
                     'js/indico/Core/Buttons.js',
                     'js/indico/Core/Effects.js',
                     'js/indico/Core/Interaction/Base.js',
                     'js/indico/Core/Widgets/Base.js',
                     'js/indico/Core/Widgets/Inline.js',
                     'js/indico/Core/Widgets/DateTime.js',
                     'js/indico/Core/Widgets/Menu.js',
                     'js/indico/Core/Widgets/RichText.js',
                     'js/indico/Core/Widgets/Navigation.js',
                     'js/indico/Core/Widgets/UserList.js',
                     'js/indico/Core/Dialogs/Popup.js',
                     'js/indico/Core/Dialogs/Base.js',
                     'js/indico/Core/Dialogs/Util.js',
                     'js/indico/Core/Dialogs/Users.js',
                     'js/indico/Core/Dialogs/PopupWidgets.js',
                     'js/indico/Core/Browser.js',
                     'js/indico/Core/Services.js',
                     'js/indico/Core/Util.js',
                     'js/indico/Core/Login.js',
                     'js/indico/Core/Dragndrop.js',
                     filters='rjsmin',
                     output='indico_core_%(version)s.min.js')

indico_management = Bundle('js/indico/Management/ConfModifDisplay.js',
                           'js/indico/Management/RoomBooking.js',
Example #37
0
    def initialize_assets(self):
        assets = self.get_assets()
        self.application.assets = assets
        if not assets:
            return

        self.application.assets_environment = Environment(
            directory=self.static_path,
            url=self.application.config.STATIC_ROOT_URL,
            debug=self.application.config.WEBASSETS_DEBUG,
            auto_build=self.application.config.WEBASSETS_AUTO_BUILD
        )

        for output_file, asset_items in assets.items():
            for asset_type, asset_files in asset_items.items():
                rebased = []
                for asset in asset_files:
                    rebased.append(join(self.static_path, asset))
                assets[output_file][asset_type] = rebased

        asset_index = 0
        for output_file, asset_items in assets.items():
            is_js = False
            is_css = False
            bundle_items = []

            if 'js' in asset_items:
                js = Bundle(
                    *asset_items['js'],
                    output='out/uncompressed_%d.js' % asset_index
                )
                bundle_items.append(js)
                is_js = True

            if 'coffee' in asset_items:
                coffee = Bundle(
                    *asset_items['coffee'],
                    filters=['coffeescript'],
                    output='out/coffee_%d.js' % asset_index
                )
                bundle_items.append(coffee)
                is_js = True

            if 'css' in asset_items:
                css = Bundle(
                    *asset_items['css'],
                    output='out/uncompressed_%d.css' % asset_index
                )
                bundle_items.append(css)
                is_css = True

            if 'scss' in asset_items:
                scss = Bundle(
                    *asset_items['scss'],
                    filters=['compass'],
                    output='out/compass_%d.css' % asset_index
                )
                bundle_items.append(scss)
                is_css = True

            filters = []
            if is_js:
                filters.append('jsmin')

            if is_css:
                filters.append('css_slimmer')

            if bundle_items:
                self.application.assets_environment.register(
                    output_file,
                    *bundle_items,
                    filters=filters,
                    output=output_file
                )
Example #38
0
from jinja2 import FileSystemLoader
from jinja2.environment import Environment as Jinja2Environment
from webassets import Environment as AssetsEnvironment, Bundle
from webassets.ext.jinja2 import AssetsExtension
from webassets.script import CommandLineEnvironment

STATIC_ROOT = environ.get('STATIC_ROOT', path.abspath(path.dirname(__file__)))
assets_env = AssetsEnvironment(path.join(STATIC_ROOT, 'static'), url='/static')

assets_env.register(
    'libs',
    Bundle('js/jquery-3.3.1.min.js',
           'js/handlebars-4.0.12.min.js',
           'js/bootstrap.min.js',
           'js/moment.js',
           'js/moment-timezone.js',
           'js/moment-tz-data.js',
           'js/typeahead.js',
           'js/jquery.dataTables.min.js',
           output='bundles/libs.js'))
assets_env.register(
    'oncall_js',
    Bundle('js/navigo.js',
           'js/incalendar.js',
           'js/oncall.js',
           output='bundles/oncall.bundle.js'))
assets_env.register(
    'css_libs',
    Bundle('css/bootstrap.min.css',
           'fonts/Source-Sans-Pro.css',
           'css/jquery.dataTables.min.css',
Example #39
0
               'scrollblocker.js',
               'timerange.js',
               'tooltips.js',
               'nullableselector.js',
               'colorpicker.js',
               'palettepicker.js',
               'itempicker.js',
               'sortablelist.js',
               'categorynavigator.js',
               'track_role_widget.js'))

indico_jquery_authors = rjs_bundle('indico_jquery_authors', 'js/indico/jquery/authors.js')

indico_badges_js = rjs_bundle('indico_badges', 'js/indico/Management/ConfModifBadgePosterPrinting.js')

indico_badges_css = Bundle('css/badges.css',
                           filters='cssmin', output='css/indico_badges_%(version)s.min.css')

fonts_sass = Bundle('sass/partials/_fonts.scss',
                    filters=('pyscss', 'cssmin'), output='css/indico_fonts_%(version)s.min.css')

indico_regform = rjs_bundle(
    'indico_regform',
    *namespace('js/indico/modules/registration/form',
               'form.js',
               'section.js',
               'field.js',
               'sectiontoolbar.js',
               'table.js'))

angular = rjs_bundle(
    'angular',
Example #40
0
 def test_post_init_set_debug_to_True(self):
     bundle = Bundle()
     bundle.debug = True
     assert bundle.debug is True
from webassets import Environment, Bundle

my_env = Environment('static/', 'static/')

common_css = Bundle('css/vendor/bootstrap.min.css',
                    'css/vendor/sb-admin-2.css',
                    'css/vendor/font-awesome.min.css',
                    output='public/css/common.css')

common_js = Bundle('js/vendor/jquery-2.1.1.js',
                   'js/vendor/d3.v3.js',
                   'js/vendor/mpld3.v0.2.js',
                   output='public/js/common.js')
my_env.register('css_all', common_css)
my_env.register('js_all', common_js)
my_env['css_all'].urls()
my_env['js_all'].urls()
Example #42
0
 def __init__(self, *a, **kw):
     Bundle.__init__(self, *a, **kw)
     self.env = assets_env
     # Kind of hacky, but gives us access to the last Bundle
     # instance used by the extension.
     test_instance.the_bundle = self
Example #43
0
 def __init__(self, *a, **kw):
     Bundle.__init__(self, *a, **kw)
     self.env = env
Example #44
0
from webassets import Bundle

from .filters import SimpleClosureJS

# Font Awesome

fontawesome_css = Bundle(
    'https://rawgithub.com/FortAwesome/Font-Awesome/v3.2.1/css/font-awesome.css',
    output='css/fontawesome-%(version)s.css')

fontawesome_webfont_eot = Bundle(
    'https://github.com/FortAwesome/Font-Awesome/blob/v3.2.1/font/fontawesome-webfont.eot?raw=true',
    output='font/fontawesome-webfont.eot')

fontawesome_webfont_woff = Bundle(
    'https://github.com/FortAwesome/Font-Awesome/blob/v3.2.1/font/fontawesome-webfont.woff?raw=true',
    output='font/fontawesome-webfont.woff')

fontawesome_webfont_ttf = Bundle(
    'https://github.com/FortAwesome/Font-Awesome/blob/v3.2.1/font/fontawesome-webfont.ttf?raw=true',
    output='font/fontawesome-webfont.ttf')

fontawesome_webfont_svg = Bundle(
    'https://rawgithub.com/FortAwesome/Font-Awesome/v3.2.1/font/fontawesome-webfont.svg',
    output='font/fontawesome-webfont.svg')

# Twitter Bootstrap

bootstrap_js = Bundle(
    'https://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js',
    output='js/bootstrap-%(version)s.js')
Example #45
0
def includeme(config):
    """
    Configures static assets
    """
    here = os.path.dirname(os.path.realpath(__file__))

    env = config.get_webassets_env()
    env.append_path(os.path.join(here, 'static'), '/forms/static')

    # "resolves" the path relative to this package
    def rel(path):
        return os.path.join(here, 'static', path)

    scriptsdir = os.path.join(here, 'static/scripts')

    config.add_webasset(
        'forms-js',
        Bundle(
            # Dependency javascript libraries must be loaded in a specific order
            rel('bower_components/jquery/dist/jquery.min.js'),
            rel('bower_components/jquery-ui/jquery-ui.min.js'),
            Bundle(rel('bower_components/jquery-cookie/jquery.cookie.js'),
                   filters='jsmin'),
            rel('bower_components/jquery-validate/dist/jquery.validate.min.js'
                ),
            rel('bower_components/bootstrap/dist/js/bootstrap.min.js'),
            rel('bower_components/knockout/dist/knockout.js'),
            rel('bower_components/knockout-sortable/build/knockout-sortable.min.js'
                ),
            rel('bower_components/select2/select2.min.js'),
            rel('bower_components/moment/min/moment.min.js'),
            rel('bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js'
                ),
            rel('bower_components/bootstrap-fileinput/js/fileinput.min.js'),
            # App-specific scripts can be loaded in any order
            Bundle(*[
                os.path.join(root, filename)
                for root, dirnames, filenames in os.walk(scriptsdir)
                for filename in filenames if filename.endswith('.js')
            ],
                   filters='jsmin'),
            output=rel('gen/forms.%(version)s.min.js')))

    config.add_webasset(
        'forms-css',
        Bundle(
            Bundle(rel('styles/main.less'),
                   filters='less',
                   depends=rel('styles/*.less'),
                   output=rel('gen/forms-main.%(version)s.min.css')),
            Bundle(rel('bower_components/select2/select2.css'),
                   filters='cssrewrite'),
            rel('bower_components/select2-bootstrap-css/select2-bootstrap.css'
                ),
            Bundle(rel(
                'bower_components/bootstrap-fileinput/css/fileinput.min.css'),
                   filters='cssrewrite'),
            filters='cssmin',
            output=rel('gen/forms.%(version)s.css')))

    log.debug('Assets configurated')
Example #46
0
#! /usr/bin/env python
#-*- coding: utf-8 -*-

from webassets import Environment, Bundle

environment = Environment('static', '')
environment.debug = True

css_map_bundle = Bundle('css/style.css',
                        'map/leaflet/leaflet.css',
                        'map/leaflet-sidebar/src/L.Control.Sidebar.css',
                        'map/leaflet-control-geocoder/Control.Geocoder.css',
                        'map/Osmose.Editor.css',
                        'map/style.css',
                        'map/Osmose.Menu.css',
                        filters='cssrewrite,cssmin',
                        output='gen/map-%(version)s.css')
environment.register('css_map', css_map_bundle)

js_map_bundle = Bundle('js/jquery-1.7.2.js',
                       'js/jquery-ui-1.10.4.dialog.js',
                       'js/mustache.js',
                       'map/leaflet/leaflet-src.js',
                       'map/leaflet-plugins/control/Permalink.js',
                       'map/leaflet-plugins/control/Permalink.Layer.js',
                       'map/Permalink.Overlay.js',
                       'map/Permalink.Item.js',
                       'map/leaflet-plugins/layer/tile/Bing.js',
                       'map/Leaflet.MapboxVectorTile.js',
                       'map/Mapillary.js',
                       'map/layers.js',
Example #47
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from webassets import Environment, Bundle

dir_static = os.path.join(
    os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'static')

static_env = Environment(dir_static)

static_env.register('js_all', Bundle('js/script.js', output='gen/all.js'))
static_env['js_all'].build()

# font-awesome is broken when included
static_env.register(
    'css_all', Bundle('css/style.css', filters='cssmin', output='gen/all.css'))
static_env['css_all'].build()
Example #48
0
 def setup(self):
     self.env = Environment(None, None)  # we won't create files
     self.env.cache = MemoryCache(capacity=100)
     self.bundle = Bundle(output="target")
     self.updater = BundleDefUpdater()
Example #49
0
def rjs_bundle(name, *files):
    return Bundle(*files, filters='rjsmin', output='js/{}_%(version)s.min.js'.format(name))
Example #50
0
from webassets import Environment, Bundle
from iamhhb import consts

# TODO: disable autobuild in production
env = Environment(directory=consts.http['static_gen_folder'],
                  url='/statics/gen',
                  load_path=[
                      consts.http['static_folder'],
                      consts.http['bower_folder'],
                  ],
                  auto_build=True)

js = Bundle('site.js', output='main.js')
css = Bundle('site.scss', filters='libsass', output='main.css')

env.register('mainjs', js)
env.register('maincss', css)
Example #51
0
def sass_module_bundle(module_name, depends=[]):
    return Bundle('sass/modules/_{0}.scss'.format(module_name),
                  filters=("pyscss", "cssrewrite", "cssmin"),
                  output="sass/{0}_%(version)s.min.css".format(module_name),
                  depends=SASS_BASE_MODULES + ['sass/modules/{0}/*.scss'.format(module_name)] + depends)
Example #52
0
                          output='lib/angular-resource.min.js')
angular_sanitize = Uglify('lib/angular-sanitize.js',
                          output='lib/angular-sanitize.min.js')

# jQuery
jquery = Uglify('lib/jquery-1.10.2.js', output='lib/jquery-1.10.2.min.js')
jquery_mousewheel = Uglify('lib/jquery.mousewheel.js',
                           output='lib/jquery.mousewheel.min.js')

# jQuery UI
jquery_ui = Bundle(
    Uglify('h:lib/jquery.ui.widget.js', output='lib/jquery.ui.widget.min.js'),
    Uglify('h:lib/jquery.ui.autocomplete.js',
           output='lib/jquery.ui.autocomplete.min.js'),
    Uglify('h:lib/jquery.ui.core.js', output='lib/jquery.ui.core.min.js'),
    Uglify('h:lib/jquery.ui.widget.js', output='lib/jquery.ui.widget.min.js'),
    Uglify('h:lib/jquery.ui.menu.js', output='lib/jquery.ui.menu.min.js'),
    Uglify('h:lib/jquery.ui.position.js',
           output='lib/jquery.ui.position.min.js'),
    CSS('h:lib/jquery-ui-smoothness.css',
        output='lib/jquery-ui-smoothness.min.css'),
)

jquery_ui_effects = Bundle(
    Uglify('h:lib/jquery.ui.effect.js', output='lib/jquery.ui.effect.min.js'),
    Uglify('h:lib/jquery.ui.effect-blind.js',
           output='lib/jquery.ui.effect-blind.min.js'),
    Uglify('h:lib/jquery.ui.effect-highlight.js',
           output='lib/jquery.ui.effect-highlight.min.js'),
    Uglify('h:lib/jquery.ui.effect-forecolor-highlight.js',
           output='lib/jquery.ui.effect-forecolor-highlight.min.js'))
Example #53
0
            if scope["path"].startswith(path):
                scope["path"] = scope["path"][len(path):] or '/'
                return await invoke_asgi(app, scope, receive, send)
        return await invoke_asgi(self.app, scope, receive, send)


app = DispatcherMiddleware(jskom_app, {
    "/httpkom": httpkom_app,
})

assets = Environment(directory=jskom_app.static_folder, url='/static')

js_libs = Bundle('lib/jquery.js',
                 'lib/mimeparse.js',
                 'lib/underscore.js',
                 'lib/mousetrap.js',
                 'lib/modernizr.custom.js',
                 'lib/exif.js',
                 filters='rjsmin',
                 output='gen/packed_libs.js')
assets.register('js_libs', js_libs)

js_angular = Bundle('lib/angular.js',
                    'lib/angular-sanitize.js',
                    filters='rjsmin',
                    output='gen/packed_angular.js')
assets.register('js_angular', js_angular)

js_jskom = Bundle('app/jskom.js',
                  'app/jskom.HttpkomConnection.js',
                  'app/jskom.MembershipList.js',
                  'app/jskom.MembershipListHandler.js',
Example #54
0
def Uglify(*names, **kw):
    kw.setdefault('filters', 'uglifyjs')
    return Bundle(*names, **kw)
Example #55
0
from webassets import Bundle

papaye_css = Bundle(
    'style.css',
    output='gen/css/papaye.css',
    filters='cssmin',
)

external_css = Bundle(
    'includes/bootstrap/css/bootstrap.min.css',
    'includes/font-awesome/css/font-awesome.min.css',
)

papaye_fonts = Bundle('includes/OpenSans/OpenSans-Regular-webfont.woff', )

papaye_js = Bundle(
    'includes/angular/angular.min.js',
    'includes/angular/angular-route.min.js',
    'includes/angular/angular-resource.min.js',
    'includes/jquery/jquery-2.1.1.min.js',
    'includes/bootstrap/js/bootstrap.min.js',
    'includes/noty/packaged/jquery.noty.packaged.min.js',
    'papaye/app.js',
    'papaye/services.js',
    'papaye/controllers.js',
    output='gen/js/papaye.js',
    filters='jsmin',
)
Example #56
0
def Coffee(*names, **kw):
    kw.setdefault('filters', 'coffeescript')
    return Bundle(*names, **kw)
Example #57
0
 def register_js_bundle(self, name, *files):
     """Registers a JS bundle in the plugin's webassets environment"""
     pretty_name = re.sub(r'_js$', '', name)
     bundle = Bundle(*files, filters='rjsmin', output='js/{}_%(version)s.min.js'.format(pretty_name))
     self.assets.register(name, bundle)
Example #58
0
def CSS(*names, **kw):
    kw.setdefault('filters', 'cssrewrite,cssversion,cleancss')
    return Bundle(*names, **kw)
Example #59
0
from webassets import Environment as AssetsEnvironment
from webassets.ext.jinja2 import AssetsExtension

assets_env = AssetsEnvironment("./bnstats/static", "/static")
templates = Jinja2Templates(directory="bnstats/templates")
templates.env.add_extension(AssetsExtension)
templates.env.assets_environment = assets_env  # type: ignore
templates.env.globals["config"] = config

js_bundle = Bundle(
    Bundle(
        "js/vendor/jquery.js",
        "js/vendor/jquery.timeago.js",
        "js/vendor/semantic.js",
        "js/vendor/tablesort.js",
        "js/vendor/chart.js",
    ),
    Bundle(
        "js/global.js",
        "js/filter.js",
        "js/profile.js",
        "js/table.js",
        "js/leaderboard.js",
    ),
    filters="rjsmin",
    output="bundle.%(version)s.js",
)
css_bundle = Bundle("css/*.css", filters="rcssmin", output="bundle.%(version)s.css")
assets_env.register("js_all", js_bundle)
assets_env.register("css_all", css_bundle)
Example #60
0
import pyqrcode
from iris.ui import auth
from beaker.middleware import SessionMiddleware
from datetime import datetime

logger = logging.getLogger(__name__)

_filename_ascii_strip_re = re.compile(r'[^A-Za-z0-9_.-]')

ui_root = os.environ.get('STATIC_ROOT', os.path.abspath(os.path.dirname(__file__)))


assets_env = AssetsEnvironment(os.path.join(ui_root, 'static'), url='/static')

assets_env.register('jquery_libs', Bundle('js/jquery-3.3.1.min.js', 'js/jquery.dataTables.min.js',
                                          'js/handlebars-4.0.12.min.js', 'js/hopscotch.min.js',
                                          'js/marked.min.js',
                                          output='bundles/jquery.libs.js'))
assets_env.register('bootstrap_libs', Bundle('js/bootstrap.min.js', 'js/typeahead.js',
                                             'js/bootstrap-datetimepicker.js', 'js/moment-timezone.js',
                                             'js/moment-tz-data.js',
                                             output='bundles/bootstrap.libs.js'))
assets_env.register('iris_js', Bundle('js/iris.js', filters='rjsmin', output='bundles/iris.js'))
assets_env.register('css_libs', Bundle('css/bootstrap.min.css', 'css/bootstrap-datetimepicker.css',
                                       'css/jquery.dataTables.min.css', 'css/hopscotch.min.css',
                                       filters='cssmin', output='bundles/libs.css'))

assets_env.register('iris_css', Bundle('css/iris.css', filters='cssmin', output='bundles/iris.css'))

jinja2_env = SandboxedEnvironment(extensions=[AssetsExtension], autoescape=True)
jinja2_env.loader = FileSystemLoader(os.path.join(ui_root, 'templates'))
jinja2_env.assets_environment = assets_env