Create Space Blueprint
Create confluence custom space blueprint
Please follow below mentioned steps to
create your own custom space blueprint:
Step 1:
First you need to install Atlassian SDK for create your own plugin structure,
compile your source code & make jar file
Step 2: After install sdk tool you need to run “atlas-create-confluence-plugin” this cmd from your command prompt. Then you need to provide some information like that:
|
group-id
|
com.test.confluence.plugin
|
|
artifact-id
|
test-confluence
|
|
version
|
1.0
|
|
package
|
com.test.confluence.plugin
|
You can change group id & artifact id as per your requirement. After entering those values it will create new folder name “test-confluence” in your system. Then navigate to this folder and delete some content.
a. Remove all content from /src/test/java
b. Remove all data from src/test/resources/
c. Delete all data from src/main/java/com/test/confluence/plugin
Step 3: Add your space blueprint definition :
a. create space dialog, in thesrc/main/resources/atlassian-plugin.xmlfile, add the following:
<web-item
key='example-space-blueprint-item'
i18n-name-key='confluence.blueprints.space.example.name'
section='system.create.space.dialog/content'>
<description
key='confluence.blueprints.space.example.description'/>
<param name='blueprintKey' value='example-space-blueprint'/>
</web-item>
Thesection='system.create.space.dialog/content'attribute is what makes the dialog available in the create space pop-up window.
b. Add the space
blueprint definition and a wizard with one page. Add below mentioned code into
the the
src/main/resources/atlassian-plugin.xml
<space-blueprint key="example-space-blueprint"
i18n-name-key="confluence.blueprints.space.example.name"
category="examples">
<dialog-wizard
key="example-space-blueprint-wizard">
<dialog-page id="exampleSpaceId"
template-key="Confluence.SpaceBlueprints.Example.dialogForm"
title-key="confluence.blueprints.space.example.dialog.create.title"
description-header-key="confluence.blueprints.space.example.dialog.create.heading"
description-content-key="confluence.blueprints.space.example.dialog.create.description"
last="true"/>
</dialog-wizard>
</space-blueprint>
You can change the
category name, for your requirement. The key
attribute for
<space-blueprint> should
be the same as the value attribute for <param key=”blueprintKey”> inside <web-item>Step 4: Add space dialog wizard
a. Add xml into the the
src/main/resources/atlassian-plugin.xml
<transformation
extension="soy">
<transformer
key="soyTransformer">
<functions>com.atlassian.confluence.plugins.soy:soy-core-functions</functions>
</transformer>
</transformation>
<transformation
extension="js">
<transformer
key="jsI18n"/>
</transformation>
<resource
type="download" name="dialog-page.js" location="/soy/dialog-page.soy"/>
b.
Create “soy” directory into the
“src/main/resources/” & then create dialog-page.soy
file, that is define step 4.a. Add the following code into soy file
{namespace Confluence.SpaceBlueprints.Example}
/**
* Dialog form template
*
* @param atlToken the XSRF token to send with
the form
* @param? fieldErrors the map of errors to
display keyed by field name
* @param? name initial value for the name
field
* @param? key initial value for the key field
*/
{template .dialogForm}
{call
Confluence.Templates.Blueprints.CreateSpace.createSpaceFormFields}
{param showSpacePermission: false /}
{param fieldErrors: $fieldErrors /}
{param name: $name /}
{param key: $key /}
{/call}
{/template}
Note: we have used namespace &
template dislogForm into the soy file. Those values are used step 3.b. If you
change those values from soy, then you need to changes those value into xml.
c. Add js in your plugin js folder ,like src/main/resources/js/test-confluence.js.
This files automatically created at plugin skeleton creation time.
AJS.bind("blueprint.wizard-register.ready",
function () {
function submitExampleSpace(e, state) {
state.pageData.ContentPageTitle =
state.pageData.name + " " +
AJS.I18n.getText("confluence.blueprints.space.example.home.title.suffix");
return
Confluence.SpaceBlueprint.CommonWizardBindings.submit(e, state);
}
function preRenderExampleSpace(e, state) {
state.soyRenderContext['atlToken'] =
AJS.Meta.get('atl-token');
state.soyRenderContext['showSpacePermission'] = false;
}
Confluence.Blueprint.setWizard('com.test.confluence.plugin.test-confluence:example-space-blueprint-item',
function(wizard) {
wizard.on("submit.exampleSpaceId", submitExampleSpace);
wizard.on("pre-render.exampleSpaceId",
preRenderExampleSpace);
wizard.on("post-render.exampleSpaceId",
Confluence.SpaceBlueprint.CommonWizardBindings.postRender);
});
});
Note: this js file highlighted text pattern is
group-id.artifact-id, that you
define project creation time.
d.
Add the
i18n strings to properties file “
src/main/resources/xxxxx.properties”
confluence.blueprints.space.example.name=External
Team Space
confluence.blueprints.space.example.description=Collaborate
& share resources with your team
confluence.blueprints.space.example.dialog.create.title=Create
External Team Space
confluence.blueprints.space.example.dialog.create.heading=About
External Team Spaces
confluence.blueprints.space.example.dialog.create.description=Collaborate
& share resources with your team
confluence.blueprints.space.example.home.title.suffix=Home
Page
Step 5: Create
your home page
a. Create
an xml folder on “src/main/resources”
b. create a new file called
example-space-home.xml:
<ac:layout>
<ac:layout-section
ac:type="two_right_sidebar">
// set for layout. in this
example we have set two column section with right sidebar
<ac:layout-cell>
add html or micro
</ac:layout-cell>
<ac:layout-cell>
// adding macro into the templete. in this
examplewe have added confluence inbuild "expand" micro.
<ac:structured-macro
ac:name="expand">
<ac:parameter
ac:name="title">Meeting Details</ac:parameter>
<ac:rich-text-body>
<p>Skype
Meeting | CONF: (1888xxxxxx)</p>
</ac:rich-text-body>
</ac:structured-macro>
</ac:layout-cell>
</ac:layout-section>
</ac:layout>
c. Add the content template to the
atlassian-plugin.xml file:
<content-template key="example-space-homepage-template"
i18n-name-key="confluence.blueprints.space.example.homepage.name">
<description
key="confluence.blueprints.space.example.homepage.desc"/>
<resource name="template" type="download"
location="/xml/example-space-home.xml"/>
</content-template>
d. Add the content template reference to the space
blueprint definition:
<space-blueprint
key="example-space-blueprint"
i18n-name-key="confluence.blueprints.space.example.name"
category="examples">
<content-template
ref="example-space-homepage-template"/>
....
Step 6: Change plugin display name, description & organization. Goto the pom file that is located into your plugin folder & then change this information like that:
<organization>
<name>Test</name>
<url>https://www.test.com/</url>
</organization>
<name>Test - Confluence Plugin</name>
<description>This is test plugin that serves multiple functionalities (eg. creating a custom space blueprint).</description>
<packaging>atlassian-plugin</packaging>
Step 7: Compile your code. Use “atlas-run” it will create .jar file in your system. Goto your plugin directory then “target” folder you can see jar file. Install this jar file in your confluence instance.
Reference
Link:
1.
Atlassian sdk download link: https://developer.atlassian.com/server/framework/atlassian-sdk/set-up-the-atlassian-plugin-sdk-and-build-a-project/
2.
Create space blueprint: https://developer.atlassian.com/server/confluence/write-a-simple-confluence-space-blueprint/
3.
Setup space home layout configure: https://confluence.atlassian.com/conf59/confluence-storage-format-792498992.html
4.
Macro use into custom xml page : In this case we
have used expand macro, storage format. https://confluence.atlassian.com/conf59/expand-macro-792499106.html
Comments
Post a Comment