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 NitdocModule.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 NitdocClass.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
abstract class NitdocPage
super HTMLPage
- var opt_nodot: Bool
- var destinationdir : String
+ var dot_dir: nullable String
var source: nullable String
redef fun head do
# 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")
+ 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 {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 ; \}")
+ 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("{self.destinationdir}/{name}.map")
+ var fmap = new IFStream.open("{output_dir}/{name}.map")
add_html(fmap.read_all)
fmap.close
end
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]
- var mbuilder: ModelBuilder
-
- # 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
+ init(mbuilder: ModelBuilder, dot_dir: nullable String) do
self.mbuilder = mbuilder
- self.opt_nodot = opt_nodot
- self.destinationdir = destination
+ 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
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")
- 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_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
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("div").add_class("subtitle")
add_html("module {mmodule.namespace(mbuilder)}")
module_comment
- #process_generate_dot
+ process_generate_dot
classes
properties
close("div")
end
fun process_generate_dot do
+ var name = "dep_{mmodule.name}"
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 m in mmodule.in_importation.smallers do
- op.append("\"{m.name}\"[URL=\"{m.name}.html\"];\n")
+ 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.direct_owner == null then
- op.append("\"{m.name}\"->\"{imported.name}\";\n")
- end
- end
+ 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, "dep_{mmodule.name}", "Modules hierarchy")
+ generate_dot(op.to_s, name, "Dependency graph for module {mmodule.name}")
end
fun sidebar do
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
# 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")
close("article")
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)
+
+ 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
if mowner != null then
var nowner = mbuilder.mmodule2nmodule[mowner]
str.append(public_owner.link(nowner))
+ str.append("::")
end
var nmodule = mbuilder.mmodule2nmodule[self]
str.append(self.link(nmodule))