| 1 | = create a trac plugin skeleton given a list of interfaces = |
| 2 | |
| 3 | == Description == |
| 4 | |
| 5 | This python package will create a plugin skeleton given its name and a list of interfaces. The console script, create-trac-plugin, front-ends TracPluginTemplateScript and creates the basic layout of the plugin using [http://pythonpaste.org/script/ PasteScript]. Then the basic contents of the [http://trac.edgewall.org/wiki/TracDev/ComponentArchitecture component] are generated by looking through the chosen interfaces and filling out the imports needed and signatures for the methods used. |
| 6 | |
| 7 | The create-component script front-ends create_component.py, which can be used as as standalone piece without the rest of the software. |
| 8 | |
| 9 | == Bugs/Feature Requests == |
| 10 | |
| 11 | Existing bugs and feature requests for CreatePluginScript are |
| 12 | [report:9?COMPONENT=CreatePluginScript here]. |
| 13 | |
| 14 | If you have any issues, create a |
| 15 | [http://trac-hacks.org/newticket?component=CreatePluginScript&owner=k0s new ticket]. |
| 16 | |
| 17 | == Download == |
| 18 | |
| 19 | Download the zipped source from [download:createpluginscript here]. |
| 20 | |
| 21 | == Source == |
| 22 | |
| 23 | You can check out CreatePluginScript from [http://trac-hacks.org/svn/createpluginscript here] using Subversion, or [source:createpluginscript browse the source] with Trac. |
| 24 | |
| 25 | == Example == |
| 26 | |
| 27 | To list the interfaces available, simply run either of the console scripts without arguments: |
| 28 | |
| 29 | {{{ |
| 30 | $ create-trac-plugin |
| 31 | Usage: |
| 32 | create-trac-plugin <name> [interface1] [interface2] [...] # to create a component with name |
| 33 | create-trac-plugin # for usage and component list |
| 34 | |
| 35 | Interfaces available: |
| 36 | |
| 37 | IAdminPanelProvider |
| 38 | IAttachmentChangeListener |
| 39 | IAttachmentManipulator |
| 40 | IAuthenticator |
| 41 | IContentConverter |
| 42 | IDatabaseConnector |
| 43 | IEnvironmentSetupParticipant |
| 44 | IHTMLPreviewAnnotator |
| 45 | IHTMLPreviewRenderer |
| 46 | ILegacyAttachmentPolicyDelegate |
| 47 | INavigationContributor |
| 48 | IPermissionGroupProvider |
| 49 | IPermissionPolicy |
| 50 | IPermissionRequestor |
| 51 | IPermissionStore |
| 52 | IPreferencePanelProvider |
| 53 | IPropertyDiffRenderer |
| 54 | IPropertyRenderer |
| 55 | IRepositoryConnector |
| 56 | IRequestFilter |
| 57 | IRequestHandler |
| 58 | IResourceManager |
| 59 | ISearchSource |
| 60 | ITemplateProvider |
| 61 | ITemplateStreamFilter |
| 62 | ITicketActionController |
| 63 | ITicketChangeListener |
| 64 | ITicketManipulator |
| 65 | ITimelineEventProvider |
| 66 | IWikiChangeListener |
| 67 | IWikiMacroProvider |
| 68 | IWikiPageManipulator |
| 69 | IWikiSyntaxProvider |
| 70 | }}} |
| 71 | |
| 72 | To make a plugin named NewPlugin that implements the ITemplateStreamFilter and IWikiSyntaxProvider interfaces, run: |
| 73 | |
| 74 | {{{ |
| 75 | $ create-trac-plugin NewPlugin ITemplateStreamFilter IWikiSyntaxProvider |
| 76 | }}} |
| 77 | |
| 78 | This will setup a directory structure using TracPluginTemplateScript: |
| 79 | |
| 80 | {{{ |
| 81 | NewPlugin/ |
| 82 | |-- NewPlugin.egg-info |
| 83 | |-- newplugin |
| 84 | | |-- __init__.py |
| 85 | | `-- newplugin.py |
| 86 | `-- setup.py |
| 87 | }}} |
| 88 | |
| 89 | {{{newplugin.py}}} will be populated with markers for the appropriate interfaces and the correct imports: |
| 90 | |
| 91 | {{{ |
| 92 | """ |
| 93 | NewPlugin: |
| 94 | a plugin for Trac |
| 95 | http://trac.edgewall.org |
| 96 | """ |
| 97 | |
| 98 | from trac.core import * |
| 99 | |
| 100 | from trac.web.api import ITemplateStreamFilter |
| 101 | from trac.wiki.api import IWikiSyntaxProvider |
| 102 | |
| 103 | class NewPlugin(Component): |
| 104 | |
| 105 | implements(ITemplateStreamFilter, IWikiSyntaxProvider) |
| 106 | |
| 107 | ### methods for ITemplateStreamFilter |
| 108 | |
| 109 | """Filter a Genshi event stream prior to rendering.""" |
| 110 | |
| 111 | def filter_stream(self, req, method, filename, stream, data): |
| 112 | """Return a filtered Genshi event stream, or the original unfiltered |
| 113 | stream if no match. |
| 114 | |
| 115 | `req` is the current request object, `method` is the Genshi render |
| 116 | method (xml, xhtml or text), `filename` is the filename of the template |
| 117 | to be rendered, `stream` is the event stream and `data` is the data for |
| 118 | the current template. |
| 119 | |
| 120 | See the Genshi documentation for more information. |
| 121 | """ |
| 122 | |
| 123 | ### methods for IWikiSyntaxProvider |
| 124 | |
| 125 | def get_link_resolvers(self): |
| 126 | """Return an iterable over (namespace, formatter) tuples. |
| 127 | |
| 128 | Each formatter should be a function of the form |
| 129 | fmt(formatter, ns, target, label), and should |
| 130 | return some HTML fragment. |
| 131 | The `label` is already HTML escaped, whereas the `target` is not. |
| 132 | """ |
| 133 | |
| 134 | def get_wiki_syntax(self): |
| 135 | """Return an iterable that provides additional wiki syntax. |
| 136 | |
| 137 | Additional wiki syntax correspond to a pair of (regexp, cb), |
| 138 | the `regexp` for the additional syntax and the callback `cb` |
| 139 | which will be called if there's a match. |
| 140 | That function is of the form cb(formatter, ns, match). |
| 141 | """ |
| 142 | }}} |
| 143 | |
| 144 | To just generate the file (to stdout), use {{{create-trac-component}}} (or {{{python create_component.py}}}): |
| 145 | |
| 146 | {{{ |
| 147 | $ create-trac-component NewPlugin ITemplateStreamFilter IWikiSyntaxProvider |
| 148 | }}} |
| 149 | |
| 150 | == Recent Changes == |
| 151 | |
| 152 | [[ChangeLog(createpluginscript, 3)]] |
| 153 | |
| 154 | == Author/Contributors == |
| 155 | |
| 156 | '''Author:''' [wiki:k0s] [[BR]] |
| 157 | '''Contributors:''' |