Merge "Link to mediawiki.org page in 'edithelppage' message"
[lhc/web/wiklou.git] / maintenance / jsduck / MetaTags.rb
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'
5
6 class SourceTag < JsDuck::MetaTag
7 def initialize
8 # This defines the name of the @tag
9 @name = 'source'
10 end
11
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
21
22 class ContextTag < JsDuck::MetaTag
23 def initialize
24 @name = 'context'
25 end
26
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
31
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
39
40 class SeeTag < JsDuck::MetaTag
41 def initialize
42 @name = 'see'
43 @multiline = true
44 end
45
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
57
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