private var model: Model
private var modelbuilder: ModelBuilder
private var mainmodule: MModule
+ private var class_hierarchy: POSet[MClass]
private var arguments: Array[String]
- private var destinationdir: nullable String
- private var sharedir: nullable String
+ private var output_dir: nullable String
+ private var dot_dir: nullable String
+ private var share_dir: nullable String
private var source: nullable String
private var opt_dir = new OptionString("Directory where doc is generated", "-d", "--dir")
modelbuilder.full_propdef_semantic_analysis
assert mmodules.length == 1
self.mainmodule = mmodules.first
+ self.class_hierarchy = mainmodule.flatten_mclass_hierarchy
end
private fun process_options do
if not opt_dir.value is null then
- destinationdir = opt_dir.value
+ output_dir = opt_dir.value
else
- destinationdir = "nitdoc_directory"
+ output_dir = "doc"
end
if not opt_sharedir.value is null then
- sharedir = opt_sharedir.value
+ share_dir = opt_sharedir.value
else
var dir = "NIT_DIR".environ
if dir.is_empty then
else
dir = "{dir}/share/nitdoc"
end
- sharedir = dir
- if sharedir is null then
+ share_dir = dir
+ if share_dir is null then
print "Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
abort
end
- dir = "{sharedir.to_s}/scripts/js-facilities.js"
- if sharedir is null then
+ dir = "{share_dir.to_s}/scripts/js-facilities.js"
+ if share_dir is null then
print "Error: Invalid nitdoc share files. Check --sharedir or envvar NIT_DIR"
abort
end
fun start do
if arguments.length == 1 then
# Create destination dir if it's necessary
- if not destinationdir.file_exists then destinationdir.mkdir
- sys.system("cp -r {sharedir.to_s}/* {destinationdir.to_s}/")
+ if not output_dir.file_exists then output_dir.mkdir
+ sys.system("cp -r {share_dir.to_s}/* {output_dir.to_s}/")
+ self.dot_dir = null
+ if not opt_nodot.value then self.dot_dir = output_dir.to_s
overview
- fullindex
+ #fullindex
modules
classes
- quicksearch_list
+ #quicksearch_list
end
end
fun overview do
- var overviewpage = new NitdocOverview.with(modelbuilder, self.opt_nodot.value, destinationdir.to_s)
- overviewpage.save("{destinationdir.to_s}/index.html")
+ var overviewpage = new NitdocOverview(modelbuilder, dot_dir)
+ overviewpage.save("{output_dir.to_s}/index.html")
end
fun fullindex do
- var fullindex = new NitdocFullindex.with(model.mmodules)
- fullindex.save("{destinationdir.to_s}/full-index.html")
+ var fullindex = new NitdocFullindex(model.mmodules)
+ fullindex.save("{output_dir.to_s}/full-index.html")
end
fun modules do
for mmodule in model.mmodules do
- var modulepage = new NitdocModules.with(mmodule, modelbuilder)
- modulepage.save("{destinationdir.to_s}/{mmodule.name}.html")
+ var modulepage = new NitdocModule(mmodule, modelbuilder, dot_dir)
+ modulepage.save("{output_dir.to_s}/{mmodule.name}.html")
end
end
fun classes do
for mclass in modelbuilder.model.mclasses do
- var classpage = new NitdocMClasses.with(mclass, modelbuilder, source)
- classpage.save("{destinationdir.to_s}/{mclass.name}.html")
+ var classpage = new NitdocClass(mclass, self, dot_dir, source)
+ classpage.save("{output_dir.to_s}/{mclass.name}.html")
end
end
# Generate QuickSearch file
fun quicksearch_list do
- var file = new OFStream.open("{destinationdir.to_s}/quicksearch-list.js")
+ var file = new OFStream.open("{output_dir.to_s}/quicksearch-list.js")
var content = new Buffer
content.append("var entries = \{ ")
for prop in model.mproperties do
if not prop isa MMethod then continue
content.append("\"{prop.name}\": [")
for propdef in prop.mpropdefs do
- content.append("\{txt: \"{propdef.mproperty.full_name}\", url:\"{propdef.mproperty.link_anchor}\" \}")
+ content.append("\{txt: \"{propdef.mproperty.full_name}\", url:\"{propdef.mproperty.anchor}\" \}")
if not propdef is prop.mpropdefs.last then content.append(", ")
end
content.append("]")
end
-class NitdocOverview
- super NitdocPage
+# Nitdoc base page
+abstract class NitdocPage
+ super HTMLPage
- var mbuilder: ModelBuilder
+ var dot_dir: nullable String
+ var source: nullable String
- # Init with Array[AModule] to get all ifnormations about each MModule containt in a program
- # opt_nodot to inform about the graph gen
- # destination: to know where will be saved dot files
- init with(mbuilder: ModelBuilder, opt_nodot: Bool, destination: String) do
- self.mbuilder = mbuilder
- self.opt_nodot = opt_nodot
- self.destinationdir = destination
+ redef fun head do
+ add("meta").attr("charset", "utf-8")
+ add("script").attr("type", "text/javascript").attr("src", "scripts/jquery-1.7.1.min.js")
+ add("script").attr("type", "text/javascript").attr("src", "quicksearch-list.js")
+ add("script").attr("type", "text/javascript").attr("src", "scripts/js-facilities.js")
+ add("link").attr("rel", "stylesheet").attr("href", "styles/main.css").attr("type", "text/css").attr("media", "screen")
end
- redef fun head do
- super
- add("title").text("Overview | Nit Standard Library")
+ redef fun body do
+ header
+ open("div").add_class("page")
+ content
+ close("div")
+ footer
end
- redef fun header do
+ fun menu is abstract
+
+ fun header do
open("header")
open("nav").add_class("main")
open("ul")
- add("li").add_class("current").text("Overview")
- open("li")
- add_html("<a href=\"full-index.html\">Full Index</a>")
- close("li")
+ menu
open("li").attr("id", "liGitHub")
open("a").add_class("btn").attr("id", "logGitHub")
add("img").attr("id", "imgGitHub").attr("src", "resources/icons/github-icon.png")
close("header")
end
- redef fun body do
+ fun content is abstract
+
+ fun footer do
+ add("footer").text("Nit standard library. Version jenkins-component=stdlib-19.")
+ end
+
+ # Generate a clickable graphviz image using a dot content
+ fun generate_dot(dot: String, name: String, alt: String) do
+ var output_dir = dot_dir
+ if output_dir == null then return
+ var file = new OFStream.open("{output_dir}/{name}.dot")
+ file.write(dot)
+ file.close
+ sys.system("\{ test -f {output_dir}/{name}.png && test -f {output_dir}/{name}.s.dot && diff {output_dir}/{name}.dot {output_dir}/{name}.s.dot >/dev/null 2>&1 ; \} || \{ cp {output_dir}/{name}.dot {output_dir}/{name}.s.dot && dot -Tpng -o{output_dir}/{name}.png -Tcmapx -o{output_dir}/{name}.map {output_dir}/{name}.s.dot ; \}")
+ open("article").add_class("graph")
+ add("img").attr("src", "{name}.png").attr("usemap", "#{name}").attr("style", "margin:auto").attr("alt", "{alt}")
+ close("article")
+ var fmap = new IFStream.open("{output_dir}/{name}.map")
+ add_html(fmap.read_all)
+ fmap.close
+ end
+
+ # Add a (source) link for a given location
+ fun show_source(l: Location): String
+ do
+ if source == null then
+ return "({l.file.filename.simplify_path})"
+ else
+ # THIS IS JUST UGLY ! (but there is no replace yet)
+ var x = source.split_with("%f")
+ source = x.join(l.file.filename.simplify_path)
+ x = source.split_with("%l")
+ source = x.join(l.line_start.to_s)
+ x = source.split_with("%L")
+ source = x.join(l.line_end.to_s)
+ return " (<a href=\"{source.to_s}\">show code</a>)"
+ end
+ end
+end
+
+# The overview page
+class NitdocOverview
+ super NitdocPage
+ private var mbuilder: ModelBuilder
+ private var mmodules = new Array[MModule]
+
+ init(mbuilder: ModelBuilder, dot_dir: nullable String) do
+ self.mbuilder = mbuilder
+ self.dot_dir = dot_dir
+ # get modules
+ var mmodules = new HashSet[MModule]
+ for mmodule in mbuilder.model.mmodules do
+ var owner = mmodule.public_owner
+ if owner != null then
+ mmodules.add(owner)
+ else
+ mmodules.add(mmodule)
+ end
+ end
+ # sort modules
+ var sorter = new ComparableSorter[MModule]
+ self.mmodules.add_all(mmodules)
+ sorter.sort(self.mmodules)
+ end
+
+ redef fun head do
super
- open("div").add_class("page")
+ add("title").text("Overview | Nit Standard Library")
+ end
+
+ redef fun menu do
+ add("li").add_class("current").text("Overview")
+ open("li")
+ add("a").attr("href", "full-index.html").text("Full Index")
+ close("li")
+ end
+
+ redef fun content do
open("div").add_class("content fullpage")
add("h1").text("Nit Standard Library")
open("article").add_class("overview")
add_html("<p>Documentation for the standard library of Nit<br />Version jenkins-component=stdlib-19<br />Date: TODAY</p>")
close("article")
open("article").add_class("overview")
+ # module list
add("h2").text("Modules")
open("ul")
- add_modules
- close("ul")
- process_generate_dot
- close("article")
- close("div")
- close("div")
- add("footer").text("Nit standard library. Version jenkins-component=stdlib-19.")
- end
-
- fun add_modules do
- var mmodules = list_mmodules
- var sorted = new Array[MModule].from(mmodules)
- var sorter = new ComparableSorter[MModule]
- sorter.sort(sorted)
- for mmodule in sorted do
+ for mmodule in mmodules do
var amodule = mbuilder.mmodule2nmodule[mmodule]
open("li")
- add("a").attr("href", "{mmodule.name}.html").text("{mmodule.to_s} ")
- add_html(amodule.short_comment)
+ add_html("{mmodule.link(amodule)} {amodule.short_comment}")
close("li")
end
+ close("ul")
+ # module graph
+ process_generate_dot
+ close("article")
+ close("div")
end
fun process_generate_dot do
var op = new Buffer
op.append("digraph dep \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
- for mmodule in list_mmodules do
+ for mmodule in mmodules do
op.append("\"{mmodule.name}\"[URL=\"{mmodule.name}.html\"];\n")
for imported in mmodule.in_importation.direct_greaters do
if imported.direct_owner == null then
op.append("\}\n")
generate_dot(op.to_s, "dep", "Modules hierarchy")
end
-
- private fun list_mmodules: Set[MModule] do
- var mmodules = new HashSet[MModule]
- for mmodule in mbuilder.model.mmodules do
- var owner = mmodule.public_owner
- if owner != null then
- mmodules.add(owner)
- else
- mmodules.add(mmodule)
- end
- end
- return mmodules
- end
-
end
+# The full index page
class NitdocFullindex
super NitdocPage
- var mmodules: Array[MModule]
+ private var mmodules: Array[MModule]
- init with(mmodules: Array[MModule]) do
+ init(mmodules: Array[MModule]) do
self.mmodules = mmodules
- opt_nodot = false
- destinationdir = ""
+ self.dot_dir = null
end
redef fun head do
add("title").text("Full Index | Nit Standard Library")
end
- redef fun header do
- open("header")
- open("nav").add_class("main")
- open("ul")
+ redef fun menu do
open("li")
- add_html("<a href=\"index.html\">Overview</a>")
+ add("a").attr("href", "index.html").text("Overview")
close("li")
add("li").add_class("current").text("Full Index")
- open("li").attr("id", "liGitHub")
- open("a").add_class("btn").attr("id", "logGitHub")
- add("img").attr("id", "imgGitHub").attr("src", "resources/icons/github-icon.png")
- close("a")
- open("div").add_class("popover bottom")
- add("div").add_class("arrow").text(" ")
- open("div").add_class("githubTitle")
- add("h3").text("Github Sign In")
- close("div")
- open("div")
- add("label").attr("id", "lbloginGit").text("Username")
- add("input").attr("id", "loginGit").attr("name", "login").attr("type", "text")
- open("label").attr("id", "logginMessage").text("Hello ")
- open("a").attr("id", "githubAccount")
- add("strong").attr("id", "nickName").text(" ")
- close("a")
- close("label")
- close("div")
- open("div")
- add("label").attr("id", "lbpasswordGit").text("Password")
- add("input").attr("id", "passwordGit").attr("name", "password").attr("type", "password")
- open("div").attr("id", "listBranches")
- add("label").attr("id", "lbBranches").text("Branch")
- add("select").add_class("dropdown").attr("id", "dropBranches").attr("name", "dropBranches").attr("tabindex", "1").text(" ")
- close("div")
- close("div")
- open("div")
- add("label").attr("id", "lbrepositoryGit").text("Repository")
- add("input").attr("id", "repositoryGit").attr("name", "repository").attr("type", "text")
- close("div")
- open("div")
- add("label").attr("id", "lbbranchGit").text("Branch")
- add("input").attr("id", "branchGit").attr("name", "branch").attr("type", "text")
- close("div")
- open("div")
- add("a").attr("id", "signIn").text("Sign In")
- close("div")
- close("div")
- close("li")
- close("ul")
- close("nav")
- close("header")
end
- redef fun body do
- super
- open("div").add_class("page")
+ redef fun content do
open("div").add_class("content fullpage")
add("h1").text("Full Index")
- add_content
- close("div")
- close("div")
- add("footer").text("Nit standard library. Version jenkins-component=stdlib-19.")
- end
-
- fun add_content do
module_column
classes_column
properties_column
+ close("div")
end
# Add to content modules column
for mclass in sorted do
open("li")
- add("a").attr("href", "{mclass.name}.html").text(mclass.name)
+ add("a").attr("href", "{mclass}.html").text(mclass.name)
close("li")
end
end
-class NitdocModules
+# A module page
+class NitdocModule
super NitdocPage
- var mmodule: MModule
- var mbuilder: ModelBuilder
+ private var mmodule: MModule
+ private var mbuilder: ModelBuilder
- init with(mmodule: MModule, mbuilder: ModelBuilder) do
+ init(mmodule: MModule, mbuilder: ModelBuilder, dot_dir: nullable String) do
self.mmodule = mmodule
self.mbuilder = mbuilder
- opt_nodot = false
- destinationdir = ""
+ self.dot_dir = dot_dir
end
redef fun head do
add("title").text("{mmodule.name} module | {amodule.short_comment}")
end
- redef fun header do
- open("header")
- open("nav").add_class("main")
- open("ul")
+ redef fun menu do
open("li")
- add_html("<a href=\"index.html\">Overview</a>")
+ add("a").attr("href", "index.html").text("Overview")
close("li")
add("li").add_class("current").text(mmodule.name)
open("li")
- add_html("<a href=\"full-index.html\" >Full Index</a>")
- close("li")
- open("li").attr("id", "liGitHub")
- open("a").add_class("btn").attr("id", "logGitHub")
- add("img").attr("id", "imgGitHub").attr("src", "resources/icons/github-icon.png")
- close("a")
- open("div").add_class("popover bottom")
- add("div").add_class("arrow").text(" ")
- open("div").add_class("githubTitle")
- add("h3").text("Github Sign In")
- close("div")
- open("div")
- add("label").attr("id", "lbloginGit").text("Username")
- add("input").attr("id", "loginGit").attr("name", "login").attr("type", "text")
- open("label").attr("id", "logginMessage").text("Hello ")
- open("a").attr("id", "githubAccount")
- add("strong").attr("id", "nickName").text(" ")
- close("a")
- close("label")
- close("div")
- open("div")
- add("label").attr("id", "lbpasswordGit").text("Password")
- add("input").attr("id", "passwordGit").attr("name", "password").attr("type", "password")
- open("div").attr("id", "listBranches")
- add("label").attr("id", "lbBranches").text("Branch")
- add("select").add_class("dropdown").attr("id", "dropBranches").attr("name", "dropBranches").attr("tabindex", "1").text(" ")
- close("div")
- close("div")
- open("div")
- add("label").attr("id", "lbrepositoryGit").text("Repository")
- add("input").attr("id", "repositoryGit").attr("name", "repository").attr("type", "text")
- close("div")
- open("div")
- add("label").attr("id", "lbbranchGit").text("Branch")
- add("input").attr("id", "branchGit").attr("name", "branch").attr("type", "text")
- close("div")
- open("div")
- add("a").attr("id", "signIn").text("Sign In")
- close("div")
- close("div")
+ add("a").attr("href", "full-index.html").text("Full Index")
close("li")
- close("ul")
- close("nav")
- close("header")
end
- redef fun body do
- super
- open("div").add_class("page")
- menu
- add_content
- close("div")
- add("footer").text("Nit standard library. Version jenkins-component=stdlib-19.")
- end
-
- # Insert all tags in content part
- fun add_content do
+ redef fun content do
+ sidebar
open("div").add_class("content")
add("h1").text(mmodule.name)
- add("div").add_class("subtitle").text("module {mmodule.name}")
+ add("div").add_class("subtitle")
+ add_html("module {mmodule.namespace(mbuilder)}")
module_comment
+ process_generate_dot
classes
properties
close("div")
close("div")
end
- fun menu do
+ fun process_generate_dot do
+ var name = "dep_{mmodule.name}"
+ var op = new Buffer
+ op.append("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
+ for m in mmodule.in_importation.poset do
+ var public_owner = m.public_owner
+ if public_owner == null then
+ public_owner = m
+ if m == mmodule then
+ op.append("\"{m.name}\"[shape=box,margin=0.03];\n")
+ else
+ op.append("\"{m.name}\"[URL=\"{m.name}.html\"];\n")
+ end
+ end
+ for imported in m.in_importation.direct_greaters do
+ if imported.public_owner == null then
+ op.append("\"{public_owner.name}\"->\"{imported.name}\";\n")
+ end
+ end
+ end
+ op.append("\}\n")
+ generate_dot(op.to_s, name, "Dependency graph for module {mmodule.name}")
+ end
+
+ fun sidebar do
var amodule = mbuilder.mmodule2nmodule[mmodule]
open("div").add_class("menu")
open("nav")
- add("h3").text("Module Hierarchy").attr("style","cursor: pointer;")
- if mmodule.in_importation.greaters.length > 0 then
- add_html("<h4>All dependencies</h4><ul>")
- var sorted = mmodule.in_importation.greaters.to_a
- var sorter = new ComparableSorter[MModule]
- sorter.sort(sorted)
- for m in sorted do
- if m == mmodule or m.public_owner != null then continue
- open("li")
- add("a").attr("href", "{m.name}.html").text(m.name)
- close("li")
- end
- add_html("</ul>")
- end
- if mmodule.in_importation.smallers.length > 0 then
- add_html("<h4>All clients</h4><ul>")
- var sorted = mmodule.in_importation.smallers.to_a
- var sorter = new ComparableSorter[MModule]
- sorter.sort(sorted)
- for m in sorted do
- if m == mmodule or m.public_owner != null then continue
- open("li")
- add("a").attr("href", "{m.name}.html").text(m.name)
- close("li")
- end
- add_html("</ul>")
+ add("h3").text("Module Hierarchy")
+ var dependencies = new Array[MModule]
+ for dep in mmodule.in_importation.greaters do
+ if dep == mmodule or dep.public_owner != null then continue
+ dependencies.add(dep)
+ end
+ if dependencies.length > 0 then
+ add("h4").text("All dependencies")
+ display_module_list(dependencies)
+ end
+ var clients = new Array[MModule]
+ for dep in mmodule.in_importation.smallers do
+ if dep == mmodule or dep.public_owner != null then continue
+ clients.add(dep)
+ end
+ if clients.length > 0 then
+ add("h4").text("All clients")
+ display_module_list(clients)
end
close("nav")
if mmodule.in_nesting.direct_greaters.length > 0 then
- var sorted = mmodule.in_nesting.direct_greaters.to_a
- var sorter = new ComparableSorter[MModule]
- sorter.sort(sorted)
open("nav")
- add("h3").text("Nested Modules").attr("style","cursor: pointer;")
- open("ul")
- for m in sorted do
- open("li")
- add("a").attr("href", "{m.name}.html").text(m.name)
- close("li")
- end
- close("ul")
-
+ add("h3").text("Nested Modules")
+ display_module_list(mmodule.in_nesting.direct_greaters.to_a)
close("nav")
end
close("div")
end
+ private fun display_module_list(list: Array[MModule]) do
+ open("ul")
+ var sorter = new ComparableSorter[MModule]
+ sorter.sort(list)
+ for m in list do
+ var am = mbuilder.mmodule2nmodule[m]
+ open("li")
+ add_html(m.link(am))
+ close("li")
+ end
+ close("ul")
+ end
+
fun classes do
var amodule = mbuilder.mmodule2nmodule[mmodule]
var intro_mclasses = mmodule.intro_mclasses
add("h2").text("Classes")
open("ul")
for c in sorted do
- var name = c.name
+ var nclass = mbuilder.mclassdef2nclassdef[c.intro].as(AStdClassdef)
if redef_mclasses.has(c) and c.intro_mmodule.public_owner != mmodule then
open("li").add_class("redef")
add("span").attr("title", "refined in this module").text("R ")
open("li").add_class("intro")
add("span").attr("title", "introduced in this module").text("I ")
end
- add("a").attr("href", "{name}.html").text(name)
+ add_html(c.link(nclass))
close("li")
end
close("ul")
var sorter = new ComparableSorter[MPropDef]
sorter.sort(sorted)
open("article").add_class("properties filterable")
- add_html("<h2>Properties</h2>")
+ add("h2").text("Properties")
open("ul")
for p in sorted do
+ if p isa MAttributeDef then continue
if p.mproperty.visibility <= none_visibility then continue
+ if not mbuilder.mpropdef2npropdef.has_key(p) then continue
+ var nprop = mbuilder.mpropdef2npropdef[p]
if p.is_intro then
open("li").add_class("intro")
add("span").attr("title", "introduction").text("I")
open("li").add_class("redef")
add("span").attr("title", "redefinition").text("R")
end
- add_html(" ")
- add("a").attr("href", "{p.mclassdef.mclass.name}.html").attr("title", "").text("{p.mproperty.name} ({p.mclassdef.mclass.name})")
+ add_html(" {p.link(nprop)} ({p.mclassdef.mclass.name})")
close("li")
end
close("ul")
end
end
-# Nit Standard Library
-class NitdocMClasses
+# A class page
+class NitdocClass
super NitdocPage
- var mclass: MClass
- var mbuilder: ModelBuilder
+ private var mclass: MClass
+ private var mbuilder: ModelBuilder
+ private var nitdoc: Nitdoc
- init with(mclass: MClass, mbuilder: ModelBuilder, source: nullable String) do
+ init(mclass: MClass, nitdoc: Nitdoc, dot_dir: nullable String, source: nullable String) do
self.mclass = mclass
- self.mbuilder = mbuilder
- self.opt_nodot = false
- self.destinationdir = ""
+ self.mbuilder = nitdoc.modelbuilder
+ self.nitdoc = nitdoc
+ self.dot_dir = dot_dir
self.source = source
end
end
end
- redef fun header do
- open("header")
- open("nav").add_class("main")
- open("ul")
+ redef fun menu do
open("li")
- add_html("<a href=\"index.html\">Overview</a>")
+ add("a").attr("href", "index.html").text("Overview")
close("li")
open("li")
var public_owner = mclass.public_owner
if public_owner is null then
- add_html("<a href=\"{mclass.intro_mmodule.name}.html\">{mclass.intro_mmodule.name}</a>")
+ var am = mbuilder.mmodule2nmodule[mclass.intro_mmodule]
+ add_html(mclass.intro_mmodule.link(am))
else
- add_html("<a href=\"{public_owner.name}.html\">{public_owner.name}</a>")
+ var am = mbuilder.mmodule2nmodule[public_owner]
+ add_html(public_owner.link(am))
end
close("li")
add("li").add_class("current").text(mclass.name)
open("li")
- add_html("<a href=\"full-index.html\" >Full Index</a>")
+ add("a").attr("href", "full-index.html").text("Full Index")
close("li")
- open("li").attr("id", "liGitHub")
- open("a").add_class("btn").attr("id", "logGitHub")
- add("img").attr("id", "imgGitHub").attr("src", "resources/icons/github-icon.png")
- close("a")
- open("div").add_class("popover bottom")
- add("div").add_class("arrow").text(" ")
- open("div").add_class("githubTitle")
- add("h3").text("Github Sign In")
- close("div")
- open("div")
- add("label").attr("id", "lbloginGit").text("Username")
- add("input").attr("id", "loginGit").attr("name", "login").attr("type", "text")
- open("label").attr("id", "logginMessage").text("Hello ")
- open("a").attr("id", "githubAccount")
- add("strong").attr("id", "nickName").text(" ")
- close("a")
- close("label")
- close("div")
- open("div")
- add("label").attr("id", "lbpasswordGit").text("Password")
- add("input").attr("id", "passwordGit").attr("name", "password").attr("type", "password")
- open("div").attr("id", "listBranches")
- add("label").attr("id", "lbBranches").text("Branch")
- add("select").add_class("dropdown").attr("id", "dropBranches").attr("name", "dropBranches").attr("tabindex", "1").text(" ")
- close("div")
- close("div")
- open("div")
- add("label").attr("id", "lbrepositoryGit").text("Repository")
- add("input").attr("id", "repositoryGit").attr("name", "repository").attr("type", "text")
- close("div")
- open("div")
- add("label").attr("id", "lbbranchGit").text("Branch")
- add("input").attr("id", "branchGit").attr("name", "branch").attr("type", "text")
- close("div")
- open("div")
- add("a").attr("id", "signIn").text("Sign In")
- close("div")
- close("div")
- close("li")
- close("ul")
- close("nav")
- close("header")
- end
-
- redef fun body do
- super
- open("div").add_class("page")
- add_content
- close("div")
- add("footer").text("Nit standard library. Version jenkins-component=stdlib-19.")
end
- # Insert all tags in content part
- fun add_content do
+ redef fun content do
open("div").add_class("menu")
properties_column
inheritance_column
close("div")
open("div").add_class("content")
- content
+ class_doc
close("div")
end
fun properties_column do
- var sorted = new Array[MProperty]
- var sorterp = new ComparableSorter[MProperty]
+ var sorter = new ComparableSorter[MPropDef]
open("nav").add_class("properties filterable")
add("h3").text("Properties")
-
- if mclass.virtual_types.length > 0 then
- add("h4").text("Virtual Types")
- open("ul")
- sorted = mclass.virtual_types.to_a
- sorterp.sort(sorted)
- for prop in sorted do
- add_html("<li class=\"redef\"><span title=\"Redefined\">R</span><a href=\"{prop.link_anchor}\">{prop.name}</a></li>")
+ # get properties
+ var vtypes = new HashSet[MVirtualTypeDef]
+ var consts = new HashSet[MMethodDef]
+ var meths = new HashSet[MMethodDef]
+ for mclassdef in mclass.mclassdefs do
+ for mpropdef in mclassdef.mpropdefs do
+ if not mbuilder.mpropdef2npropdef.has_key(mpropdef) then continue
+ if mpropdef.mproperty.visibility <= none_visibility then continue
+ if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
+ if mpropdef isa MMethodDef then
+ if mpropdef.mproperty.is_init then
+ consts.add(mpropdef)
+ else
+ meths.add(mpropdef)
+ end
+ end
end
- close("ul")
end
- if mclass.constructors.length > 0 then
- sorted = mclass.constructors.to_a
- sorterp.sort(sorted)
- add("h4").text("Constructors")
- open("ul")
- for prop in sorted do
- add_html("<li class=\"intro\"><span title=\"Introduced\">I</span><a href=\"{prop.link_anchor}\">{prop.name}</a></li>")
- end
- close("ul")
+ for mprop in mclass.inherited_methods do
+ var mpropdef = mprop.intro
+ if not mbuilder.mpropdef2npropdef.has_key(mpropdef) then continue
+ if mprop.visibility <= none_visibility then continue
+ if mprop.intro_mclassdef.mclass.name == "Object" then continue
+ meths.add(mpropdef)
end
- add("h4").text("Methods")
- open("ul")
- if mclass.intro_methods.length > 0 then
- sorted = mclass.intro_methods.to_a
- sorterp.sort(sorted)
- for prop in sorted do
- if prop.visibility is public_visibility or prop.visibility is protected_visibility then add_html("<li class=\"intro\"><span title=\"Introduced\">I</span><a href=\"{prop.link_anchor}\">{prop.name}</a></li>")
- end
+ # virtual types
+ if vtypes.length > 0 then
+ var vts = new Array[MVirtualTypeDef]
+ vts.add_all(vtypes)
+ sorter.sort(vts)
+ add("h4").text("Virtual Types")
+ display_mpropdef_list(vts)
end
- if mclass.inherited_methods.length > 0 then
- sorted = mclass.inherited_methods.to_a
- sorterp.sort(sorted)
- for prop in sorted do
- if prop.visibility is public_visibility or prop.visibility is protected_visibility then add_html("<li class=\"inherit\"><span title=\"Inherited\">H</span><a href=\"{prop.link_anchor}\">{prop.name}</a></li>")
- end
+ if consts.length > 0 then
+ var cts = new Array[MMethodDef]
+ cts.add_all(consts)
+ sorter.sort(cts)
+ add("h4").text("Constructors")
+ display_mpropdef_list(cts)
end
- if mclass.redef_methods.length > 0 then
- sorted = mclass.redef_methods.to_a
- sorterp.sort(sorted)
- for prop in sorted do
- if prop.visibility is public_visibility or prop.visibility is protected_visibility then add_html("<li class=\"redef\"><span title=\"Refined\">R</span><a href=\"{prop.link_anchor}\">{prop.name}</a></li>")
+ if meths.length > 0 then
+ var mts = new Array[MMethodDef]
+ mts.add_all(meths)
+ sorter.sort(mts)
+ add("h4").text("Methods")
+ display_mpropdef_list(mts)
+ end
+ close("nav")
+ end
+
+ private fun display_mpropdef_list(list: Array[MPropDef]) do
+ open("ul")
+ for prop in list do
+ var nprop = mbuilder.mpropdef2npropdef[prop]
+ if prop.is_intro and prop.mproperty.intro_mclassdef.mclass != mclass then
+ open("li").add_class("inherit")
+ add("span").attr("title", "Inherited").text("H")
+ else if prop.is_intro then
+ open("li").add_class("intro")
+ add("span").attr("title", "Introduced").text("I")
+ else
+ open("li").add_class("redef")
+ add("span").attr("title", "Redefined").text("R")
end
+ add_html(prop.link(nprop))
+ close("li")
end
close("ul")
- close("nav")
end
fun inheritance_column do
var sorterp = new ComparableSorter[MClass]
open("nav")
add("h3").text("Inheritance")
- if mclass.parents.length > 0 then
- sorted = mclass.parents.to_a
+ if mclass.ancestors.length > 1 then
+ sorted = mclass.ancestors.to_a
sorterp.sort(sorted)
add("h4").text("Superclasses")
open("ul")
- for sup in sorted do add_html("<li><a href=\"{sup.name}.html\">{sup.name}</a></li>")
+ for sup in sorted do
+ if sup == mclass then continue
+ open("li")
+ add("a").attr("href", "{sup.name}.html").text(sup.name)
+ close("li")
+ end
close("ul")
end
- if mclass.descendants.length is 0 then
+ if mclass.descendants.length <= 1 then
add("h4").text("No Known Subclasses")
else if mclass.descendants.length <= 100 then
sorted = mclass.descendants.to_a
sorterp.sort(sorted)
add("h4").text("Subclasses")
open("ul")
- for sub in sorted do add_html("<li><a href=\"{sub.name}\">{sub.name}</a></li>")
+ for sub in sorted do
+ if sub == mclass then continue
+ open("li")
+ add("a").attr("href", "{sub.name}.html").text(sub.name)
+ close("li")
+ end
close("ul")
else if mclass.children.length <= 100 then
sorted = mclass.children.to_a
sorterp.sort(sorted)
add("h4").text("Direct Subclasses Only")
open("ul")
- for sub in sorted do add_html("<li><a href=\"{sub.name}\">{sub.name}</a></li>")
+ for sub in sorted do
+ if sub == mclass then continue
+ open("li")
+ add("a").attr("href", "{sub.name}.html").text(sub.name)
+ close("li")
+ end
close("ul")
else
add("h4").text("Too much Subclasses to list")
close("nav")
end
- fun content do
+ fun class_doc do
var nclass = mbuilder.mclassdef2nclassdef[mclass.intro]
var sorted = new Array[MModule]
sorted.add_all(mclass.concerns.keys)
var subtitle = ""
var lmmodule = new List[MModule]
# Insert the subtitle part
- add("h1").text(mclass.name)
+ add("h1").text(mclass.to_s)
open("div").add_class("subtitle")
if mclass.visibility is none_visibility then subtitle += "private "
- subtitle += "{mclass.kind} <a href=\"{mclass.public_owner.name}.html\">{mclass.public_owner.name}</a>::{mclass.name}"
+ subtitle += "{mclass.kind} {mclass.public_owner.namespace(mbuilder)}::{mclass}"
add_html(subtitle)
close("div")
add_html("<div style=\"float: right;\"><a id=\"lblDiffCommit\"></a></div>")
# We add the class description
open("section").add_class("description")
if nclass isa AStdClassdef and not nclass.comment.is_empty then add_html("<pre class=\"text_label\" title=\"122\" name=\"\" tag=\"{mclass.mclassdefs.first.location.to_s}\" type=\"2\">{nclass.comment} </pre><textarea id=\"fileContent\" class=\"edit\" cols=\"76\" rows=\"1\" style=\"display: none;\"></textarea><a id=\"cancelBtn\" style=\"display: none;\">Cancel</a><a id=\"commitBtn\" style=\"display: none;\">Commit</a><pre id=\"preSave\" class=\"text_label\" type=\"2\"></pre>")
+ process_generate_dot
close("section")
open("section").add_class("concerns")
add("h2").add_class("section-header").text("Concerns")
end
close("section")
end
- # Insert constructors if there is almost one
+ # constructors
if mclass.constructors.length > 0 then
var sortedc = mclass.constructors.to_a
sorterprop.sort(sortedc)
for prop in sortedc do description(prop)
close("section")
end
+ # methods
open("section").add_class("methods")
add("h2").add_class("section-header").text("Methods")
for mmodule, mmethods in mclass.all_methods do
if mclass.has_mmodule(mmodule) then
add_html("<p class=\"concern-doc\">{mmodule.name}: {nmodule.short_comment}</p>")
else
- add_html("<h3 class=\"concern-toplevel\">Methods refined in <a href=\"{mmodule.name}.html\">{mmodule.name}</a></h3><p class=\"concern-doc\">{mmodule.name}: {nmodule.short_comment}</p>")
+ add_html("<h3 class=\"concern-toplevel\">Methods refined in {mmodule.link(nmodule)}</h3><p class=\"concern-doc\">{mmodule.name}: {nmodule.short_comment}</p>")
end
end
var sortedc = mmethods.to_a
sorterprop.sort(sortedc)
for prop in sortedc do description(prop)
end
- # Insert inherited methods
+ # inherited methods
if mclass.inherited_methods.length > 0 then
var sortedc = new Array[MClass]
sortedc.add_all(mclass.inherited.keys)
sorterc.sort(sortedc)
add("h3").text("Inherited Methods")
- for i_mclass in sortedc do
- var sortedp = mclass.inherited[i_mclass].to_a
+ for imclass in sortedc do
+ var inclass = mbuilder.mclassdef2nclassdef[imclass.intro].as(AStdClassdef)
+ var sortedp = mclass.inherited[imclass].to_a
sorterprop.sort(sortedp)
open("p")
- add_html("Defined in <a href=\"{i_mclass.name}.html\">{i_mclass.name}</a>: ")
+ add_html("Defined in {imclass.link(inclass)}: ")
for method in sortedp do
- add_html("<a href=\"{method.link_anchor}\">{method.name}</a>")
+ #TODO link to inherited propdef
+ add_html("<a href=\"\">{method.name}</a>")
if method != sortedp.last then add_html(", ")
end
close("p")
close("section")
end
- # Insert description tags for 'prop'
fun description(prop: MProperty) do
- open("article").add_class("fun public {if prop.is_redef then "redef" else ""}").attr("id", "{prop.anchor}")
+ if not mbuilder.mpropdef2npropdef.has_key(prop.intro) then return
+ var nprop = mbuilder.mpropdef2npropdef[prop.intro]
+ if not nprop isa AMethPropdef then return
+ var classes = new Array[String]
+ if nprop isa AInitPropdef then
+ classes.add("init")
+ else
+ classes.add("fun")
+ end
+ if prop.is_redef then classes.add("redef")
+ if prop.visibility == none_visibility then
+ classes.add("private")
+ else if prop.visibility == protected_visibility then
+ classes.add("protected")
+ else
+ classes.add("public")
+ end
+ open("article").add_classes(classes).attr("id", "{prop.anchor}")
var sign = prop.name
- if prop.apropdef != null then sign += prop.apropdef.signature
- add_html("<h3 class=\"signature\">{sign}</h3>")
- add_html("<div class=\"info\">{if prop.is_redef then "redef" else ""} fun {prop.intro_mclassdef.namespace(mclass)}::{prop.name}</div><div style=\"float: right;\"><a id=\"lblDiffCommit\"></a></div>")
-
+ open("h3").add_class("signature")
+ add_html("{prop.name}{nprop.signature}")
+ close("h3")
+ open("div").add_class("info")
+ add_html("{if prop.is_redef then "redef" else ""} fun {prop.intro_mclassdef.namespace(mclass)}::{prop.name}</div><div style=\"float: right;\"><a id=\"lblDiffCommit\"></a>")
+ close("div")
open("div").add_class("description")
- if prop.apropdef is null or prop.apropdef.comment == "" then
+ if nprop.comment == "" then
add_html("<a class=\"newComment\" title=\"32\" tag=\"\">New Comment</a>")
else
- add_html("<pre class=\"text_label\" title=\"\" name=\"\" tag=\"\" type=\"1\">{prop.apropdef.comment}</pre>")
+ add_html("<pre class=\"text_label\" title=\"\" name=\"\" tag=\"\" type=\"1\">{nprop.comment}</pre>")
end
add_html("<textarea id=\"fileContent\" class=\"edit\" cols=\"76\" rows=\"1\" style=\"display: none;\"></textarea><a id=\"cancelBtn\" style=\"display: none;\">Cancel</a><a id=\"commitBtn\" style=\"display: none;\">Commit</a><pre id=\"preSave\" class=\"text_label\" type=\"2\"></pre>")
open("p")
- if prop.local_class != mclass then add_html("inherited from {prop.local_class.intro_mmodule.name} ")
+ if prop.local_class != mclass then
+ var mredef = prop.local_class.intro_mmodule
+ var nredef = mbuilder.mmodule2nmodule[mredef]
+ add_html("inherited from {mredef.link(nredef)} ")
+ end
#TODO display show code if doc github
- add_html("defined by the module <a href=\"{prop.intro_mclassdef.mmodule.name}.html\">{prop.intro_mclassdef.mmodule.name}</a> {if prop.apropdef is null then "" else show_source(prop.apropdef.location)}.")
+ var mintro = prop.intro_mclassdef.mmodule
+ var nintro = mbuilder.mmodule2nmodule[mintro]
+ add_html("defined by the module {mintro.link(nintro)}{if prop.apropdef is null then "" else show_source(prop.apropdef.location)}.")
for parent in mclass.parents do
- if prop isa MMethod then if parent.constructors.has(prop) then add_html(" Previously defined by: <a href=\"{parent.intro_mmodule.name}.html\">{parent.intro_mmodule.name}</a> for <a href=\"{parent.name}.html\">{parent.name}</a>.")
+ var mparent = parent.intro_mmodule
+ var nparent = mbuilder.mmodule2nmodule[mparent]
+ if prop isa MMethod then if parent.constructors.has(prop) then add_html(" Previously defined by: {mparent.link(nparent)} for <a href=\"{parent.name}.html\">{parent.name}</a>.")
end
close("p")
close("div")
close("article")
end
-end
-
-class NitdocPage
- super HTMLPage
-
- var opt_nodot: Bool
- var destinationdir : String
- var source: nullable String
-
- redef fun head do
- add("meta").attr("charset", "utf-8")
- add("script").attr("type", "text/javascript").attr("src", "scripts/jquery-1.7.1.min.js")
- add("script").attr("type", "text/javascript").attr("src", "quicksearch-list.js")
- add("script").attr("type", "text/javascript").attr("src", "scripts/js-facilities.js")
- add("link").attr("rel", "stylesheet").attr("href", "styles/main.css").attr("type", "text/css").attr("media", "screen")
- end
-
- redef fun body do header
- fun header do end
-
- # Generate a clickable graphviz image using a dot content
- fun generate_dot(dot: String, name: String, alt: String) do
- if opt_nodot then return
- var file = new OFStream.open("{self.destinationdir}/{name}.dot")
- file.write(dot)
- file.close
- sys.system("\{ test -f {self.destinationdir}/{name}.png && test -f {self.destinationdir}/{name}.s.dot && diff {self.destinationdir}/{name}.dot {self.destinationdir}/{name}.s.dot >/dev/null 2>&1 ; \} || \{ cp {self.destinationdir}/{name}.dot {self.destinationdir}/{name}.s.dot && dot -Tpng -o{self.destinationdir}/{name}.png -Tcmapx -o{self.destinationdir}/{name}.map {self.destinationdir}/{name}.s.dot ; \}")
- open("article").add_class("graph")
- add("img").attr("src", "{name}.png").attr("usemap", "#{name}").attr("style", "margin:auto").attr("alt", "{alt}")
- close("article")
- var fmap = new IFStream.open("{self.destinationdir}/{name}.map")
- add_html(fmap.read_all)
- fmap.close
- end
+ fun process_generate_dot do
+ var pe = nitdoc.class_hierarchy[mclass]
+ var cla = new HashSet[MClass]
+ var sm = new HashSet[MClass]
+ var sm2 = new HashSet[MClass]
+ sm.add(mclass)
+ while cla.length + sm.length < 10 and sm.length > 0 do
+ cla.add_all(sm)
+ sm2.clear
+ for x in sm do
+ sm2.add_all(pe.poset[x].direct_smallers)
+ end
+ var t = sm
+ sm = sm2
+ sm2 = t
+ end
+ cla.add_all(pe.greaters)
- # Add a (source) link fo a given location
- fun show_source(l: Location): String
- do
- if source == null then
- return "({l.file.filename.simplify_path})"
- else
- # THIS IS JUST UGLY ! (but there is no replace yet)
- var x = source.split_with("%f")
- source = x.join(l.file.filename.simplify_path)
- x = source.split_with("%l")
- source = x.join(l.line_start.to_s)
- x = source.split_with("%L")
- source = x.join(l.line_end.to_s)
- return " (<a href=\"{source.to_s}\">show code</a>)"
+ var op = new Buffer
+ var name = "dep_{mclass.name}"
+ op.append("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
+ for c in cla do
+ if c == mclass then
+ op.append("\"{c.name}\"[shape=box,margin=0.03];\n")
+ else
+ op.append("\"{c.name}\"[URL=\"{c.name}.html\"];\n")
+ end
+ for c2 in pe.poset[c].direct_greaters do
+ if not cla.has(c2) then continue
+ op.append("\"{c.name}\"->\"{c2.name}\";\n")
+ end
+ if not pe.poset[c].direct_smallers.is_empty then
+ var others = true
+ for c2 in pe.poset[c].direct_smallers do
+ if cla.has(c2) then others = false
+ end
+ if others then
+ op.append("\"{c.name}...\"[label=\"\"];\n")
+ op.append("\"{c.name}...\"->\"{c.name}\"[style=dotted];\n")
+ end
+ end
end
+ op.append("\}\n")
+ generate_dot(op.to_s, name, "Dependency graph for class {mclass.name}")
end
-
end
redef class AModule
end
redef class MModule
-
super Comparable
redef type OTHER: MModule
redef fun <(other: OTHER): Bool do return self.name < other.name
- var amodule: nullable AModule
-
# Get the list of all methods in a module
fun imported_methods: Set[MMethod] do
var methods = new HashSet[MMethod]
end
return methods
end
+
+ # Return a link (html a tag) to the nitdoc module page
+ fun link(amodule: AModule): String do
+ return "<a href=\"{name}.html\" title=\"{amodule.short_comment}\">{name}</a>"
+ end
+
+ # Return the module namespace decorated with html
+ fun namespace(mbuilder: ModelBuilder): String do
+ var str = new Buffer
+ var mowner = public_owner
+ if mowner != null then
+ var nowner = mbuilder.mmodule2nmodule[mowner]
+ str.append(public_owner.link(nowner))
+ end
+ var nmodule = mbuilder.mmodule2nmodule[self]
+ str.append(self.link(nmodule))
+ return str.to_s
+ end
end
redef class MPropDef
super Comparable
redef type OTHER: MPropDef
redef fun <(other: OTHER): Bool do return self.mproperty.name < other.mproperty.name
+
+ # Return a link (html a tag) to the nitdoc class page
+ fun link(nprop: APropdef): String do
+ return "<a href=\"{mclassdef.mclass.name}.html#{mproperty.anchor}\" title=\"{nprop.short_comment}\">{mproperty}</a>"
+ end
end
redef class MProperty
-
super Comparable
redef type OTHER: MProperty
redef fun <(other: OTHER): Bool do return self.name < other.name
return classdef.mclass
end
- fun class_text: String do
- return local_class.name
- end
-
- fun link_anchor: String do
- return "{class_text}.html#{anchor}"
- end
-
fun anchor: String do
return "PROP_{c_name}"
end
end
redef class MClass
-
super Comparable
redef type OTHER: MClass
redef fun <(other: OTHER): Bool do return self.name < other.name
+ # Add type parameters
+ redef fun to_s do
+ if arity > 0 then
+ return "{name}[{intro.parameter_names.join(", ")}]"
+ else
+ return name
+ end
+ end
+
+ # Return a link (html a tag) to the nitdoc class page
+ fun link(aclass: AStdClassdef): String do
+ return "<a href=\"{name}.html\" title=\"{aclass.short_comment}\">{self}</a>"
+ end
+
# Associate all MMethods to each MModule concerns
fun all_methods: HashMap[MModule, Set[MMethod]] do
var hm = new HashMap[MModule, Set[MMethod]]
return owner.public_owner.as(not null)
end
end
-
- # Associate Amodule to all MModule concern by 'self'
- fun amodule(amodules: HashMap[MModule, AModule]) do
- for owner, childs in concerns do
- if childs != null then for child in childs do child.amodule = amodules[child]
- owner.amodule = amodules[owner]
- end
- end
# Associate MClass to all MMethod include in 'inherited_methods'
fun inherited: HashMap[MClass, Set[MMethod]] do
if not n_params.is_empty then
ret = "{ret}({n_params.join(", ")})"
end
- if n_type != null and n_type.to_s != "" then ret += " {n_type.to_s}"
+ if n_type != null and n_type.to_s != "" then ret += ": {n_type.to_s}"
return ret
end
end
redef class AMethPropdef
redef fun short_comment do
- var ret = ""
+ var ret = new Buffer
if n_doc != null then
var txt = n_doc.n_comment.first.text
txt = txt.replace("# ", "")
txt = txt.replace("\n", "")
- ret += txt
+ ret.append(txt)
end
- return ret
+ return ret.to_s
end
redef fun signature: String do
var sign = ""
- if n_signature != null then sign = " {n_signature.to_s}"
+ if n_signature != null then sign = "{n_signature.to_s}"
return sign
end
redef private fun comment: String do
- var ret = ""
+ var ret = new Buffer
if n_doc != null then
for t in n_doc.n_comment do
var txt = t.text.replace("# ", "")
txt = txt.replace("#", "")
- ret += "{txt}"
+ ret.append(txt)
end
end
- return ret
+ return ret.to_s
end
end