Commit dbc7d05d authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add :position attribute to meta-tags.

The tags can now position their content either above or below the
other content, while defaulting to placing it below like all tags
were before.
parent a7e3e4b7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,10 @@ module JsDuck
    # existance of the tag.
    attr_reader :boolean

    # Whether to render the tag before other content (:top) or after
    # it (:bottom).  Defaults to :bottom.
    attr_accessor :position

    # Here the appropriate class or member will be injected,
    # so the to_value and to_html methods can for produce
    # different output based on whether the tag is inside class,
+2 −0
Original line number Diff line number Diff line
@@ -55,9 +55,11 @@ module JsDuck

    # Instanciates tag class.
    # When .key is missing, creates it from .name
    # When .position is missing, defaults to :bottom
    def create_tag(cls)
      tag = cls.new
      tag.key = tag.name.to_sym unless tag.key
      tag.position = :bottom unless tag.position
      tag
    end
  end
+4 −3
Original line number Diff line number Diff line
@@ -31,9 +31,10 @@ module JsDuck
      register_keys
    end

    # Returns array of all available tag instances
    def tags
      @tags
    # Returns array of all available tag instances.
    # When position provided, returns only tags in that position
    def tags(position=nil)
      position ? @tags.find_all {|t| t.position == position} : @tags
    end

    # Accesses tag by key or name
+10 −5
Original line number Diff line number Diff line
@@ -13,9 +13,10 @@ module JsDuck
          "<div>",
            render_sidebar,
            "<div class='doc-contents'>",
              render_meta_data(@cls[:html_meta], :top),
              render_private_class_notice,
              @cls[:doc],
              render_meta_data(@cls[:html_meta]),
              render_meta_data(@cls[:html_meta], :bottom),
            "</div>",
            "<div class='members'>",
              render_all_sections,
@@ -33,10 +34,10 @@ module JsDuck
      ]
    end

    def render_meta_data(meta_data)
    def render_meta_data(meta_data, position)
      return if meta_data.size == 0

      MetaTagRegistry.instance.tags.map {|tag| meta_data[tag.key] }
      MetaTagRegistry.instance.tags(position).map {|tag| meta_data[tag.key] }
    end

    def render_sidebar
@@ -257,13 +258,17 @@ module JsDuck
    end

    def render_long_doc(m)
      doc = [m[:doc]]
      doc = []

      doc << render_meta_data(m[:html_meta], :top)

      doc << m[:doc]

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

      doc << render_meta_data(m[:html_meta])
      doc << render_meta_data(m[:html_meta], :bottom)

      doc << render_params_and_return(m)