├── LICENSE ├── README.md ├── app └── views │ └── settings │ └── _redmine_mermaid_macro_settings.html.erb ├── assets └── stylesheets │ └── redmine_mermaid_macro.css ├── doc └── images │ └── example.png ├── init.rb └── lib └── mermaid_macro_hook.rb /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Taiki IKEGAME 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Redmine Mermaid Macro Plugin 2 | 3 | > [RedMica UI Extension](https://github.com/redmica/redmica_ui_extension) is a more functional plugin. 4 | 5 | This plugin adds a `mermaid` graph macro to wiki formated fields. 6 | 7 | About mermaid: https://mermaid.js.org/ 8 | 9 | ## Example 10 | 11 | ``` 12 | {{mermaid 13 | graph TD; 14 | A-->B; 15 | A-->C; 16 | B-->D; 17 | C-->D; 18 | }} 19 | ``` 20 | 21 |  22 | 23 | ## Installation 24 | 25 | 1. Clone or copy files into the Redmine plugins directory 26 | ``` 27 | // < v10 28 | git clone -b mermaid9 https://github.com/taikii/redmine_mermaid_macro.git plugins/redmine_mermaid_macro 29 | 30 | // >= v10 31 | git clone -b mermaid10 https://github.com/taikii/redmine_mermaid_macro.git plugins/redmine_mermaid_macro 32 | ``` 33 | 2. Restart Redmine 34 | 35 | ## Configration 36 | 37 | You can configure `mermaid.js` URL on `Administration -> Plugins` page. 38 | Default value is UNPKG CDN. 39 | https://unpkg.com/mermaid/dist/mermaid.min.js 40 | 41 | ## License 42 | 43 | [MIT](LICENSE) 44 | -------------------------------------------------------------------------------- /app/views/settings/_redmine_mermaid_macro_settings.html.erb: -------------------------------------------------------------------------------- 1 |
<%= text_field_tag 'settings[mermaid_url]', @settings['mermaid_url'], size: 100 %>
2 | -------------------------------------------------------------------------------- /assets/stylesheets/redmine_mermaid_macro.css: -------------------------------------------------------------------------------- 1 | .mermaid rect.task { 2 | height: 20px; 3 | } 4 | 5 | -------------------------------------------------------------------------------- /doc/images/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taikii/redmine_mermaid_macro/e48be4110942688b9059b1e72f6e25448cec23ff/doc/images/example.png -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('lib/mermaid_macro_hook', __dir__) 2 | 3 | Redmine::Plugin.register :redmine_mermaid_macro do 4 | name 'Redmine Mermaid Macro plugin' 5 | author 'Taiki IKEGAME' 6 | description 'Add mermaid graphs to your wiki.' 7 | version '1.0.5' 8 | url 'https://github.com/taikii/redmine_mermaid_macro' 9 | author_url 'https://taikii.github.io' 10 | 11 | settings :default => { 'mermaid_url' => 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.js' }, 12 | :partial => 'settings/redmine_mermaid_macro_settings' 13 | 14 | Redmine::WikiFormatting::Macros.register do 15 | desc "Add mermaid graphs to your wiki. Example:\n\n" + 16 | "{{mermaid\n" + 17 | "graph TD;\n" + 18 | " A-->B;\n" + 19 | " A-->C;\n" + 20 | " B-->D;\n" + 21 | " C-->D;\n" + 22 | "}}" 23 | macro :mermaid do |obj, args, text| 24 | divid = "mermaid_" + SecureRandom.urlsafe_base64(8) 25 | out = ''.html_safe 26 | out << content_tag(:div, text, id: divid, class: 'mermaid') 27 | out << javascript_tag("if (typeof mermaidInitialized != 'undefined') {mermaid.init(undefined, '#" + divid + "');};") 28 | out 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/mermaid_macro_hook.rb: -------------------------------------------------------------------------------- 1 | class MermaidMacroHook < Redmine::Hook::ViewListener 2 | include ActionView::Helpers::TagHelper 3 | include ActionView::Helpers::JavaScriptHelper 4 | 5 | def view_layouts_base_html_head(context={}) 6 | html = "" 7 | html << stylesheet_link_tag('redmine_mermaid_macro.css' , :plugin => 'redmine_mermaid_macro', :media => 'all') 8 | return html 9 | end 10 | 11 | def view_layouts_base_body_bottom(context={}) 12 | html = "" 13 | html << javascript_include_tag(Setting.plugin_redmine_mermaid_macro['mermaid_url']) 14 | html << javascript_tag("mermaid.initialize({startOnLoad:true});var mermaidInitialized = 1;") 15 | return html 16 | end 17 | 18 | end 19 | --------------------------------------------------------------------------------