readable var _opt_dir: OptionString = new OptionString("Directory where doc is generated", "-d", "--dir")
readable var _opt_source: OptionString = new OptionString("What link for source (%f for filename, %l for first line, %L for last line)", "--source")
readable var _opt_public: OptionBool = new OptionBool("Generate only the public API", "--public")
+ readable var _opt_private: OptionBool = new OptionBool("Generate the private API", "--private")
+ readable var _opt_nodot: OptionBool = new OptionBool("Do not generate graphes with graphviz", "--no-dot")
+ readable var _opt_sharedir: OptionString = new OptionString("Directory containing the nitdoc files", "--sharedir")
+ readable var _opt_overview_text: OptionString = new OptionString("Text displayed as introduction of Overview page", "--overview-text")
+ readable var _opt_footer_text: OptionString = new OptionString("Text displayed as footer of all pages", "--footer-text")
+ var sharedir: nullable String
fun public_only: Bool
do
return false
end
+ fun with_private: Bool
+ do
+ if self._opt_private.value == true then return true
+ return false
+ end
+
# The current processed filename
var filename: String
dir.mkdir
+ sys.system("cp -r '{sharedir.to_s}'/* {dir}/")
+
# Compute the set of direct owned nested modules
var owns = new HashMap[MMModule, Array[MMModule]]
for mod in modules do
end
var head = "<meta charset=\"utf-8\">" +
- "<script type=\"text/javascript\" src=\"http://moz-concept.com/nitdoc/scripts/jquery-1.7.1.min.js\"></script>\n" +
- "<script type=\"text/javascript\" src=\"http://moz-concept.com/nitdoc/scripts/js-facilities.js\"></script>\n" +
- "<link rel=\"stylesheet\" href=\"http://moz-concept.com/nitdoc/styles/main.css\" type=\"text/css\" media=\"screen\" />"
+ "<script type=\"text/javascript\" src=\"scripts/jquery-1.7.1.min.js\"></script>\n" +
+ "<script type=\"text/javascript\" src=\"quicksearch-list.js\"></script>\n" +
+ "<script type=\"text/javascript\" src=\"scripts/js-facilities.js\"></script>\n" +
+ "<link rel=\"stylesheet\" href=\"styles/main.css\" type=\"text/css\" media=\"screen\" />"
+
+ var action_bar = "<header><nav class='main'><ul><li class=\"current\">Overview</li><li><a href='full-index.html'>Full Index</a></li><li><a href=\"help.html\">Help</a></li></ul></nav></header>\n"
- var action_bar = "<header><nav class='main'><ul><li class=\"current\">Overview</li><li><a href='full-index.html'>Full Index</a></li></ul></nav></header>\n"
+ var overview_text = ""
+ if self._opt_overview_text.value != null then overview_text = self._opt_overview_text.value.as(not null)
+
+ var footer_text = ""
+ if self._opt_footer_text.value != null then footer_text = self._opt_footer_text.value.as(not null)
# generate the index
self.filename = "index.html"
add(action_bar)
add("<div class=\"page\">")
add("<div class=\"content fullpage\">")
- add("<h1>Modules</h1>\n<article class='overview'><ul>")
+ add("<h1>Modules</h1>\n<article class='overview'>{overview_text}<ul>")
var modss = mainmod.mhe.greaters_and_self.to_a
sort(modss)
for mod in modss do
add("</article></div>")
add("<div class='clear'></div>")
add("</div>")
+ add("<footer>{footer_text}</footer>")
add("</body></html>\n")
write_to("{dir}/index.html")
assert mod isa MMSrcModule
if not mod.require_doc(self) then continue
self.filename = mod.html_name
- action_bar = "<header><nav class='main'><ul><li><a href='./'>Overview</a></li><li class=\"current\">{mod.name}</li><li><a href='full-index.html'>Full Index</a></li></ul></nav></header>\n"
+ action_bar = "<header><nav class='main'><ul><li><a href='./index.html'>Overview</a></li><li class=\"current\">{mod.name}</li><li><a href='full-index.html'>Full Index</a></li><li><a href=\"help.html\">Help</a></li></ul></nav></header>\n"
clear
add("<!DOCTYPE html>")
add("<html><head>{head}<title>Module {mod.name}</title></head><body>\n")
add("<div class=\"page\">")
mod.file_page_doc(self)
add("</div>")
+ add("<footer>{footer_text}</footer>")
add("</body></html>\n")
write_to("{dir}/{mod.html_name}.html")
end
for c in mainmod.local_classes do
if not c.require_doc(self) then continue
self.filename = c.html_name
- action_bar = "<header><nav class='main'><ul><li><a href='./'>Overview</a></li><li>{c.global.intro.mmmodule.toplevel_owner.html_link(self)}</li><li class=\"current\">{c.name}</li><li><a href='full-index.html'>Full Index</a></li></ul></nav></header>\n"
+ action_bar = "<header><nav class='main'><ul><li><a href='./index.html'>Overview</a></li><li>{c.global.intro.mmmodule.toplevel_owner.html_link(self)}</li><li class=\"current\">{c.name}</li><li><a href='full-index.html'>Full Index</a></li><li><a href=\"help.html\">Help</a></li></ul></nav></header>\n"
clear
add("<!DOCTYPE html>")
add("<html><head>{head}<title>Class {c.name}</title></head><body>\n")
add("<div class=\"page\">")
c.file_page_doc(self)
add("</div>")
+ add("<footer>{footer_text}</footer>")
add("</body></html>\n")
write_to("{dir}/{c.html_name}.html")
end
self.filename = "fullindex"
- action_bar = "<header><nav class='main'><ul><li><a href='./'>Overview</a></li><li class=\"current\">Full Index</li></ul></nav></header>\n"
+ action_bar = "<header><nav class='main'><ul><li><a href='./index.html'>Overview</a></li><li class=\"current\">Full Index</li><li><a href=\"help.html\">Help</a></li></ul></nav></header>\n"
clear
add("<!DOCTYPE html>")
add("<html><head>{head}<title>Full Index</title></head><body>\n")
mainmod.file_index_page_doc(self)
add("</div>")
add("</div>")
+ add("<footer>{footer_text}</footer>")
add("</body></html>\n")
write_to("{dir}/full-index.html")
+
+ self.filename = "quicksearch-list"
+ clear
+ mainmod.file_quicksearch_list_doc(self)
+ write_to("{dir}/quicksearch-list.js")
end
do
var s = opt_source.value
if s == null then
- add("in #{l.file.filename.simplify_path}")
+ add("in {l.file.filename.simplify_path}")
else
# THIS IS JUST UGLY ! (but there is no replace yet)
var x = s.split_with("%f")
# `name' must also match the name of the graph in the dot content (eg. digraph NAME {...)
fun gen_dot(dot: String, name: String, alt: String)
do
+ if opt_nodot.value then return
var f = new OFStream.open("{self.dir}/{name}.dot")
f.write(dot)
f.close
super("nitdoc")
filename = "-unset-"
option_context.add_option(opt_public)
+ option_context.add_option(opt_private)
option_context.add_option(opt_dir)
option_context.add_option(opt_source)
+ option_context.add_option(opt_nodot)
+ option_context.add_option(opt_sharedir)
+ option_context.add_option(opt_overview_text)
+ option_context.add_option(opt_footer_text)
end
redef fun process_options
super
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
end
redef fun handle_property_conflict(lc, impls)
end
end
-redef class String
- # Replace all occurence of pattern ith string
- fun replace(p: Pattern, string: String): String
- do
- return self.split_with(p).join(string)
- end
-
- # Escape the following characters < > & and " with their html counterpart
- fun html_escape: String
- do
- var ret = self
- if ret.has('&') then ret = ret.replace('&', "&")
- if ret.has('<') then ret = ret.replace('<', "<")
- if ret.has('>') then ret = ret.replace('>', ">")
- if ret.has('"') then ret = ret.replace('"', """)
- return ret
- end
-
- # Remove "/./", "//" and "bla/../"
- fun simplify_path: String
- do
- var a = self.split_with("/")
- var a2 = new Array[String]
- for x in a do
- if x == "." then continue
- if x == "" and not a2.is_empty then continue
- if x == ".." and not a2.is_empty then
- a2.pop
- continue
- end
- a2.push(x)
- end
- return a2.join("/")
- 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
end
# Generalization of metamodel entities
-class MMEntity
+interface MMEntity
# Return a link to
fun html_link(dctx: DocContext): String is abstract
# The doc node from the AST
# Return null is none
fun doc: nullable ADoc do return null
+
+ # Return a jason entry for quicksearch list JSON Object
+ fun json_entry(dctx: DocContext): String is abstract
+
+ # Return the qualified name as string
+ fun qualified_name: String is abstract
+
end
redef class MMModule
return "<a href=\"{html_name}.html\" title=\"{short_doc}\">{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
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]
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 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
+ end
+end
+
redef class MMLocalProperty
super MMEntity
# Anchor of the property description in the module html file
return "PROP_{local_class}_{cmangle(name)}"
end
+ redef fun json_entry(dctx) do
+ return "\{txt:\"{qualified_name}\",url:\"{local_class.html_name}.html#{html_anchor}\"\},"
+ end
+
+ redef fun qualified_name do
+ return "{intro_module.qualified_name}::{local_class.html_name}::{html_name}"
+ end
+
fun html_open_link(dctx: DocContext): String
do
if not require_doc(dctx) then print "not required {self}"
return m == m.toplevel_owner
end
- # Return true if the global class must be documented according to the visibility configured
+ # Return true if the global property must be documented according to the visibility configured
fun require_doc(dctx: DocContext): Bool
do
- if global.visibility_level == 3 then return false # Private
+ if global.visibility_level == 3 and not dctx.with_private then return false # Private
if dctx.public_only then
var m = intro_module
if m != m.toplevel_owner then return false # Unexported
if lp == tlp then continue
dctx.add(" {lp.mmmodule.html_link(dctx)}")
if lp.local_class.global != lc.global then
- dctx.add(" for {lp.local_class.html_link(dctx)}")
+ dctx.add(" for {lp.local_class.html_link(dctx)} ")
end
n = lp.node
return "<a href=\"{html_name}.html\" title=\"{short_doc}\">{self}</a>"
end
+ redef fun json_entry(dctx) do
+ return "\{txt:\"{qualified_name}\",url:\"{html_name}.html\"\},"
+ end
+
+ redef fun qualified_name do
+ return "{intro_module.qualified_name}::{html_name}"
+ end
+
redef fun short_doc do return global.intro.short_doc
redef fun doc do return global.intro.doc
# Return true if the global class must be documented according to the visibility configured
fun require_doc(dctx: DocContext): Bool
do
- if global.visibility_level == 3 then return false # Private
+ if global.visibility_level == 3 and not dctx.with_private then return false # Private
if dctx.public_only then
var m = intro_module
if m != m.toplevel_owner then return false # Unexported
cla.add_all(cshe.greaters_and_self)
var op = new Buffer
+ var name = "class_{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 == self then
dctx.stage(". Definition in:")
for lc in crhe.greaters do
if lc.mmmodule.toplevel_owner != m then continue
- dctx.add(" {lc.mmmodule.html_link(dctx)}")
+ dctx.add(" {lc.mmmodule.html_link(dctx)} ")
assert lc isa MMSrcLocalClass
var n = lc.node
if n != null then
var res = new Buffer
if arity > 0 then
res.append("(")
- res.append(self.params[0].name.to_s)
- res.append(": ")
- res.append(self[0].html_link(dctx))
- for i in [1..arity[ do
- res.append(", ")
+ for i in [0..arity[ do
+ if i > 0 then res.append(", ")
res.append(self.params[i].name.to_s)
res.append(": ")
res.append(self[i].html_link(dctx))
+ if self.vararg_rank == i then
+ res.append("...")
+ end
end
res.append(")")
end