From bade1737e3327196d55d16db3b100cf1fd4a0da2 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 14 Oct 2011 17:40:56 +0200 Subject: [PATCH] make view (ActionView::Base) available to macros --- app/helpers/application_helper.rb | 2 +- lib/redmine/wiki_formatting/macros.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1f7d786cba..cd64295932 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -459,7 +459,7 @@ module ApplicationHelper project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) only_path = options.delete(:only_path) == false ? false : true - text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) } + text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args, :view => self) } @parsed_headings = [] text = parse_non_pre_blocks(text) do |text| diff --git a/lib/redmine/wiki_formatting/macros.rb b/lib/redmine/wiki_formatting/macros.rb index 8c01eac05d..6e2b91fac8 100644 --- a/lib/redmine/wiki_formatting/macros.rb +++ b/lib/redmine/wiki_formatting/macros.rb @@ -16,9 +16,15 @@ module Redmine module WikiFormatting module Macros module Definitions - def exec_macro(name, obj, args) + def exec_macro(name, obj, args, options={}) method_name = "macro_#{name}" - send(method_name, obj, args) if respond_to?(method_name) + if respond_to?(method_name) + if method(method_name).arity == 2 + send(method_name, obj, args) + else + send(method_name, obj, args, options) + end + end end def extract_macro_options(args, *keys)