-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinit.rb
101 lines (89 loc) · 3.57 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#
# vendor/plugins/redmine_wiki_html_util/init.rb
#
require 'redmine'
require 'open-uri'
Redmine::Plugin.register :redmine_wiki_html_util do
name 'Redmine Wiki HTML Util'
author 'Arlo Carreon'
author_url 'http://www.arlocarreon.com/blog/redmine/redmine-wiki-html-utility/'
description 'Allows you to embedd RAW HTML into your wiki, load stylesheets and javascript. Made for html/css/js demo wikis'
version '0.0.1'
Redmine::WikiFormatting::Macros.register do
desc "Embed raw html\nUsage:\n<pre>{{html\nHTML CODE\n}}</pre>"
macro :html, :parse_args => false do |obj, args, text|
page = obj.page
raise 'Page not found' if page.nil?
# For security, only allow insertion on protected (locked) wiki pages
if page.protected
content = text || args
result = "#{ CGI::unescapeHTML(content) }".html_safe
return result
else
return "<!-- Macro removed due to wiki page being unprotected -->"
end
end
end
Redmine::WikiFormatting::Macros.register do
desc "Embed raw css"
macro :css, :parse_args => false do |obj, args, text|
page = obj.page
raise 'Page not found' if page.nil?
# For security, only allow insertion on protected (locked) wiki pages
if page.protected
content = text || args
content = "<style type=\"text/css\">"+content+"</style>"
result = "#{ CGI::unescapeHTML(content) }".html_safe
return result
else
return "<!-- Macro removed due to wiki page being unprotected -->"
end
end
end
Redmine::WikiFormatting::Macros.register do
desc "Insert a CSS file into the DOM\nUsage:\n<pre>{{css_url(http://css.url)}}</pre>"
macro :css_url do |obj, args|
page = obj.page
raise 'Page not found' if page.nil?
# For security, only allow insertion on protected (locked) wiki pages
if page.protected
result = "<script> var head = document.getElementsByTagName('head')[0], t = document.createElement('link'); t.href = "+args[0]+"; t.media='all'; t.rel='stylesheet'; head.appendChild(t); </script>"
result = "#{ CGI::unescapeHTML(result) }".html_safe
return result
else
return "<!-- Macro removed due to wiki page being unprotected -->"
end
end
end
Redmine::WikiFormatting::Macros.register do
desc "Embed raw js"
macro :js, :parse_args => false do |obj, args, text|
page = obj.page
raise 'Page not found' if page.nil?
# For security, only allow insertion on protected (locked) wiki pages
if page.protected
content = text || args
content = "<script>"+content+"</script>"
result = "#{ CGI::unescapeHTML(content) }".html_safe
return result
else
return "<!-- Macro removed due to wiki page being unprotected -->"
end
end
end
Redmine::WikiFormatting::Macros.register do
desc "Insert a JS file into the DOM\nUsage:\n<pre>{{js_url(http://js.url)}}</pre>"
macro :js_url do |obj, args|
page = obj.page
raise 'Page not found' if page.nil?
# For security, only allow insertion on protected (locked) wiki pages
if page.protected
result = "<script> var head = document.getElementsByTagName('head')[0], t = document.createElement('script'); t.src = "+args[0]+"; t.type='text/javascript'; head.appendChild(t); </script>"
result = "#{ CGI::unescapeHTML(result) }".html_safe
return result
else
return "<!-- Macro removed due to wiki page being unprotected -->"
end
end
end
end