def run(self): from webassets import Bundle from webassets import Environment from webassets.script import CommandLineEnvironment css = Bundle('curious/src/css/app.css', output='curious/dist/curious.css') js = Bundle('curious/src/js/*.js', output='curious/dist/curious.js') jsm = Bundle('curious/src/js/*.js', filters='jsmin', output='curious/dist/curious.min.js') jst = Bundle('curious/src/html/*.html', filters='jst', output='curious/dist/curious_jst.js') assets_env = Environment('./curious/static') assets_env.cache = self.cache_dir assets_env.register('css', css) assets_env.register('js', js) assets_env.register('jsmin', jsm) assets_env.register('jst', jst) log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(assets_env, log) cmdenv.build()
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_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(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 _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 _set_env(debug=True, cache=False): env = Environment(BASE_PATH) if debug: env.manifest = False env.cache = cache 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 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 run(self): from webassets import Bundle from webassets import Environment from webassets.script import CommandLineEnvironment css = Bundle('curious/src/css/app.css', output='curious/dist/curious.css') js = Bundle('curious/src/js/*.js', output='curious/dist/curious.js') jsmin = Bundle('curious/src/js/*.js', filters='jsmin', output='curious/dist/curious.min.js') jst = Bundle('curious/src/html/*.html', filters='jst', output='curious/dist/curious_jst.js') assets_env = Environment('./curious/static') assets_env.cache = self.cache_dir assets_env.register('css', css) assets_env.register('js', js) assets_env.register('jsmin', jsmin) assets_env.register('jst', jst) log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(assets_env, log) cmdenv.build()
from webassets import Environment from webassets import Bundle static = Environment('./www', '/') static.cache = False header_js = Bundle( 'js/lib/jquery-1.8.1.min.js', 'js/lib/modernizr.js', 'js/responsive-ad.js', filters='uglifyjs', output='js/electris-header.min.js') footer_js = Bundle( 'js/lib/underscore-min.js', 'js/lib/moment.min.js', 'js/lib/jquery.timeago.js', 'js/lib/jquery.touchclick.js', 'bootstrap/js/bootstrap.min.js', 'js/audio.js', 'js/app.js', filters='uglifyjs', output='js/electris-footer.min.js') css = Bundle( 'bootstrap/css/bootstrap.min.css', 'bootstrap/css/bootstrap-responsive.min.css', 'css/template.css', 'css/app.css', 'css/sponsorship.css', filters='yui_css',
from webassets import Environment from webassets import Bundle static = Environment('./www', '/') static.cache = False header_js = Bundle('js/lib/jquery-1.8.1.min.js', 'js/lib/modernizr.js', 'js/responsive-ad.js', filters='uglifyjs', output='js/electris-header.min.js') footer_js = Bundle('js/lib/underscore-min.js', 'js/lib/moment.min.js', 'js/lib/jquery.timeago.js', 'js/lib/jquery.touchclick.js', 'bootstrap/js/bootstrap.min.js', 'js/audio.js', 'js/app.js', filters='uglifyjs', output='js/electris-footer.min.js') css = Bundle('bootstrap/css/bootstrap.min.css', 'bootstrap/css/bootstrap-responsive.min.css', 'css/template.css', 'css/app.css', 'css/sponsorship.css', filters='yui_css', output='css/electris.min.css') static.register('js_header', header_js)
js = Bundle('src/js/*.js', output='dist/exotic.js') jsm = Bundle('src/js/*.js', filters='jsmin', output='dist/exotic.min.js') jst = Bundle('src/html/*.html', filters='jst', output='dist/exotic_jst.js') assets_env = Environment('.') try: os.mkdir('.webassets-cache') except: pass assets_env.cache = '.webassets-cache' assets_env.register('css', css) assets_env.register('js', js) assets_env.register('jsmin', jsm) assets_env.register('jst', jst) if __name__ == "__main__": from webassets.script import CommandLineEnvironment import logging log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(assets_env, log) cmdenv.build()
import os from werkzeug.wrappers import Request, Response from werkzeug.wsgi import SharedDataMiddleware from webassets import Environment, Bundle, ExternalAssets environment = Environment('static', '/static') environment.versions = 'hash' manifest_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '.static-manifest')) environment.manifest = 'file://%s' % manifest_path environment.cache = False environment.auto_build = True environment.url = '//0.0.0.0:5001/static/' #environment.debug = True #less = Bundle('less/main.less', filters='less', output='gencss/less.css') css = Bundle( Bundle('less/main.less', filters='less', output='gencss/less.css'), 'css/main.css', 'css/sub/sub-main.css', filters='cssrewrite', output='gencss/css-merged.%(version)s.css' ) external_solo = ExternalAssets('map.png') external_main = ExternalAssets( 'css/img/*',
from webassets import Environment css = Bundle('src/css/app.css', output='dist/exotic.css') js = Bundle('src/js/*.js', output='dist/exotic.js') jsm = Bundle('src/js/*.js', filters='jsmin', output='dist/exotic.min.js') jst = Bundle('src/html/*.html', filters='jst', output='dist/exotic_jst.js') assets_env = Environment('.') try: os.mkdir('.webassets-cache') except: pass assets_env.cache = '.webassets-cache' assets_env.register('css', css) assets_env.register('js', js) assets_env.register('jsmin', jsm) assets_env.register('jst', jst) if __name__ == "__main__": from webassets.script import CommandLineEnvironment import logging log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(assets_env, log) cmdenv.build()