1. Miks Kalniņš
  2. moin-2.0


moin-2.0 / contrib / ExamplePlugin / ExampleMoinPlugin / __init__.py

# Copyright: 2012 MoinMoin:Miks Kalnins <mikskalnins@maikumori.com>
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

    ExampleMoinPlugin - Example plugin for MoinMoin wiki engine.

    Example configuration:

    from wikiconfig import *

    class LocalConfig(Config):
        example_plugin_config = {
            "default_name": "Jack Sparrow",
        plugins_config = {
            "ExampleMoinPlugin": example_plugin_config,
        plugins_enabled = [
        theme_default = "Modernized"

    MOINCFG = LocalConfig
    DEBUG = True

from flask import Blueprint
from flask import Response

from MoinMoin.themes import render_template
from MoinMoin.plugin import BlueprintBase
from MoinMoin.app import before_wiki, teardown_wiki

class ExampleMoinPlugin(BlueprintBase):

    name = u"Example Plugin"
    author = u"Miks Kalnins"
    description = u"An example plugin for MoinMoin wiki engine to demonstrate some of the plugin systems features."

    blueprint = Blueprint('example', __name__, template_folder='templates')
    blueprint_options = dict(url_prefix="/+example")

    def __init__(self, cfg):
        self.default_name = cfg.get("default_name", "Anonymous")


        self.blueprint.add_url_rule("/", "index", self.index)
        self.blueprint.add_url_rule("/hello/", "hello", self.hello, defaults=dict(name=None))
        self.blueprint.add_url_rule("/hello/<name>", "hello", self.hello)

    def index(self):
        return render_template("example_index.html",
                               title="ExampleMoinPlugin - Index",
                               content="Hello from ExampleMoinPlugin!")

    def hello(self, name):
        if not name:
            name = self.default_name
        return u"Hello, {0}!".format(name)