@@ -93,21 +93,28 module Redmine | |||
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | MACROS_RE = / |
|
96 | (!)? # escaping | |
|
97 | ( | |
|
96 | 98 | \{\{ # opening tag |
|
97 | 99 | ([\w]+) # macro name |
|
98 | 100 | (\(([^\}]*)\))? # optional arguments |
|
99 | 101 | \}\} # closing tag |
|
102 | ) | |
|
100 | 103 | /x unless const_defined?(:MACROS_RE) |
|
101 | 104 | |
|
102 | 105 | def inline_macros(text) |
|
103 | 106 | text.gsub!(MACROS_RE) do |
|
104 |
all, macro = $ |
|
|
105 |
args = ($ |
|
|
106 |
|
|
|
107 | @macros_runner.call(macro, args) | |
|
108 | rescue => e | |
|
109 | "<div class=\"flash error\">Error executing the <strong>#{macro}</strong> macro (#{e})</div>" | |
|
110 | end || all | |
|
107 | esc, all, macro = $1, $2, $3.downcase | |
|
108 | args = ($5 || '').split(',').each(&:strip) | |
|
109 | if esc.nil? | |
|
110 | begin | |
|
111 | @macros_runner.call(macro, args) | |
|
112 | rescue => e | |
|
113 | "<div class=\"flash error\">Error executing the <strong>#{macro}</strong> macro (#{e})</div>" | |
|
114 | end || all | |
|
115 | else | |
|
116 | all | |
|
117 | end | |
|
111 | 118 | end |
|
112 | 119 | end |
|
113 | 120 |
@@ -62,7 +62,7 module Redmine | |||
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | # Builtin macros |
|
65 |
desc " |
|
|
65 | desc "Sample macro." | |
|
66 | 66 | macro :hello_world do |obj, args| |
|
67 | 67 | "Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}") |
|
68 | 68 | end |
@@ -72,10 +72,27 module Redmine | |||
|
72 | 72 | out = '' |
|
73 | 73 | @@available_macros.keys.collect(&:to_s).sort.each do |macro| |
|
74 | 74 | out << content_tag('dt', content_tag('code', macro)) |
|
75 |
out << content_tag('dd', |
|
|
75 | out << content_tag('dd', textilizable(@@available_macros[macro.to_sym])) | |
|
76 | 76 | end |
|
77 | 77 | content_tag('dl', out) |
|
78 | 78 | end |
|
79 | ||
|
80 | desc "Include a wiki page. Example:\n\n !{{include(Foo)}}" | |
|
81 | macro :include do |obj, args| | |
|
82 | if @project && !@project.wiki.nil? | |
|
83 | page = @project.wiki.find_page(args.first) | |
|
84 | if page && page.content | |
|
85 | @included_wiki_pages ||= [] | |
|
86 | raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title) | |
|
87 | @included_wiki_pages << page.title | |
|
88 | out = textilizable(page.content, :text) | |
|
89 | @included_wiki_pages.pop | |
|
90 | out | |
|
91 | else | |
|
92 | raise "Page #{args.first} doesn't exist" | |
|
93 | end | |
|
94 | end | |
|
95 | end | |
|
79 | 96 | end |
|
80 | 97 | end |
|
81 | 98 | end |
@@ -120,6 +120,9 class ApplicationHelperTest < HelperTestCase | |||
|
120 | 120 | def test_macro_hello_world |
|
121 | 121 | text = "{{hello_world}}" |
|
122 | 122 | assert textilizable(text).match(/Hello world!/) |
|
123 | # escaping | |
|
124 | text = "!{{hello_world}}" | |
|
125 | assert_equal '<p>{{hello_world}}</p>', textilizable(text) | |
|
123 | 126 | end |
|
124 | 127 | |
|
125 | 128 | def test_date_format_default |
General Comments 0
You need to be logged in to leave comments.
Login now