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

Support for multiline meta-tags.

When @multiline is set to true in MetaTag implementation, multiple
lines after the tag up to next @tag will be included to meta-tag
contents.
parent e7add9b1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ module JsDuck
      if tag.hidden
        nil
      else
        {:name => tag.name, :title => tag.title, :content => tag.transform(meta[:content])}
        {:name => tag.name, :title => tag.title, :doc => tag.transform(meta[:doc])}
      end
    end

+21 −7
Original line number Diff line number Diff line
@@ -146,13 +146,9 @@ module JsDuck
          boolean_at_tag(/@abstract/, :abstract)
        elsif look(/@/)
          @input.scan(/@/)
          meta_tag = @meta_tags_map[look(/\w+/)]
          if meta_tag
            add_tag(:meta)
            @current_tag[:name] = match(/\w+/)
            skip_horiz_white
            @current_tag[:content] = @input.scan(/.*$/)
            skip_white
          tag = @meta_tags_map[look(/\w+/)]
          if tag
            meta_at_tag(tag)
          else
            @current_tag[:doc] += "@"
          end
@@ -162,6 +158,24 @@ module JsDuck
      end
    end

    # Matches the given meta-tag
    def meta_at_tag(tag)
      prev_tag = @current_tag

      add_tag(:meta)
      @current_tag[:name] = match(/\w+/)
      skip_horiz_white

      # Fors singleline tags, scan to the end of line and finish the
      # tag.  For multiline tags we leave the tag open for :doc
      # addition just like with built-in multiline tags.
      unless tag.multiline
        @current_tag[:doc] = @input.scan(/.*$/).strip
        skip_white
        @current_tag = prev_tag
      end
    end

    # matches @class name ...
    def at_class
      match(/@class/)
+2 −2
Original line number Diff line number Diff line
@@ -337,7 +337,7 @@ module JsDuck
    end

    def detect_meta(doc_map)
      doc_map[:meta] ? doc_map[:meta].map {|tag| {:name => tag[:name], :content => tag[:content]} } : []
      doc_map[:meta] ? doc_map[:meta].map {|tag| {:name => tag[:name], :doc => tag[:doc]} } : []
    end

    def detect_deprecated(doc_map)
@@ -429,7 +429,7 @@ module JsDuck
    # Combines :doc-s of most tags
    # Ignores tags that have doc comment themselves and subproperty tags
    def detect_doc(docs)
      ignore_tags = [:param, :return]
      ignore_tags = [:param, :return, :meta]
      doc_tags = docs.find_all { |tag| !ignore_tags.include?(tag[:tagname]) && !subproperty?(tag) }
      doc_tags.map { |tag| tag[:doc] }.compact.join(" ")
    end
+3 −0
Original line number Diff line number Diff line
@@ -11,6 +11,9 @@ module JsDuck
    # Title to use when rendering the meta-tag info
    attr_reader :title

    # True to include all lines up to next @tag as part of this meta-tag
    attr_reader :multiline

    # True to not render the meta tag at all
    attr_reader :hidden

+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ module JsDuck
      tag_names.each do |name|
        tags = @cls[:meta].find_all {|m| m[:name] == name }
        if tags.length > 0
          content = tags.map{|t| t[:content] }.join(', ')
          content = tags.map{|t| t[:doc] }.join(', ')
          html << "<li><strong>#{CGI.escapeHTML(tags[0][:title])}:</strong> #{content}</li>"
        end
      end
Loading