Module: Redmine::WikiFormatting::Macros::Definitions

Included in:
ApplicationHelper
Defined in:
lib/redmine/wiki_formatting/macros.rb

Instance Method Summary collapse

Instance Method Details

#exec_macro(name, obj, args, text) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/redmine/wiki_formatting/macros.rb', line 27

def exec_macro(name, obj, args, text)
  macro_options = Redmine::WikiFormatting::Macros.available_macros[name.to_sym]
  return unless macro_options

  method_name = "macro_#{name}"
  unless macro_options[:parse_args] == false
    args = args.split(',').map(&:strip)
  end

  begin
    if self.class.instance_method(method_name).arity == 3
      send(method_name, obj, args, text)
    elsif text
      raise "This macro does not accept a block of text"
    else
      send(method_name, obj, args)
    end
  rescue => e
    "<div class=\"flash error\">Error executing the <strong>#{h name}</strong> macro (#{h e.to_s})</div>".html_safe
  end
end

#extract_macro_options(args, *keys) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/redmine/wiki_formatting/macros.rb', line 49

def extract_macro_options(args, *keys)
  options = {}
  while args.last.to_s.strip =~ %r{^(.+?)\=(.+)$} && keys.include?($1.downcase.to_sym)
    options[$1.downcase.to_sym] = $2
    args.pop
  end
  return [args, options]
end

#macro_exists?(name) ⇒ Boolean

Returns true if name is the name of an existing macro

Returns:

  • (Boolean)


23
24
25
# File 'lib/redmine/wiki_formatting/macros.rb', line 23

def macro_exists?(name)
  Redmine::WikiFormatting::Macros.available_macros.key?(name.to_sym)
end