Commit 4d5751df authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Started Page class for generating HTML doc pages.

The to_html method currently creates the top section of page.
Definitely quite buggy, but at least we have started it.

JsDuck.write_tree now also outputs empty Docs.icons object,
which keeps UI from crashing - but we should fill it with
actual icons-map in the future.
parent 99eed460
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ require 'jsduck/parser'
require 'jsduck/doc_parser'
require 'jsduck/merger'
require 'jsduck/tree'
require 'jsduck/page'
require 'json'

require 'optparse'
@@ -62,8 +63,18 @@ module JsDuck
  # in JSON form into a file.
  def JsDuck.write_tree(filename, docs)
    js = "Docs.classData = " + JSON.generate( Tree.new.create(docs) ) + ";"
    js += "Docs.icons = {};"
    File.open(filename, 'w') {|f| f.write(js) }
  end

  # Writes documentation page for each class
  def JsDuck.write_pages(path, docs, verbose)
    docs.each do |cls|
      filename = path + "/" + cls[:name] + ".html"
      puts "Writing to #{filename} ..." if verbose
      File.open(filename, 'w') {|f| f.write( Page.new(cls).to_html ) }
    end
  end
end


@@ -106,5 +117,6 @@ if __FILE__ == $0 then

  docs = JsDuck.parse_files(input_files, verbose)
  JsDuck.write_tree(output_dir+"/tree.js", docs)
  JsDuck.write_pages(output_dir, docs, verbose)
end

lib/jsduck/page.rb

0 → 100644
+46 −0
Original line number Diff line number Diff line
module JsDuck

  # Creates HTML documentation page for one class.
  class Page
    def initialize(cls)
      @cls = cls
    end

    def to_html
      [
       '<div xmlns:ext="http://www.extjs.com" class="body-wrap">',
       heading,
       abstract,
       description,
       "</div>",
      ].join("\n")
    end

    def heading
      "<h1>Class <a href='source/sample.html#cls-#{@cls[:name]}'>#{@cls[:name]}</a></h1>"
    end

    def abstract
      parts = @cls[:name].split(/\./)
      namespace = parts.slice(0, parts.length - 1).join(".")
      short_name = parts.last
      [
       "<table cellspacing='0'>",
       abstract_row("Package:", namespace),
       abstract_row("Defined In:", "sample.js"),
       abstract_row("Class:", "<a href='source/sample.html#cls-#{@cls[:name]}'>#{short_name}</a>"),
       abstract_row("Extends:", @cls[:extends] || "Object"),
       "</table>",
      ].join("\n")
    end

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

    def description
      "<div class='description'>#{@cls[:doc]}</div>"
    end
  end

end