Commit 5a31be6f authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Render "Defaults to:" text inside Tag::Default.

parent 98a2d4ee
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -220,10 +220,6 @@ module JsDuck

      doc << m[:doc]

      if m[:default] && m[:default] != "undefined"
        doc << "<p>Defaults to: <code>" + Util::HTML.escape(m[:default]) + "</code></p>"
      end

      doc << render_tags(m, :bottom)

      doc << render_params_and_return(m)
+10 −1
Original line number Diff line number Diff line
require "jsduck/tag/tag"
require "jsduck/docs_code_comparer"
require "jsduck/util/html"

module JsDuck::Tag
  # There is no @default tag.
@@ -9,14 +10,22 @@ module JsDuck::Tag
  #     @cfg [blah=somedefault]
  #
  # This tag class exists to take care of the merging of :default
  # fields.
  # fields and to generate the "Defaults to:" text in final HTML.
  class Default < Tag
    def initialize
      @key = :default
      @merge_context = [:cfg, :property, :css_var]
      @html_position = :bottom
    end

    def merge(h, docs, code)
      h[:default] = JsDuck::DocsCodeComparer.merge_if_matches(:default, docs, code)
    end

    def to_html(m)
      return if m[:default] == "undefined"

      "<p>Defaults to: <code>" + JsDuck::Util::HTML.escape(m[:default]) + "</code></p>"
    end
  end
end