confluence添加用户_玩转Confluence插件开发创建一个简单的蓝图(07)

本文档详细介绍了如何开发Confluence插件,以创建一个自定义的蓝图模板。从创建插件框架开始,通过运行插件、构建模板、添加资源、更新配置文件,最终实现模板在Confluence中的应用。步骤包括:创建插件框架、运行未修改的插件、为模板创建内容、创建模板文件、添加资源、更新atlassian-plugin.xml文件,并构建运行插件,最后展示模板在创建页面时的效果。
摘要由CSDN通过智能技术生成
上一节我们介绍了Confluence创建一个Hello World宏,这一节我们介绍通过插件怎创建一个简单的蓝图模板,Confluence蓝图允许用户基于预定义的内容创建新页面。 这篇文件中的代码我已经放到 github [1]中,地址在文章的最下方,如果需要可以自行获取。

1.创建插件框架

  1. 打开终端并导航到之前创建好的工作目录confluence-plugin-tutorial
  2. 运行以下命令创建Confluence插件框架。
atlas-create-confluence-plugin
  1. 根据提示输入对应的groupId、artifactId、version和package信息,并输入Y以确认。
Define value for groupId: : com.jenseny.confluence.tutorial
Define value for artifactId: : simple-blueprint
Define value for version:  1.0.0-SNAPSHOT: : 
Define value for package:  com.jenseny.confluence.tutorial: : 
Confirm properties configuration:
groupId: com.jenseny.confluence.tutorial
artifactId: simple-blueprint
version: 1.0.0-SNAPSHOT
package: com.jenseny.confluence.tutorial
 Y: : y

  1. 把项目导入到IDE中,我这边使用idea

2.运行插件

到目前为止我们没有对插件做任何的修改,但是仍然可以在Confluence中运行该框架。

  1. 启动Confluence服务,运行以下命令。
atlas-run

此命令将构建插件代码,启动一个Confluence实例,然后安装该插件。这可能需要几分钟的时间。

  1. 找到Confluence的URL。默认为localhost:1990/confluence
  2. 在浏览器中输入URL,然后使用admin/admin账号登录。

3.为模板创建一些内容

模板是使用Confluence源格式描述页面的XML文件。最简单的蓝图模板仅需一个XHTML模板即可完成出色的工作。

  1. 在Confluence页面顶部点击创建按钮,系统弹出“创建”对话框。您可以通过在其中添加自己的蓝图来自定义此对话框。

  2. 单击空白页选项,然后单击创建按钮。系统会为您创建新页面。5dec2e31ecc382d6b9370594869962c1.png

  3. 在页面上添加一个两行两列的表,然后输入标题保存页面。c7fc283b2b2722e70d6857d06e78e6fd.png

  4. 点击页面右上角的更多选项,选择查看存储格式菜单。9c9e288b9ca4871e543a8144ccf6f854.png

  5. 页面的存储格式在新的浏览器窗口中打开。7e4d75f7ecdf5471a6250142507b593c.png先不要关闭这个浏览器窗口

4.创建一个模板

  1. src/main/resources/目录下创建一个子目录templates
  2. 然后在子目录中创建一个mytemplate.xml文件。
  3. 将存储格式的内容去掉多余的部分,复制到mytemplate.xml文件。
<table>
    <colgroup>
        <col/>
        <col/>
    colgroup>
    <tbody>
        <tr>
            <th>姓名th>
            <th>日期th>
        tr>
        <tr>
            <td>
                在此处输入名字。
            td>
            <td>
                在此处输入日期。
            td>
        tr>
    tbody>
table>

5.向项目添加其他资源

  1. 将如下图片保存到src/main/resources/images目录中。

myblueprint.png39ca96b8e0eee2ee5971b0a5fa0a42d7.png

  1. 此时,我们的项目应该包含如下文件。
