import model_utils
import abstract_compiler
-class Nitdoc
+class NitdocContext
private var toolcontext: ToolContext
private var model: Model
private var modelbuilder: ModelBuilder
private var dot_dir: nullable String
private var share_dir: nullable String
private var source: nullable String
+ private var min_visibility: MVisibility
private var opt_dir = new OptionString("Directory where doc is generated", "-d", "--dir")
private var opt_source = new OptionString("What link for source (%f for filename, %l for first line, %L for last line)", "--source")
private var opt_sharedir = new OptionString("Directory containing the nitdoc files", "--sharedir")
private var opt_nodot = new OptionBool("Do not generate graphes with graphiviz", "--no-dot")
+ private var opt_private: OptionBool = new OptionBool("Generate the private API", "--private")
private var opt_custom_title: OptionString = new OptionString("Title displayed in the top of the Overview page and as suffix of all page names", "--custom-title")
private var opt_custom_menu_items: OptionString = new OptionString("Items displayed in menu before the 'Overview' item (Each item must be enclosed in 'li' tags)", "--custom-menu-items")
private var opt_custom_overview_text: OptionString = new OptionString("Text displayed as introduction of Overview page before the modules list", "--custom-overview-text")
private var opt_custom_footer_text: OptionString = new OptionString("Text displayed as footer of all pages", "--custom-footer-text")
+
init(toolcontext: ToolContext) do
# We need a model to collect stufs
self.toolcontext = toolcontext
toolcontext.option_context.add_option(opt_source)
toolcontext.option_context.add_option(opt_sharedir)
toolcontext.option_context.add_option(opt_nodot)
+ toolcontext.option_context.add_option(opt_private)
toolcontext.option_context.add_option(opt_custom_title)
toolcontext.option_context.add_option(opt_custom_footer_text)
toolcontext.option_context.add_option(opt_custom_overview_text)
print "Error: Invalid nitdoc share files. Check --sharedir or envvar NIT_DIR"
abort
end
+
+ if opt_private.value then
+ min_visibility = none_visibility
+ else
+ min_visibility = protected_visibility
+ end
end
- if not opt_source.value is null then
- source = ""
- else
- source = opt_source.value
- end
+ source = opt_source.value
end
fun start do
content.append("],")
end
for mclass in model.mclasses do
- if mclass.visibility <= none_visibility then continue
+ if mclass.visibility < min_visibility then continue
content.append("\"{mclass.name}\": [")
content.append("\{txt: \"{mclass.name}\", url:\"{mclass.url}\" \},")
content.append("],")
end
var name2mprops = new HashMap[String, Set[MPropDef]]
for mproperty in model.mproperties do
- if mproperty.visibility <= none_visibility then continue
+ if mproperty.visibility < min_visibility then continue
if mproperty isa MAttribute then continue
if not name2mprops.has_key(mproperty.name) then name2mprops[mproperty.name] = new HashSet[MPropDef]
name2mprops[mproperty.name].add_all(mproperty.mpropdefs)
var dot_dir: nullable String
var source: nullable String
- var nitdoc: Nitdoc
+ var ctx: NitdocContext
- init(nitdoc: Nitdoc) do
- self.nitdoc = nitdoc
+ init(ctx: NitdocContext) do
+ self.ctx = ctx
end
fun append(str: String) do html.append(str)
append("<script type='text/javascript' src='scripts/js-facilities.js'></script>")
append("<link rel='stylesheet' href='styles/main.css' type='text/css' media='screen'/>")
var title = ""
- if nitdoc.opt_custom_title.value != null then
- title = " | {nitdoc.opt_custom_title.value.to_s}"
+ if ctx.opt_custom_title.value != null then
+ title = " | {ctx.opt_custom_title.value.to_s}"
end
append("<title>{self.title}{title}</title>")
end
fun menu do
- if nitdoc.opt_custom_menu_items.value != null then
- append(nitdoc.opt_custom_menu_items.value.to_s)
+ if ctx.opt_custom_menu_items.value != null then
+ append(ctx.opt_custom_menu_items.value.to_s)
end
end
fun content is abstract
fun footer do
- if nitdoc.opt_custom_footer_text.value != null then
- append("<footer>{nitdoc.opt_custom_footer_text.value.to_s}</footer>")
+ if ctx.opt_custom_footer_text.value != null then
+ append("<footer>{ctx.opt_custom_footer_text.value.to_s}</footer>")
end
end
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>)"
+ return " (<a href=\"{source.to_s}\">source</a>)"
end
end
private var mbuilder: ModelBuilder
private var mmodules = new Array[MModule]
- init(nitdoc: Nitdoc, dot_dir: nullable String) do
- super(nitdoc)
- self.mbuilder = nitdoc.modelbuilder
+ init(ctx: NitdocContext, dot_dir: nullable String) do
+ super(ctx)
+ self.mbuilder = ctx.modelbuilder
self.dot_dir = dot_dir
# get modules
var mmodules = new HashSet[MModule]
redef fun content do
append("<div class='content fullpage'>")
var title = "Overview"
- if nitdoc.opt_custom_title.value != null then
- title = nitdoc.opt_custom_title.value.to_s
+ if ctx.opt_custom_title.value != null then
+ title = ctx.opt_custom_title.value.to_s
end
append("<h1>{title}</h1>")
var text = ""
- if nitdoc.opt_custom_overview_text.value != null then
- text = nitdoc.opt_custom_overview_text.value.to_s
+ if ctx.opt_custom_overview_text.value != null then
+ text = ctx.opt_custom_overview_text.value.to_s
end
append("<article class='overview'>{text}</article>")
append("<article class='overview'>")
class NitdocFullindex
super NitdocPage
- init(nitdoc: Nitdoc) do
- super(nitdoc)
+ init(ctx: NitdocContext) do
+ super(ctx)
self.dot_dir = null
end
fun module_column do
var sorter = new ComparableSorter[MModule]
var sorted = new Array[MModule]
- for mmodule in nitdoc.modelbuilder.model.mmodule_importation_hierarchy do
+ for mmodule in ctx.modelbuilder.model.mmodule_importation_hierarchy do
sorted.add(mmodule)
end
sorter.sort(sorted)
append("<h2>Modules</h2>")
append("<ul>")
for mmodule in sorted do
- append("<li>{mmodule.link(nitdoc.modelbuilder)}</li>")
+ append("<li>{mmodule.link(ctx.modelbuilder)}</li>")
end
append("</ul>")
append("</article>")
# Add to content classes modules
fun classes_column do
- var sorted = nitdoc.modelbuilder.model.mclasses
+ var sorted = ctx.modelbuilder.model.mclasses
var sorter = new ComparableSorter[MClass]
sorter.sort(sorted)
append("<article class='modules filterable'>")
append("<h2>Classes</h2>")
append("<ul>")
for mclass in sorted do
- append("<li>{mclass.link(nitdoc.modelbuilder)}</li>")
+ if mclass.visibility < ctx.min_visibility then continue
+ append("<li>{mclass.link(ctx.modelbuilder)}</li>")
end
append("</ul>")
append("</article>")
# Insert the properties column of fullindex page
fun properties_column do
- var sorted = nitdoc.modelbuilder.model.mproperties
+ var sorted = ctx.modelbuilder.model.mproperties
var sorter = new ComparableSorter[MProperty]
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.link(nitdoc.modelbuilder)} ({mproperty.intro.mclassdef.mclass.link(nitdoc.modelbuilder)})</li>")
+ append("<li>{mproperty.intro.link(ctx.modelbuilder)} ({mproperty.intro.mclassdef.mclass.link(ctx.modelbuilder)})</li>")
end
append("</ul>")
append("</article>")
private var mmodule: MModule
private var mbuilder: ModelBuilder
- init(mmodule: MModule, nitdoc: Nitdoc, dot_dir: nullable String) do
- super(nitdoc)
+ init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
+ super(ctx)
self.mmodule = mmodule
- self.mbuilder = nitdoc.modelbuilder
+ self.mbuilder = ctx.modelbuilder
self.dot_dir = dot_dir
end
append("<h2>Classes</h2>")
append("<ul>")
for c in sorted do
+ if c.visibility < ctx.min_visibility then continue
if redef_mclasses.has(c) and c.intro_mmodule.public_owner != mmodule then
append("<li class='redef'>")
append("<span title='refined in this module'>R </span>")
append("<ul>")
for mprop in sorted do
if mprop isa MAttributeDef then continue
- if mprop.mproperty.visibility <= none_visibility then continue
+ if mprop.mproperty.visibility < ctx.min_visibility then continue
append(mprop.html_list_item(mbuilder))
end
append("</ul>")
private var meths = new HashSet[MMethodDef]
private var inherited = new HashSet[MPropDef]
- init(mclass: MClass, nitdoc: Nitdoc, dot_dir: nullable String, source: nullable String) do
- super(nitdoc)
+ init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
+ super(ctx)
self.mclass = mclass
- self.mbuilder = nitdoc.modelbuilder
+ self.mbuilder = ctx.modelbuilder
self.dot_dir = dot_dir
self.source = source
# load properties
for mclassdef in mclass.mclassdefs do
for mpropdef in mclassdef.mpropdefs do
- if mpropdef.mproperty.visibility <= none_visibility then continue
+ 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
# get inherited properties
for mprop in mclass.inherited_mproperties do
var mpropdef = mprop.intro
- if mprop.visibility <= none_visibility then continue
+ if mprop.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
var sorted_meths = new Array[MMethodDef]
var sorted = new Array[MModule]
sorted_meths.add_all(meths)
- nitdoc.mainmodule.linearize_mpropdefs(sorted_meths)
+ ctx.mainmodule.linearize_mpropdefs(sorted_meths)
for meth in meths do
if inherited.has(meth) then continue
var mmodule = meth.mclassdef.mmodule
if inherited.length > 0 then
var sorted_inherited = new Array[MPropDef]
sorted_inherited.add_all(inherited)
- nitdoc.mainmodule.linearize_mpropdefs(sorted_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
end
fun process_generate_dot do
- var pe = nitdoc.class_hierarchy[mclass]
+ var pe = ctx.class_hierarchy[mclass]
var cla = new HashSet[MClass]
var sm = new HashSet[MClass]
var sm2 = new HashSet[MClass]
# Return the module signature decorated with html
fun html_full_signature(mbuilder: ModelBuilder): String do
var res = new Buffer
- if visibility <= none_visibility then
- res.append("private ")
- else if visibility == protected_visibility then
- res.append("protected ")
- end
+ if visibility < public_visibility then res.append("{visibility.to_s} ")
res.append("{kind} {html_namespace(mbuilder)}")
return res.to_s
end
fun full_name: String do
return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
end
+
+ fun html_inheritance(page: NitdocClass): String do
+ var res = new Buffer
+ # definitions block
+ res.append("<p class='info'>")
+ page.ctx.mainmodule.linearize_mpropdefs(mproperty.mpropdefs)
+ var previous_defs = new Array[MPropDef]
+ var next_defs = new Array[MPropDef]
+ var self_passed = false
+ for def in mproperty.mpropdefs do
+ if def == self then
+ self_passed = true
+ continue
+ end
+ if not self_passed then
+ if not page.mclass.ancestors.has(def.mclassdef.mclass) then continue
+ if def.is_intro then continue
+ previous_defs.add(def)
+ else
+ if not page.mclass.descendants.has(def.mclassdef.mclass) then continue
+ next_defs.add(def)
+ end
+ end
+ var source = ""
+ if page.mbuilder.mpropdef2npropdef.has_key(self) then
+ source = " {page.show_source(page.mbuilder.mpropdef2npropdef[self].location)}"
+ end
+ res.append("defined by {mclassdef.mmodule.html_full_namespace(page.mbuilder)}{source}")
+ if not is_intro then
+ source = ""
+ if page.mbuilder.mpropdef2npropdef.has_key(mproperty.intro) then
+ source = " {page.show_source(page.mbuilder.mpropdef2npropdef[mproperty.intro].location)}"
+ end
+ res.append(", introduced by {mproperty.intro.mclassdef.mclass.link(page.mbuilder)}{source}")
+ end
+ if not previous_defs.is_empty then
+ res.append(", inherited from ")
+ for i in [0..previous_defs.length[ do
+ var def = previous_defs[i]
+ source = ""
+ if page.mbuilder.mpropdef2npropdef.has_key(def) then
+ source = " {page.show_source(page.mbuilder.mpropdef2npropdef[def].location)}"
+ end
+ res.append("{def.mclassdef.mclass.link(page.mbuilder)}{source}")
+ if i < previous_defs.length - 1 then res.append(", ")
+ end
+ end
+ if not next_defs.is_empty then
+ res.append(", redefined by ")
+ for i in [0..next_defs.length[ do
+ var def = next_defs[i]
+ source = ""
+ if page.mbuilder.mpropdef2npropdef.has_key(def) then
+ source = " {page.show_source(page.mbuilder.mpropdef2npropdef[def].location)}"
+ end
+ res.append("{def.mclassdef.mclass.link(page.mbuilder)}{source}")
+ if i < next_defs.length - 1 then res.append(", ")
+ end
+ end
+ res.append(".</p>")
+ return res.to_s
+ end
end
redef class MMethodDef
classes.add("fun")
if mprop.is_init then classes.add("init")
if is_redef then classes.add("redef")
- if mprop.visibility == none_visibility then
- classes.add("private")
- else if mprop.visibility == protected_visibility then
- classes.add("protected")
- else
- classes.add("public")
- end
+ classes.add(mproperty.visibility.to_s)
res.append("<article class='{classes.join(" ")}' id='{anchor}'>")
if nprop isa AAttrPropdef then
if nprop.mreadpropdef == self then
res.append("<pre class=\"text_label\" title=\"\" name=\"\" tag=\"\" type=\"1\">{nprop.comment}</pre>")
end
res.append("<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>")
- # definitions block
- res.append("<p class='info'>")
- page.nitdoc.mainmodule.linearize_mpropdefs(mprop.mpropdefs)
- var previous_defs = new Array[MMethodDef]
- var next_defs = new Array[MMethodDef]
- var self_passed = false
- for def in mprop.mpropdefs do
- if def == self then
- self_passed = true
- continue
- end
- if not self_passed then
- if not page.mclass.ancestors.has(def.mclassdef.mclass) then continue
- if def.is_intro then continue
- previous_defs.add(def)
- else
- if not page.mclass.descendants.has(def.mclassdef.mclass) then continue
- next_defs.add(def)
- end
- end
- res.append("defined by {mclassdef.mmodule.html_full_namespace(page.mbuilder)}")
- if not is_intro then
- res.append(", introduced by {mprop.intro.mclassdef.mclass.link(page.mbuilder)}")
- end
- if not previous_defs.is_empty then
- res.append(", inherited from ")
- for i in [0..previous_defs.length[ do
- res.append(previous_defs[i].mclassdef.mclass.link(page.mbuilder))
- if i < previous_defs.length - 1 then res.append(", ")
- end
- end
- if not next_defs.is_empty then
- res.append(", redefined by ")
- for i in [0..next_defs.length[ do
- res.append(next_defs[i].mclassdef.mclass.link(page.mbuilder))
- if i < next_defs.length - 1 then res.append(", ")
- end
- end
- res.append(".</p>")
+ res.append(html_inheritance(page))
res.append("</div>")
res.append("</article>")
return res.to_s
redef fun html_info(page) do
var res = new Buffer
res.append("<div class='info'>")
- if mproperty.visibility <= none_visibility then
- res.append("private ")
- else if mproperty.visibility <= protected_visibility then
- res.append("protected ")
- end
+ if mproperty.visibility < public_visibility then res.append("{mproperty.visibility.to_s} ")
if mproperty.intro_mclassdef.mclass != page.mclass then res.append("redef ")
res.append("fun {mproperty.html_namespace(page.mbuilder)}")
res.append("</div>")
var classes = new Array[String]
classes.add("type")
if is_redef then classes.add("redef")
- if mprop.visibility == none_visibility then
- classes.add("private")
- else if mprop.visibility == protected_visibility then
- classes.add("protected")
- else
- classes.add("public")
- end
+ classes.add(mproperty.visibility.to_s)
res.append("<article class='{classes.join(" ")}' id='{anchor}'>")
res.append("<h3 class='signature'>{mprop.name}: {bound.link(page.mbuilder)}</h3>")
res.append(html_info(page))
res.append("<a class=\"newComment\" title=\"32\" tag=\"\">New Comment</a>")
end
res.append("<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>")
- # definitions block
- res.append("<p class='info'>")
- page.nitdoc.mainmodule.linearize_mpropdefs(mprop.mpropdefs)
- var previous_defs = new Array[MVirtualTypeDef]
- var next_defs = new Array[MVirtualTypeDef]
- var self_passed = false
- for def in mprop.mpropdefs do
- if def == self then
- self_passed = true
- continue
- end
- if not self_passed then
- if not page.mclass.ancestors.has(def.mclassdef.mclass) then continue
- if def.is_intro then continue
- previous_defs.add(def)
- else
- if not page.mclass.descendants.has(def.mclassdef.mclass) then continue
- next_defs.add(def)
- end
- end
- res.append("defined by {mclassdef.mmodule.html_full_namespace(page.mbuilder)}")
- if not is_intro then
- res.append(", introduced by {mprop.intro.mclassdef.mclass.link(page.mbuilder)}")
- end
- if not previous_defs.is_empty then
- res.append(", inherited from ")
- for i in [0..previous_defs.length[ do
- res.append(previous_defs[i].mclassdef.mclass.link(page.mbuilder))
- if i < previous_defs.length - 1 then res.append(", ")
- end
- end
- if not next_defs.is_empty then
- res.append(", redefined by ")
- for i in [0..next_defs.length[ do
- res.append(next_defs[i].mclassdef.mclass.link(page.mbuilder))
- if i < next_defs.length - 1 then res.append(", ")
- end
- end
- res.append(".</p>")
+ res.append(html_inheritance(page))
res.append("</div>")
res.append("</article>")
return res.to_s
var toolcontext = new ToolContext
# Here we launch the nit index
-var nitdoc = new Nitdoc(toolcontext)
+var nitdoc = new NitdocContext(toolcontext)
nitdoc.start