def webassets_init(): global env static_path = get_webassets_path() public = config.get(u'ckan.base_public_folder') public_folder = os.path.abspath(os.path.join( os.path.dirname(__file__), u'..', public)) base_path = os.path.join(public_folder, u'base') env = Environment() env.directory = static_path env.debug = config.get(u'debug', False) env.url = u'/webassets/' env.append_path(base_path, u'/base/') logger.debug(u'Base path {0}'.format(base_path)) create_library(u'vendor', os.path.join( base_path, u'vendor')) create_library(u'base', os.path.join(base_path, u'javascript')) create_library(u'datapreview', os.path.join(base_path, u'datapreview')) create_library(u'css', os.path.join(base_path, u'css'))
def _init_webassets(debug=False): assets_env = Environment(directory=SITE_ASSET_DIR, url=SITE_ASSET_URL_PREFIX, cache=WEBASSETS_CACHE_DIR, load_path=[SITE_ASSET_SRC_DIR]) assets_env.debug = debug js = Bundle('js/*.js', filters='uglifyjs', output='js/app.js') css = Bundle('sass/*.scss', filters='scss,cssmin', output='css/app.css') assets_env.register('app_js', js) assets_env.register('app_css', css) cmd = CommandLineEnvironment(assets_env, log) p = Process(target=lambda: cmd.watch()) def signal_handler(sig, frame): try: p.terminate() except Exception: pass sys.exit(0) signal.signal(signal.SIGINT, signal_handler) p.start() return assets_env
def _setup_env(app='', debug=True, cache=True): """Setup the webassets environment.""" if app: app_path = path.join('..', '..', app, 'static') env = Environment( path.join(INPUT_FILES, '..', '..', 'skel', 'assets'), path.join(BASE_LOCATION, '..')) else: app_path = path.join('..', 'static') env = Environment( path.join(INPUT_FILES, '..', '..', 'skel', 'assets'), path.join(BASE_LOCATION)) # We use underscore's templates by default. env.config['JST_COMPILER'] = '_.template' if debug: env.config['CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'WHITESPACE_ONLY' env.manifest = False else: env.config['CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'ADVANCED_OPTIMIZATIONS' env.debug = False env.cache = cache #javascript _bundle_app_coffee(app_path, env, debug) _bundle_3rd_party_js(app_path, env, debug) #css _bundle_3rd_party_css(app_path, env, debug) #images _bundle_images(app, env, is_skel=True) return env
def _setup_env(debug=True, cache=True): """Setup the webassets environment.""" env = Environment(INPUT_FILES, OUTPUT_FILES) # We use underscore's templates by default. env.config['JST_COMPILER'] = '_.template' if debug: env.config['CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'WHITESPACE_ONLY' env.manifest = False else: env.config['CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'ADVANCED_OPTIMIZATIONS' env.debug = False env.cache = cache #javascript _bundle_app_jsts(env, debug) _bundle_app_coffee(env, debug) _bundle_3rd_party_js(env, debug) #css _bundle_app_less(env, debug) _bundle_3rd_party_css(env, debug) #images _bundle_images(env) return env
def webassets_init(): global env static_path = get_webassets_path() public = config.get(u'ckan.base_public_folder') public_folder = os.path.abspath( os.path.join(os.path.dirname(__file__), u'..', public)) base_path = os.path.join(public_folder, u'base') env = Environment() env.directory = static_path env.debug = asbool(config.get(u'debug', False)) env.url = u'/webassets/' add_public_path(base_path, u'/base/') logger.debug(u'Base path {0}'.format(base_path)) create_library(u'vendor', os.path.join(base_path, u'vendor')) create_library(u'base', os.path.join(base_path, u'javascript')) create_library(u'datapreview', os.path.join(base_path, u'datapreview')) create_library(u'css', os.path.join(base_path, u'css'))
def _setup_env(debug=True, cache=True): """Setup the webassets environment.""" env = Environment(INPUT_FILES, OUTPUT_FILES) # We use underscore's templates by default. env.config['JST_COMPILER'] = '_.template' if debug: env.config['CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'WHITESPACE_ONLY' env.manifest = False else: env.config[ 'CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'ADVANCED_OPTIMIZATIONS' env.debug = False env.cache = cache #javascript _bundle_app_jsts(env, debug) _bundle_app_coffee(env, debug) _bundle_3rd_party_js(env, debug) #css _bundle_app_less(env, debug) _bundle_3rd_party_css(env, debug) #images _bundle_images(env) return env
def _setup_env(app='', debug=True, cache=True): """Setup the webassets environment.""" if app: app_path = path.join('..', '..', app, 'static') env = Environment(path.join(INPUT_FILES, '..', '..', 'skel', 'assets'), path.join(BASE_LOCATION, '..')) else: app_path = path.join('..', 'static') env = Environment(path.join(INPUT_FILES, '..', '..', 'skel', 'assets'), path.join(BASE_LOCATION)) # We use underscore's templates by default. env.config['JST_COMPILER'] = '_.template' if debug: env.config['CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'WHITESPACE_ONLY' env.manifest = False else: env.config[ 'CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'ADVANCED_OPTIMIZATIONS' env.debug = False env.cache = cache #javascript _bundle_skel(app_path, env, debug) #css _bundle_3rd_party_css(app_path, env, debug) #images _bundle_images(app, env, is_skel=True) return env
def includeme(config): """pyramid include. declare the add_thumb_view""" here = os.path.dirname(__file__) settings = config.registry.settings config_dir = settings.get('garasu_webassets.config', '{}/configs'.format(here)) LOG.debug(config_dir) # config_dir = AssetResolver(None).resolve(config_dir).abspath() asset_dir = settings.get('garasu_webassets.assets', '{}/assets'.format(here)) LOG.debug(asset_dir) # asset_dir = AssetResolver(None).resolve(asset_dir).abspath() env = Environment(directory=asset_dir, url=settings['garasu_webassets.url']) env.manifest = settings['garasu_webassets.manifest'] env.debug = asbool(settings['garasu_webassets.debug']) env.cache = asbool(settings['garasu_webassets.cache']) env.auto_build = asbool(settings['garasu_webassets.auto_build']) def text(value): if type(value) is six.binary_type: return value.decode('utf-8') else: return value def yaml_stream(fname, mode): if path.exists(fname): return open(fname, mode) raise FileNotFoundError fin = fileinput.input('/'.join([config_dir, settings['garasu_webassets.bundles']]), openhook=yaml_stream) with closing(fin): lines = [text(line).rstrip() for line in fin] stream_yaml = six.StringIO('\n'.join(lines)) loader = YAMLLoader(stream_yaml) result = loader.load_bundles() env.register(result) # for item in env: # LOG.debug(item.output) # path_file = '/'.join([public_dir, item.output]) # src_file = '/'.join([asset_dir, item.output]) # shutil.copy(src_file, path_file) def _get_assets(request, *args, **kwargs): bundle = Bundle(*args, **kwargs) with bundle.bind(env): urls = bundle.urls() return urls config.add_request_method(_get_assets, 'web_assets') def _get_assets_env(request): return env config.add_request_method(_get_assets_env, 'web_env', reify=True)
def gen_static(): # Setup a logger log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) assets_env = Environment() assets_env.directory = "static/" assets_env.debug = True assets_env.register(bundles) cmdenv = CommandLineEnvironment(assets_env, log) # This would also work cmdenv.build()
def register_assets(settings): """ Initialize webassets environment and its bundles. Arguments: settings (conf.model.SettingsModel): Settings registry instance. Returns: webassets.Environment: New configured Webasset environment. """ logger = logging.getLogger('optimus') if not settings.ENABLED_BUNDLES: logger.warning(("Asset registering skipped as there are no enabled " "bundle")) return None logger.info("Starting asset registering") # Assets bundles AVAILABLE_BUNDLES = getattr(settings, 'BUNDLES', {}) # Initialize webassets environment assets_env = AssetsEnvironment() assets_env.debug = settings.DEBUG assets_env.url = settings.STATIC_URL assets_env.directory = settings.STATIC_DIR assets_env.load_path = [settings.SOURCES_DIR] assets_env.cache = settings.WEBASSETS_CACHE assets_env.url_expire = settings.WEBASSETS_URLEXPIRE # assets_env.optimus_registry = AssetRegistry() # Register enabled assets bundles for bundle_name in settings.ENABLED_BUNDLES: logger.debug("Registering bundle: {}".format(bundle_name)) assets_env.register(bundle_name, AVAILABLE_BUNDLES[bundle_name]) assets_env.optimus_registry.add_bundle(bundle_name, AVAILABLE_BUNDLES[bundle_name]) # When after bundle has been registered we can resolve it for bundle_name in settings.ENABLED_BUNDLES: logger.info(" Processing: {}".format( assets_env[bundle_name].resolve_output() )) # Avoid to loop on every bundle part if we are not in debug logger if logger.getEffectiveLevel() == logging.DEBUG: for url in assets_env[bundle_name].urls(): logger.debug(" - {}".format(url)) return assets_env
def register_assets(): """ Initialize webassets environment and its bundles NOTE: The asset bundles building is lazy, webassets only do building when he is invoked by his template tag **assets** and if it detect that a file in a bundle has changed. """ logger = logging.getLogger('optimus') if not settings.ENABLED_BUNDLES: logger.warning( "Asset registering skipped as there are no enabled bundles") return None logger.info("Starting asset registering") # Assets bundles AVAILABLE_BUNDLES = getattr(settings, 'BUNDLES', {}) # Initialize webassets environment assets_env = AssetsEnvironment() assets_env.debug = settings.DEBUG assets_env.url = settings.STATIC_URL assets_env.directory = settings.STATIC_DIR assets_env.load_path = [settings.SOURCES_DIR] assets_env.cache = settings.WEBASSETS_CACHE # assets_env.optimus_registry = AssetRegistry() # Register enabled assets bundles for bundle_name in settings.ENABLED_BUNDLES: logger.debug("Registering bundle: %s", bundle_name) # Little trick because Bundle does not know their used name in the webassets # environment AVAILABLE_BUNDLES[bundle_name]._internal_env_name = bundle_name assets_env.register(bundle_name, AVAILABLE_BUNDLES[bundle_name]) assets_env.optimus_registry.add_bundle(AVAILABLE_BUNDLES[bundle_name]) # for debugging purpopse for bundle_name in settings.ENABLED_BUNDLES: logger.info(" Processing: %s", assets_env[bundle_name].resolve_output()) # TODO: conditionnal on the log level to avoid to loop on multiple items if not # in a debug log level for url in assets_env[bundle_name].urls(): logger.debug(" - %s", url) return assets_env
def scss_compile(static_path): webassets = Environment() webassets.directory = static_path webassets.url = static_path webassets.register('css_all', css_all) #webassets.manifest = 'cache' if not app.debug else False webassets.manifest = False webassets.cache = False webassets.debug = False log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(webassets, log) # This would also work cmdenv.build()
def register_assets(): """ Initialize webassets environment and its bundles NOTE: The asset bundles building is lazy, webassets only do building when he is invoked by his template tag **assets** and if it detect that a file in a bundle has changed. """ logger = logging.getLogger('optimus') if not settings.ENABLED_BUNDLES: logger.warning("Asset registering skipped as there are no enabled bundles") return None logger.info("Starting asset registering") # Assets bundles AVAILABLE_BUNDLES = copy.deepcopy(COMMON_BUNDLES) AVAILABLE_BUNDLES.update(getattr(settings, 'EXTRA_BUNDLES', {})) # Initialize webassets environment assets_env = AssetsEnvironment() assets_env.debug = settings.DEBUG assets_env.url = settings.STATIC_URL assets_env.directory = settings.STATIC_DIR assets_env.load_path = [settings.SOURCES_DIR] assets_env.cache = settings.WEBASSETS_CACHE # assets_env.optimus_registry = AssetRegistry() # Register enabled assets bundles for bundle_name in settings.ENABLED_BUNDLES: logger.debug("Registering bundle: %s", bundle_name) # Little trick because Bundle does not know their used name in the webassets # environment AVAILABLE_BUNDLES[bundle_name]._internal_env_name = bundle_name assets_env.register(bundle_name, AVAILABLE_BUNDLES[bundle_name]) assets_env.optimus_registry.add_bundle(AVAILABLE_BUNDLES[bundle_name]) # for debugging purpopse for bundle_name in settings.ENABLED_BUNDLES: logger.info(" Processing: %s", assets_env[bundle_name].resolve_output()) # TODO: conditionnal on the log level to avoid to loop on multiple items if not # in a debug log level for url in assets_env[bundle_name].urls(): logger.debug(" - %s", url) return assets_env
def get_webassets_env(conf): '''Get a preconfigured WebAssets environment''' # Configure webassets assets_environment = AssetsEnvironment(conf.get('static_files_dir', DEFAULT_STATIC), '/') assets_environment.debug = conf.get('debug', False) assets_environment.auto_build = conf.get('debug', False) assets_environment.config['less_paths'] = ( 'bower/bootstrap/less', 'bower/etalab-assets/less', 'bower/bootstrap-markdown/less', ) # Load bundle from yaml file loader = YAMLLoader(resource_stream(__name__, '../assets.yaml')) bundles = loader.load_bundles() for name, bundle in bundles.items(): assets_environment.register(name, bundle) return assets_environment
def _init_webassets(debug=False, generate=False): assets_env = Environment(directory=SITE_ASSET_DIR, url=SITE_ASSET_URL_PREFIX, cache=WEBASSETS_CACHE_DIR, load_path=[SITE_ASSET_SRC_DIR]) assets_env.debug = debug js = Bundle('js/*.js', filters='uglifyjs', output='js/app.js') css = Bundle('sass/*.scss', filters='scss,cssmin', output='css/app.css') assets_env.register('app_js', js) assets_env.register('app_css', css) cmd = CommandLineEnvironment(assets_env, log) if generate: cmd.build() return assets_env Process(target=lambda: cmd.watch()).start() return assets_env
def _init_webassets(debug=False, generate=False): assets_env = Environment(directory=SITE_ASSET_DIR, url=SITE_ASSET_URL_PREFIX, cache=WEBASSETS_CACHE_DIR, load_path=[SITE_ASSET_SRC_DIR]) assets_env.debug = debug js = Bundle('js/*.js', filters='uglifyjs', output='js/app.js') css = Bundle('sass/*.scss', filters='scss,cssmin', output='css/app.css') assets_env.register('app_js', js) assets_env.register('app_css', css) cmd = CommandLineEnvironment(assets_env, log) if generate: cmd.build() return assets_env Process(target=lambda: cmd.watch()).start() return assets_env
from os.path import join, exists, expandvars import flask import qrcode import requests from webassets_babel import BabelFilter from webassets import Environment, Bundle from webassets.exceptions import FilterError from webassets.filter import register_filter logging.basicConfig(level=logging.DEBUG) app = flask.Flask(__name__) my_env = Environment(directory='static/', url='static/') my_env.debug = 'HEROKU' not in os.environ if platform.system() == 'Windows': npm = expandvars('%AppData%/npm') my_env.config.setdefault('BABEL_BIN', join(npm, 'babel.cmd')) PRESET_PATH = join(npm, "node_modules/RedQR/") else: PRESET_PATH = "/app/" PRESET_PATH = join(PRESET_PATH, "node_modules") assert exists(PRESET_PATH) PRESETS = ['react', 'es2015'] PRESETS = ','.join( join(PRESET_PATH, 'babel-preset-{}'.format(name)) for name in PRESETS )
#! /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/layers.js', 'map/leaflet.active-layers.min.js',
#! /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.VectorGrid.bundled.js', 'map/Mapillary.js', 'map/layers.js',
output="public/js/common.js" ) js_bottom = Bundle( # Vendorized libraries loaded at the bottom of the page "vendor/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.min.js", "vendor/bower_components/jquery.tagsinput/jquery.tagsinput.min.js", "vendor/jquery-blockui/jquery.blockui.js", "vendor/bower_components/bootstrap.growl/bootstrap-growl.min.js", # 'vendor/dropzone/dropzone.js', # 'vendor/hgrid/hgrid.js', 'vendor/bower_components/jquery-autosize/jquery.autosize.min.js', # Site-specific JS Bundle( 'js/project.js', 'js/addons.js', # 'js/dropzone-patch.js', # 'js/rubeus.js' ), filters='jsmin', output='public/js/site.js' ) logger.debug('Registering asset bundles') env.register('js', js) env.register('css', css) env.register('js_bottom', js_bottom) # Don't bundle in debug mode env.debug = settings.DEBUG_MODE
output="public/js/common.js" ) js_bottom = Bundle( # Vendorized libraries loaded at the bottom of the page "vendor/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.min.js", "vendor/bower_components/jquery.tagsinput/jquery.tagsinput.min.js", "vendor/jquery-blockui/jquery.blockui.js", "vendor/bower_components/bootstrap.growl/bootstrap-growl.min.js", # 'vendor/dropzone/dropzone.js', # 'vendor/hgrid/hgrid.js', 'vendor/bower_components/jquery-autosize/jquery.autosize.min.js', # Site-specific JS Bundle( 'js/project.js', 'js/addons.js', # 'js/dropzone-patch.js', # 'js/rubeus.js' ), filters='jsmin', output='public/js/site.js' ) logger.debug('Registering asset bundles') env.register('js', js) env.register('css', css) env.register('js_bottom', js_bottom) # Don't bundle in debug mode env.debug = settings.DEBUG_MODE
#!/usr/bin/env python # -*- coding: utf-8 -*- from webassets import Bundle from webassets import Environment import app.config as config env = Environment('./static', '/static') env.debug = config.DEBUG env.register( 'base_css', Bundle("bootstrap/css/bootstrap.min.css", "bootstrap/css/bootstrap-responsive.min.css", "bootstrap-datepicker/css/datepicker.css", "bootstrap-fileupload/css/bootstrap-fileupload.min.css", "css/main.css")) env.register( 'base_js', Bundle("jquery-form/jquery.form.js", "bootstrap/js/bootstrap.min.js", "bootstrap-datepicker/js/bootstrap-datepicker.js", "underscore/js/underscore.min.js", "js/sprintf.js", "js/common.js", "js/logger.js", "js/formatter.js", "js/palette.manager.js", "js/expenses.ui.js", "js/expenses.manager.js")) env.register('users_js', Bundle("js/users.ui.js", "js/users.manager.js")) env.register('categories_js', Bundle("js/categories.ui.js", "js/categories.manager.js"))
#!/usr/bin/env python # -*- coding: utf-8 -*- import web from webassets import Bundle from webassets import Environment env = Environment('./static', '/static') env.debug = web.debug ## Register your budles here! #env.register('base_css', # Bundle("bootstrap/css/bootstrap.min.css", # "bootstrap/css/bootstrap-responsive.min.css", # "bootstrap-datepicker/css/datepicker.css", # "bootstrap-fileupload/css/bootstrap-fileupload.min.css", # "css/main.css"))
#!/usr/bin/env python # -*- coding: utf-8 -*- import web from webassets import Bundle from webassets import Environment env = Environment('./static', '/static') env.debug = web.debug ## Register your budles here! #env.register('base_css', # Bundle("bootstrap/css/bootstrap.min.css", # "bootstrap/css/bootstrap-responsive.min.css", # "bootstrap-datepicker/css/datepicker.css", # "bootstrap-fileupload/css/bootstrap-fileupload.min.css", # "css/main.css"))