Esempio n. 1
0
def configure_assets(debug: bool, autobuild: bool) -> webassets.Environment:
    js = webassets.Bundle('js/lib/jquery.js',
                          'js/lib/jquery-ui.js',
                          'js/lib/jquery.hotkeys.js',
                          'js/lib/handlebars.js',
                          'js/lib/moment.js',
                          'js/lib/jstorage.js',
                          'js/util.js',
                          'js/message.js',
                          'js/sendria.js',
                          filters='rjsmin',
                          output='assets/bundle.%(version)s.js')
    scss = webassets.Bundle('css/sendria.scss',
                            filters='pyscss',
                            output='assets/sendria.%(version)s.css')
    css = webassets.Bundle('css/reset.css',
                           'css/jquery-ui.css',
                           scss,
                           filters=('cssrewrite', 'cssmin'),
                           output='assets/bundle.%(version)s.css')

    assets = webassets.Environment(directory=STATIC_DIR, url=STATIC_URL)
    assets.debug = debug  # yuck! but the commandline script only supports *disabling* debug
    assets.auto_build = autobuild

    assets.register('js_all', js)
    assets.register('css_all', css)

    return assets
Esempio n. 2
0
def build_assets():
    env = webassets.Environment(load_path=[settings.ASSETS], directory=cssout, url=settings.MEDIA_URL, cache=False, manifest=False)
    for bundle in css_bundles:
        k, v = bundle.popitem()
        reg = webassets.Bundle(*v, filters='less', output=k+'.css')
        env.register(k, reg)
        env[k].urls()
Esempio n. 3
0
 def build_bundle(output, inputs):
     out_dir = os.path.join(kw['output_folder'],
                            os.path.dirname(output))
     inputs = [
         os.path.relpath(i, out_dir) for i in inputs
         if os.path.isfile(i)
     ]
     cache_dir = os.path.join(kw['cache_folder'], 'webassets')
     utils.makedirs(cache_dir)
     env = webassets.Environment(out_dir,
                                 os.path.dirname(output),
                                 cache=cache_dir)
     if inputs:
         bundle = webassets.Bundle(*inputs,
                                   output=os.path.basename(output))
         env.register(output, bundle)
         # This generates the file
         try:
             env[output].build(force=True)
         except Exception as e:
             self.logger.error("Failed to build bundles.")
             self.logger.exception(e)
             self.logger.notice(
                 "Try running ``nikola clean`` and building again.")
     else:
         with open(os.path.join(out_dir, os.path.basename(output)),
                   'wb+'):
             pass  # Create empty file
Esempio n. 4
0
 def partial_asset_build(self, path, timemsg=''):
     """Check if `path` refers to a changed css or js and only build that asset if possible, for improved performance."""
     if 'less' in path:
         bundle = self.is_css_bundle(path)
         if bundle:
             env = webassets.Environment(load_path=[settings.ASSETS],
                 directory=self.cssout, url=settings.MEDIA_URL, cache=False, manifest=False)
             css_files = self.css_bundles[bundle]
             reg = webassets.Bundle(*css_files, filters='less', output=bundle + '.css')
             env.register(bundle, reg)
             env[bundle].urls()
             print("{0}: CSS bundle rebuilt: {1}.".format(timemsg, bundle))
         else:
             print("{0}: All Assets rebuilt.".format(timemsg))
             self.build_assets()
     elif 'js' in path:
         if self.js_bundles:
             self._concat_js()
             print("{0}: JS bundles rebuilt.".format(timemsg))
         else:
             print("{0}: All Assets rebuilt.".format(timemsg))
             self.build_assets()
     # If we can't figure out what to build partially, give up and do a full build.
     else:
         print("{0}: All Assets rebuilt.".format(timemsg))
         self.build_assets()
Esempio n. 5
0
def generate_index(config: Config, songs: List[Dict]) -> str:
    static_dir = os.path.join(HERE, "static")
    output_dir = os.path.join(config.out_dir, "static")
    assets_env = webassets.Environment(directory=output_dir, url="./static", load_path=[static_dir])
    all_js = webassets.Bundle("bundle.js", output="bundle.js")
    all_css = webassets.Bundle("main.css", output="bundle.css")
    assets_env.register("all_js", all_js)
    assets_env.register("all_css", all_css)

    loader = jinja2.FileSystemLoader(searchpath=HERE)
    env = jinja2.Environment(loader=loader, extensions=[AssetsExtension])
    env.assets_environment = assets_env  # type: ignore

    template = env.get_template(TEMPLATE_FILE)
    output = template.render(
        config=config,
        songs=songs,
        title=config.title,
        base_url=config.base_url,
        description=config.description,
        feed_url=urljoin(config.base_url, "index.xml") if config.generate_feed else None,
    )
    with open(os.path.join(config.out_dir, "index.html"), "w") as f:
        f.write(output)
    return f.name
