CDMS recently asked whether is was possible to display a set of plots on a confluence page, such that one plot at a time can be selected and viewed (this is something that is done using custom javascript on their existing documentation pages). There did not seem to be any existing confluence macro or plugin which exactly satisfied their requirements, so I looked into building a custom confluence macro. After a little reading and downloading the Atlassian SDK it turned out to be quite easy to create simple plugins for confluence to add functionality like this. Basically all that was needed was:
- A small Java class which extends BaseMacro and has a single execute method which takes the user's options and performs any necessary "business logic" (in this case scanning for images attached to the current page which match the user's selection requirements).
- A velocity macro which takes the output of the Java class and renders it as HTML
- A simple javascript function which uses jquery to switch the plot images when the user selects a plot
- A helpfile (velocity), a plugin descriptor (xml) and a maven pom (xml)
The complete source code can be found here, and the result is shown below:
Feel free to ask if you are interested in help getting started creating your own custom macros for confluence.