A Python content management system designed for kirsle.net featuring a blog, comments and photo albums. https://rophako.kirsle.net/
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

plugin.py 1.2 KiB

  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals, absolute_import
  3. """Dynamic CMS plugin loader."""
  4. import os
  5. from importlib import import_module
  6. def load_plugin(name, as_blueprint=True, template_path=None):
  7. """Load a Rophako CMS plugin.
  8. * `name` is a Python module name, i.e. `rophako.modules.blog`
  9. * `as_blueprint` is True if the module exports a blueprint object called
  10. `mod` that can be attached to the Flask app. Set this value to False if
  11. you simply need to include a Python module that isn't a blueprint.
  12. * `template_path` is a filesystem path where the blueprint's templates
  13. can be found. If not provided, the path is automatically determined
  14. based on the module name, which is suitable for the built-in plugins."""
  15. from rophako.app import app, BLUEPRINT_PATHS
  16. module = import_module(name)
  17. if as_blueprint:
  18. mod = getattr(module, "mod")
  19. app.register_blueprint(mod)
  20. # Get the template path to add to the BLUEPRINT_PATHS.
  21. if template_path is None:
  22. module_path = name.replace(".", "/")
  23. template_path = os.path.join(module_path, "templates")
  24. BLUEPRINT_PATHS.append(template_path)