Esempio n. 6
0
def environment(**options):
    assets_env = webassets.Environment('./static', '/static')
    env = jinja2.Environment(
        extensions=[webassets.ext.jinja2.AssetsExtension], **options)
    env.globals.update({
        'static': staticfiles_storage.url,
        'url': reverse,
    })
    env.assets_environment = assets_env
    return env
Esempio n. 7
0
 def build_assets(self):
     """Build assets, that is, bundle and compile the LESS and JS files in `settings.ASSETS`."""
     shutil.rmtree(self.renderpath + '/media', ignore_errors=True)
     shutil.copytree(self.staticpath, self.renderpath + '/media')
     env = webassets.Environment(load_path=[settings.ASSETS], directory=self.cssout, url=settings.MEDIA_URL, cache=False, manifest=False)
     for k, v in self.css_bundles.items():
         reg = webassets.Bundle(*v, filters='less', output=k + '.css')
         env.register(k, reg)
         env[k].urls()
     if self.js_bundles:
         self._concat_js()
     self._write_favicon_htaccess()
Esempio n. 8
0
def build_assets():
    env = webassets.Environment(load_path=[settings.ASSETS],
                                directory=cssout,
                                url=settings.MEDIA_URL,
                                cache=False,
                                manifest=False)
    start_css = webassets.Bundle('less/sandstone/fonts.less',
                                 'less/thunderbird/start.less',
                                 filters='less',
                                 output='start-style.css')
    env.register('start-style', start_css)
    env['start-style'].urls()
Esempio n. 9
0
    def webassets_init(self):
        self.assets_env = webassets.Environment(
            join(config.src_home, 'libsrc'), '/lib')
        self.assets_env.updater = 'always'
        self.assets_env.url_expire = True

        if config.debug_mode:
            self.assets_env.debug = True
            self.assets_env.url = '/lib/libsrc'
            self.default_local = True
            self.auto_build = True
        else:
            self.assets_env.debug = False
Esempio n. 10
0
def configure_assets(debug=False, static_dir=None):
    """Configure WebAssets."""
    assets = webassets.Environment(static_dir, '/')
    assets.auto_build = debug
    assets.debug = debug

    # Load bundle from yaml file.
    assets_loader = webassets.loaders.YAMLLoader(
        pkg_resources.resource_stream(__name__, 'assets.yaml'))
    bundles = assets_loader.load_bundles()
    for name, bundle in bundles.items():
        assets.register(name, bundle)

    return assets
Esempio n. 11
0
 def build_bundle(output, inputs):
     out_dir = os.path.join(kw['output_folder'],
                            os.path.dirname(output))
     inputs = [i for i in inputs if os.path.isfile(
         os.path.join(out_dir, i))]
     cache_dir = os.path.join(kw['cache_folder'], 'webassets')
     if not os.path.isdir(cache_dir):
         os.makedirs(cache_dir)
     env = webassets.Environment(out_dir, os.path.dirname(output),
                                 cache=cache_dir)
     bundle = webassets.Bundle(*inputs, output=os.path.basename(output))
     env.register(output, bundle)
     # This generates the file
     env[output].urls()
Esempio n. 12
0
 def build_bundle(output, inputs):
     out_dir = os.path.join(kw['output_folder'],
                            os.path.dirname(output))
     inputs = [
         i for i in inputs if os.path.isfile(os.path.join(out_dir, i))
     ]
     cache_dir = os.path.join(kw['cache_folder'], 'webassets')
     utils.makedirs(cache_dir)
     env = webassets.Environment(out_dir,
                                 os.path.dirname(output),
                                 cache=cache_dir)
     if inputs:
         bundle = webassets.Bundle(*inputs,
                                   output=os.path.basename(output))
         env.register(output, bundle)
         # This generates the file
         env[output].urls()
     else:
         with open(os.path.join(out_dir, os.path.basename(output)),
                   'wb+'):
             pass  # Create empty file
