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
def build(): _check_dir() print('Building...') sys.path.append('sorriso') from kajikifilter import Kajiki from babelfilter import BabelJS import webassets.filter webassets.filter.register_filter(BabelJS) assets_yml_path = os.path.join('sorriso', 'assets.yml') webassets_env = webassets.loaders.YAMLLoader( assets_yml_path).load_environment() for f in glob.glob('sorriso/templates/*.xhtml'): __, fname = os.path.split(f) if fname.startswith('_'): continue output_file = os.path.join(outputdir, fname.replace('xhtml', 'html')) webassets_env.add( webassets.Bundle( f, filters=Kajiki(templates_path='sorriso/templates', context={'page': os.path.splitext(fname)[0]}), output=output_file, depends=[webassets.Bundle('sorriso/templates/_layout.xhtml')])) for bundle in webassets_env: bundle.build() shutil.rmtree(outputdir + '/img', ignore_errors=True) shutil.copytree('sorriso/img', outputdir + '/img') shutil.rmtree(outputdir + '/fonts', ignore_errors=True) shutil.copytree('sorriso/fonts', outputdir + '/fonts') print('Done!')
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ config = Configurator(settings=settings) config.include('nurl.pyramid_nurl') # renderers config.add_renderer('jsonp', JSONP(param_name='callback')) # URL patterns config.add_static_view(path='nurl.webapp:static', name='static', cache_max_age=3600) config.add_route('home', '/') config.add_route('shortened', '/{short_ref}') # restful endpoints config.add_route('shortener_v1', '/api/v1/shorten') css = webassets.Bundle('bootstrap.min.css', webassets.Bundle('styles.css', filters='yui_css'), output='bundle.min.css') config.add_webasset('css', css) config.registry.settings['webassets_env'] = config.get_webassets_env() config.add_subscriber(add_webassets_env, NewRequest) config.scan() return config.make_wsgi_app()
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
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ set_cache_regions_from_settings(settings) config = Configurator(settings=settings) css = webassets.Bundle('bootstrap.min.css', webassets.Bundle('styles.css', filters='yui_css'), output='bundle.min.css') config.add_webasset('css', css) config.registry.settings['webassets_env'] = config.get_webassets_env() config.add_subscriber(add_webassets_env, NewRequest) db_uri = settings['mongodb.db_uri'] conn = pymongo.Connection(db_uri) config.registry.settings['db_conn'] = conn try: if asbool(settings.get('nurl.check_whitelist', False)): with open(os.path.join(APP_PATH, '..', 'whitelist.txt')) as whitelist: config.registry.settings['nurl.whitelist'] = get_whitelist( whitelist, asbool(settings.get('nurl.check_whitelist_auto_www', False))) except IOError: config.registry.settings['nurl.check_whitelist'] = False config.add_subscriber(add_mongo_db, NewRequest) config.add_renderer('jsonp', JSONP(param_name='callback')) config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.add_route('shortened', '/{short_ref}') #rest api version 1 config.add_route('shortener_v1', '/api/v1/shorten') config.scan() application = config.make_wsgi_app() #newrelic agent try: if asbool(settings.get('newrelic.enable', False)): newrelic.agent.initialize( os.path.join(APP_PATH, '..', 'newrelic.ini'), settings['newrelic.environment']) return newrelic.agent.wsgi_application()(application) else: return application except IOError: config.registry.settings['newrelic.enable'] = False return application
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()
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
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()
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()
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()
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()
def build_header_css(self): self.webassets_init() scss_filter = webassets.filter.get_filter( 'scss', use_compass=True, debug_info=config.debug_mode, libs=[join(config.src_home, 'libsrc/scss/asset_url.rb')]) self.assets_env.register('external_header', webassets.Bundle( 'scss/main_header_standalone.scss', filters=scss_filter, output='compiled.external_header.css', debug=False), output='../lib/external_header.css') print self.assets_env['external_header'].urls()
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
for name, hunk in self.iter_templates_with_base(hunks): name = path_without_assets_base(name) contents = hunk.data().replace('\n', '\\n').replace("'", r"\'") out.write("{namespace}['{name}']".format(namespace=namespace, name=name)) out.write("= '{template}';\n".format(template=contents)) version_suffix = '-%(version)s' if settings.DEBUG: version_suffix = '' environment.register( "dashboard-js", webassets.Bundle( *asset_paths['dashboard-js-files'], # filters='jsmin', output='dashboard' + version_suffix + '.js')) environment.register( "app-init-js", webassets.Bundle( *asset_paths['app-init-files'], # filters='jsmin', output='app-init' + version_suffix + '.js')) environment.register( "dashboard-js-templates", webassets.Bundle( *asset_paths['dashboard-js-template-files'], filters=MustacheFilter, output='dashboard-templates' + version_suffix + '.js',
def webassets_bundle(self): print('Bundling webassets...') opts = {} self.final_bundles = [] # Note: IMPORTANT any time a file that is imported into other scss # files is changed (i.e. common.scss is imported into almost every # file), the webassets cache must be cleared # TODO: fix for source maps. # Sadly, the latest versions of sass do not work with compass # (Contrary to what compass says on their website) # sudo gem install sass # sudo gem install compass # sudo apt-get install ruby-full scss_filter = webassets.filter.get_filter( 'scss', use_compass=True, debug_info=config.debug_mode, libs=[join(config.src_home, 'libsrc/scss/asset_url.rb')]) css_filter = None if config.debug_mode else 'yui_css' app_scss = webassets.Bundle('scss/base.scss', "scss/fonts.scss", "scss/dialogs.scss", "scss/community.scss", "scss/expr.scss", "scss/settings.scss", "scss/signup_flow.scss", "scss/menu.scss", "scss/jplayer.scss", "scss/forms.scss", "scss/overlay.scss", "scss/skin.scss", 'scss/edit.scss', 'scss/codemirror.css', filters=scss_filter, output='compiled.app.css', debug=False) self.assets_env.register('app.css', app_scss, filters=css_filter, output='../lib/app.css') self.final_bundles.append('app.css') # edit_scss = webassets.Bundle( # 'scss/edit.scss', # 'scss/codemirror.css', # 'scss/overlay', # filters=scss_filter, # output='compiled.edit.css', # debug=False # ) # self.assets_env.register( # 'edit.css', # edit_scss, # filters=css_filter, # output='../lib/edit.css' # ) # self.final_bundles.append('edit.css') self.assets_env.register('curl.js', 'curl.js', filters='yui_js', output='../lib/curl.js') # build cram bundles if not config.debug_mode: # can't figure out how to make cram work from another dir old_dir = os.getcwd() os.chdir(join(config.src_home, 'libsrc')) self.system('./cram.sh') os.chdir(old_dir) self.assets_env.register('site.js', 'compiled.site.js', filters='yui_js', output='../lib/site.js') self.final_bundles.append('site.js') self.assets_env.register('expr.js', 'compiled.expr.js', filters='yui_js', output='../lib/expr.js') self.final_bundles.append('expr.js') self.assets_env.register('edit.js', 'compiled.edit.js', filters='yui_js', output='../lib/edit.js') self.final_bundles.append('edit.js') # CSS for expressions, and also site pages minimal_scss = webassets.Bundle('scss/minimal.scss', 'scss/jplayer.scss', 'scss/audio_player.scss', 'scss/fonts.scss', filters=scss_filter, output='compiled.minimal.css', debug=False) self.assets_env.register('minimal.css', minimal_scss, filters=css_filter, output='../lib/minimal.css') self.final_bundles.append('minimal.css') email_scss = webassets.Bundle('scss/email.scss', filters=scss_filter, output='compiled.email.css', debug=False) self.assets_env.register('email.css', email_scss, output='../lib/email.css') self.final_bundles.append('email.css') self.assets_env.register('external_header', webassets.Bundle( 'scss/main_header_standalone.scss', filters=scss_filter, output='compiled.external_header.css', debug=False), filters=css_filter, output='../lib/external_header.css') self.final_bundles.append('external_header')
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
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
name = 'mustache' options = {'namespace': 'GGRC.Templates'} def process_templates(self, out, hunks, **kwargs): namespace = self.namespace or 'GGRC.Templates' out.write("{namespace} = {namespace} || {{}};\n".format( '{}', namespace=namespace)) for name, hunk in self.iter_templates_with_base(hunks): name = path_without_assets_base(name) contents = hunk.data().replace('\n', '\\n').replace("'", r"\'") out.write("{namespace}['{name}']".format(namespace=namespace, name=name)) out.write("= '{template}';\n".format(template=contents)) version_suffix = '-%(version)s' if settings.DEBUG: version_suffix = '' environment.register( "dashboard-js-templates", webassets.Bundle( *asset_paths['dashboard-js-template-files'], filters=MustacheFilter, output='dashboard-templates' + version_suffix + '.js', # Always keep `debug` False here, since raw mustache is not valid JS debug=False))
environment.directory = os.path.join(settings.MODULE_DIR, 'static') environment.load_path = [ 'assets/javascripts', 'assets/vendor/javascripts', 'assets/vendor/bootstrap-sass/vendor/assets/javascripts', 'assets/vendor/remoteipart/vendor/assets/javascripts', 'assets/stylesheets', 'assets/vendor/stylesheets', 'assets/js_specs', ] environment.register( "dashboard-js", webassets.Bundle( *asset_paths['dashboard-js-files'], #filters='jsmin', output='dashboard-%(version)s.js')) environment.register( "dashboard-css", webassets.Bundle(*asset_paths['dashboard-css-files'], output='dashboard-%(version)s.css')) if settings.ENABLE_JASMINE: environment.register( "dashboard-js-specs", webassets.Bundle(*asset_paths['dashboard-js-spec-files'], output='dashboard-%(version)s-specs.js')) environment.register( "dashboard-js-spec-helpers",