|____atlassian-plugin.xml
|____css
| |____simple-blueprint.css
|____images
| |____myblueprint.png
| |____pluginIcon.png
| |____pluginLogo.png
|____js
| |____simple-blueprint.js
|____simple-blueprint.properties
|____templates
| |____mytemplate.xml

6.将模块添加到atlassian-plugin.xml文件

每个蓝图都依赖于三个模块

模块名称作用
blueprint蓝图标识
content-template描述插件内容的模板。如果您的插件包含多个模板,则可以有多个。
web-item将蓝图选项添加到“创建”对话框。
  1. 打开atlassian-plugin.xml文件。
  2. 添加一个content-template模块。
   <content-template key="simple-blueprint-template" i18n-name-key="my.blueprint.title">
       <resource name="template" type="download" location="/templates/mytemplate.xml" />
   content-template>
  1. 添加一个blueprint模块。
<blueprint key="my-blueprint" content-template-key="simple-blueprint-template" index-key="my-index" i18n-name-key="my.blueprint.name"/>
  1. 添加一个“创建”对话框,并引用blueprint模块。
<web-item key="create-by-sample-template" i18n-name-key="my.create-link.title" section="system.create.dialog/content">
    <description key="my.create-link.description" />
    <resource name="icon" type="download" location="/images/myblueprint.png" />
    <param name="blueprintKey" value="my-blueprint" />
 web-item>
  1. 现在,atlassian-plugin.xml文件的内容如下。
<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}description>
        <version>${project.version}version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
        <param name="plugin-icon">images/pluginIcon.pngparam>
        <param name="plugin-logo">images/pluginLogo.pngparam>
    plugin-info>

    
    <resource type="i18n" name="i18n" location="simple-blueprint"/>
    
    
    <web-resource key="simple-blueprint-resources" name="simple-blueprint Web Resources">
        <dependency>com.atlassian.auiplugin:ajsdependency>
        
        <resource type="download" name="simple-blueprint.css" location="/css/simple-blueprint.css"/>
        <resource type="download" name="simple-blueprint.js" location="/js/simple-blueprint.js"/>
        <resource type="download" name="images/" location="/images"/>

        <context>simple-blueprintcontext>
    web-resource>

    <content-template key="simple-blueprint-template" i18n-name-key="my.blueprint.title">
        <resource name="template" type="download" location="/templates/mytemplate.xml" />
    content-template>
    
    <blueprint key="my-blueprint" content-template-key="simple-blueprint-template" index-key="my-index" i18n-name-key="my.blueprint.name"/>

    <web-item key="create-by-sample-template" i18n-name-key="my.create-link.title" section="system.create.dialog/content">
        <description key="my.create-link.description" />
        <resource name="icon" type="download" location="/images/myblueprint.png" />
        <param name="blueprintKey" value="my-blueprint" />
    web-item>
atlassian-plugin>
  1. 编辑src/main/resources/simple-blueprint.properties文件,添加如下内容。
my.blueprint.name=Example Blueprint
my.blueprint.title=Sample Template
my.create-link.title=My Sample Template
my.create-link.description=Create a new Simple Blueprint template

7. 构建运行插件

  1. 打开终端,然后导航到插件的根文件夹。
cd simple-blueprint/
  1. 运行以下命令启动Confluence。
atlas-run

此命令将构建插件代码,启动一个Confluence实例,然后安装该插件。这可能需要几分钟的时间。

  1. 启动后,我们点击导航栏创建按钮旁边的更多选项按钮,看到如下效果。619491d13cbb7582f2e5e5c4fb2ed449.png
  2. 单击创建的模板选项,可以看到系统使用我们创建的模板创建一个新页面。bc86a62efa9b01754893bb6c619e15df.png
以上就是关于一个简单版蓝图的介绍,之后的章节里会有更深入的关于蓝图的介绍。下一节我会为你介绍怎样创建一个简单版的空间蓝图。

参考资料

[1]

Confluence插件代码仓库: https://github.com/jenseny/confluence-plugin-tutorial.git

c384146dcce2d2ba1bb02a00530ef3e2.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值