-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.rb
78 lines (67 loc) · 2.5 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# encoding: utf-8
require 'redmine'
require_dependency 'admonition_hooks'
Redmine::Plugin.register :redmine_wiki_admonition do
name 'Redmine Wiki Admonitions'
author 'Grzegorz Rajchman'
author_url 'https://github.com/mrliptontea'
description 'Adds macros for simple admonition blocks'
version '0.0.1'
RedCloth3::ALLOWED_TAGS << "div"
Redmine::WikiFormatting::Macros.register do
desc "Adds a `note` block\n" +
"Usage:\n" +
"<pre>{{note(You should note:)\n" +
"That this is in fact a note.\n" +
"}}</pre>\n"
macro :note, :parse_args => false do |obj, args, text|
body = text.present? ? text : args
head = body != args ? args : nil
body = textilizable(body, :object => obj, :headings => false)
if head.present?
head = textilizable(head)
head.sub!(/<(p|h\d+)>/, '<p class="admonition-header">').sub!(/<\/(p|h\d+)>/, '</p>')
content = head + body
else
content = body
end
content_tag('div', content.html_safe, :class => "admonition note")
end
desc "Adds a `danger` block\n" +
"Usage:\n" +
"<pre>{{danger(Beware!)\n" +
"It's dangerous to go alone.\n" +
"}}</pre>\n"
macro :danger, :parse_args => false do |obj, args, text|
body = text.present? ? text : args
head = body != args ? args : nil
body = textilizable(body, :object => obj, :headings => false)
if head.present?
head = textilizable(head)
head.sub!(/<(p|h\d+)>/, '<p class="admonition-header">').sub!(/<\/(p|h\d+)>/, '</p>')
content = head + body
else
content = body
end
content_tag('div', content.html_safe, :class => "admonition danger")
end
desc "Adds a `important` block\n" +
"Usage:\n" +
"<pre>{{important(This is important:)\n" +
"The two most important days in your life are the day you are born and the day you find out why.\n" +
"}}</pre>\n"
macro :important, :parse_args => false do |obj, args, text|
body = text.present? ? text : args
head = body != args ? args : nil
body = textilizable(body, :object => obj, :headings => false)
if head.present?
head = textilizable(head)
head.sub!(/<(p|h\d+)>/, '<p class="admonition-header">').sub!(/<\/(p|h\d+)>/, '</p>')
content = head + body
else
content = body
end
content_tag('div', content.html_safe, :class => "admonition important")
end
end
end