Project

General

Profile

Feature #18257 » 18257.diff

Jens Krämer, 2014-11-14 02:52

View differences:

lib/redmine/wiki_formatting/macros.rb
154 154
        end
155 155

  
156 156
        # Sets description for the next macro to be defined
157
        def desc(txt)
158
          @@desc = txt
157
        # For complex descriptions that use textile syntax, you may also
158
        # provide a markdown equivalent using the :markdown option.
159
        def desc(*args)
160
          options = args.extract_options!
161
          @@desc = if options.blank?
162
            args.shift
163
          else
164
            options[:default] = args.shift
165
            ->(){ options[Setting.text_formatting.to_sym] || options[:default] }
166
          end
159 167
        end
160 168
      end
161 169

  
......
173 181
        out = ''.html_safe
174 182
        @@available_macros.each do |macro, options|
175 183
          out << content_tag('dt', content_tag('code', macro.to_s))
176
          out << content_tag('dd', textilizable(options[:desc]))
184
          desc = options[:desc]
185
          desc = desc.call if desc.respond_to?(:call)
186
          out << content_tag('dd', textilizable(desc))
177 187
        end
178 188
        content_tag('dl', out)
179 189
      end
180 190

  
181 191
      desc "Displays a list of child pages. With no argument, it displays the child pages of the current wiki page. Examples:\n\n" +
182 192
             "  !{{child_pages}} -- can be used from a wiki page only\n" +
183
             "  !{{child_pages(depth=2)}} -- display 2 levels nesting only\n"
193
             "  !{{child_pages(depth=2)}} -- display 2 levels nesting only\n" +
184 194
             "  !{{child_pages(Foo)}} -- lists all children of page Foo\n" +
185
             "  !{{child_pages(Foo, parent=1)}} -- same as above with a link to page Foo"
195
             "  !{{child_pages(Foo, parent=1)}} -- same as above with a link to page Foo",
196
           markdown:("Displays a list of child pages. With no argument, it displays the child pages of the current wiki page. Examples:\n\n" +
197
             "~~~~\n" +
198
             "!{{child_pages}} -- can be used from a wiki page only\n" +
199
             "!{{child_pages(depth=2)}} -- display 2 levels nesting only\n" +
200
             "!{{child_pages(Foo)}} -- lists all children of page Foo\n" +
201
             "!{{child_pages(Foo, parent=1)}} -- same as above with a link to page Foo\n" +
202
             "~~~~\n\n")
186 203
      macro :child_pages do |obj, args|
187 204
        args, options = extract_macro_options(args, :parent, :depth)
188 205
        options[:depth] = options[:depth].to_i if options[:depth].present?
......
200 217
        render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id)
201 218
      end
202 219

  
203
      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)}}"
220
      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)}}",
221
        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"
204 222
      macro :include do |obj, args|
205 223
        page = Wiki.find_page(args.first.to_s, :project => @project)
206 224
        raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
......
212 230
        out
213 231
      end
214 232

  
215
      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}}"
233
      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}}",
234
        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"
216 235
      macro :collapse do |obj, args, text|
217 236
        html_id = "collapse-#{Redmine::Utils.random_hex(4)}"
218 237
        show_label = args[0] || l(:button_show)
......
225 244
        out
226 245
      end
227 246

  
228
      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>"
247
      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"
229 248
      macro :thumbnail do |obj, args|
230 249
        args, options = extract_macro_options(args, :size, :title)
231 250
        filename = args.first
......
246 265
        end
247 266
      end
248 267

  
249
      desc <<DESC
268
      desc "Wraps the enclosed image/thumbnail/text in a box with an optional caption. Example:
269

  
270
<pre>
271
{{figure(This is a caption)
272
!some-image.jpg!
273
}}
274
</pre>
275
", markdown: "
250 276
Wraps the enclosed image/thumbnail/text in a box with an optional caption. Example:
251 277

  
252
<pre>{{figure(This is a caption)
278
~~~~
279
{{figure(This is a caption)
253 280
!some-image.jpg!
254
}}</pre>
255
DESC
281
}}
282
~~~~
283
"
256 284
      macro :figure do |obj, args, text|
257 285
        puts obj.inspect
258 286
        args, options = extract_macro_options(args, :size)
(1-1/2)