Skip to content
Rene Saarsoo edited this page Aug 5, 2013 · 4 revisions

We'll start our tutorial with the simplest of all - a boolean tag.

Let's define an @inner tag, which we could use to label methods which can't be accessed outside of class. For example:

/**
 * Escapes regular expression metacharacters inside a string.
 * @param {String} str Input string.
 * @return {String} Escaped string.
 * @inner
 */
function escapeRe(str) {
    ...
}

We call such tags boolean tags because they just either exist inside a doc-comment or not. And here's how to implement this one:

require "jsduck/tag/boolean_tag"

class Inner < JsDuck::Tag::BooleanTag
  def initialize
    @pattern = "inner"
    @signature = {:long => "inner", :short => "in"}
    super
  end
end

Because boolean tag is such a common pattern, there is a special BooleanTag class that we can extend. Inside the class we define an initialize method (a constructor in Ruby world), define some member variables and call the superclass method to do some additional setup.

  • @pattern defines a name of a tag to detect inside doc-comments.
  • @signature defines the labels to display in final documentation. The following screenshot should clarify the effects of it:

Screenshot of @inner tag rendering

As you can see the :long field defines the longer label to display after member name, and :short is for the label in dropdown menu.

Just this small label "inner" might not be enough - so continue with the next chapter to add some additional HTML output.

Clone this wiki locally