src: remove remaining references of subclasses on AMethPropdef
[nit.git] / src / nitdoc.nit
index fef6e46..91f00b8 100644 (file)
@@ -73,14 +73,10 @@ class NitdocContext
                toolcontext.option_context.add_option(opt_github_gitdir)
                toolcontext.option_context.add_option(opt_piwik_tracker)
                toolcontext.option_context.add_option(opt_piwik_site_id)
-               toolcontext.process_options
+               toolcontext.tooldescription = "Usage: nitdoc [OPTION]... <file.nit>...\nGenerates HTML pages of API documentation from Nit source files."
+               toolcontext.process_options(args)
                self.arguments = toolcontext.option_context.rest
 
-               if arguments.length < 1 then
-                       print "usage: nitdoc [options] file..."
-                       toolcontext.option_context.usage
-                       exit(1)
-               end
                self.process_options
 
                model = new Model
@@ -109,14 +105,9 @@ class NitdocContext
                if opt_sharedir.value != null then
                        share_dir = opt_sharedir.value
                else
-                       var dir = "NIT_DIR".environ
-                       if dir.is_empty then
-                               dir = "{sys.program_name.dirname}/../share/nitdoc"
-                       else
-                               dir = "{dir}/share/nitdoc"
-                       end
-                       share_dir = dir
-                       if share_dir == null then
+                       var dir = toolcontext.nit_dir
+                       share_dir = "{dir}/share/nitdoc"
+                       if dir == null or not share_dir.file_exists then
                                print "Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
                                abort
                        end
@@ -160,7 +151,7 @@ class NitdocContext
        end
 
        private fun overview do
-               var overviewpage = new NitdocOverview(self, dot_dir)
+               var overviewpage = new NitdocOverview(self)
                overviewpage.save("{output_dir.to_s}/index.html")
        end
 
@@ -172,14 +163,14 @@ class NitdocContext
        private fun modules do
                for mmodule in model.mmodules do
                        if mmodule.name == "<main>" then continue
-                       var modulepage = new NitdocModule(mmodule, self, dot_dir)
+                       var modulepage = new NitdocModule(mmodule, self)
                        modulepage.save("{output_dir.to_s}/{mmodule.url}")
                end
        end
 
        private fun classes do
                for mclass in mbuilder.model.mclasses do
-                       var classpage = new NitdocClass(mclass, self, dot_dir, source)
+                       var classpage = new NitdocClass(mclass, self)
                        classpage.save("{output_dir.to_s}/{mclass.url}")
                end
        end
@@ -222,8 +213,6 @@ end
 # Nitdoc base page
 abstract class NitdocPage
 
-       var dot_dir: nullable String
-       var source: nullable String
        var ctx: NitdocContext
        var shareurl = "."
 
@@ -274,7 +263,7 @@ abstract class NitdocPage
 
        # Generate a clickable graphviz image using a dot content
        protected fun generate_dot(dot: String, name: String, alt: String) do
-               var output_dir = dot_dir
+               var output_dir = ctx.dot_dir
                if output_dir == null then return
                var file = new OFStream.open("{output_dir}/{name}.dot")
                file.write(dot)
@@ -291,6 +280,7 @@ abstract class NitdocPage
        # Add a (source) link for a given location
        protected fun show_source(l: Location): String
        do
+               var source = ctx.source
                if source == null then
                        return "({l.file.filename.simplify_path})"
                else
@@ -301,6 +291,7 @@ abstract class NitdocPage
                        source = x.join(l.line_start.to_s)
                        x = source.split_with("%L")
                        source = x.join(l.line_end.to_s)
+                       source = source.simplify_path
                        return " (<a target='_blank' title='Show source' href=\"{source.to_s}\">source</a>)"
                end
        end
@@ -367,10 +358,9 @@ class NitdocOverview
        private var mbuilder: ModelBuilder
        private var mmodules = new Array[MModule]
 
-       init(ctx: NitdocContext, dot_dir: nullable String) do
+       init(ctx: NitdocContext) do
                super(ctx)
                self.mbuilder = ctx.mbuilder
-               self.dot_dir = dot_dir
                # get modules
                var mmodules = new HashSet[MModule]
                for mmodule in mbuilder.model.mmodule_importation_hierarchy do
@@ -441,7 +431,7 @@ class NitdocOverview
                        end
                end
                # build graph
