diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-08-17 14:46:55 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-08-17 14:46:55 +0000 |
commit | 73aece0bafb918468d89c00550aaaed35c1d2efb (patch) | |
tree | 41fb309e46eb172b1391d1256a04fe90ce6a0a9d /lib/redmine/wiki_formatting/macros.rb | |
parent | af5a814f4cf11d3c288b00e0b7b9d89b7a5ef74d (diff) | |
download | redmine-73aece0bafb918468d89c00550aaaed35c1d2efb.tar.gz redmine-73aece0bafb918468d89c00550aaaed35c1d2efb.zip |
Macros processing overhaul (#3061, #11633).
* macro arguments are no longer parsed by text formatters
* macro output is escaped unless it's html safe
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10209 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/wiki_formatting/macros.rb')
-rw-r--r-- | lib/redmine/wiki_formatting/macros.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/redmine/wiki_formatting/macros.rb b/lib/redmine/wiki_formatting/macros.rb index 708e2280a..55bde5e29 100644 --- a/lib/redmine/wiki_formatting/macros.rb +++ b/lib/redmine/wiki_formatting/macros.rb @@ -19,6 +19,11 @@ module Redmine module WikiFormatting module Macros module Definitions + # Returns true if +name+ is the name of an existing macro + def macro_exists?(name) + Redmine::WikiFormatting::Macros.available_macros.key?(name.to_sym) + end + def exec_macro(name, obj, args) macro_options = Redmine::WikiFormatting::Macros.available_macros[name.to_sym] return unless macro_options @@ -27,7 +32,12 @@ module Redmine unless macro_options[:parse_args] == false args = args.split(',').map(&:strip) end - send(method_name, obj, args) if respond_to?(method_name) + + begin + send(method_name, obj, args) if respond_to?(method_name) + rescue => e + "<div class=\"flash error\">Error executing the <strong>#{h name}</strong> macro (#{h e.to_s})</div>".html_safe + end end def extract_macro_options(args, *keys) @@ -97,7 +107,7 @@ module Redmine # Builtin macros desc "Sample macro." macro :hello_world do |obj, args| - "Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}") + h("Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}")) end desc "Displays a list of all available macros, including description if available." |