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, 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'])