@@ -48,7 +48,7 module Redmine | |||||
48 |
|
48 | |||
49 | def extract_macro_options(args, *keys) |
|
49 | def extract_macro_options(args, *keys) | |
50 | options = {} |
|
50 | options = {} | |
51 | while args.last.to_s.strip =~ %r{^(.+)\=(.+)$} && keys.include?($1.downcase.to_sym) |
|
51 | while args.last.to_s.strip =~ %r{^(.+?)\=(.+)$} && keys.include?($1.downcase.to_sym) | |
52 | options[$1.downcase.to_sym] = $2 |
|
52 | options[$1.downcase.to_sym] = $2 | |
53 | args.pop |
|
53 | args.pop | |
54 | end |
|
54 | end |
@@ -100,6 +100,25 class Redmine::WikiFormatting::MacrosTest < ActionView::TestCase | |||||
100 | assert_equal '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>', textilizable(text, :object => Issue.find(1)) |
|
100 | assert_equal '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>', textilizable(text, :object => Issue.find(1)) | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
|
103 | def test_extract_macro_options_should_with_args | |||
|
104 | options = extract_macro_options(["arg1", "arg2"], :foo, :size) | |||
|
105 | assert_equal([["arg1", "arg2"], {}], options) | |||
|
106 | end | |||
|
107 | ||||
|
108 | def test_extract_macro_options_should_with_options | |||
|
109 | options = extract_macro_options(["foo=bar", "size=2"], :foo, :size) | |||
|
110 | assert_equal([[], {:foo => "bar", :size => "2"}], options) | |||
|
111 | end | |||
|
112 | ||||
|
113 | def test_extract_macro_options_should_with_args_and_options | |||
|
114 | options = extract_macro_options(["arg1", "arg2", "foo=bar", "size=2"], :foo, :size) | |||
|
115 | assert_equal([["arg1", "arg2"], {:foo => "bar", :size => "2"}], options) | |||
|
116 | end | |||
|
117 | ||||
|
118 | def test_extract_macro_options_should_parse_options_lazily | |||
|
119 | options = extract_macro_options(["params=x=1&y=2"], :params) | |||
|
120 | assert_equal([[], {:params => "x=1&y=2"}], options) | |||
|
121 | end | |||
103 |
|
122 | |||
104 | def test_macro_exception_should_be_displayed |
|
123 | def test_macro_exception_should_be_displayed | |
105 | Redmine::WikiFormatting::Macros.macro :exception do |obj, args| |
|
124 | Redmine::WikiFormatting::Macros.macro :exception do |obj, args| |
General Comments 0
You need to be logged in to leave comments.
Login now