Commit 84f67898 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

"Defined In" filename in class documentation.

Link from class documentation to to the file it was defined in.
parent 2408c7a5
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -16,20 +16,30 @@ module JsDuck
      @merger = Merger.new
    end

    def parse(input, filename="")
    # Parses chunk of JavaScript.  The resulting documentation is
    # accumulated inside this class and can be later accessed through
    # #result method.
    #
    # - input  the JavaScript source
    # - filename  name of the JS file where it came from
    # - html_filename  name of the HTML file where the source was saved.
    #
    def parse(input, filename="", html_filename="")
      @current_class = nil
      Parser.new(input).parse.each do |docset|
        doc = @doc_parser.parse(docset[:comment])
        code = docset[:code]
        href = filename + "#line-" + docset[:linenr].to_s
        register(add_href(@merger.merge(doc, code), href))
        href = html_filename + "#line-" + docset[:linenr].to_s
        register(add_href(@merger.merge(doc, code), href, filename))
      end
    end

    # Tags doc-object with link to source code where it came from
    def add_href(doc, href)
    # Tags doc-object with link to source code where it came from.
    # For class we also store the name of the JavaScript file.
    def add_href(doc, href, filename)
      doc[:href] = href
      if doc[:tagname] == :class
        doc[:filename] = filename
        doc[:cfg].each {|cfg| cfg[:href] = href }
        doc[:method].each {|method| method[:href] = href }
      end
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ module JsDuck
        puts "Parsing #{fname} ..." if @verbose
        code = IO.read(fname)
        src_fname = src.write(code, fname)
        agr.parse(code, File.basename(src_fname))
        agr.parse(code, File.basename(fname), File.basename(src_fname))
      end
      agr.result
    end
+5 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ module JsDuck
      [
       "<table cellspacing='0'>",
        abstract_row("Extends:", @cls.parent ? class_link(@cls.parent.full_name) : "Object"),
        abstract_row("Defind In:", file_link),
       "</table>",
      ].join("\n")
    end
@@ -44,6 +45,10 @@ module JsDuck
      "<a href='output/#{name}.html' ext:cls='#{name}'>#{name}</a>"
    end

    def file_link
      "<a href='source/#{@cls[:href]}'>#{@cls[:filename]}</a>"
    end

    def abstract_row(label, info)
      "<tr><td class='label'>#{label}</td><td class='hd-info'>#{info}</td></tr>"
    end