-redef class MMLocalClass
- super MMEntity
- # Anchor of the class description in the module html file
- fun html_anchor: String do return "CLASS_{self}"
-
- redef fun html_link(dctx)
- do
- var m = mmmodule
- if not need_doc(dctx) then m = global.mmmodule
- m = dctx.known_owner_of(m)
- if m == dctx.mmmodule then
- return "<a href=\"#{html_anchor}\">{self}</a>"
- else
- return "<a href=\"{m}.html#{html_anchor}\">{self}</a>"
- end
- end
-
- redef fun short_doc do return global.intro.short_doc
-
- redef fun doc do return global.intro.doc
-
- redef fun need_doc(dctx) do
- if mmmodule == dctx.mmmodule then
- for m in dctx.owned_modules do
- if m.global_classes.has(global) then
- var c = m[global]
- if c.need_doc(dctx) then return true
- end
- end
- end
- return false
- end
-
- redef fun locate(dctx) do return "in {mmmodule.html_link(dctx)}"
-
- fun known_intro(dctx: DocContext): MMLocalClass do return dctx.known_owner_of(global.intro.mmmodule)[global]
-
- redef fun prototype_head(dctx)
- do
- var res = new Buffer
- var ki = known_intro(dctx)
- var is_redef = ki != self
- if is_redef then res.append("redef ")
- if global.visibility_level == 3 then res.append("private ")
- res.append("class ")
- if is_redef then res.append("{ki.mmmodule.html_link(dctx)}::")
- return res.to_s
- end
-
- redef fun prototype_body(dctx)
- do
- var res = new Buffer
- if arity > 0 then
- res.append("[")
- for i in [0..arity[ do
- var t = get_formal(i)
- res.append(t.name.to_s)
- res.append(": ")
- res.append(t.bound.html_link(dctx))
- end
- res.append("]")
- end
- return res.to_s
- end
-
- # Extract the doc of a class
- fun extract_class_doc(dctx: DocContext)
- do
- dctx.add("<a name=\"{html_anchor}\"></a><h2>{self}</h2><small>{mmmodule.html_link(dctx)}::</small><br/>{prototype_head(dctx)}<b>{self}</b>{prototype_body(dctx)}\n")
- dctx.add("<blockquote>\n")
- dctx.add("<dl>\n")
-
- var sup2 = new Array[String]
- var intro_module = dctx.known_owner_of(global.mmmodule)
- if intro_module != mmmodule then
- dctx.add("<dt>Refine {self} from: <dd>{intro_module.html_link(dctx)}\n")
- sup2.clear
- var mods = new Array[MMModule]
- for c in crhe.greaters do
- if c.need_doc(dctx) then
- var km = dctx.known_owner_of(c.mmmodule)
- if km != mmmodule and km != intro_module and not mods.has(km) then
- mods.add(km)
- end
- end
- end
- for c in crhe.linear_extension do
- if mods.has(c.mmmodule) then sup2.add(c.mmmodule.html_link(dctx))
- end
- if not sup2.is_empty then dctx.add("<dt>Previous refinements in: <dd>{sup2.join(", ")}\n")
- end
- if not cshe.greaters.is_empty then
- sup2.clear
- var clas = new Array[MMLocalClass]
- for c in cshe.direct_greaters do
- sup2.add(c.html_link(dctx))
- end
- dctx.add("<dt>Direct superclasses: <dd>{sup2.join(", ")}\n")
- sup2.clear
- for c in cshe.linear_extension do
- if c != self then sup2.add(c.html_link(dctx))
- end
- dctx.add("<dt>All superclasses: <dd>{sup2.join(", ")}\n")
- end
- if not cshe.direct_smallers.is_empty then
- sup2.clear
- for c in cshe.direct_smallers do
- sup2.add(c.html_link(dctx))
- end
- dctx.add("<dt>Direct subclasses: <dd>{sup2.join(", ")}\n")
- end
- sup2.clear
- for c in crhe.smallers do
- c.compute_super_classes
- for c2 in c.mmmodule.local_classes do
- if not c2 isa MMConcreteClass then continue
- c2.compute_super_classes
- c2.compute_ancestors
- end
- for c2 in c.cshe.direct_smallers do
- if c2.global.intro == c2 then
- sup2.add("{c2.html_link(dctx)}")
- end
- end
- end
- if not sup2.is_empty then
- dctx.add("<dt>Other direct subclasses in known modules: <dd>{sup2.join(", ")}\n")
- end
- sup2.clear
- for c in crhe.order do
- if not mmmodule.mhe <= c.mmmodule and c.need_doc(dctx) then
- sup2.add(c.mmmodule.html_link(dctx))
- end
- end
- if not sup2.is_empty then
- dctx.add("<dt>Refinements in known modules: <dd>{sup2.join(", ")}\n")
- end
- dctx.add("</dl>\n")
-
- var doc = doc
- if doc != null then
- dctx.add("<pre>{doc.to_html}</pre>\n")
- end
-
- var details = new Array[Array[MMLocalProperty]]
- for i in [0..4[ do details.add(property_summary(dctx, i))
- for i in [0..4[ do property_detail(dctx, i, details[i])
-
- dctx.add("</blockquote><hr/>\n")
- end
-
- fun pass_name(pass: Int): String
- do
- var names = once ["Virtual Types", "Consructors", "Methods", "Attributes"]
- return names[pass]
- end
-
- fun accept_prop(p: MMLocalProperty, pass: Int): Bool
- do
- if pass == 0 then
- return p isa MMTypeProperty
- else if pass == 1 then
- return p.global.is_init
- else if pass == 2 then
- return p isa MMMethod and not p.global.is_init
- else if pass == 3 then
- return p isa MMAttribute
- end
- abort
- end
-
- fun property_summary(dctx: DocContext, pass: Int): Array[MMLocalProperty]
- do
- var passname = pass_name(pass)
- dctx.open_stage
- dctx.stage("<table border=\"1\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\">\n")
- dctx.stage("<tr bgcolor=\"#CCCCFF\"><th colspan=\"2\">{passname} Summary of {self}</th></tr>\n")
-
- var new_props = new Array[MMLocalProperty]
- for g in global_properties do
- if not accept_prop(g.intro, pass) then continue
- if mmmodule.visibility_for(g.intro.mmmodule) < g.visibility_level then continue
- var p = self[g]
- if p.local_class != self or not p.need_doc(dctx) then
- var cla = new Array[MMLocalClass]
- for m in dctx.owned_modules do
- if not m.global_classes.has(global) then continue
- var c = m[global]
- if not c isa MMConcreteClass then continue
- if not c.has_global_property(g) then continue
- var p2 = c[g]
- if p2.local_class != c or not p2.need_doc(dctx) then continue
- cla.add(c)
- end
- if cla.is_empty then continue
- cla = crhe.order.select_smallests(cla)
- end
-
- new_props.add(p)
- if p.global.intro == p then
- dctx.register(p)
- end
- end
- dctx.sort(new_props)
- for p in new_props do
- dctx.add("<tr><td width=\"20%\" align=\"right\">{p.prototype_head(dctx)}</td><td><b>{p.html_link(dctx)}</b>{p.prototype_body(dctx)}<br/> {p.short_doc}</td></tr>\n")
- end
- dctx.stage("</table><br/>\n")
-
- dctx.open_stage
- dctx.stage("<table border=\"1\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\">\n")
- if pass != 1 then
- # skip pass 1 because constructors are not inherited
- var cmap = new HashMap[MMLocalClass, Array[MMLocalProperty]]
- var mmap = new HashMap[MMModule, Array[MMLocalProperty]]
- for c in che.greaters do
- if c isa MMSrcLocalClass then
- var km = dctx.known_owner_of(c.mmmodule)
- var kc = km[c.global]
- if kc == self then continue
- var props: Array[MMLocalProperty]
- if km == mmmodule then
- if cmap.has_key(kc) then
- props = cmap[kc]
- else
- props = new Array[MMLocalProperty]
- cmap[kc] = props
- end
- else
- if mmap.has_key(km) then
- props = mmap[km]
- else
- props = new Array[MMLocalProperty]
- mmap[km] = props
- end
- end
- for g in c.global_properties do
- var p = c[g]
- if p.local_class == c and p.need_doc(dctx) and accept_prop(p, pass) then
- props.add(kc[g])
- end
- end
- end
- end
- dctx.open_stage
- dctx.stage("<tr bgcolor=\"#EEEEFF\"><th colspan=\"2\"><small>Inherited {passname}</small></th><tr>\n")
- for c in cshe.linear_extension do
- if not cmap.has_key(c) then continue
- var props = cmap[c]
- if props.is_empty then continue
- dctx.sort(props)
- var properties = new Array[String]
- for p in props do properties.add(p.html_link(dctx))
- dctx.add("<tr><td width=\"20%\"><small>from {c.html_link(dctx)}</small></td><td><small>{properties.join(", ")}</small></td><tr>\n")
- end
- dctx.close_stage
-
- dctx.open_stage
- dctx.stage("<tr bgcolor=\"#EEEEFF\"><th colspan=\"2\"><small>Imported {passname}</small></th><tr>\n")
- for m in mmmodule.mhe.linear_extension do
- if not mmap.has_key(m) then continue
- var props = mmap[m]
- if props.is_empty then continue
- dctx.sort(props)
- var properties = new Array[String]
- for p in props do properties.add(p.html_link(dctx))
- dctx.add("<tr><td width=\"20%\"><small>from {m.html_link(dctx)}</small></td><td><small>{properties.join(", ")}</small></td><tr>\n")
- end
- dctx.close_stage
- end
-
- var mmap = new HashMap[MMModule, Array[MMLocalProperty]]
- for c in crhe.order do
- if mmmodule.mhe <= c.mmmodule or dctx.owned_modules.has(c.mmmodule) or not c isa MMSrcLocalClass then continue
- var km = dctx.known_owner_of(c.mmmodule)
- if mmmodule.mhe <= km then continue
- var kc = km[c.global]
- var props: Array[MMLocalProperty]
- if mmap.has_key(km) then
- props = mmap[km]
- else
- props = new Array[MMLocalProperty]
- mmap[km] = props
- end
- for g in c.global_properties do
- var p = c[g]
- if p.local_class == c and p.need_doc(dctx) and accept_prop(p, pass) then
- var kp = kc[g]
- if not props.has(kp) then props.add(kp)
- end
- end
- # c.properties_inherited_from(dctx, self, pass)
- end
- dctx.open_stage
- dctx.stage("<tr bgcolor=\"#EEEEFF\"><th colspan=\"2\"><small>Added {passname} in known modules</small></th><tr>\n")
- for c in crhe.order do
- var m = c.mmmodule
- if not mmap.has_key(m) then continue
- var props = mmap[m]
- if props.is_empty then continue
- dctx.sort(props)
- var properties = new Array[String]
- for p in props do properties.add(p.html_link(dctx))
- dctx.add("<tr><td width=\"20%\"><small>in {m.html_link(dctx)}</small></td><td><small>{properties.join(", ")}</small></td><tr>\n")
- end
- dctx.close_stage
- dctx.stage("</table><br/><br/>\n")
- dctx.close_stage
-
- dctx.close_stage
- return new_props
- end
-
- fun property_detail(dctx: DocContext, pass: Int, new_props: Array[MMLocalProperty])
- do
- var passname = pass_name(pass)
- dctx.open_stage
- dctx.stage("<table border=\"1\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\">\n")
- dctx.stage("<tr bgcolor=\"#CCCCFF\"><th>{passname} Detail of {self}</th><tr>\n")
- dctx.stage("</table>\n")
-
- dctx.open_stage
- for p in new_props do
- dctx.add("<a name=\"{p.html_anchor}\"></a><h3>{p}</h3><p><small>{p.mmmodule.html_link(dctx)}::{p.local_class.html_link(dctx)}::</small><br/>{p.prototype_head(dctx)} <b>{p.name}</b>{p.prototype_body(dctx)}</p>\n")
- dctx.add("<blockquote>")
- var doc = p.doc
- if doc != null then
- dctx.add("<pre>{doc.to_html}</pre>\n")
- end
- dctx.stage("</blockquote>\n")
- dctx.close_stage
-
- dctx.open_stage
- dctx.stage("<hr/>\n")
- end
- dctx.close_stage
-
- dctx.close_stage
- end
-
- # Add rows for properties inheriterd to some heirs
- fun properties_inherited_from(dctx: DocContext, heir: MMLocalClass, pass: Int)
- do
- var properties = new Array[String]
- for g in global_properties do
- var p = self[g]
- if p.local_class == self and p.need_doc(dctx) and accept_prop(p, pass) then
- properties.add(p.html_link(dctx))
- end
- end
- if not properties.is_empty then
- var s: String
- if heir.global == global then
- s = mmmodule.html_link(dctx)
- else
- s = self.html_link(dctx)
- end
- dctx.add("<tr><td width=\"20%\"><small>in {s}</small></td><td><small>{properties.join(", ")}</small></td><tr>\n")
+# Nitdoc phase explores the model and generate pages for each mentity found
+private class Nitdoc
+ super Phase
+
+ redef fun process_mainmodule(mainmodule, mmodules)
+ do
+ var modelbuilder = toolcontext.modelbuilder
+ var model = modelbuilder.model
+
+ var min_visibility = private_visibility
+ if not toolcontext.opt_private.value then min_visibility = protected_visibility
+ var accept_attribute = true
+ if toolcontext.opt_no_attributes.value then accept_attribute = false
+
+ var catalog = new Catalog(toolcontext.modelbuilder)
+ catalog.build_catalog(mainmodule.model.mpackages)
+
+ var filter = new ModelFilter(
+ min_visibility,
+ accept_attribute = accept_attribute,
+ accept_fictive = true,
+ accept_generated = true,
+ accept_test = false,
+ accept_redef = true,
+ accept_extern = true,
+ accept_empty_doc = true,
+ accept_example = true,
+ accept_broken = false)
+
+ var doc = new DocModel(model, mainmodule, modelbuilder, catalog, filter)
+
+ model.nitdoc_md_processor = doc.md_processor
+ doc.no_dot = toolcontext.opt_nodot.value
+ doc.no_code = toolcontext.opt_nocode.value
+ doc.code_url = toolcontext.opt_source.value
+ doc.share_url = toolcontext.opt_shareurl.value
+ doc.custom_brand = toolcontext.opt_custom_brand.value
+ doc.custom_title = toolcontext.opt_custom_title.value
+ doc.custom_footer = toolcontext.opt_custom_footer.value
+ doc.custom_intro = toolcontext.opt_custom_intro.value
+ doc.tracker_url = toolcontext.opt_piwik_tracker.value
+ doc.piwik_site_id = toolcontext.opt_piwik_site_id.value
+
+ # Prepare output dir
+ var test_mode = toolcontext.opt_test.value
+ var no_render = toolcontext.opt_norender.value
+ var output_dir = toolcontext.opt_dir.value or else "doc"
+
+ if not no_render then
+ output_dir.mkdir
+
+ # Copy assets
+ var share_dir = toolcontext.opt_share_dir.value or else "{toolcontext.share_dir}/nitdoc"
+ sys.system("cp -r -- {share_dir.escape_to_sh}/* {output_dir.escape_to_sh}/")
+ end
+
+ # Collect model to document
+ var mpackages = model.collect_mpackages(filter)
+ var mgroups = model.collect_mgroups(filter)
+ var nmodules = model.collect_mmodules(filter)
+ var mclasses = model.collect_mclasses(filter)
+ var mprops = model.collect_mproperties(filter)
+
+ var mentities = new Array[MEntity]
+ mentities.add_all mpackages
+ mentities.add_all mgroups
+ mentities.add_all nmodules
+ mentities.add_all mclasses
+ mentities.add_all mprops
+
+ var persons = doc.catalog.persons
+ var tags = doc.catalog.tag2proj.keys
+
+ # Prepare progress bar
+ var count = 0
+ var pages = 1 # count homepage
+ pages += mentities.length
+ pages += persons.length
+ pages += tags.length
+
+ print "Generating documentation pages..."
+ var progress = new TermProgress(pages, 0)
+ if not test_mode then progress.display
+
+ # Make pages
+ count += 1
+ if not test_mode then progress.update(count, "homepage")
+ if not no_render then doc.gen_page(new PageHome("Overview"), output_dir)
+
+ for mentity in mentities do
+ count += 1
+ if not test_mode then progress.update(count, "page {count}/{pages}")
+ if not no_render then doc.gen_page(new PageMEntity(mentity), output_dir)
+ end
+ for name, person in persons do
+ count += 1
+ if not test_mode then progress.update(count, "page {count}/{pages}")
+ if not no_render then doc.gen_page(new PagePerson(person), output_dir)
+ end
+ for tag in tags do
+ count += 1
+ if not test_mode then progress.update(count, "page {count}/{pages}")
+ if not no_render then doc.gen_page(new PageTag(tag), output_dir)
+ end
+
+ if not test_mode then print "" # finalise progress
+ if not no_render then
+ doc.create_index_file("{output_dir}/quicksearch-list.js")
+ print "Documentation produced in `{output_dir}`"
+ end
+
+ if test_mode then
+ print "Generated {count}/{pages} pages"
+ print " PageHome: 1"
+ print " PageMPackage: {mpackages.length}"
+ print " PageMGroup: {mgroups.length}"
+ print " PageMModule: {nmodules.length}"
+ print " PageMClass: {mclasses.length}"
+ print " PageMProperty: {mprops.length}"
+ print " PagePerson: {persons.length}"
+ print " PageTag: {tags.length}"