Commit 117ca608 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Create Tag::Doc for formatting the main description.

For now we're also introducing a special html_position=:doc.
But the next step will be to get rid of that.
parent 941585d1
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -24,10 +24,9 @@ module JsDuck
      @cls = cls
      @formatter.class_context = cls[:name]
      @formatter.doc_context = cls[:files][0]
      cls[:doc] = @formatter.format(cls[:doc]) if cls[:doc]
      format_tags(cls)
      # format all members (except hidden ones)
      cls[:members] = cls[:members].map {|m| m[:hide] ? m : format_member(m)  }
      format_tags_data(cls)
      cls
    end

@@ -40,7 +39,7 @@ module JsDuck

    def format_member(m)
      @formatter.doc_context = m[:files][0]
      m[:doc] = @formatter.format(m[:doc]) if m[:doc]
      format_tags(m)
      if expandable?(m) || Shortener.too_long?(m[:doc])
        m[:shortDoc] = Shortener.shorten(m[:doc])
      end
@@ -53,7 +52,6 @@ module JsDuck
      m[:return] = format_item(m[:return], is_css_tag) if m[:return]
      m[:throws] = m[:throws].map {|t| format_item(t, is_css_tag) } if m[:throws]
      m[:properties] = m[:properties].map {|b| format_item(b, is_css_tag) } if m[:properties]
      format_tags_data(m)
      m
    end

@@ -83,7 +81,7 @@ module JsDuck
      end
    end

    def format_tags_data(context)
    def format_tags(context)
      TagRegistry.html_renderers.each do |tag|
        if context[tag.key]
          tag.format(context, @formatter)
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ module JsDuck
            render_sidebar,
            "<div class='doc-contents'>",
              render_tags(@cls, :top),
              @cls[:doc],
              render_tags(@cls, :doc),
              render_tags(@cls, :bottom),
            "</div>",
            "<div class='members'>",
@@ -218,7 +218,7 @@ module JsDuck

      doc << render_tags(m, :top)

      doc << m[:doc]
      doc << render_tags(m, :doc)

      doc << render_tags(m, :bottom)

lib/jsduck/tag/doc.rb

0 → 100644
+20 −0
Original line number Diff line number Diff line
require "jsduck/tag/tag"

module JsDuck::Tag
  # A special class for rendering the documentation field inside
  # classes and members.
  class Doc < Tag
    def initialize
      @key = :doc
      @html_position = :doc
    end

    def format(m, formatter)
      m[:doc] = formatter.format(m[:doc])
    end

    def to_html(m)
      m[:doc]
    end
  end
end
+2 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ module JsDuck
      @keys = {}
      @mergers = {}
      @signatures = []
      @html_renderers = {:top => [], :bottom => []}
      @html_renderers = {:top => [], :doc => [], :bottom => []}
      @member_types = []

      @loader = TagLoader.new
@@ -97,7 +97,7 @@ module JsDuck
    # for both sections are returned.
    def html_renderers(position = :all)
      if position == :all
        @html_renderers[:top] + @html_renderers[:bottom]
        @html_renderers[:top] + @html_renderers[:doc] + @html_renderers[:bottom]
      else
        @html_renderers[position]
      end