1 # Custom tags for JSDuck 5.x
3 # - https://github.com/senchalabs/jsduck/wiki/Custom-tags
4 # - https://github.com/senchalabs/jsduck/wiki/Custom-tags/7f5c32e568eab9edc8e3365e935bcb836cb11f1d
5 require 'jsduck/tag/tag'
7 class CommonTag
< JsDuck
::Tag::Tag
9 @html_position = POS_DOC
+ 0.1
13 def parse_doc(scanner
, _position
)
15 return { tagname
: @tagname, doc
: :multiline }
17 text
= scanner
.match(/.*$/)
18 return { tagname
: @tagname, doc
: text
}
22 def process_doc(context
, tags
, _position
)
23 context
[@tagname] = tags
26 def format(context
, formatter
)
27 context
[@tagname].each
do |tag
|
28 tag
[:doc] = formatter
.format(tag
[:doc])
33 class SourceTag
< CommonTag
41 context
[@tagname].map
do |source
|
43 <h3 class='pa'>Source</h3>
50 class SeeTag
< CommonTag
57 def format(context
, formatter
)
58 position
= context
[:files][0]
59 context
[@tagname].each
do |tag
|
60 tag
[:doc] = '<li>' + render_long_see(tag
[:doc], formatter
, position
) + '</li>'
66 <h3 class="pa">Related</h3>
68 #{context[@tagname].map { |tag| tag[:doc] }.join("\n")}
73 def render_long_see(tag
, formatter
, position
)
74 match
= /\A([^\s]+)( .*)?\Z/m
.match(tag
)
78 doc
= match
[2] ? ': ' + match
[2] : ''
79 return formatter
.format("{@link #{name}} #{doc}")
81 JsDuck
::Logger.warn(nil, 'Unexpected @see argument: "' + tag
+ '"', position
)
87 class ContextTag
< CommonTag
94 def format(context
, formatter
)
95 position
= context
[:files][0]
96 context
[@tagname].each
do |tag
|
97 tag
[:doc] = render_long_context(tag
[:doc], formatter
, position
)
103 <h3 class="pa">Context</h3>
104 #{context[@tagname].last[:doc]}
108 def render_long_context(tag
, formatter
, position
)
109 match
= /\A([^\s]+)/m
.match(tag
)
113 return formatter
.format("`context` : {@link #{name}}")
115 JsDuck
::Logger.warn(nil, 'Unexpected @context argument: "' + tag
+ '"', position
)