Esempio n. 13
0
  cd /
  webpack --watch --watch-poll
"""

from . import settings

# Initialize webassets to handle the asset pipeline
import imp
import os
import webassets
import webassets.updater
import yaml

from webassets.filter.jst import JSTemplateFilter

environment = webassets.Environment()
manifest = os.path.join(settings.BASE_DIR, 'ggrc', 'assets', 'assets.manifest')
environment.manifest = 'file:' + manifest
environment.versions = 'hash:32'

# `asset-debug` mode doesn't merge bundles into a single file
environment.debug = settings.DEBUG_ASSETS

# `settings-debug` mode doesn't finger-print files (no cache-busting)
if settings.DEBUG:
    environment.url_expire = False

environment.updater = webassets.updater.TimestampUpdater()

# Read asset listing from YAML file
Esempio n. 14
0
def get_env():
    """Return the SuttaCentral webassets environment."""

    env = webassets.Environment(str(sc.static_dir), '/')
    env.auto_build = not config.compile_assets
    env.cache = str(sc.webassets_cache_dir)
    env.debug = not config.compile_assets
    env.manifest = 'json:{}'.format(sc.webassets_manifest_path)

    compile_fonts()

    css_normalize = webassets.Bundle('css/vendor/normalize-2.1.3.css')

    css_utf8 = webassets.Bundle('css/utf8.css')

    css_main = webassets.Bundle('css/main.scss',
                                depends=('css/*.scss', 'css/*/*.scss'),
                                filters='pyscss',
                                output='css/compiled/main-%(version)s.css')

    css_core = webassets.Bundle(css_normalize,
                                css_main,
                                css_utf8,
                                filters='cssmin',
                                output='css/compiled/core-%(version)s.css')

    env.register('css_core', css_core)

    sc_uid_expansion_data_file = build_sc_uid_expansion(env)

    sc_data_scripts_file = get_js_datascripts_filename()

    js_core = webassets.Bundle('js/vendor/underscore-1.8.3.js',
                               'js/sc_state.js',
                               'js/vendor/clipboard.js',
                               'js/vendor/jquery.hashchange-1.3.min.js',
                               'js/vendor/jquery.easytabs-3.2.0.min.js',
                               'js/vendor/jquery.dropdown.js',
                               'js/vendor/polyglot.js',
                               'js/vendor/jquery.mobile.custom.min.js',
                               'js/lib/jquery.scrolllock.js',
                               'js/lib/jquery.unveil.js',
                               'js/lib/jquery.details.js',
                               'js/exports.js',
                               'js/intr.js',
                               'js/sc_utility.js',
                               sc_uid_expansion_data_file,
                               'js/text.js',
                               'js/text_selections.js',
                               'js/search.js',
                               'js/sidebar.js',
                               'js/sc_functions.js',
                               'js/sc_init.js',
                               'js/header_menu.js',
                               'js/sc_formatter.js',
                               'js/sc_popupnotes.js',
                               'js/sc_lzh2en_lookup.js',
                               'js/text_image.js',
                               'js/discourse.js',
                               'js/fonts.js',
                               sc_data_scripts_file,
                               'js/tracking.js',
                               filters=None if sc.config.debug else 'rjsmin',
                               output='js/compiled/core-%(version)s.js')
    env.register('js_core', js_core)

    # For some reason, webassets does not create these directories if
    # they do not exist...
    if not sc.webassets_cache_dir.exists():
        sc.webassets_cache_dir.mkdir(parents=True)

    return env
Esempio n. 15
0
def _create_env(source_dir, output_dir, **kwargs):
    # some pieces of webassets assume the directories are absolute
    source_dir = os.path.abspath(source_dir)
    output_dir = os.path.abspath(output_dir)
    env = webassets.Environment(directory=output_dir,
                                url='/assets/generated',
                                manifest='cache',
                                **kwargs)
    env.append_path(source_dir, url='/assets')
    env.config['UGLIFYJS_EXTRA_ARGS'] = ['--mangle', '--compress']
    env.register('css',
                 'style.less',
                 filters=['less', 'cssrewrite',
                          YCSSMin()],
                 output='beaker-%(version)s.css',
                 depends=[
                     '*.less', 'bootstrap/less/*.less',
                     'font-awesome/less/*.less',
                     'bootstrap-datepicker/less/*.less',
                     'bootstrap-select/less/*.less'
                 ])
    env.register(
        'js',
        # third-party
        'bootstrap/js/bootstrap-transition.js',
        'bootstrap/js/bootstrap-modal.js',
        'bootstrap/js/bootstrap-dropdown.js',
        'bootstrap/js/bootstrap-tab.js',
        'bootstrap/js/bootstrap-alert.js',
        'bootstrap/js/bootstrap-button.js',
        'bootstrap/js/bootstrap-collapse.js',
        'bootstrap/js/bootstrap-affix.js',
        'bootstrap/js/bootstrap-tooltip.js',
        'bootstrap/js/bootstrap-popover.js',
        'typeahead.js/dist/typeahead.js',
        'bootstrap-datepicker/js/bootstrap-datepicker.js',
        'bootstrap-select/js/bootstrap-select.js',
        'bootstrap-growl/jquery.bootstrap-growl.js',
        'bootbox/bootbox.js',
        'moment/moment.js',
        'moment-duration-format/lib/moment-duration-format.js',
        'URI.js/src/URI.js',
        'underscore/underscore.js',
        'backbone/backbone.js',
        'backbone-pageable/lib/backbone-pageable.js',
        'backgrid/lib/backgrid.js',
        'marked/lib/marked.js',
        # ours
        webassets.Bundle('jst/*/*.html',
                         'jst/*.html',
                         filters=[JST(template_function='_.template')],
                         output='beaker-jst-%(version)s.js'),
        'local-datetime.js',
        'link-tabs-to-anchor.js',
        'xhr-error.js',
        'beaker-backgrid.js',
        'beaker-typeaheads.js',
        'beaker-bootbox.js',
        'beaker-popover.js',
        'bootstrap-select-defaults.js',
        'activity-model.js',
        'activity.js',
        'distro-model.js',
        'distro-picker.js',
        'identity-model.js',
        'lab-model.js',
        'pool-create.js',
        'pools.js',
        'query-builder.js',
        'reserve-workflow.js',
        'installation-model.js',
        'scheduler-model.js',
        'access-policy.js',
        'access-policy-model.js',
        'system-activity.js',
        'system-add.js',
        'system-access-policy.js',
        'system-commands.js',
        'system-executed-tasks.js',
        'system-hardware.js',
        'system-loan.js',
        'system-model.js',
        'system-owner.js',
        'system-pool.js',
        'system-power-settings.js',
        'system-provision.js',
        'system-quick-info.js',
        'system-rename.js',
        'system-report-problem.js',
        'system-scheduler-settings.js',
        'system-pool-access-policy.js',
        'system-pool-info.js',
        'system-pool-systems.js',
        'power-types-model.js',
        'power-types.js',
        'group-details.js',
        'group-members.js',
        'group-owners.js',
        'group-permissions.js',
        'group-rootpassword.js',
        'group-create.js',
        'groups.js',
        'labcontrollers.js',
        'comments-link.js',
        'ctrl-enter-form-submit.js',
        'job-header.js',
        'job-info.js',
        'job-recipes.js',
        'recipe-progress.js',
        'users.js',
        'prefs.js',
        'logs-link.js',
        'recipe-page.js',
        'recipe-header.js',
        'recipe-info.js',
        'recipe-installation.js',
        'recipe-tasks.js',
        'recipe-tasks-old.js',
        'recipe-reservation.js',
        'reservation-duration-selection.js',
        filters=['uglifyjs'],
        output='beaker-%(version)s.js')
    return env
Esempio n. 16
0
import glob
import os

import webassets
import webassets.filter

ASSETS_DIRECTORY = 'oh_queue/static'

assets_env = webassets.Environment(
    directory=ASSETS_DIRECTORY,
    url='/static',
)
assets_env.config['BABEL_BIN'] = 'node_modules/babel-cli/bin/babel.js'

babel = webassets.filter.get_filter('babel', presets='es2015,react')

assets_env.register(
    'style.css',
    'css/style.css',
    output='public/style.css',
)


def glob_assets(pattern):
    cwd = os.getcwd()
    try:
        os.chdir(ASSETS_DIRECTORY)
        return glob.glob(pattern, recursive=True)
    finally:
        os.chdir(cwd)