wiki:CreatePluginScript

Version 5 (modified by Olemis Lang, 14 years ago) (diff)

Updating new maintainer

create a trac plugin skeleton given a list of interfaces

Description

This python package will create a trac plugin skeleton given its name and a list of interfaces it is to implement. The console script, create-trac-plugin, front-ends TracPluginTemplateScript and creates the basic layout of the plugin using PasteScript. Then the basic contents of the component are generated by looking through the chosen interfaces and filling out the imports needed and signatures for the methods used.

The create-trac-component console script front-ends create_component.py, which can be used as as standalone piece without the rest of the package.

Bugs/Feature Requests

Existing bugs and feature requests for CreatePluginScript are here.

If you have any issues, create a new ticket.

Download

Download the zipped source from [download:createpluginscript here].

If you just want create_component.py go here.

Source

You can check out CreatePluginScript from here using Subversion, or browse the source with Trac.

Example

To list the interfaces available, simply run either of the console scripts without arguments:

$ create-trac-plugin 
Usage: 
 create-trac-plugin <name> [interface1] [interface2] [...] # to create a component with name
 create-trac-plugin # for usage and component list

Interfaces available:

IAdminPanelProvider
IAttachmentChangeListener
IAttachmentManipulator
IAuthenticator
IContentConverter
IDatabaseConnector
IEnvironmentSetupParticipant
IHTMLPreviewAnnotator
IHTMLPreviewRenderer
ILegacyAttachmentPolicyDelegate
INavigationContributor
IPermissionGroupProvider
IPermissionPolicy
IPermissionRequestor
IPermissionStore
IPreferencePanelProvider
IPropertyDiffRenderer
IPropertyRenderer
IRepositoryConnector
IRequestFilter
IRequestHandler
IResourceManager
ISearchSource
ITemplateProvider
ITemplateStreamFilter
ITicketActionController
ITicketChangeListener
ITicketManipulator
ITimelineEventProvider
IWikiChangeListener
IWikiMacroProvider
IWikiPageManipulator
IWikiSyntaxProvider

To make a plugin named NewPlugin that implements the ITemplateStreamFilter and IWikiSyntaxProvider interfaces, run:

$ create-trac-plugin NewPlugin ITemplateStreamFilter IWikiSyntaxProvider

This will setup a directory structure using TracPluginTemplateScript:

NewPlugin/
|-- NewPlugin.egg-info # generated by PasteScript
|-- newplugin
|   |-- __init__.py
|   `-- newplugin.py
`-- setup.py

newplugin.py will be populated with markers for the appropriate interfaces and the correct imports:

"""
NewPlugin:
a plugin for Trac
http://trac.edgewall.org
"""

from trac.core import *

from trac.web.api import ITemplateStreamFilter
from trac.wiki.api import IWikiSyntaxProvider

class NewPlugin(Component):

    implements(ITemplateStreamFilter, IWikiSyntaxProvider)

    ### methods for ITemplateStreamFilter

    """Filter a Genshi event stream prior to rendering."""

    def filter_stream(self, req, method, filename, stream, data):
        """Return a filtered Genshi event stream, or the original unfiltered
        stream if no match.

        `req` is the current request object, `method` is the Genshi render
        method (xml, xhtml or text), `filename` is the filename of the template
        to be rendered, `stream` is the event stream and `data` is the data for
        the current template.

        See the Genshi documentation for more information.
        """

    ### methods for IWikiSyntaxProvider

    def get_link_resolvers(self):
        """Return an iterable over (namespace, formatter) tuples.

        Each formatter should be a function of the form
        fmt(formatter, ns, target, label), and should
        return some HTML fragment.
        The `label` is already HTML escaped, whereas the `target` is not.
        """

    def get_wiki_syntax(self):
        """Return an iterable that provides additional wiki syntax.

        Additional wiki syntax correspond to a pair of (regexp, cb),
        the `regexp` for the additional syntax and the callback `cb`
        which will be called if there's a match.
        That function is of the form cb(formatter, ns, match).
        """

To just generate the file (to stdout), use create-trac-component (or python create_component.py):

$ create-trac-component NewPlugin ITemplateStreamFilter IWikiSyntaxProvider

Recent Changes

3945 by k0s on 2008-07-03 20:39:14
initial import of the script
3944 by k0s on 2008-07-03 20:38:33
New hack CreatePluginScript, created by k0s
(more)

Author/Contributors

Originally developed at The Open Planning Project

Author: k0s
Contributors: Olemis Lang