Class | YARD::Tags::Library |
In: |
lib/yard/tags/library.rb
|
Parent: | Object |
Keeps track of all the registered meta-data tags and directives. Also allows for defining of custom tags and customizing the tag parsing syntax.
To define a custom tag, use {define_tag}. You should pass the tag name and the factory method to use when creating the tag. If you do not provide a factory method to use, it will default to {DefaultFactory#parse_tag}
You can also define tag objects manually by simply implementing a "tagname_tag" method that returns a {Tag} object, but they will not take advantage of tag factory parsing:
def mytag_tag(text) Tag.new(:mytag, text) end
Directives can be defined by calling the {define_directive} method, taking the directive name, an optional tag factory parser method (to parse the data in the directive into a temporary {Tag} object) and a {Directive} subclass that performs the directive processing. For more information on creating a Directive subclass, see the {Directive} class documentation.
Similar to tags, Directives can also be defined manually, in this case using the method name "mydirective_directive" and returning a new {Directive} object:
def mydirective_directive(tag, parser) MyDirective.new(tag, parser) end
In YARD 0.8.0+, tags can be namespaced using the ’.’ character. It is recommended to namespace project specific tags, like +@yard.tag_name+, so that tags do not collide with other plugins or new built-in tags.
If you have specialized tag parsing needs you can substitute the {factory} object with your own by setting {Library.default_factory= Library.default_factory} to a new class with its own parsing methods before running YARD. This is useful if you want to change the syntax of existing tags (@see, @since, etc.)
@example Defining a custom tag
define_tag "Parameter", :param, :with_types_and_name define_tag "Author", :author
@example Defining a custom directive
define_directive :method, :with_title_and_text, MethodDirective
@see DefaultFactory @see define_tag @see define_directive @see Directive
factory | [RW] | A factory class to handle parsing of tags, defaults to {default_factory} |
labels | [R] |
@return [SymbolHash{Symbol=>String}] the map of tag names and their
respective display labels. |
transitive_tags | [RW] |
Sets the list of tags that should apply to any children inside the
namespace they are defined in. For instance, a "@since" tag should
apply to all methods inside a module it is defined in. Transitive tags can
be overridden by directly defining a tag on the child object.
@return [Array<Symbol>] a list of transitive tags @since 0.6.0 |
visible_tags | [RW] |
Sets the list of tags to display when rendering templates. The order of
tags in the list is also significant, as it represents the order that tags
are displayed in templates.
You can use the {Array#place} to insert new tags to be displayed in the templates at specific positions: Library.visible_tags.place(:mytag).before(:return) @return [Array<Symbol>] a list of ordered tags @since 0.6.0 |
@!attribute default_factory Replace the factory object responsible for parsing tags by setting this to an object (or class) that responds to parse_TAGNAME methods where TAGNAME is the name of the tag.
You should set this value before performing any source parsing with YARD, otherwise your factory class will not be used.
@example
YARD::Tags::Library.default_factory = MyFactory
@param [Class, Object] factory the factory that parses all tags
@see DefaultFactory
@macro [attach] yard.directive
@!method $1_directive @!visibility private @yard.directive $1 [$2] $-1
@overload define_directive(tag, tag_meth = nil, directive_class)
Convenience method to define a new directive using a {Tag} factory method and {Directive} subclass that implements the directive callbacks. @param [#to_s] tag the tag name of the directive @param [#to_s] tag_meth the tag factory method to use when parsing tag information @param [Class<Directive>] the directive class that implements the directive behaviour @see define_tag
Convenience method to define a new tag using one of {Tag}’s factory methods, or the regular {DefaultFactory#parse_tag} factory method if none is supplied.
@!macro [attach] yard.tag
@!method $2_tag @!visibility private @yard.tag $2 [$3] $1
@param [to_s] label the label used when displaying the tag in templates @param [to_s] tag the tag name to create @param [to_s, Class<Tag>] meth the {Tag} factory method to call when
creating the tag or the name of the class to directly create a tag for
Returns the factory method used to parse the tag text for a specific tag
@param [Symbol] tag the tag name @return [Symbol] the factory method name for the tag @return [Class<Tag>,Symbol] the Tag class to use to parse the tag
or the method to call on the factory class
@return [nil] if the tag is freeform text @since 0.6.0
Returns the factory method used to parse the tag text for a specific directive
@param [Symbol] directive the directive name @return [Symbol] the factory method name for the tag @return [Class<Tag>,Symbol] the Tag class to use to parse the tag or
the methods to call on the factory class
@return [nil] if the tag is freeform text @since 0.8.0
Creates a new directive with tag information and a docstring parser object. @param [String] tag_name the name of the tag @param [String] tag_buf the tag data @param [DocstringParser] parser the parser object parsing the docstring @return [Directive] the newly created directive
@param [to_s] tag_name the name of the tag to look for @return [Boolean] whether a directive by the given name is registered in
the library.
@param [to_s] tag_name the name of the tag to look for @return [Boolean] whether a tag by the given name is registered in
the library.