##// END OF EJS Templates
Added:...
Jean-Philippe Lang -
r1139:05823373724e
parent child
Show More
@@ -93,21 +93,28 module Redmine
93 end
93 end
94
94
95 MACROS_RE = /
95 MACROS_RE = /
96 (!)? # escaping
97 (
96 \{\{ # opening tag
98 \{\{ # opening tag
97 ([\w]+) # macro name
99 ([\w]+) # macro name
98 (\(([^\}]*)\))? # optional arguments
100 (\(([^\}]*)\))? # optional arguments
99 \}\} # closing tag
101 \}\} # closing tag
102 )
100 /x unless const_defined?(:MACROS_RE)
103 /x unless const_defined?(:MACROS_RE)
101
104
102 def inline_macros(text)
105 def inline_macros(text)
103 text.gsub!(MACROS_RE) do
106 text.gsub!(MACROS_RE) do
104 all, macro = $&, $1.downcase
107 esc, all, macro = $1, $2, $3.downcase
105 args = ($3 || '').split(',').each(&:strip)
108 args = ($5 || '').split(',').each(&:strip)
106 begin
109 if esc.nil?
107 @macros_runner.call(macro, args)
110 begin
108 rescue => e
111 @macros_runner.call(macro, args)
109 "<div class=\"flash error\">Error executing the <strong>#{macro}</strong> macro (#{e})</div>"
112 rescue => e
110 end || all
113 "<div class=\"flash error\">Error executing the <strong>#{macro}</strong> macro (#{e})</div>"
114 end || all
115 else
116 all
117 end
111 end
118 end
112 end
119 end
113
120
@@ -62,7 +62,7 module Redmine
62 end
62 end
63
63
64 # Builtin macros
64 # Builtin macros
65 desc "Example macro."
65 desc "Sample macro."
66 macro :hello_world do |obj, args|
66 macro :hello_world do |obj, args|
67 "Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}")
67 "Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}")
68 end
68 end
@@ -72,10 +72,27 module Redmine
72 out = ''
72 out = ''
73 @@available_macros.keys.collect(&:to_s).sort.each do |macro|
73 @@available_macros.keys.collect(&:to_s).sort.each do |macro|
74 out << content_tag('dt', content_tag('code', macro))
74 out << content_tag('dt', content_tag('code', macro))
75 out << content_tag('dd', simple_format(@@available_macros[macro.to_sym]))
75 out << content_tag('dd', textilizable(@@available_macros[macro.to_sym]))
76 end
76 end
77 content_tag('dl', out)
77 content_tag('dl', out)
78 end
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 end
96 end
80 end
97 end
81 end
98 end
@@ -120,6 +120,9 class ApplicationHelperTest < HelperTestCase
120 def test_macro_hello_world
120 def test_macro_hello_world
121 text = "{{hello_world}}"
121 text = "{{hello_world}}"
122 assert textilizable(text).match(/Hello world!/)
122 assert textilizable(text).match(/Hello world!/)
123 # escaping
124 text = "!{{hello_world}}"
125 assert_equal '<p>{{hello_world}}</p>', textilizable(text)
123 end
126 end
124
127
125 def test_date_format_default
128 def test_date_format_default
General Comments 0
You need to be logged in to leave comments. Login now