Merge changes I48dcf831,I8922b80e
[mediawiki.git] / maintenance / jsduck / MetaTags.rb
blob83cc0884ce3facefd324eba6a61ab871fe835d98
1 # See also:
2 # - https://github.com/senchalabs/jsduck/wiki/Tags
3 # - https://github.com/senchalabs/jsduck/wiki/Custom-tags
4 require 'jsduck/meta_tag'
6 class SourceTag < JsDuck::MetaTag
7   def initialize
8     # This defines the name of the @tag
9     @name = 'source'
10   end
12   # Generate HTML output for this tag.
13   # One can make use of the #format method to easily support
14   # Markdown and {@link} tags inside the contents of the tag.
15   #
16   # @param tags All matches of this tag on one class.
17   def to_html(tags)
18     '<h3 class="pa">Source</h3>' + tags.map {|tag| format(tag) }.join("\n")
19   end
20 end
22 class ContextTag < JsDuck::MetaTag
23   def initialize
24     @name = 'context'
25   end
27   # @param tags All matches of this tag on one class.
28   def to_html(tags)
29     return '<h3 class="pa">Context</h3>' +  render_long_context(tags.last)
30   end
32   def render_long_context(tag)
33     if tag =~ /\A([^\s]+)/m
34       name = $1
35       return format("`this` : {@link #{name}}")
36     end
37   end
38 end
40 class SeeTag < JsDuck::MetaTag
41   def initialize
42     @name = 'see'
43     @multiline = true
44   end
46   # @param tags All matches of this tag on one class.
47   def to_html(tags)
48     doc = []
49     doc << '<h3 class="pa">Related</h3>'
50     doc << [
51         '<ul>',
52         tags.map {|tag| render_long_see(tag) },
53         '</ul>',
54       ]
55     doc
56   end
58   def render_long_see(tag)
59     if tag =~ /\A([^\s]+)( .*)?\Z/m
60       name = $1
61       doc = $2 ? ': ' + $2 : ''
62       return [
63         '<li>',
64         format("{@link #{name}} #{doc}"),
65         '</li>'
66       ]
67     end
68   end
69 end