Merge "(Bug 60030) Use $content of the hook for toc hiding"
[lhc/web/wiklou.git] / maintenance / jsduck / MetaTags.rb
1 # Custom tags for JSDuck 4.x
2 # See also:
3 # - https://github.com/senchalabs/jsduck/wiki/Tags
4 # - https://github.com/senchalabs/jsduck/wiki/Custom-tags
5 # - https://github.com/senchalabs/jsduck/wiki/Custom-tags/7f5c32e568eab9edc8e3365e935bcb836cb11f1d
6 require 'jsduck/meta_tag'
7
8 class SourceTag < JsDuck::MetaTag
9 def initialize
10 # This defines the name of the @tag
11 @name = 'source'
12 end
13
14 # Generate HTML output for this tag.
15 # One can make use of the #format method to easily support
16 # Markdown and {@link} tags inside the contents of the tag.
17 #
18 # @param tags All matches of this tag on one class.
19 def to_html(tags)
20 '<h3 class="pa">Source</h3>' + tags.map {|tag| format(tag) }.join("\n")
21 end
22 end
23
24 class ContextTag < JsDuck::MetaTag
25 def initialize
26 @name = 'context'
27 end
28
29 # @param tags All matches of this tag on one class.
30 def to_html(tags)
31 return '<h3 class="pa">Context</h3>' + render_long_context(tags.last)
32 end
33
34 def render_long_context(tag)
35 if tag =~ /\A([^\s]+)/m
36 name = $1
37 return format("`this` : {@link #{name}}")
38 end
39 end
40 end
41
42 class SeeTag < JsDuck::MetaTag
43 def initialize
44 @name = 'see'
45 @multiline = true
46 end
47
48 # @param tags All matches of this tag on one class.
49 def to_html(tags)
50 doc = []
51 doc << '<h3 class="pa">Related</h3>'
52 doc << [
53 '<ul>',
54 tags.map {|tag| render_long_see(tag) },
55 '</ul>',
56 ]
57 doc
58 end
59
60 def render_long_see(tag)
61 if tag =~ /\A([^\s]+)( .*)?\Z/m
62 name = $1
63 doc = $2 ? ': ' + $2 : ''
64 return [
65 '<li>',
66 format("{@link #{name}} #{doc}"),
67 '</li>'
68 ]
69 end
70 end
71 end
72
73 # As of JSDuck 5 this is in core
74 class FiresTag < JsDuck::MetaTag
75 def initialize
76 @name = 'fires'
77 @multiline = true
78 end
79
80 # @param tags All matches of this tag on one class.
81 def to_html(tags)
82 doc = []
83 doc << '<h3 class="pa">Fires</h3>'
84 doc << [
85 '<ul>',
86 tags.map {|tag| render_long_event(tag) },
87 '</ul>',
88 ]
89 doc
90 end
91
92 def render_long_event(tag)
93 if tag =~ /\A(\w+)( .*)?\Z/m
94 name = $1
95 doc = $2 ? ': ' + $2 : ''
96 return [
97 '<li>',
98 format("{@link #event-#{name}} #{doc}"),
99 '</li>'
100 ]
101 end
102 end
103 end