Commit 99c9f98c authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Show tooltip for the "*" stars created by @new tag.

Showing the text:

    New since {version}

This is quite a hack, but was really needed. Damn!
parent 77a96217
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@ module JsDuck
    #
    #     {:long => "something", :short => "SOM"}
    #
    # Additionally the hash can contain a :tooltip which is the text
    # to be shown when the signature bubble is hovered over in docs.
    attr_reader :signature

    # True to include all lines up to next @tag as part of this meta-tag
+1 −0
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ module JsDuck

      reg = MetaTagRegistry.new
      reg.load([:builtins] + @meta_tag_paths)
      reg[:new].create_tooltip!(@imports, @new_since)
      MetaTagRegistry.instance = reg
    end

+12 −6
Original line number Diff line number Diff line
@@ -260,21 +260,27 @@ module JsDuck
        end
      end

      after = ""
      MetaTagRegistry.instance.signatures.each do |s|
        after += "<strong class='#{s[:key]} signature'>#{s[:long]}</strong>" if m[:meta][s[:key]]
      end

      uri = "#!/api/#{m[:owner]}-#{m[:id]}"

      return [
        before,
        "<a href='#{uri}' class='name #{expandable}'>#{name}</a>",
        params,
        after
        render_meta_signatures(m)
      ]
    end

    def render_meta_signatures(m)
      html = ""
      MetaTagRegistry.instance.signatures.each do |s|
        if m[:meta][s[:key]]
          title = s[:tooltip] ? "title='#{s[:tooltip]}'" : ""
          html += "<strong class='#{s[:key]} signature' #{title}>#{s[:long]}</strong>"
        end
      end
      html
    end

    def render_short_param(param)
      p = param[:html_type] + " " + param[:name]
      return param[:optional] ? "["+p+"]" : p
+13 −0
Original line number Diff line number Diff line
@@ -11,6 +11,19 @@ module JsDuck::Tag
      @boolean = true
    end

    # Initializes the tooltip text.
    #
    # HACK: This is a special method that's only called for the @new
    # tag. It doesn't fit well into the current meta-tags system.  But
    # until we rework the meta-tags system, this will have to do.
    def create_tooltip!(imports, new_since)
      if new_since
        @signature[:tooltip] = "New since #{new_since}"
      elsif imports.length > 0
        @signature[:tooltip] = "New since #{imports.last[:version]}"
      end
    end

    def to_value(contents)
      true
    end