Feature #18257 » 18257.diff
| lib/redmine/wiki_formatting/macros.rb | ||
|---|---|---|
|
end
|
||
|
# Sets description for the next macro to be defined
|
||
|
def desc(txt)
|
||
|
@@desc = txt
|
||
|
# For complex descriptions that use textile syntax, you may also
|
||
|
# provide a markdown equivalent using the :markdown option.
|
||
|
def desc(*args)
|
||
|
options = args.extract_options!
|
||
|
options.symbolize_keys!
|
||
|
if default = args.shift
|
||
|
options[:default] = default
|
||
|
end
|
||
|
@@desc = ->(){
|
||
|
options[Setting.text_formatting.to_sym] || options[:default]
|
||
|
}
|
||
|
end
|
||
|
end
|
||
| ... | ... | |
|
out = ''.html_safe
|
||
|
@@available_macros.each do |macro, options|
|
||
|
out << content_tag('dt', content_tag('code', macro.to_s))
|
||
|
out << content_tag('dd', textilizable(options[:desc]))
|
||
|
desc = options[:desc]
|
||
|
desc = desc.call if desc.respond_to?(:call)
|
||
|
out << content_tag('dd', textilizable(desc.to_s))
|
||
|
end
|
||
|
content_tag('dl', out)
|
||
|
end
|
||
|
desc "Displays a list of child pages. With no argument, it displays the child pages of the current wiki page. Examples:\n\n" +
|
||
|
" !{{child_pages}} -- can be used from a wiki page only\n" +
|
||
|
" !{{child_pages(depth=2)}} -- display 2 levels nesting only\n"
|
||
|
" !{{child_pages(depth=2)}} -- display 2 levels nesting only\n" +
|
||
|
" !{{child_pages(Foo)}} -- lists all children of page Foo\n" +
|
||
|
" !{{child_pages(Foo, parent=1)}} -- same as above with a link to page Foo"
|
||
|
" !{{child_pages(Foo, parent=1)}} -- same as above with a link to page Foo",
|
||
|
markdown:("Displays a list of child pages. With no argument, it displays the child pages of the current wiki page. Examples:\n\n" +
|
||
|
"~~~~\n" +
|
||
|
"!{{child_pages}} -- can be used from a wiki page only\n" +
|
||
|
"!{{child_pages(depth=2)}} -- display 2 levels nesting only\n" +
|
||
|
"!{{child_pages(Foo)}} -- lists all children of page Foo\n" +
|
||
|
"!{{child_pages(Foo, parent=1)}} -- same as above with a link to page Foo\n" +
|
||
|
"~~~~\n\n")
|
||
|
macro :child_pages do |obj, args|
|
||
|
args, options = extract_macro_options(args, :parent, :depth)
|
||
|
options[:depth] = options[:depth].to_i if options[:depth].present?
|
||
| ... | ... | |
|
render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id)
|
||
|
end
|
||
|
desc "Include a wiki page. Example:\n\n !{{include(Foo)}}\n\nor to include a page of a specific project wiki:\n\n !{{include(projectname:Foo)}}"
|
||
|
desc "Include a wiki page. Example:\n\n !{{include(Foo)}}\n\nor to include a page of a specific project wiki:\n\n !{{include(projectname:Foo)}}",
|
||
|
markdown: "Include a wiki page. Example:\n\n~~~~\n!{{include(Foo)}}\n~~~~\n\nor to include a page of a specific project wiki:\n\n~~~~\n!{{include(projectname:Foo)}}\n~~~~\n"
|
||
|
macro :include do |obj, args|
|
||
|
page = Wiki.find_page(args.first.to_s, :project => @project)
|
||
|
raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
|
||
| ... | ... | |
|
out
|
||
|
end
|
||
|
desc "Inserts of collapsed block of text. Example:\n\n {{collapse(View details...)\nThis is a block of text that is collapsed by default.\nIt can be expanded by clicking a link.\n}}"
|
||
|
desc "Inserts of collapsed block of text. Example:\n\n {{collapse(View details...)\nThis is a block of text that is collapsed by default.\nIt can be expanded by clicking a link.\n}}",
|
||
|
markdown: "Inserts of collapsed block of text. Example:\n\n~~~~\n{{collapse(View details...)\nThis is a block of text that is collapsed by default.\nIt can be expanded by clicking a link.\n}}\n~~~~\n"
|
||
|
macro :collapse do |obj, args, text|
|
||
|
html_id = "collapse-#{Redmine::Utils.random_hex(4)}"
|
||
|
show_label = args[0] || l(:button_show)
|
||
| ... | ... | |
|
out
|
||
|
end
|
||
|
desc "Displays a clickable thumbnail of an attached image. Examples:\n\n<pre>{{thumbnail(image.png)}}\n{{thumbnail(image.png, size=300, title=Thumbnail)}}</pre>"
|
||
|
desc "Displays a clickable thumbnail of an attached image. Examples:\n\n<pre>{{thumbnail(image.png)}}\n{{thumbnail(image.png, size=300, title=Thumbnail)}}</pre>", markdown: "Displays a clickable thumbnail of an attached image. Examples:\n\n~~~~\n{{thumbnail(image.png)}}\n{{thumbnail(image.png, size=300, title=Thumbnail)}}\n~~~~\n"
|
||
|
macro :thumbnail do |obj, args|
|
||
|
args, options = extract_macro_options(args, :size, :title)
|
||
|
filename = args.first
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
desc <<DESC
|
||
|
desc "Wraps the enclosed image/thumbnail/text in a box with an optional caption. Example:
|
||
|
<pre>
|
||
|
{{figure(This is a caption)
|
||
|
!some-image.jpg!
|
||
|
}}
|
||
|
</pre>
|
||
|
", markdown: "
|
||
|
Wraps the enclosed image/thumbnail/text in a box with an optional caption. Example:
|
||
|
<pre>{{figure(This is a caption)
|
||
|
~~~~
|
||
|
{{figure(This is a caption)
|
||
|
!some-image.jpg!
|
||
|
}}</pre>
|
||
|
DESC
|
||
|
}}
|
||
|
~~~~
|
||
|
"
|
||
|
macro :figure do |obj, args, text|
|
||
|
puts obj.inspect
|
||
|
args, options = extract_macro_options(args, :size)
|
||
|
caption = args.first
|
||
|
content_tag :figure do
|
||
| test/unit/lib/redmine/wiki_formatting/macros_test.rb | ||
|---|---|---|
|
end
|
||
|
def teardown
|
||
|
Setting.text_formatting = @original_formatting if @original_formatting
|
||
|
end
|
||
|
def test_macro_description_markup
|
||
|
Redmine::WikiFormatting::Macros.register do
|
||
|
desc 'textile default docs', markdown: 'markdown docs'
|
||
|
macro :foo do |obj, args|
|
||
|
"Foo: #{args.size} (#{args.join(',')}) (#{args.class.name})"
|
||
|
end
|
||
|
end
|
||
|
@original_formatting = Setting.text_formatting
|
||
|
Setting.text_formatting = 'plain'
|
||
|
assert_match /textile default docs/, textilizable('{{macro_list}}')
|
||
|
Setting.text_formatting = 'textile'
|
||
|
assert_match /textile default docs/, textilizable('{{macro_list}}')
|
||
|
Setting.text_formatting = 'markdown'
|
||
|
assert_match /markdown docs/, textilizable('{{macro_list}}')
|
||
|
end
|
||
|
def test_macro_registration
|
||
- « Previous
- 1
- 2
- Next »