def register_package(pkg, prefix=None):
"""
Allow to register an app packages by loading and exposing: templates, static,
and exceptions for abort()
Structure of package
root
| $package_name
| __init__.py
|
| /templates
|
|
|
| /static
|
| assets.yml
:param pkg: str - __package__
or __name__
or The root dir
or the dotted resource package (package.path.path,
usually __name__ of templates and static
:param prefix: str - to prefix the template path
"""
root_pkg_dir = pkg
if not os.path.isdir(pkg) and "." in pkg:
root_pkg_dir = pkg_resources.resource_filename(pkg, "")
template_path = os.path.join(root_pkg_dir, "templates")
static_path = os.path.join(root_pkg_dir, "static")
logging.info("Registering App: " + pkg)
if os.path.isdir(template_path):
loader = jinja2.FileSystemLoader(template_path)
if prefix:
ploader = jinja2.PrefixLoader({
prefix: loader
})
loader = ploader
Mocha._template_paths.add(loader)
if os.path.isdir(static_path):
Mocha._static_paths.add(static_path)
Mocha._add_asset_bundle(static_path)
评论列表
文章目录