自定义宏

Redmine有一个完善的宏系统,用来在格式化的文章页面内加入动态内容

宏的语法以及如何在文章中调用宏,我们后文再说

要新自定义的宏,一般是在开发插件的时候来进行,参考 http://www.redmine.org/projects/redmine/wiki/RedmineMacros#Adding-custom-macros

因为如意通公司并不打算开发自己的插件,但是页面中确实需要加自定义的宏,所以就直接hack了Redmine,修改了 /tmp/redmine-3.2.0/lib/redmine/wiki_formatting/macros.rb 文件(注意,修改后需要重新启动Redmine才生效),新增的宏如下:

html宏

这是一个用来在页面嵌入html代码的宏,这个宏存在安全风险,所以务必只在Redmine运行于内网的时候才加入这个宏

      desc "Insert html" + "\n\n" + " !{{html\n<HTML CODE HERE>\n}}"
      macro :html do |obj, args, text|
        text.html_safe
      end

mermaid宏

这是一个用来在页面嵌入mermaid的宏,mermaid 是一个基于web的时序图和流程图编辑和展现工具,这个宏依赖于已经安装的mermaid服务

      desc "Insert mermaid diagram" + "\n\n" + " !{{mermaid(title,showsource=true)\n<MERMAID CODE HERE>\n}}"
      macro :mermaid do |obj, args, text|
        diagram = "\<script src=\"http:\/\/192.168.0.121:82\/mermaid\/mermaid\/dist\/mermaid.full.min.js\"\>\<\/script\>\<div class=\"mermaid\"\>" + text + "\<\/div\>"
        args, options = extract_macro_options(args, :showsource)
        title = args[0] || ""
        showsource = options[:showsource] || "false"
        if showsource == "true"
           source = "\<pre\>\<code\>" + text + "\<\/code\>\<\/pre\>"
           out = "\<h4\>" + title + "\<\/h4\>" + source + diagram
        else
           out = "\<h4\>" + title + "\<\/h4\>" + diagram
        end
        out.html_safe
      end

mindmap宏

这是一个用来在页面嵌入mindmap的宏,这里的mindmap是一个基于web的mindmap软件 wisemapping,所以这个宏依赖于已经安装的wisemapping服务

      desc "Insert mindmap" + "\n\n" + " !{{mindmap(title,width=800,height=600,border=1)\n<Wisemapping URL HERE>\n}}"
      macro :mindmap do |obj, args, text|
        args, options = extract_macro_options(args, :width, :height, :border)
        title = args[0] || ""
        width = options[:width] || "800"
        raise 'Invalid width parameter' unless width.nil? || width.match(/^\d+$/)
        height = options[:height] || "600"
        raise 'Invalid height parameter' unless height.nil? || height.match(/^\d+$/)
        border = options[:border] || "1"
        raise 'Invalid border parameter' unless border.nil? || border.match(/^\d+$/)
        out = "\<h4\>" + title + "\<\/h4\>\<iframe style=\"width:" + width + "px;height:" + height + "px;border: " + border + "px solid black\" src=\"" + text + "\"\> \<\/iframe\>"
        out.html_safe
      end

manual宏

这是一个用来在页面嵌入如意通科技手册官网上的gitbook手册的宏,所以这个宏依赖于 如意通手册官网

      desc "Insert manual" + "\n\n" + " !{{manual(title)\n<Manual NAME HERE>\n}}"
      macro :manual do |obj, args, text|
        args, options = extract_macro_options(args)
        title = args[0] || ""
        out = "\<h4\>" + title + "\<\/h4\>\<iframe style=\"width:1024px;height:768px;border:1px solid black\" src=\"http:\/\/manual.rooyee.im\/" + text + "\/\"\> \<\/iframe\>"
        out.html_safe
      end

results matching ""

    No results matching ""