# Path: rophako/plugin.py
# def load_plugin(name, as_blueprint=True, template_path=None):
#     """Load a Rophako CMS plugin.
# 
#     * `name` is a Python module name, i.e. `rophako.modules.blog`
#     * `as_blueprint` is True if the module exports a blueprint object called
#       `mod` that can be attached to the Flask app. Set this value to False if
#       you simply need to include a Python module that isn't a blueprint.
#     * `template_path` is a filesystem path where the blueprint's templates
#       can be found. If not provided, the path is automatically determined
#       based on the module name, which is suitable for the built-in plugins."""
#     from rophako.app import app, BLUEPRINT_PATHS
#     module = import_module(name)
#     if as_blueprint:
#         mod = getattr(module, "mod")
#         app.register_blueprint(mod)
# 
#         # Get the template path to add to the BLUEPRINT_PATHS.
#         if template_path is None:
#             module_path   = name.replace(".", "/")
#             template_path = os.path.join(module_path, "templates")
# 
#         BLUEPRINT_PATHS.append(template_path)


import os
import datetime
from yamlsettings import YamlSettings
from rophako.plugin import load_plugin
class ConfigHandler(object):
    settings = None

    def load_settings(self):
        """Load the settings and make them available in the global config."""
        settings_file = os.environ.get("ROPHAKO_SETTINGS", "settings.yml")
        project_settings = YamlSettings("defaults.yml", settings_file,
            default_section="rophako")
        self.settings = project_settings.get_settings()

        # Extrapolate {basedir} in certain keys.
        # TODO: find a better way...
        self.site.site_root = self.site.site_root.format(basedir=basedir)
        self.emoticons.root_private = self.emoticons.root_private.format(
            basedir=basedir
        )
        self.photo.root_private = self.photo.root_private.format(basedir=basedir)
        self.blog.copyright = self.blog.copyright.format(
            year=datetime.datetime.utcnow().strftime("%Y")
        )

    def print_settings(self):
        """Pretty-print the contents of the configuration."""
        print(self.settings)

    def load_plugins(self):
        """Load all the plugins specified by the config file."""
        for plugin in self.blueprints:
            plugin = plugin.strip()
            if not plugin: continue

# Path: rophako/plugin.py
# def load_plugin(name, as_blueprint=True, template_path=None):
#     """Load a Rophako CMS plugin.
# 
#     * `name` is a Python module name, i.e. `rophako.modules.blog`
#     * `as_blueprint` is True if the module exports a blueprint object called
#       `mod` that can be attached to the Flask app. Set this value to False if
#       you simply need to include a Python module that isn't a blueprint.
#     * `template_path` is a filesystem path where the blueprint's templates
#       can be found. If not provided, the path is automatically determined
#       based on the module name, which is suitable for the built-in plugins."""
#     from rophako.app import app, BLUEPRINT_PATHS
#     module = import_module(name)
#     if as_blueprint:
#         mod = getattr(module, "mod")
#         app.register_blueprint(mod)
# 
#         # Get the template path to add to the BLUEPRINT_PATHS.
#         if template_path is None:
#             module_path   = name.replace(".", "/")
#             template_path = os.path.join(module_path, "templates")
# 
#         BLUEPRINT_PATHS.append(template_path)


# Path: rophako/settings.py
import os
import datetime
from yamlsettings import YamlSettings
from rophako.plugin import load_plugin

class ConfigHandler(object):
    settings = None

    def load_settings(self):
        """Load the settings and make them available in the global config."""
        settings_file = os.environ.get("ROPHAKO_SETTINGS", "settings.yml")
        project_settings = YamlSettings("defaults.yml", settings_file,
            default_section="rophako")
        self.settings = project_settings.get_settings()

        # Extrapolate {basedir} in certain keys.
        # TODO: find a better way...
        self.site.site_root = self.site.site_root.format(basedir=basedir)
        self.emoticons.root_private = self.emoticons.root_private.format(
            basedir=basedir
        )
        self.photo.root_private = self.photo.root_private.format(basedir=basedir)
        self.blog.copyright = self.blog.copyright.format(
            year=datetime.datetime.utcnow().strftime("%Y")
        )

    def print_settings(self):
        """Pretty-print the contents of the configuration."""
        print(self.settings)

    def load_plugins(self):
        """Load all the plugins specified by the config file."""
        for plugin in self.blueprints:
            plugin = plugin.strip()
            if not plugin: continue

            load_plugin(plugin)