- var d = opt_dir.value
- if d != null then dir = d
-
- if not opt_nodot.value then
- # Test if dot is runable
- var res = sys.system("sh -c dot </dev/null >/dev/null 2>&1")
- if res != 0 then
- stderr.write "--no-dot implied since `dot' is not available. Try to install graphviz.\n"
- opt_nodot.value = true
- end
- end
-
- sharedir = opt_sharedir.value
- if sharedir == null then
- var dir = "NIT_DIR".environ
- if dir.is_empty then
- dir = "{sys.program_name.dirname}/../share/nitdoc"
- if dir.file_exists then sharedir = dir
- else
- dir = "{dir}/share/nitdoc"
- if dir.file_exists then sharedir = dir
- end
- if sharedir == null then
- fatal_error(null, "Error: Cannot locate nitdoc shared files. Uses --sharedir or envvar NIT_DIR.")
- end
- dir = "{sharedir.to_s}/scripts/js-facilities.js"
- if sharedir == null then
- fatal_error(null, "Error: Invalid nitdoc shared files. Check --sharedir or envvar NIT_DIR.")
- end
-
- end
- var git = opt_github_repo_name.value
- if not git == null then github_repo = git
- end
-
- redef fun handle_property_conflict(lc, impls)
- do
- # THIS IS SO UGLY! See MMVirtualModule
- if lc.mmmodule == self.mainmod then
- return # We just accept, so one in impls is arbitrary inherited
- end
- super
- end
-end
-
-# A virtual module is used to work as an implicit main module that combine unrelated modules
-# Since conflict may arrise in a virtual module (the main method for instance) conflicts are disabled
-class MMVirtualModule
- super MMModule
- init(ctx: MMContext, mods: Array[MMModule])
- do
- # We need to compute the whole metamodel since there is no mmbuilder to do it
- super(" main".to_symbol, mods.first.directory, ctx, new Location(null,0,0,0,0))
- ctx.add_module(self, mods)
- for m in mods do
- self.add_super_module(m, 1)
- end
- self.import_global_classes
- self.import_local_classes
- for c in self.local_classes do
- c.compute_super_classes
- end
- for c in self.local_classes do
- c.compute_ancestors
- end
-
- end
- redef fun require_doc(dctx) do return false
-end
-
-# Conditionnal part of the text content of a DocContext
-class StageContext
- # Content of the current stage
- readable var _content: Array[String] = new Array[String]
-
- # Is a normal string already added?
- readable writable var _validate: Bool = false
-
- # Parent stage is any
- readable var _parent: nullable StageContext = null
-
- init(parent: nullable StageContext) do _parent = parent
-end
-
-
-# Efficiently sort object with their to_s method
-class AlphaSorter[E: Object]
- super AbstractSorter[E]
- redef fun compare(a, b)
- do
- var sa: String
- var sb: String
- var d = _dico
- if d.has_key(a) then
- sa = d[a]
- else
- sa = a.to_s
- d[a] = sa
- end
- if d.has_key(b) then
- sb = d[b]
- else
- sb = b.to_s
- d[b] = sb
- end
- return sa <=> sb
- end
-
- # Keep track of to_s values
- var _dico: HashMap[Object, String] = new HashMap[Object, String]
-
- init do end
-end
-
-# Generalization of metamodel entities
-interface MMEntity
- # Return a link to
- fun html_link(dctx: DocContext): String is abstract
-
- # Return a one liner description
- fun short_doc: String do return " "
-
- # The doc node from the AST
- # Return null is none
- fun doc: nullable ADoc do return null
-
- # Return a JSON entry for quicksearch list
- fun json_entry(dctx: DocContext): String is abstract
-
- # Return the qualified name as string
- fun qualified_name: String is abstract
-
-end
-
-redef class MMModule
- super MMEntity
- redef fun html_link(dctx) do
- if short_doc == " " then
- return "<a href=\"{html_name}.html\"\">{self}</a>"
- else
- return "<a href=\"{html_name}.html\" title=\"{short_doc}\">{self}</a>"
- end
- end
-
- fun html_anchor: String do
- return "<a id=\"MOD_{html_name}\"></a>"
- end
-
- fun html_link_to_anchor: String do
- return "<a href=\"#MOD_{html_name}\" title=\"Jump to definitions from module {html_name}\">{self}</a>"
- end
-
- redef fun json_entry(dctx) do
- return "\{txt:\"{self.qualified_name}\",url:\"{html_name}.html\"\},"
- end
-
- redef fun qualified_name do
- var buffer = new Buffer
- for m in mnhe.smallers do
- buffer.append("{m.html_name}::")
- end
- buffer.append("{self.name}")
- return buffer.to_s
- end
-
- fun require_doc(dctx: DocContext): Bool
- do
- if dctx.public_only and not is_toplevel then return false
- return true
- end
-
- # Return true if the module is a top-level owner or a top-level module
- fun is_toplevel: Bool
- do
- var pd = directory.parent
- return pd == null or (pd.owner == null and directory.owner == self)
- end
-
- # Element in the module nesting tree
- fun mnhe: PartialOrderElement[MMModule] do return mnhe_.as(not null)
- var mnhe_: nullable PartialOrderElement[MMModule] = null
-
- # Element in the top level module importation hierarchy
- fun tmhe: PartialOrderElement[MMModule] do return tmhe_.as(not null)
- var tmhe_: nullable PartialOrderElement[MMModule] = null
-
- fun toplevel_owner: MMModule
- do
- var m = self
- loop
- var ds = m.mnhe.direct_smallers
- if ds.length == 0 then return m
- if ds.length == 1 then m = ds.first else abort
- end
- end
-
- fun html_name: String
- do
- return "{name}"
- end
-
- fun direct_owner: nullable MMModule
- do
- var d = directory
- while d.owner == self do d = d.parent.as(not null)
- return d.owner
- end
-
- # Fill the body for the page associated to the module
- fun file_page_doc(dctx: DocContext)
- do
- dctx.add("<div class=\"menu\">\n")
-
- var mods = new Array[MMModule]
- mods = self.mhe.greaters.to_a
- dctx.sort(mods)
-
- dctx.open_stage
- dctx.stage("<nav>\n")
- dctx.stage("<h3>Module Hierarchy</h3>\n")
- dctx.stage("<h4>All dependencies</h4>\n")
- dctx.stage("<ul>\n")
- for mod in mods do
- if not mod.require_doc(dctx) then continue
- if self.mnhe <= mod then continue # do not want nested stuff
- if mod.direct_owner != null and not mod.direct_owner.mnhe <= self then continue # not in the right nesting
- dctx.add("<li>{mod.html_link(dctx)}</li>")
- end
- dctx.stage("</ul>\n")
-
- mods = self.mhe.smallers.to_a
- dctx.sort(mods)
- dctx.stage("<h4>All clients</h4>\n")
- dctx.stage("<ul>\n")
- for mod in mods do
- if not mod.require_doc(dctx) then continue
- if self.mnhe <= mod then continue # do not want nested stuff
- if mod.direct_owner != null and not mod.direct_owner.mnhe <= self then continue # not in the right nesting
- dctx.add("<li>{mod.html_link(dctx)}</li>")
- end
- dctx.stage("</ul>\n")
- dctx.stage("</nav>\n")
- dctx.close_stage
-
- if not dctx.public_only then
- mods = self.mnhe.direct_greaters.to_a
- dctx.sort(mods)
- dctx.open_stage
- dctx.stage("<nav>\n")
- dctx.stage("<h3>Nested Modules</h3><ul>\n")
- for mod in mods do
- if not mod.require_doc(dctx) then continue
- dctx.add("<li>{mod.html_link(dctx)}</li>")
- end
- dctx.stage("</ul></nav>\n")
- dctx.close_stage
- end
-
- dctx.add("</div>") # metadata
-
- dctx.add("<div class=\"content\">\n")
- dctx.add("<h1>{name}</h1>\n")
- dctx.add("<div class='subtitle'>module ")
- for m in mnhe.smallers do
- dctx.add("{m.html_link(dctx)}::")
- end
- dctx.add("{self.name}</div>\n")
-
- dctx.add("<section class='description'>\n")
-
- var doc = doc
- if doc != null then
- dctx.add("<div id=\"description\">\n")
- dctx.add("<pre>{doc.to_html}</pre>\n")
- dctx.add("</div>\n")
- end
-
- 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")
- var ms = new Array[nullable MMModule]
- do
- var m0: nullable MMModule = self
- while m0 != null do
- m0 = m0.direct_owner
- ms.add(m0)
- end
- end
- var cla = new HashSet[MMModule]
- cla.add(self)
- for m0 in self.mhe.greaters do
- if not m0.require_doc(dctx) then continue
- if self.visibility_for(m0) <= 1 then continue # private or hidden
- if self.mnhe <= m0 then continue # do not want nested stuff
- if m0.direct_owner != null and not m0.direct_owner.mnhe <= self then continue # not in the right nesting
- cla.add(m0)
- end
- for m0 in self.mhe.smallers do
- if not m0.require_doc(dctx) then continue
- if m0.visibility_for(self) <= 1 then continue # private or hidden
- if m0.direct_owner != null and not m0.direct_owner.mnhe <= self then continue # not in the right nesting
- cla.add(m0)
- end
- for m0 in self.mnhe.smallers do
- cla.add(m0)
- end
- ms = ms.reversed
- for m0 in ms do
- if m0 != null then
- op.append("subgraph \"cluster_{m0.name}\"\{\n")
- end
- for c in cla do
- if c.direct_owner != m0 then continue
- if c == self then
- op.append("\"{c.name}\"[shape=box,margin=0.03];\n")
- else
- op.append("\"{c.name}\"[URL=\"{c.html_name}.html\"];\n")
- end
- end
- if m0 != null then
- op.append("\"{m0.name}\"[URL=\"{m0.html_name}.html\"];\n")
- for c in m0.mhe.direct_greaters do
- if not cla.has(c) then continue
- op.append("\"{m0.name}\"->\"{c.name}\";\n")
- end
- end
- end
- for m0 in ms do
- # Close the nesting subgraph
- if m0 != null then
- op.append("\}\n")
- end
- end
- for c in cla do
- for c2 in c.tmhe.direct_greaters do
- if not cla.has(c2) then continue
- op.append("\"{c.name}\"->\"{c2.name}\";\n")
- end
- end
- op.append("\}\n")
- dctx.gen_dot(op.to_s, name.to_s, "Dependency graph for module {name}")
- dctx.add("</section>")
-
- var clas = new Array[MMLocalClass]
- var props = new HashMap[MMGlobalProperty, Array[MMLocalProperty]]
- var gprops = new Array[MMLocalProperty]
- do
- var m = self
- for g in m.global_classes do
- var lc = m[g]
- if not lc.require_doc(dctx) then continue
- var im = g.intro.mmmodule
- if self.visibility_for(im) <= 1 then continue # private import or invisible import
- var keep = false
- for lc2 in lc.crhe.greaters_and_self do
- if not lc2 isa MMSrcLocalClass then continue
- if not self.mnhe <= lc2.mmmodule then continue # not introduced/redefined here/stolen
- keep = true
- end
- if not keep then continue
- clas.add(self[g])
- lc.compute_super_classes
- for gp in lc.global_properties do
- if self.visibility_for(gp.intro.local_class.mmmodule) <= 1 then continue # private import or invisible import
- var lp = lc[gp]
- var mp = lp.local_class.mmmodule
- if not self.mnhe <= mp then continue # not introduced/redefined here/stolen
- lp = self[g][gp]
- if not lp.require_doc(dctx) then continue
- if props.has_key(lp.global) then
- if not props[lp.global].has(lp) then
- props[lp.global].add(lp)
- end
- else
- props[lp.global] = [lp]
- gprops.add(lp.global.intro)
- end
- end
- end
- end
- dctx.add("<section class=\"module\">\n")
- dctx.open_stage
- dctx.stage("<article class=\"classes filterable\">\n")
- dctx.stage("<h2>Classes</h2>\n")
- dctx.sort(clas)
- dctx.stage("<ul>\n")
- for lc in clas do
- if self.mnhe <= lc.global.intro.mmmodule then
- dctx.add("<li class='intro'><span title='introduced in this module'>I</span> ")
- else
- dctx.add("<li class='redef'><span title='refined in this module'>R</span> ")
- end
- dctx.add("{lc.html_link(dctx)}</li>\n")
- end
- dctx.stage("</ul></article>\n")
- dctx.close_stage
-
- dctx.open_stage
- dctx.stage("<article class=\"properties filterable\">\n")
- dctx.stage("<h2>Properties</h2>\n")
- dctx.sort(gprops)
- dctx.stage("<ul>\n")
- for lgp in gprops do
- var gp = lgp.global
- var lps = props[gp]
-
- if gp.intro isa MMAttribute then continue
-
- var lpi = self[gp.intro.local_class.global][gp]
-
- if lps.has(lpi) then
- dctx.add("<li class='intro'><span title='introduction in an other module'>I</span> {lpi.html_open_link(dctx)}{lpi.html_name} ({lpi.local_class})</a></li>\n")
- lps.remove(lpi)
- else
- dctx.add("<li class='intro'><span title='introduction in this module'>I</span> {lpi.html_name}")
- dctx.add(" ({lpi.local_class})</li>\n")
- end
- if lps.length >= 1 then
- dctx.sort(lps)
- for lp in lps do
- dctx.add("<li class='redef'><span title='redefinition'>R</span> {lp.html_open_link(dctx)}{lp.html_name} ({lp.local_class})</a></li>")
- end
- end
- end
- dctx.stage("</ul></article>\n")
- dctx.close_stage
- dctx.add("</section>\n")
- dctx.add("</div>\n")
- end
-
- # Fill the body for the page associated to the full index
- fun file_index_page_doc(dctx: DocContext)
- do
-
- dctx.add("<h1>Full Index</h1>\n")
-
- var clas = new Array[MMLocalClass]
- var props = new HashMap[MMGlobalProperty, Array[MMLocalProperty]]
- var gprops = new Array[MMLocalProperty]
- var mods = new Array[MMModule]
- for m in mhe.greaters_and_self do
- if not m.require_doc(dctx) then continue
- mods.add(m)
- end
- for g in global_classes do
- var lc = self[g]
- if not lc.require_doc(dctx) then continue
- clas.add(lc)
- for gp in lc.global_properties do
- var lp = lc[gp]
- if not lp.require_doc(dctx) then continue
- if props.has_key(lp.global) then
- if not props[lp.global].has(lp) then
- props[lp.global].add(lp)
- end
- else
- props[lp.global] = [lp]
- gprops.add(lp.global.intro)
- end
- end
- end
- dctx.open_stage
- dctx.stage("<article class=\"modules filterable\">\n")
- dctx.stage("<h2>Modules</h2>\n")
- dctx.sort(mods)
- dctx.stage("<ul>\n")
- for m in mods do
- dctx.add("<li>{m.html_link(dctx)}</li>")
- end
- dctx.stage("</ul></article>\n")
- dctx.close_stage
-
- dctx.open_stage
- dctx.stage("<article class=\"classes filterable\">\n")
- dctx.stage("<h2>Classes</h2>\n")
- dctx.sort(clas)
- dctx.stage("<ul>\n")
- for lc in clas do
- dctx.add("<li>{lc.html_link(dctx)}</li>")
- end
- dctx.stage("</ul></article>\n")
- dctx.close_stage
-
- dctx.open_stage
- dctx.stage("<article class=\"properties filterable\">\n")
- dctx.stage("<h2>Properties</h2>\n")
- dctx.sort(gprops)
- dctx.stage("<ul>\n")
- for lgp in gprops do
- var gp = lgp.global
- var lps = props[gp]
-
- if gp.intro isa MMAttribute then continue
-
- var lpi = self[gp.intro.local_class.global][gp]
-
- lps.remove(lpi)
- dctx.add("<li class='intro'><span title='introduction'>I</span> {lpi.html_open_link(dctx)}{lpi.html_name} ({lpi.local_class})</a></li>\n")
- if lps.length >= 1 then
- dctx.sort(lps)
- for lp in lps do
- dctx.add("<li class='redef'><span title='redefinition'>R</span> {lp.html_open_link(dctx)}{lp.html_name} ({lp.local_class})</a></li>\n")
- end
- end
- end
- dctx.stage("</ul></article>\n")
- dctx.close_stage
- end
-
- # Fill the quicksearch list JSON object
- fun file_quicksearch_list_doc(dctx: DocContext)
- do
- var entities = new HashMap[String, Array[MMEntity]]
- var props = new HashMap[MMGlobalProperty, Array[MMLocalProperty]]
- for m in mhe.greaters_and_self do
- if not m.require_doc(dctx) then continue
- var a = new Array[MMEntity]
- a.add(m)
- entities[m.html_name] = a
- end
- for g in global_classes do
- var lc = self[g]
- if not lc.require_doc(dctx) then continue
- var a = new Array[MMEntity]
- a.add(lc)
- entities[lc.html_name] = a
- for gp in lc.global_properties do
- var lp = lc[gp]
- if not lp.require_doc(dctx) then continue
- if lp.kind == "var" then continue
- if props.has_key(lp.global) then
- if not props[lp.global].has(lp) then
- props[lp.global].add(lp)
- end
- else
- props[lp.global] = [lp]
- end
- end
- end
-
- for k, v in props do
- entities[k.short_name] = v
- end
-
- var keys = entities.keys.to_a
- var sorter = new AlphaSorter[String]
- sorter.sort(keys)
-
- dctx.open_stage
- dctx.stage("var entries = \{")
- for key in keys do
- dctx.add("\"{key}\": [")
- for entity in entities[key] do
- dctx.add(entity.json_entry(dctx))
- end
- dctx.add("],")
- end
- dctx.stage("\};")
- dctx.close_stage
- end
-end
-
-redef class MMGlobalProperty
- # Return the short name of the property
- fun short_name: String do
- return self.intro.html_name