-               var op = new Buffer
+               var op = new FlatBuffer
                op.append("digraph dep \{ 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
                        op.append("\"{mmodule.name}\"[URL=\"{mmodule.url}\"];\n")
@@ -460,7 +450,6 @@ class NitdocSearch
 
        init(ctx: NitdocContext) do
                super(ctx)
-               self.dot_dir = null
        end
 
        redef fun title do return "Search"
@@ -549,11 +538,10 @@ class NitdocModule
        private var intro_mclasses = new HashSet[MClass]
        private var redef_mclasses = new HashSet[MClass]
 
-       init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
+       init(mmodule: MModule, ctx: NitdocContext) do
                super(ctx)
                self.mmodule = mmodule
                self.mbuilder = ctx.mbuilder
-               self.dot_dir = dot_dir
                # get local mclasses
                for m in mmodule.in_nesting.greaters do
                        for mclassdef in m.mclassdefs do
@@ -714,7 +702,7 @@ class NitdocModule
                        end
                end
                # build graph
-               var op = new Buffer
+               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
@@ -742,11 +730,9 @@ class NitdocClass
        private var meths = new HashSet[MMethodDef]
        private var inherited = new HashSet[MPropDef]
 
-       init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
+       init(mclass: MClass, ctx: NitdocContext) do
                super(ctx)
                self.mclass = mclass
-               self.dot_dir = dot_dir
-               self.source = source
                # load properties
                var locals = new HashSet[MProperty]
                for mclassdef in mclass.mclassdefs do
@@ -1100,7 +1086,7 @@ class NitdocClass
                end
                cla.add_all(pe.greaters)
 
-               var op = new Buffer
+               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
@@ -1141,7 +1127,7 @@ redef class MModule
        #       module_owner_name.html
        private fun url: String do
                if url_cache == null then
-                       var res = new Buffer
+                       var res = new FlatBuffer
                        res.append("module_")
                        var mowner = public_owner
                        if mowner != null then
@@ -1158,7 +1144,7 @@ redef class MModule
        #       MOD_owner_name
        private fun anchor: String do
                if anchor_cache == null then
-                       var res = new Buffer
+                       var res = new FlatBuffer
                        res.append("MOD_")
                        var mowner = public_owner
                        if mowner != null then
@@ -1175,7 +1161,7 @@ redef class MModule
        #       <a href="url" title="short_comment">html_name</a>
        private fun html_link(page: NitdocPage) do
                if html_link_cache == null then
-                       var res = new Buffer
+                       var res = new FlatBuffer
                        if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
                                res.append("<a href='{url}' title='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{html_name}</a>")
                        else
@@ -1287,7 +1273,7 @@ redef class MClass
        #       <a href="url" title="short_comment">html_name(signature)</a>
        private fun html_link(page: NitdocPage) do
                if html_link_cache == null then
-                       var res = new Buffer
+                       var res = new FlatBuffer
                        res.append("<a href='{url}'")
                        if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
                                var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
@@ -1306,7 +1292,7 @@ redef class MClass
        #       <a href="url" title="short_comment">html_name</a>
        private fun html_short_link(page: NitdocPage) do
                if html_short_link_cache == null then
-                       var res = new Buffer
+                       var res = new FlatBuffer
                        res.append("<a href='{url}'")
                        if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
                                var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
@@ -1325,7 +1311,7 @@ redef class MClass
        #       <a href="url" title="short_comment">html_name</a>
        private fun html_link_anchor(page: NitdocPage) do
                if html_link_anchor_cache == null then
-                       var res = new Buffer
+                       var res = new FlatBuffer
                        res.append("<a href='#{anchor}'")
                        if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
                                var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
@@ -1587,7 +1573,7 @@ redef class MPropDef
        #       <a href="url" title="short_comment">html_name</a>
        private fun html_link(page: NitdocPage) do
                if html_link_cache == null then
-                       var res = new Buffer
+                       var res = new FlatBuffer
                        if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then
                                var nprop = page.ctx.mbuilder.mpropdef2npropdef[self]
                                res.append("<a href=\"{url}\" title=\"{nprop.short_comment}\">{mproperty.html_name}</a>")
@@ -1750,7 +1736,7 @@ redef class MSignature
        end
 
        private fun untyped_signature(page: NitdocPage): String do
-               var res = new Buffer
+               var res = new FlatBuffer
                if not mparameters.is_empty then
                        res.append("(")
                        for i in [0..mparameters.length[ do
@@ -1790,11 +1776,11 @@ redef class ADoc
        end
 
        private fun full_comment: String do
-               var res = new Buffer
+               var res = new FlatBuffer
                for t in n_comment do
                        var text = t.text
                        text = text.substring_from(1)
-                       if text.first == ' ' then text = text.substring_from(1)
+                       if text.chars.first == ' ' then text = text.substring_from(1)
                        res.append(text.html_escape)
                end
                var str = res.to_s
@@ -1819,7 +1805,7 @@ redef class AModule
 
        private fun full_markdown: String do
                if n_moduledecl != null and n_moduledecl.n_doc != null then
-                       return n_moduledecl.n_doc.full_markdown.html
+                       return n_moduledecl.n_doc.to_mdoc.full_markdown.write_to_string
                end
                return ""
        end
@@ -1846,7 +1832,7 @@ redef class AStdClassdef
        end
 
        private fun full_markdown: String do
-               if n_doc != null then return n_doc.full_markdown.html
+               if n_doc != null then return n_doc.to_mdoc.full_markdown.write_to_string
                return ""
        end
 
@@ -1870,7 +1856,7 @@ redef class APropdef
        end
 
        private fun full_markdown: String do
-               if n_doc != null then return n_doc.full_markdown.html
+               if n_doc != null then return n_doc.to_mdoc.full_markdown.write_to_string
                return ""
        end