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, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/redmine/wiki_formatting/macros.rb', line 29

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

  if options[:inline_attachments] == false
    Redmine::WikiFormatting::Macros.inline_attachments = false
  else
    Redmine::WikiFormatting::Macros.inline_attachments = true
  end

  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 t(:error_macro_does_not_accept_block)
    else
      send(method_name, obj, args)
    end
  rescue => e
    %|<div class="flash error">#{t(:error_can_not_execute_macro_html, :name => name, :error => e.to_s)}</div>|.html_safe
  end
end

#extract_macro_options(args, *keys) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/redmine/wiki_formatting/macros.rb', line 57

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)


25
26
27
# File 'lib/redmine/wiki_formatting/macros.rb', line 25

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