- append("<li><a href='index.html'>Overview</a></li>")
- append("<li class='current'>Search</li>")
- end
-
- redef fun content do
- append("<div class='content fullpage'>")
- append("<h1>{title}</h1>")
- module_column
- classes_column
- properties_column
- append("</div>")
- end
-
- # Add to content modules column
- private fun module_column do
- var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
- var sorter = new MModuleNameSorter
- sorter.sort(sorted)
- append("<article class='modules filterable'>")
- append("<h2>Modules</h2>")
- append("<ul>")
- for mmodule in sorted do
- if mmodule.name == "<main>" then continue
- append("<li>")
- mmodule.html_link(self)
- append("</li>")
- end
- append("</ul>")
- append("</article>")
- end
-
- # Add to content classes modules
- private fun classes_column do
- var sorted = ctx.mbuilder.model.mclasses
- var sorter = new MClassNameSorter
- sorter.sort(sorted)
- append("<article class='modules filterable'>")
- append("<h2>Classes</h2>")
- append("<ul>")
- for mclass in sorted do
- if mclass.visibility < ctx.min_visibility then continue
- append("<li>")
- mclass.html_link(self)
- append("</li>")
- end
- append("</ul>")
- append("</article>")
- end
-
- # Insert the properties column of fullindex page
- private fun properties_column do
- var sorted = ctx.mbuilder.model.mproperties
- var sorter = new MPropertyNameSorter
- sorter.sort(sorted)
- append("<article class='modules filterable'>")
- append("<h2>Properties</h2>")
- append("<ul>")
- for mproperty in sorted do
- if mproperty.visibility < ctx.min_visibility then continue
- if mproperty isa MAttribute then continue
- append("<li>")
- mproperty.intro.html_link(self)
- append(" (")
- mproperty.intro.mclassdef.mclass.html_link(self)
- append(")</li>")
- end
- append("</ul>")
- append("</article>")
- end
-
-end
-
-# A module page
-class NitdocModule
- super NitdocPage
-
- private var mmodule: MModule
- private var mbuilder: ModelBuilder
- private var local_mclasses = new HashSet[MClass]
- private var intro_mclasses = new HashSet[MClass]
- private var redef_mclasses = new HashSet[MClass]
-
- init(mmodule: MModule, ctx: NitdocContext) do
- super(ctx)
- self.mmodule = mmodule
- self.mbuilder = ctx.mbuilder
- # get local mclasses
- for m in mmodule.in_nesting.greaters do
- for mclassdef in m.mclassdefs do
- if mclassdef.mclass.visibility < ctx.min_visibility then continue
- if mclassdef.is_intro then
- intro_mclasses.add(mclassdef.mclass)
- else
- if mclassdef.mclass.mpropdefs_in_module(self).is_empty then continue
- redef_mclasses.add(mclassdef.mclass)
- end
- local_mclasses.add(mclassdef.mclass)
- end
- end
- end
-
- redef fun title do
- if mbuilder.mmodule2nmodule.has_key(mmodule) and not mbuilder.mmodule2nmodule[mmodule].short_comment.is_empty then
- var nmodule = mbuilder.mmodule2nmodule[mmodule]
- return "{mmodule.html_name} module | {nmodule.short_comment}"
- else
- return "{mmodule.html_name} module"
- end
- end
-
- redef fun menu do
- super
- append("<li><a href='index.html'>Overview</a></li>")
- append("<li class='current'>{mmodule.html_name}</li>")
- append("<li><a href='search.html'>Search</a></li>")
- end
-
- redef fun content do
- append("<div class='sidebar'>")
- classes_column
- importation_column
- append("</div>")
- append("<div class='content'>")
- module_doc
- append("</div>")
- end
-
- private fun classes_column do
- var sorter = new MClassNameSorter
- var sorted = new Array[MClass]
- sorted.add_all(intro_mclasses)
- sorted.add_all(redef_mclasses)
- sorter.sort(sorted)
- if not sorted.is_empty then
- append("<nav class='properties filterable'>")
- append("<h3>Classes</h3>")
- append("<h4>Classes</h4>")
- append("<ul>")
- for mclass in sorted do mclass.html_sidebar_item(self)
- append("</ul>")
- append("</nav>")
- end
- end
-
- private fun importation_column do
- append("<nav>")
- append("<h3>Module Hierarchy</h3>")
- var dependencies = new Array[MModule]
- for dep in mmodule.in_importation.greaters do
- if dep == mmodule or dep.direct_owner == mmodule or dep.public_owner == mmodule then continue
- dependencies.add(dep)
- end
- if mmodule.in_nesting.direct_greaters.length > 0 then
- append("<h4>Nested Modules</h4>")
- display_module_list(mmodule.in_nesting.direct_greaters.to_a)
- end
- if dependencies.length > 0 then
- append("<h4>All dependencies</h4>")
- display_module_list(dependencies)
- end
- var clients = new Array[MModule]
- for dep in mmodule.in_importation.smallers do
- if dep.name == "<main>" then continue
- if dep == mmodule then continue
- clients.add(dep)
- end
- if clients.length > 0 then
- append("<h4>All clients</h4>")
- display_module_list(clients)
- end
- append("</nav>")
- end
-
- private fun display_module_list(list: Array[MModule]) do
- append("<ul>")
- var sorter = new MModuleNameSorter
- sorter.sort(list)
- for m in list do
- append("<li>")
- m.html_link(self)
- append("</li>")
- end
- append("</ul>")
- end
-
- private fun module_doc do
- # title
- append("<h1>{mmodule.html_name}</h1>")
- append("<div class='subtitle info'>")
- mmodule.html_signature(self)
- append("</div>")
- # comment
- mmodule.html_comment(self)
- process_generate_dot
- # classes
- var class_sorter = new MClassNameSorter
- # intro
- if not intro_mclasses.is_empty then
- var sorted = new Array[MClass]
- sorted.add_all(intro_mclasses)
- class_sorter.sort(sorted)
- append("<section class='classes'>")
- append("<h2 class='section-header'>Introduced classes</h2>")
- for mclass in sorted do mclass.html_full_desc(self)
- append("</section>")
- end
- # redefs
- var redefs = new Array[MClass]
- for mclass in redef_mclasses do if not intro_mclasses.has(mclass) then redefs.add(mclass)
- class_sorter.sort(redefs)
- if not redefs.is_empty then
- append("<section class='classes'>")
- append("<h2 class='section-header'>Refined classes</h2>")
- for mclass in redefs do mclass.html_full_desc(self)
- append("</section>")
- end
- end
-
- private fun process_generate_dot do
- # build poset with public owners
- var poset = new POSet[MModule]
- for mmodule in self.mmodule.in_importation.poset do
- if mmodule.name == "<main>" then continue
- #if mmodule.public_owner != null then continue
- if not mmodule.in_importation < self.mmodule and not self.mmodule.in_importation < mmodule and mmodule != self.mmodule then continue
- poset.add_node(mmodule)
- for omodule in mmodule.in_importation.poset do
- if mmodule == omodule then continue
- if omodule.name == "<main>" then continue
- if not omodule.in_importation < self.mmodule and not self.mmodule.in_importation < omodule then continue
- if omodule.in_importation < mmodule then
- poset.add_node(omodule)
- poset.add_edge(omodule, mmodule)
- end
- if mmodule.in_importation < omodule then
- poset.add_node(omodule)
- poset.add_edge(mmodule, omodule)
- end
- #if omodule.public_owner != null then continue
- #if mmodule.in_importation < omodule then
- #poset.add_node(omodule)
- #poset.add_edge(mmodule, omodule)
- #end
- end
- end
- # build graph
- var op = new FlatBuffer
- var name = "dep_{mmodule.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 mmodule in poset do
- if mmodule == self.mmodule then
- op.append("\"{mmodule.name}\"[shape=box,margin=0.03];\n")
- else
- op.append("\"{mmodule.name}\"[URL=\"{mmodule.url}\"];\n")
- end
- for omodule in poset[mmodule].direct_greaters do
- op.append("\"{mmodule.name}\"->\"{omodule.name}\";\n")
- end
- end
- op.append("\}\n")
- generate_dot(op.to_s, name, "Dependency graph for module {mmodule.name}")
- end
-end
-
-# A class page
-class NitdocClass
- super NitdocPage
-
- private var mclass: MClass
- private var vtypes = new HashSet[MVirtualTypeDef]
- private var consts = new HashSet[MMethodDef]
- private var meths = new HashSet[MMethodDef]
- private var inherited = new HashSet[MPropDef]
-
- init(mclass: MClass, ctx: NitdocContext) do
- super(ctx)
- self.mclass = mclass
- # load properties
- var locals = new HashSet[MProperty]
- for mclassdef in mclass.mclassdefs do
- for mpropdef in mclassdef.mpropdefs do
- if mpropdef.mproperty.visibility < ctx.min_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
- locals.add(mpropdef.mproperty)
- end
- end
- # get inherited properties
- for pclass in mclass.in_hierarchy(ctx.mainmodule).greaters do
- if pclass == mclass then continue
- for pclassdef in pclass.mclassdefs do
- for mprop in pclassdef.intro_mproperties do
- var mpropdef = mprop.intro
- if mprop.visibility < ctx.min_visibility then continue # skip if not correct visibiility
- if locals.has(mprop) then continue # skip if local
- if mclass.name != "Object" and mprop.intro_mclassdef.mclass.name == "Object" and (mprop.visibility <= protected_visibility or mprop.intro_mclassdef.mmodule.public_owner == null or mprop.intro_mclassdef.mmodule.public_owner.name != "standard") then continue # skip toplevels
- 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
- inherited.add(mpropdef)
- end
- end
- end
- end
-
- redef fun title do
- var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
- if nclass isa AStdClassdef then
- return "{mclass.html_name} class | {nclass.short_comment}"
- else
- return "{mclass.html_name} class"
- end
- end
-
- redef fun menu do
- super
- append("<li><a href='index.html'>Overview</a></li>")
- var public_owner = mclass.public_owner
- if public_owner == null then
- append("<li>")
- mclass.intro_mmodule.html_link(self)
- append("</li>")
- else
- append("<li>")
- public_owner.html_link(self)
- append("</li>")
- end
- append("<li class='current'>{mclass.html_name}</li>")
- append("<li><a href='search.html'>Search</a></li>")
- end
-
- redef fun content do
- append("<div class='sidebar'>")
- properties_column
- inheritance_column
- append("</div>")
- append("<div class='content'>")
- class_doc
- append("</div>")
- end
-
- private fun properties_column do
- var sorter = new MPropDefNameSorter
- append("<nav class='properties filterable'>")
- append("<h3>Properties</h3>")
- # virtual types
- if vtypes.length > 0 then
- var vts = new Array[MVirtualTypeDef]
- vts.add_all(vtypes)
- sorter.sort(vts)
- append("<h4>Virtual Types</h4>")
- append("<ul>")
- for mprop in vts do
- mprop.html_sidebar_item(self)
- end
- append("</ul>")
- end
- # constructors
- if consts.length > 0 then
- var cts = new Array[MMethodDef]
- cts.add_all(consts)
- sorter.sort(cts)
- append("<h4>Constructors</h4>")
- append("<ul>")
- for mprop in cts do
- if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
- mprop.html_sidebar_item(self)
- end
- append("</ul>")
- end
- # methods
- if meths.length > 0 then
- var mts = new Array[MMethodDef]
- mts.add_all(meths)
- sorter.sort(mts)
- append("<h4>Methods</h4>")
- append("<ul>")
- for mprop in mts do
- mprop.html_sidebar_item(self)
- end
- append("</ul>")
- end
- append("</nav>")
- end
-
- private fun inheritance_column do
- var sorted = new Array[MClass]
- var sorterp = new MClassNameSorter
- append("<nav>")
- append("<h3>Inheritance</h3>")
- var greaters = mclass.in_hierarchy(ctx.mainmodule).greaters.to_a
- if greaters.length > 1 then
- ctx.mainmodule.linearize_mclasses(greaters)
- append("<h4>Superclasses</h4>")
- append("<ul>")
- for sup in greaters do
- if sup == mclass then continue
- append("<li>")
- sup.html_link(self)
- append("</li>")
- end
- append("</ul>")
- end
- var smallers = mclass.in_hierarchy(ctx.mainmodule).smallers.to_a
- var direct_smallers = mclass.in_hierarchy(ctx.mainmodule).direct_smallers.to_a
- if smallers.length <= 1 then
- append("<h4>No Known Subclasses</h4>")
- else if smallers.length <= 100 then
- ctx.mainmodule.linearize_mclasses(smallers)
- append("<h4>Subclasses</h4>")
- append("<ul>")
- for sub in smallers do
- if sub == mclass then continue
- append("<li>")
- sub.html_link(self)
- append("</li>")
- end
- append("</ul>")
- else if direct_smallers.length <= 100 then
- ctx.mainmodule.linearize_mclasses(direct_smallers)
- append("<h4>Direct Subclasses Only</h4>")
- append("<ul>")
- for sub in direct_smallers do
- if sub == mclass then continue
- append("<li>")
- sub.html_link(self)
- append("</li>")
- end
- append("</ul>")
- else
- append("<h4>Too much Subclasses to list</h4>")
- end
- append("</nav>")
- end
-
- private fun class_doc do
- # title
- append("<h1>{mclass.html_name}{mclass.html_short_signature}</h1>")
- append("<div class='subtitle info'>")
- if mclass.visibility < public_visibility then append("{mclass.visibility.to_s} ")
- append("{mclass.kind.to_s} ")
- mclass.html_namespace(self)
- append("{mclass.html_short_signature}</div>")
- # comment
- mclass.html_comment(self)
- process_generate_dot
- # concerns
- var concern2meths = new ArrayMap[MModule, Array[MMethodDef]]
- var sorted_meths = new Array[MMethodDef]
- var sorted = new Array[MModule]
- sorted_meths.add_all(meths)
- ctx.mainmodule.linearize_mpropdefs(sorted_meths)
- for meth in meths do
- if inherited.has(meth) then continue
- var mmodule = meth.mclassdef.mmodule
- if not concern2meths.has_key(mmodule) then
- sorted.add(mmodule)
- concern2meths[mmodule] = new Array[MMethodDef]
- end
- concern2meths[mmodule].add(meth)
- end
- var sections = new ArrayMap[MModule, Array[MModule]]
- for mmodule in concern2meths.keys do
- var owner = mmodule.public_owner
- if owner == null then owner = mmodule
- if not sections.has_key(owner) then sections[owner] = new Array[MModule]
- if owner != mmodule then sections[owner].add(mmodule)
- end
- append("<section class='concerns'>")
- append("<h2 class='section-header'>Concerns</h2>")
- append("<ul>")
- for owner, mmodules in sections do
- var nowner = ctx.mbuilder.mmodule2nmodule[owner]
- append("<li>")
- if nowner.short_comment.is_empty then
- append("<a href=\"#{owner.anchor}\">{owner.html_name}</a>")
- else
- append("<a href=\"#{owner.anchor}\">{owner.html_name}</a>: {nowner.short_comment}")
- end
- if not mmodules.is_empty then
- append("<ul>")
- for mmodule in mmodules do
- var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
- if nmodule.short_comment.is_empty then
- append("<li><a href=\"#{mmodule.anchor}\">{mmodule.html_name}</a></li>")
- else
- append("<li><a href=\"#{mmodule.anchor}\">{mmodule.html_name}</a>: {nmodule.short_comment}</li>")
- end
- end
- append("</ul>")
- end
- append("</li>")
- end
- append("</ul>")
- append("</section>")
- # properties
- var prop_sorter = new MPropDefNameSorter
- var lmmodule = new List[MModule]
- var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
- # virtual and formal types
- var local_vtypes = new Array[MVirtualTypeDef]
- for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
- if local_vtypes.length > 0 or mclass.arity > 0 then
- append("<section class='types'>")
- append("<h2>Formal and Virtual Types</h2>")
- # formal types
- if mclass.arity > 0 and nclass isa AStdClassdef then
- for ft, bound in mclass.parameter_types do
- append("<article id='FT_{ft}'>")
- append("<h3 class='signature' data-untyped-signature='{ft.to_s}'><span>{ft}: ")
- bound.html_link(self)
- append("</span></h3>")
- append("<div class=\"info\">formal generic type</div>")
- append("</article>")
- end
- end
- # virtual types
- prop_sorter.sort(local_vtypes)
- for prop in local_vtypes do prop.html_full_desc(self, self.mclass)
- append("</section>")
- end
- # constructors
- var local_consts = new Array[MMethodDef]
- for const in consts do if not inherited.has(const) then local_consts.add(const)
- prop_sorter.sort(local_consts)
- if local_consts.length > 0 then
- append("<section class='constructors'>")
- append("<h2 class='section-header'>Constructors</h2>")
- for prop in local_consts do prop.html_full_desc(self, self.mclass)
- append("</section>")
- end
- # methods
- if not concern2meths.is_empty then
- append("<section class='methods'>")
- append("<h2 class='section-header'>Methods</h2>")
- for owner, mmodules in sections do
- append("<a id=\"{owner.anchor}\"></a>")
- if owner != mclass.intro_mmodule and owner != mclass.public_owner then
- var nowner = ctx.mbuilder.mmodule2nmodule[owner]
- append("<h3 class=\"concern-toplevel\">Methods refined in ")
- owner.html_link(self)
- append("</h3>")
- append("<p class=\"concern-doc\">")
- owner.html_link(self)
- if not nowner.short_comment.is_empty then
- append(": {nowner.short_comment}")
- end
- append("</p>")
- end
- if concern2meths.has_key(owner) then
- var mmethods = concern2meths[owner]
- prop_sorter.sort(mmethods)
- for prop in mmethods do prop.html_full_desc(self, self.mclass)
- end
- for mmodule in mmodules do
- append("<a id=\"{mmodule.anchor}\"></a>")
- var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
- if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
- append("<p class=\"concern-doc\">")
- mmodule.html_link(self)
- if not nmodule.short_comment.is_empty then
- append(": {nmodule.short_comment}")
- end
- append("</p>")
- end
- var mmethods = concern2meths[mmodule]
- prop_sorter.sort(mmethods)
- for prop in mmethods do prop.html_full_desc(self, self.mclass)
- end
- end
- append("</section>")
- end
- # inherited properties
- if inherited.length > 0 then
- var sorted_inherited = new Array[MPropDef]
- sorted_inherited.add_all(inherited)
- ctx.mainmodule.linearize_mpropdefs(sorted_inherited)
- var classes = new ArrayMap[MClass, Array[MPropDef]]
- for mmethod in sorted_inherited.reversed do
- var mclass = mmethod.mclassdef.mclass
- if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
- classes[mclass].add(mmethod)
- end
- append("<section class='inherited'>")
- append("<h2 class='section-header'>Inherited Properties</h2>")
- for c, mmethods in classes do
- prop_sorter.sort(mmethods)
- append("<p>Defined in ")
- c.html_link(self)
- append(": ")
- for i in [0..mmethods.length[ do
- var mmethod = mmethods[i]
- mmethod.html_link(self)
- if i <= mmethods.length - 1 then append(", ")
- end
- append("</p>")
- end
- append("</section>")
- end
- end
-
- private fun process_generate_dot do
- var pe = ctx.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 FlatBuffer
- 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.url}\"];\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}")