def init(confdict, http, webassets, tpl, css): """ Initializes this module acoording to :ref:`our module initialization guidelines <module_initialization>` with the following configuration keys: :confkey:`rootdir` :faint:`[default=None]` Denotes the root folder containing all svg files. Will fall back to a sub-folder of the folder in :mod:`score.tpl`'s configuration, as described in :func:`score.tpl.init`. :confkey:`combine` :faint:`[default=False]` Whether svg files should be delivered as a single file. If this value is `true` (as defined by :func:`score.init.parse_bool`), the default url will point to the combined svg sprite. :confkey:`cachedir` :faint:`[default=None]` A dedicated cache folder for this module. It is generally sufficient to provide a ``cachedir`` for :mod:`score.tpl`, as this module will use a sub-folder of that by default. """ conf = dict(defaults.items()) conf.update(confdict) if not conf['cachedir'] and webassets.cachedir: conf['cachedir'] = os.path.join(webassets.cachedir, 'svg') if conf['cachedir']: init_cache_folder(conf, 'cachedir', autopurge=True) return ConfiguredSvgModule(http, webassets, tpl, css, conf['rootdir'], conf['combine'], conf['cachedir'])
def init(confdict, webassets, tpl, http): """ Initializes this module acoording to :ref:`our module initialization guidelines <module_initialization>` with the following configuration keys: :confkey:`rootdir` :confdefault:`None` Denotes the root folder containing all css files. Will fall back to a sub-folder of the folder in :mod:`score.tpl`'s configuration, as described in :func:`score.tpl.init`. :confkey:`cachedir` :confdefault:`None` A dedicated cache folder for this module. It is generally sufficient to provide a ``cachedir`` for :mod:`score.tpl`, as this module will use a sub-folder of that by default. :confkey:`combine` :confdefault:`False` Whether css files should be delivered as a single file. If this value is `true` (as defined by :func:`score.init.parse_bool`), the default url will point to the combined css file. :confkey:`minify` :confdefault:`False` Whether css assets should be minified. :confkey:`group.*` Keys starting with ``group.*`` will register :term:`asset groups <asset group>`. The following configuration will create a :term:`virtual asset` called ``meal`` which has the combined content of the assets 'bacon.css' and 'spam.css':: group.meal = bacon.css spam.css Note that groups defined this way *must* reference real assets, i.e. at the point this value is interpreted, there are no virtual assets yet! If you need to add virtual assets to a group, you will need to create the asset group after all required virtual assets have been registered. """ conf = dict(defaults.items()) conf.update(confdict) if not conf['rootdir']: conf['rootdir'] = os.path.join(tpl.rootdir, 'css') conf['minify'] = parse_bool(conf['minify']) conf['combine'] = parse_bool(conf['combine']) if not conf['cachedir'] and tpl.cachedir: conf['cachedir'] = os.path.join(tpl.cachedir, 'css') if conf['cachedir']: init_cache_folder(conf, 'cachedir', autopurge=True) else: warnings.warn('No cachedir configured, SCSS rendering will not work.') cssconf = ConfiguredCssModule( webassets, tpl, http, conf['rootdir'], conf['cachedir'], conf['combine'], conf['minify']) for name, pathlist in extract_conf(conf, 'group.').items(): paths = parse_list(pathlist) _create_group(cssconf, webassets, name + '.css', paths) return cssconf
def init(confdict, webassets=None): """ Initializes this module acoording to :ref:`our module initialization guidelines <module_initialization>` with the following configuration keys: :confkey:`rootdir` :faint:`[default=None]` Denotes the root folder containing all templates. When a new format is created via :meth:`.Renderer.register_format`, it will have a sub-folder of this folder as its default root (unless, of course, the `rootdir` parameter of that function is provided). If this value is omitted, all calls to :meth:`.Renderer.register_format` must provide a format-specific root folder. :confkey:`cachedir` :faint:`[default=None]` A cache folder that will be used to cache rendered templates. Will fall back to a sub-folder (called ``tpl``) of the cachedir in the *webassets*, if one was provided. Although this module will work without a cache folder, it is highly recommended that it is either initialized with a ``cachedir`` or a *webassets* with a valid ``cachedir``, even if the value points to the system's temporary folder. :confkey:`default_format` :faint:`[default=None]` The default format of files where the :term:`template format` could not be determined automatically. This must be the name of another, registered format. :confkey:`engine.*` All keys starting with ``engine.`` will be registered as engines. For example, if the key ``engine.php`` is provided, the engine will be instantiated via :func:`score.init.init_object` and registered for the extension ``php``. """ conf = dict(defaults.items()) conf.update(confdict) if not conf['cachedir'] and webassets and webassets.cachedir: conf['cachedir'] = os.path.join(webassets.cachedir, 'tpl') if conf['cachedir']: init_cache_folder(conf, 'cachedir', autopurge=True) if conf['rootdir']: if not os.path.isdir(conf['rootdir']): import score.tpl raise ConfigurationError(score.tpl, 'Given rootdir is not a folder') renderer = Renderer(conf['rootdir'], conf['cachedir'], conf['default_format']) extensions = set() for key in extract_conf(conf, 'engine.'): extensions.add(key.split('.', 1)[0]) for ext in extensions: engine = init_object(conf, 'engine.' + ext) renderer.register_engine(ext, engine) return ConfiguredTplModule(renderer, conf['rootdir'], conf['cachedir'], conf['default_format'])
def init(confdict, http=None, netfs=None): """ Initializes this module acoording to :ref:`our module initialization guidelines <module_initialization>` with the following configuration keys: :confkey:`cachedir` :default:`None` A writable folder that will be used to cache intermediate values. This value is mostly unused in this module, but the initialized value can be used by other modules. The :mod:`css module <score.css>`, for example, will create a sub-folder beneath this folder, if it was initialized without an explicit `cachedir` of its own. :confkey:`versionmanager` :default:`score.webassets.versioning.Dummy` The :class:`VersionManager <score.webassets.versioning.VersionManager>` to use. This value will be converted to an object using :func:`score.init.parse_object`. See the :mod:`package description <score.webassets.versioning>` for available implementations. :confkey:`netfs` :default:`True` The initializer will upload all webassets to a :mod:`score.netfs` server, if one was configured. You can disable this feature by passing a `False` value here """ conf = dict(defaults.items()) conf.update(confdict) if conf['cachedir']: init_cache_folder(conf, 'cachedir', autopurge=True) versionmanager = parse_object(conf, 'versionmanager') if netfs and parse_bool(conf['netfs']): versionmanager = NetfsVersionManager(versionmanager, netfs) def assetnotfound(ctx, exception): raise HTTPNotFound() if http: http.exception_handlers[AssetNotFound] = assetnotfound return ConfiguredWebassetsModule(conf['cachedir'], versionmanager)
def init(confdict, ctx=None): """ Initializes this module acoording to :ref:`our module initialization guidelines <module_initialization>` with the following configuration keys: :confkey:`server` :faint:`[default=localhost:14000]` The server to connect to for all remote operations. Read using the generic :func:`score.init.parse_host_port`. The special value ``None`` indicates that all remote operations will immediately raise an exception. It is still possible to use higher level functions like :meth:`put <.ConfiguredNetfsModule.put>` and :meth:`get <.ConfiguredNetfsModule.get>` (although :meth:`get <.ConfiguredNetfsModule.get>` will raise an exception if the requested file is not present in the local folder.) :confkey:`cachedir` :faint:`[default=None]` A local folder that will hold downloaded files. If this value is omitted, the module will create a new temporary folder on demand, that will be used as the local folder for this session. :confkey:`deltmpcache` :faint:`[default=True]` This option is only relevant if the configuration did not contain a ``cachedir``. If this value is `True`, any temporary folder that was created for this session—as described for the configuration value ``cachedir``, above—will be removed when the :class:`.ConfiguredNetfsModule` is freed. The only use case where you might need this configuration is when you want to operate on a temporary folder, but still keep its contents when you are done with this module. """ conf = dict(defaults.items()) conf.update(confdict) if conf['server'] in (None, 'None'): host, port = None, None else: host, port = parse_host_port(conf['server'], defaults['server']) cachedir = None delcache = False if conf['cachedir']: cachedir = init_cache_folder(conf, 'cachedir') else: delcache = parse_bool(conf['deltmpcache']) c = ConfiguredNetfsModule(host, port, cachedir, delcache) c.ctx_conf = ctx if ctx and conf['ctx.member'] not in ('None', None): ctx.register(conf['ctx.member'], lambda _: c.connect()) return c
def init(confdict, webassets, http, tpl, html=None): """ Initializes this module acoording to :ref:`our module initialization guidelines <module_initialization>` with the following configuration keys: :confkey:`rootdir` :confdefault:`None` Denotes the root folder containing all javascript files. Will fall back to a sub-folder of the folder in :mod:`score.tpl`'s configuration, as described in :func:`score.tpl.init`. :confkey:`cachedir` :confdefault:`None` A dedicated cache folder for this module. It is generally sufficient to provide a ``cachedir`` for :mod:`score.tpl`, as this module will use a sub-folder of that by default. :confkey:`minifier` :confdefault:`None` The minifier to use for minification. Will be initialized using :func:`score.init.init_object`. See :mod:`score.tpl.minifier` for available minifiers. :confkey:`combine` :confdefault:`False` Whether javascript files should be delivered as a single file. If this value is `true` (as defined by :func:`score.init.parse_bool`), the default url will point to the combined javascript file. """ conf = dict(defaults.items()) conf.update(confdict) if conf['minifier']: conf['minifier'] = init_object(conf, 'minifier') if not conf['cachedir'] and webassets.cachedir: conf['cachedir'] = os.path.join(webassets.cachedir, 'js') if conf['cachedir']: init_cache_folder(conf, 'cachedir', autopurge=True) conf['combine'] = parse_bool(conf['combine']) return ConfiguredJsModule( http, tpl, webassets, conf['rootdir'], conf['cachedir'], conf['combine'], conf['minifier'])