Hello Devs,
This is about implementing support for creating rendering macros by editing
wiki pages! The corresponding JIRA issue is
http://jira.xwiki.org/jira/browse/XWIKI-3213.
Introduction
------------
There are two main xwiki classes involved: XWiki.WikiMacro &
XWiki.WikiMacroParameter. Fields of these classes are as below:
XWiki.WikiMacro
|
|-> name (Name of the macro)
|
|-> description (Short description about the macro - for display purposes)
|
|-> content (Macro content, this is what will be executed when the macro is
invoked, can be any xwiki/2.0 content)
XWiki.WikiMacroParameter
|
|-> name (Name of the parameter)
|
|-> macro (Name of the macro to which this parameter applies to)
|
|-> description (Description of this macro parameter - for display purposes)
|
|-> mandatory (boolean value indicating if this parameter is mandatory)
So the basic idea is, when a user saves (or updates) a page containing an
Object of XWiki.WikiMacro type, we will dynamically register (or
re-register) a macro as defined by that object.
Question:
1. What about macro name conflicts? Should we ask macro name to be unique?
(This can be done if we introduce a document sheet and a template for
creating macros)
Implementation steps
--------------------
1. The original idea was to create XWiki.WikiMacro &
XWiki.WikiMacroParameter classes upon XE startup (if those classes are not
present). But I would like to start a little different here, we create
xwiki-application-wikimacro application to host these two documents and
later remove this app and add the initialization code. This will allow me to
focus on other more important tasks upfront and meanwhile i can make any
changes easily to these wiki pages if they are kept inside an application.
2. Document update / save event listening & Macro registration can be
implemented using the ObservationManager and dynamic component registration
mechanisms.
- Currently ObservationManager can only send general document save / update
events. We can either use these events and filter only those we are
interested (ones where an XWiki.WikiMacro object is saved / updated) OR we
can introduce a new event like ObjectChangedEvent (which would be
constructed given a class name) that is fired by xwiki-core appropriately.
- This document event listening & dynamic macro component registration code
will be put inside xwiki-rendering/xwiki-rendering-macro-wikibridge
3. Finally DefaultMacroManager needs to be updated so that it listens to
ComponentManager events and filters out those events corresponding to Macro
component registrations and updates the internal macro cache.
So, above is the approach I have in mind for implementing the wiki-macro
bridge. If you have any comments, please let me know.
Thanks.
- Asiri