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 SeeTag
< CommonTag
40 def format(context
, formatter
)
41 position
= context
[:files][0]
42 context
[@tagname].each
do |tag
|
43 tag
[:doc] = '<li>' + render_long_see(tag
[:doc], formatter
, position
) + '</li>'
49 <h3 class="pa">Related</h3>
51 #{context[@tagname].map { |tag| tag[:doc] }.join("\n")}
56 def render_long_see(tag
, formatter
, position
)
57 match
= /\A([^\s]+)( .*)?\Z/m
.match(tag
)
61 doc
= match
[2] ? ': ' + match
[2] : ''
62 return formatter
.format("{@link #{name}} #{doc}")
64 JsDuck
::Logger.warn(nil, 'Unexpected @see argument: "' + tag
+ '"', position
)
70 class ContextTag
< CommonTag
77 def format(context
, formatter
)
78 position
= context
[:files][0]
79 context
[@tagname].each
do |tag
|
80 tag
[:doc] = render_long_context(tag
[:doc], formatter
, position
)
86 <h3 class="pa">Context</h3>
87 #{context[@tagname].last[:doc]}
91 def render_long_context(tag
, formatter
, position
)
92 match
= /\A([^\s]+)/m
.match(tag
)
96 return formatter
.format("`context` : {@link #{name}}")
98 JsDuck
::Logger.warn(nil, 'Unexpected @context argument: "' + tag
+ '"', position
)