コード例 #1
0
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'))
コード例 #2
0
ファイル: webassets_tools.py プロジェクト: PublicaMundi/ckan
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'))
コード例 #3
0
ファイル: registry.py プロジェクト: sveetch/Optimus
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
コード例 #4
0
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
コード例 #5
0
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()
コード例 #6
0
ファイル: assets.py プロジェクト: Meodudlye/Optimus
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
コード例 #7
0
ファイル: wsgiapp.py プロジェクト: alexander-ae/Clay
 def create_jinja_environment(self):
     rv = super(WSGIApplication, self).create_jinja_environment()
     assets_env = AssetsEnvironment('./source/static')
     assets_env.url = '/static'
     rv.assets_environment = assets_env
     return rv
コード例 #8
0
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/*',