def register_assets(assets: Environment): assets.register('scss_campaign', 'scss/campaign/campaign.scss', filters='pyscss', output='css/campaign.css') assets.register('scss_handout', 'scss/campaign/handout.scss', filters='pyscss', output='css/handout.css')
class AssetsExtension(object): css_all = Bundle('css/main.css', 'css/gh-fork-ribbon.css', 'css/flags.css', output='css/all.min.css', filters='yui_css') css_admin = Bundle('css/selectize.css', 'css/datetimepicker.css', output='css/admin.min.css', filters='yui_css') css_ie = Bundle('css/gh-fork-ribbon.ie.css', output='css/ie.min.css', filters='yui_css') js_all = Bundle('js/main.js', output='js/all.min.js', filters='yui_js') js_admin = Bundle('js/admin.js', 'js/selectize.js', 'js/moment.js', 'js/datetimepicker.js', output='js/admin.min.js', filters='yui_js') js_maps = Bundle('js/gmap3.js', 'js/loadgpx.js', output='js/maps.min.js', filters='yui_js') def __init__(self, app=None): self.app = app self.env = Environment( join(dirname(__file__), '../static'), '/static', auto_build=app.debug if app else False, debug=(True if app.debug else 'merge') if app else False, manifest="cache" if app and app.debug else None, cache=app.debug if app else False, yui_compressor_path='/usr/share/yui-compressor/yui-compressor.jar') if self.app: self.app.jinja_env.add_extension(extension=JinjaExtension) self.app.jinja_env.assets_environment = self.env self._register_bundles() def _register_bundles(self): for key in dir(self): value = getattr(self, key) if isinstance(value, Bundle): self.env.register(key, value) def build(self): logger = getLogger('webassets') logger.addHandler(StreamHandler()) logger.setLevel(DEBUG) cli_environment = CommandLineEnvironment(self.env, logger) cli_environment.invoke("build", args={})
def register_assets(assets: Environment): assets.register('scss_character', 'scss/character/character.scss', filters='pyscss', output='css/character.css') assets.register('scss_character_coc7e', 'scss/character/character_coc7e.scss', filters='pyscss', output='css/character_coc7e.css') assets.register('scss_character_tftl', 'scss/character/character_tftl.scss', filters='pyscss', output='css/character_tftl.css')
def get_webassets_env_from_settings(settings, prefix='webassets'): """This function will take all webassets.* parameters, and call the ``Environment()`` constructor with kwargs passed in. The only two parameters that are not passed as keywords are: * base_dir * base_url which are passed in positionally. Read the ``WebAssets`` docs for ``Environment`` for more details. """ # Make a dictionary of the webassets.* elements... kwargs = {} # assets settings cut_prefix = len(prefix) + 1 for k in settings: if k.startswith(prefix): val = settings[k] if isinstance(val, six.string_types): if val.lower() in auto_booly: val = asbool(val) elif val.lower().startswith('json:') and k[cut_prefix:] != 'manifest': val = json.loads(val[5:]) kwargs[k[cut_prefix:]] = val if 'base_dir' not in kwargs: raise Exception("You need to provide webassets.base_dir in your configuration") if 'base_url' not in kwargs: raise Exception("You need to provide webassets.base_url in your configuration") asset_dir = kwargs.pop('base_dir') asset_url = kwargs.pop('base_url') if ':' in asset_dir: try: asset_dir = AssetResolver(None).resolve(asset_dir).abspath() except ImportError: pass if 'debug' in kwargs: kwargs['debug'] = maybebool(kwargs['debug']) if 'cache' in kwargs: cache = kwargs['cache'] = maybebool(kwargs['cache']) if cache and isinstance(cache, six.string_types) and not path.isdir(cache): makedirs(cache) # 'updater' is just passed in... if 'auto_build' in kwargs: kwargs['auto_build'] = maybebool(kwargs['auto_build']) if 'jst_compiler' in kwargs: kwargs['JST_COMPILER'] = kwargs.pop('jst_compiler') if 'jst_namespace' in kwargs: kwargs['JST_NAMESPACE'] = kwargs.pop('jst_namespace') if 'manifest' in kwargs: kwargs['manifest'] = maybebool(kwargs['manifest']) if 'url_expire' in kwargs: kwargs['url_expire'] = maybebool(kwargs['url_expire']) if 'static_view' in kwargs: kwargs['static_view'] = asbool(kwargs['static_view']) else: kwargs['static_view'] = False if 'cache_max_age' in kwargs: kwargs['cache_max_age'] = int(kwargs.pop('cache_max_age')) else: kwargs['cache_max_age'] = None if 'load_path' in kwargs: # force load_path to be an array and split on whitespace if not isinstance(kwargs['load_path'], list): kwargs['load_path'] = kwargs['load_path'].split() paths = kwargs.pop('paths', None) if 'bundles' in kwargs: if isinstance(kwargs['bundles'], six.string_types): kwargs['bundles'] = kwargs['bundles'].split() bundles = kwargs.pop('bundles', None) assets_env = Environment(asset_dir, asset_url, **kwargs) if paths is not None: for map_path, map_url in json.loads(paths).items(): assets_env.append_path(map_path, map_url) def yaml_stream(fname): if path.exists(fname): return open(fname, 'rb') else: return assets_env.resolver.resolver.resolve(fname).stream() if isinstance(bundles, list): loaded = {} for bpath in bundles: with closing(yaml_stream(bpath)) as s: loader = YAMLLoader(s) loaded.update(loader.load_bundles()) assets_env.register(loaded) elif isinstance(bundles, dict): assets_env.register(bundles) return assets_env
def get_webassets_env_from_settings(settings, prefix='webassets'): """This function will take all webassets.* parameters, and call the ``Environment()`` constructor with kwargs passed in. The only two parameters that are not passed as keywords are: * base_dir * base_url which are passed in positionally. Read the ``WebAssets`` docs for ``Environment`` for more details. """ # Make a dictionary of the webassets.* elements... kwargs = {} # assets settings cut_prefix = len(prefix) + 1 for k in settings: if k.startswith(prefix): val = settings[k] if isinstance(val, six.string_types): if val.lower() in auto_booly: val = asbool(val) elif val.lower().startswith('json:') and k[cut_prefix:] != 'manifest': val = json.loads(val[5:]) kwargs[k[cut_prefix:]] = val if 'base_dir' not in kwargs: raise Exception("You need to provide webassets.base_dir in your configuration") if 'base_url' not in kwargs: raise Exception("You need to provide webassets.base_url in your configuration") asset_dir = kwargs.pop('base_dir') asset_url = kwargs.pop('base_url') if ':' in asset_dir: try: asset_dir = AssetResolver(None).resolve(asset_dir).abspath() except ImportError: pass if 'debug' in kwargs: kwargs['debug'] = maybebool(kwargs['debug']) if 'cache' in kwargs: cache = kwargs['cache'] = maybebool(kwargs['cache']) if cache and isinstance(cache, six.string_types) and not path.isdir(cache): makedirs(cache) # 'updater' is just passed in... if 'auto_build' in kwargs: kwargs['auto_build'] = maybebool(kwargs['auto_build']) if 'jst_compiler' in kwargs: kwargs['JST_COMPILER'] = kwargs.pop('jst_compiler') if 'jst_namespace' in kwargs: kwargs['JST_NAMESPACE'] = kwargs.pop('jst_namespace') if 'manifest' in kwargs: kwargs['manifest'] = maybebool(kwargs['manifest']) if 'url_expire' in kwargs: kwargs['url_expire'] = maybebool(kwargs['url_expire']) if 'static_view' in kwargs: kwargs['static_view'] = asbool(kwargs['static_view']) else: kwargs['static_view'] = False if 'cache_max_age' in kwargs: kwargs['cache_max_age'] = int(kwargs.pop('cache_max_age')) else: kwargs['cache_max_age'] = None if 'load_path' in kwargs: # force load_path to be an array and split on whitespace if not isinstance(kwargs['load_path'], list): kwargs['load_path'] = kwargs['load_path'].split() paths = kwargs.pop('paths', None) if 'bundles' in kwargs: if isinstance(kwargs['bundles'], six.string_types): kwargs['bundles'] = kwargs['bundles'].split() bundles = kwargs.pop('bundles', None) assets_env = Environment(asset_dir, asset_url, **kwargs) if paths is not None: for map_path, map_url in json.loads(paths).items(): assets_env.append_path(map_path, map_url) def yaml_stream(fname): if path.exists(fname): return open(fname, 'rb') else: return assets_env.resolver.resolver.resolve(fname).stream() if isinstance(bundles, list): loaded = {} for bpath in reversed(bundles): with closing(yaml_stream(bpath)) as s: loader = YAMLLoader(s) loaded.update(loader.load_bundles()) assets_env.register(loaded) elif isinstance(bundles, dict): assets_env.register(bundles) return assets_env
app.jinja_loader = jinja2.FileSystemLoader([ os.path.abspath(os.path.join(app.root_path, "templates")), os.path.abspath(os.path.abspath("static-templates")), ]) push = PushBullet(config["pushbullet"]["api-key"]) assets = Environment(os.path.abspath(os.path.join("static", "assets")), "assets/") assets.append_path(app.static_folder, "/") assets.auto_build = False assets.url_expire = True assets.cache = False assets.manifest = "file:{}".format(os.path.abspath(os.path.join("static", ".webassets-manifest"))) # Create assets assets.register('bootstrap-css', 'css/bootstrap.css', filters='cssmin', output='bootstrap.css') assets.register('sidebar-css', 'css/bootstrap.css', 'css/shared-sidebar.css', filters='cssmin', output='shared.css') assets.register('frc-css', 'css/bootstrap.css', 'css/frc.css', filters='cssmin', output='frc.css') assets.register('markdown-css', 'css/bootstrap.css', 'css/markdown-sidebar.css', filters='cssmin', output='documentation.css') # Shared javascript assets.register('analytics-js', 'js/analytics.js', filters='rjsmin', output='analytics.js') assets.register('shared-js', 'js/analytics.js', 'js/jquery.js',
push = configuration_resources.get_pushbullet() redis = StrictRedis() assets = Environment(os.path.abspath(os.path.join("static", "assets")), "assets/") assets.append_path(app.static_folder, "/") assets.auto_build = False assets.url_expire = True assets.cache = False assets.manifest = "file:{}".format( os.path.abspath(os.path.join("static", ".webassets-manifest"))) # Create assets assets.register('bootstrap-css', 'css/bootstrap.css', filters='cssmin', output='bootstrap.css') assets.register('sidebar-css', 'css/shared-sidebar.css', 'css/bootstrap.css', filters='cssmin', output='shared.css') assets.register('frc-css', 'css/bootstrap.css', 'css/frc.css', filters='cssmin', output='frc.css') assets.register('markdown-css',