commit 3b7bb74439c8850febf9bd2d10d00d71e9bf5d40 Author: Jens Kraemer Date: Fri Oct 31 09:45:32 2014 +0100 add macro docs in markdown refs #170239 diff --git a/lib/redmine/wiki_formatting/macros.rb b/lib/redmine/wiki_formatting/macros.rb index e7803af..4cec411 100644 --- a/lib/redmine/wiki_formatting/macros.rb +++ b/lib/redmine/wiki_formatting/macros.rb @@ -154,8 +154,16 @@ module Redmine 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! + @@desc = if options.blank? + args.shift + else + options[:default] = args.shift + ->(){ options[Setting.text_formatting.to_sym] || options[:default] } + end end end @@ -173,16 +181,25 @@ module Redmine 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)) 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? @@ -200,7 +217,8 @@ module Redmine 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) @@ -212,7 +230,8 @@ module Redmine 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) @@ -225,7 +244,7 @@ module Redmine out end - desc "Displays a clickable thumbnail of an attached image. Examples:\n\n
{{thumbnail(image.png)}}\n{{thumbnail(image.png, size=300, title=Thumbnail)}}
" + desc "Displays a clickable thumbnail of an attached image. Examples:\n\n
{{thumbnail(image.png)}}\n{{thumbnail(image.png, size=300, title=Thumbnail)}}
", 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 @@ -246,13 +265,22 @@ module Redmine end end - desc < +{{figure(This is a caption) +!some-image.jpg! +}} + +", markdown: " Wraps the enclosed image/thumbnail/text in a box with an optional caption. Example: -
{{figure(This is a caption)
+~~~~
+{{figure(This is a caption)
 !some-image.jpg!
-}}
-DESC +}} +~~~~ +" macro :figure do |obj, args, text| puts obj.inspect args, options = extract_macro_options(args, :size)