atlas-create-confluence-plugin
command from the Atlassian SDK and enter the necessary data:group-id
: com.stiltsoft.confluence.plugins
artifact-id
: wiki-markup-blueprint-plugin
version
: 1.0.0-SNAPSHOT
package
: com.stiltsoft.confluence.plugins.blueprint.markup
<dependencies> <dependency> <groupId>com.atlassian.confluence</groupId> <artifactId>confluence</artifactId> <version>${confluence.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.confluence.plugins</groupId> <artifactId>confluence-create-content-plugin</artifactId> <version>${create-content.version}</version> <scope>provided</scope> </dependency> </dependencies> <properties> <confluence.version>5.1-m1</confluence.version> <create-content.version>1.3.8</create-content.version> <confluence.data.version>5.1-m1</confluence.data.version> <amps.version>4.1.5</amps.version> </properties>
Blueprints
into the plugin descriptor atlassian-plugin.xml
. <web-item key="wiki-markup-blueprint-item" i18n-name-key="wiki.markup.blueprint.name" section="system.create.dialog/content"> <description key="wiki.markup.blueprint.description"/> <resource name="icon" type="download" location="images/stiltsoft.png"/> <param name="blueprintKey" value="wiki-markup-blueprint"/> </web-item>
web-item
module adds the Wiki Markup
menu item to the Create Dialog
window and has the following options:i18n-name-key
attribute is the key by which the name of the displayed menu item is found in the resource filesection
attribute - defines where the menu item appears (in order for it to appear in the Create Dialog
window, specify the value system.create.dialog/content
)resource
tag - used to indicate the path to the displayed iconparam
- defines a parameter with the name blueprintKey
and a value equal to the key of the blueprint
module, announced later in atlassian-plugin.xml
blueprint
module: <blueprint key="wiki-markup-blueprint" create-result="view" content-template-key="wiki-markup-blueprint-page" index-key="wiki-markup-blueprint-index"> <dialog-wizard key="blueprint-wizard"> <dialog-page id="insertMarkupForm" template-key="WikiMarkup.Blueprint.form" title-key="wiki.markup.blueprint.dialog.title" last="true"/> </dialog-wizard> </blueprint>
blueprint
module is a core value for developers. It includes the following parameters:key
attribute - the key of the module in the descriptorcreate-result
attribute - defines the behavior that is expected after the completion of all steps to create a new page using Blueprints
. It can take edit
values ​​(after all steps are completed, we enter the page editing mode) and view
(after all steps are completed, we enter the page view mode, the page is created automatically).content-template-key
attribute - refers to the key of the content-template
module, announced later in atlassian-plugin.xml
index-key
attribute - defines the name of the label, which will be put in the created page (It is worth noting that the index'a
mechanism index'a
quite multifaceted, but in this example is not considered by us)blueprint
module's dialog-wizard
blueprint
defines the dynamic behavior of what the user sees when creating content using your Blueprint
plugin. The parameter has the following attributes:id
attribute - participates in the formation of html
content and is used as part of the css
class in the current content creation window that the user seestemplate-key
- defines the name of the soy
template for dynamically generating the contents of the windowtitle-key
attribute - the key that contains the window title in the resource fileweb-resource
module. The following is the contents of the templates.soy
file: {namespace WikiMarkup.Blueprint} /** * Wiki Markup form */ {template .form} <form id="wiki-markup-form" action="#" method="post" class="aui"> <div> {getText('wiki.markup.blueprint.dialog.form.label.page.title')} </div> <input id="page-title" type="text" name="title"> <div> {getText('wiki.markup.blueprint.dialog.form.label.markup')} </div> <textarea id="wiki-markup" name="wikiMarkup"></textarea> </form> {/template}
content-template
module defines the page template that is used to create the page: <content-template key="wiki-markup-blueprint-page" i18n-name-key="wiki.markup.blueprint.page.name"> <resource name="template" type="download" location="xml/content-template.xml"/> <context-provider class="com.stiltsoft.confluence.plugins.blueprint.markup.WikiMarkupProvider"/> </content-template>
content-template
module has the following parameters:key
attribute - the key of the module in the descriptor (used in the blueprint
module)resource
tag - define a template that participates in the creation of a new pagecontext-provider
tag is an optional parameter that can participate in the creation of a page by generating additional variables.xml
file may contain dynamic variables that are taken from the context. In the plugin we are developing, the template looks like this: <at:var at:name="wikiInXhtml" at:rawXhtml='true'/>
context-provider
. In our example, the context-provider
, which converts the wiki markup entered by the user on the input form into xhtml
markup used in Confluence. The context-provider
'a code is presented below: package com.stiltsoft.confluence.plugins.blueprint.markup; import com.atlassian.confluence.content.render.xhtml.DefaultConversionContext; import com.atlassian.confluence.content.render.xhtml.XhtmlException; import com.atlassian.confluence.renderer.PageContext; import com.atlassian.confluence.xhtml.api.EditorFormatService; import com.atlassian.plugin.PluginParseException; import com.atlassian.plugin.web.ContextProvider; import java.util.Map; public class WikiMarkupProvider implements ContextProvider { private EditorFormatService editorFormatService; public WikiMarkupProvider(EditorFormatService editorFormatService) { this.editorFormatService = editorFormatService; } @Override public void init(Map<String, String> params) throws PluginParseException { } @Override public Map<String, Object> getContextMap(Map<String, Object> ctx) { try { String wikiMarkup = (String) ctx.get("wikiMarkup"); String xhtml = editorFormatService.convertWikiToEdit(wikiMarkup, new DefaultConversionContext(new PageContext())); ctx.put("wikiInXhtml", xhtml); } catch (XhtmlException ignored) { } return ctx; } }
atlassian-plugin.xml
define a web-resource
module in atlassian-plugin.xml
: <web-resource key="blueprint-resources" name="Blueprint Resources"> <transformation extension="js"> <transformer key="jsI18n"/> </transformation> <transformation extension="soy"> <transformer key="soyTransformer"> <functions>com.atlassian.confluence.plugins.soy:soy-core-functions</functions> </transformer> </transformation> <resource type="download" name="wiki-markup.css" location="css/wiki-markup.css"/> <resource type="download" name="templates-soy.js" location="soy/templates.soy"/> <resource type="download" name="wiki-markup.js" location="js/wiki-markup.js"/> <dependency>com.atlassian.confluence.plugins.confluence-create-content-plugin:resources</dependency> <context>atl.general</context> <context>atl.admin</context> </web-resource>
web-resource
module, you can familiarize yourself with the documentation on the site .com.atlassian.confluence.plugins.confluence-create-content-plugin:resources
. In addition, wiki-markup.js
should register your Blueprint
plugin as follows: (function ($) { Confluence.Blueprint.setWizard('com.stiltsoft.confluence.plugins.wiki-markup-blueprint-plugin:wiki-markup-blueprint-item', function() { }); })(AJS.$);
Blueprint
plug-in for creating a page from wiki markup comes to an end. If you did everything correctly, you can now install the plugin and try it in action.Source: https://habr.com/ru/post/173797/
All Articles