Validate macro name and options.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10211 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
fc3a09e49a
commit
29d54f5d50
|
@ -125,10 +125,16 @@ module Redmine
|
||||||
# # args is a string
|
# # args is a string
|
||||||
# end
|
# end
|
||||||
def macro(name, options={}, &block)
|
def macro(name, options={}, &block)
|
||||||
|
options.assert_valid_keys(:desc, :parse_args)
|
||||||
|
unless name.to_s.match(/\A\w+\z/)
|
||||||
|
raise "Invalid macro name: #{name} (only 0-9, A-Z, a-z and _ characters are accepted)"
|
||||||
|
end
|
||||||
|
unless block_given?
|
||||||
|
raise "Can not create a macro without a block!"
|
||||||
|
end
|
||||||
name = name.to_sym if name.is_a?(String)
|
name = name.to_sym if name.is_a?(String)
|
||||||
available_macros[name] = {:desc => @@desc || ''}.merge(options)
|
available_macros[name] = {:desc => @@desc || ''}.merge(options)
|
||||||
@@desc = nil
|
@@desc = nil
|
||||||
raise "Can not create a macro without a block!" unless block_given?
|
|
||||||
Definitions.send :define_method, "macro_#{name}".downcase, &block
|
Definitions.send :define_method, "macro_#{name}".downcase, &block
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue