compiler: global compiler escape the module name
[nit.git] / src / doc / doc_pages.nit
index c0a1b2f..5d71b02 100644 (file)
@@ -86,15 +86,9 @@ end
 
 # The Nitdoc class explores the model and generate pages for each mentities found
 class Nitdoc
+       var ctx: ToolContext
        var model: Model
        var mainmodule: MModule
-       var ctx: ToolContext
-
-       init(ctx: ToolContext, model: Model, mainmodule: MModule) do
-               self.ctx = ctx
-               self.model = model
-               self.mainmodule = mainmodule
-       end
 
        fun generate do
                init_output_dir
@@ -115,11 +109,7 @@ class Nitdoc
                var sharedir = ctx.opt_sharedir.value
                if sharedir == null then
                        var dir = ctx.nit_dir
-                       if dir == null then
-                               print "Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
-                               abort
-                       end
-                       sharedir = "{dir}/share/nitdoc"
+                       sharedir = dir/"share/nitdoc"
                        if not sharedir.file_exists then
                                print "Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
                                abort
@@ -127,9 +117,9 @@ class Nitdoc
                end
                # copy shared files
                if ctx.opt_shareurl.value == null then
-                       sys.system("cp -r {sharedir.to_s}/* {output_dir.to_s}/")
+                       sys.system("cp -r -- {sharedir.to_s.escape_to_sh}/* {output_dir.to_s.escape_to_sh}/")
                else
-                       sys.system("cp -r {sharedir.to_s}/resources/ {output_dir.to_s}/resources/")
+                       sys.system("cp -r -- {sharedir.to_s.escape_to_sh}/resources/ {output_dir.to_s.escape_to_sh}/resources/")
                end
 
        end
@@ -163,6 +153,7 @@ class Nitdoc
 
        private fun classes do
                for mclass in model.mclasses do
+                       if mclass.visibility <= ctx.min_visibility then continue
                        var page = new NitdocClass(ctx, model, mainmodule, mclass)
                        page.render.write_to_file("{ctx.output_dir.to_s}/{page.page_url}")
                end
@@ -170,6 +161,7 @@ class Nitdoc
 
        private fun properties do
                for mproperty in model.mproperties do
+                       if mproperty.visibility <= ctx.min_visibility then continue
                        var page = new NitdocProperty(ctx, model, mainmodule, mproperty)
                        page.render.write_to_file("{ctx.output_dir.to_s}/{page.page_url}")
                end
@@ -194,7 +186,10 @@ class QuickSearch
        private var mclasses = new HashSet[MClass]
        private var mpropdefs = new HashMap[String, Set[MPropDef]]
 
-       init(ctx: ToolContext, model: Model) do
+       var ctx: ToolContext
+       var model: Model
+
+       init do
                for mmodule in model.mmodules do
                        if mmodule.is_fictive then continue
                        mmodules.add mmodule
@@ -251,12 +246,6 @@ abstract class NitdocPage
        private var mainmodule: MModule
        private var name_sorter = new MEntityNameSorter
 
-       init(ctx: ToolContext, model: Model, mainmodule: MModule) do
-               self.ctx = ctx
-               self.model = model
-               self.mainmodule = mainmodule
-       end
-
        # Render the page as a html template
        fun render: Template do
                var shareurl = "."
@@ -322,14 +311,16 @@ abstract class NitdocPage
 
        # Clickable graphviz image using dot format
        # return null if no graph for this page
-       fun tpl_graph(dot: FlatBuffer, name: String, title: nullable String): nullable TplArticle do
+       fun tpl_graph(dot: Buffer, name: String, title: nullable String): nullable TplArticle do
                if ctx.opt_nodot.value then return null
                var output_dir = ctx.output_dir
-               var file = new OFStream.open("{output_dir}/{name}.dot")
+               var path = output_dir / name
+               var path_sh = path.escape_to_sh
+               var file = new OFStream.open("{path}.dot")
                file.write(dot)
                file.close
-               sys.system("\{ test -f {output_dir}/{name}.png && test -f {output_dir}/{name}.s.dot && diff {output_dir}/{name}.dot {output_dir}/{name}.s.dot >/dev/null 2>&1 ; \} || \{ cp {output_dir}/{name}.dot {output_dir}/{name}.s.dot && dot -Tpng -o{output_dir}/{name}.png -Tcmapx -o{output_dir}/{name}.map {output_dir}/{name}.s.dot ; \}")
-               var fmap = new IFStream.open("{output_dir}/{name}.map")
+               sys.system("\{ test -f {path_sh}.png && test -f {path_sh}.s.dot && diff -- {path_sh}.dot {path_sh}.s.dot >/dev/null 2>&1 ; \} || \{ cp -- {path_sh}.dot {path_sh}.s.dot && dot -Tpng -o{path_sh}.png -Tcmapx -o{path_sh}.map {path_sh}.s.dot ; \}")
+               var fmap = new IFStream.open("{path}.map")
                var map = fmap.read_all
                fmap.close
 
@@ -337,11 +328,12 @@ abstract class NitdocPage
                var alt = ""
                if title != null then
                        article.title = title
-                       alt = "alt='{title}'"
+                       alt = "alt='{title.html_escape}'"
                end
                article.css_classes.add "text-center"
                var content = new Template
-               content.add "<img src='{name}.png' usemap='#{name}' style='margin:auto' {alt}/>"
+               var name_html = name.html_escape
+               content.add "<img src='{name_html}.png' usemap='#{name_html}' style='margin:auto' {alt}/>"
                content.add map
                article.content = content
                return article
@@ -671,13 +663,11 @@ class NitdocGroup
 
        private var mgroup: MGroup
 
-       private var concerns: ConcernsTree
-       private var intros: Set[MClass]
-       private var redefs: Set[MClass]
+       private var concerns: ConcernsTree is noinit
+       private var intros: Set[MClass] is noinit
+       private var redefs: Set[MClass] is noinit
 
-       init(ctx: ToolContext, model: Model, mainmodule: MModule, mgroup: MGroup) do
-               super
-               self.mgroup = mgroup
+       init do
                self.concerns = model.concerns_tree(mgroup.collect_mmodules)
                self.concerns.sort_with(new MConcernRankSorter)
                self.intros = mgroup.in_nesting_intro_mclasses(ctx.min_visibility)
@@ -798,14 +788,12 @@ class NitdocModule
        super NitdocPage
 
        private var mmodule: MModule
-       private var concerns: ConcernsTree
-       private var mclasses2mdefs: Map[MClass, Set[MClassDef]]
-       private var mmodules2mclasses: Map[MModule, Set[MClass]]
+       private var concerns: ConcernsTree is noinit
+       private var mclasses2mdefs: Map[MClass, Set[MClassDef]] is noinit
+       private var mmodules2mclasses: Map[MModule, Set[MClass]] is noinit
 
 
-       init(ctx: ToolContext, model: Model, mainmodule: MModule, mmodule: MModule) do
-               super
-               self.mmodule = mmodule
+       init do
                var mclassdefs = new HashSet[MClassDef]
                mclassdefs.add_all mmodule.intro_mclassdefs(ctx.min_visibility)
                mclassdefs.add_all mmodule.redef_mclassdefs(ctx.min_visibility)
@@ -1007,17 +995,17 @@ class NitdocModule
                        end
                end
                # build graph
-               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")
+               var op = new RopeBuffer
+               var name = "dep_module_{mmodule.nitdoc_id}"
+               op.append("digraph \"{name.escape_to_dot}\" \{ 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
                        if mmodule == self.mmodule then
-                               op.append("\"{mmodule.name}\"[shape=box,margin=0.03];\n")
+                               op.append("\"{mmodule.name.escape_to_dot}\"[shape=box,margin=0.03];\n")
                        else
-                               op.append("\"{mmodule.name}\"[URL=\"{mmodule.nitdoc_url}\"];\n")
+                               op.append("\"{mmodule.name.escape_to_dot}\"[URL=\"{mmodule.nitdoc_url.escape_to_dot}\"];\n")
                        end
                        for omodule in poset[mmodule].direct_greaters do
-                               op.append("\"{mmodule.name}\"->\"{omodule.name}\";\n")
+                               op.append("\"{mmodule.name.escape_to_dot}\"->\"{omodule.name.escape_to_dot}\";\n")
                        end
                end
                op.append("\}\n")
@@ -1041,13 +1029,11 @@ class NitdocClass
        super NitdocPage
 
        private var mclass: MClass
-       private var concerns: ConcernsTree
-       private var mprops2mdefs: Map[MProperty, Set[MPropDef]]
-       private var mmodules2mprops: Map[MModule, Set[MProperty]]
+       private var concerns: ConcernsTree is noinit
+       private var mprops2mdefs: Map[MProperty, Set[MPropDef]] is noinit
+       private var mmodules2mprops: Map[MModule, Set[MProperty]] is noinit
 
-       init(ctx: ToolContext, model: Model, mainmodule: MModule, mclass: MClass) do
-               super
-               self.mclass = mclass
+       init do
                var mpropdefs = new HashSet[MPropDef]
                mpropdefs.add_all mclass.intro_mpropdefs(ctx.min_visibility)
                mpropdefs.add_all mclass.redef_mpropdefs(ctx.min_visibility)
@@ -1390,9 +1376,9 @@ class NitdocClass
                        end
                end
 
-               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")
+               var op = new RopeBuffer
+               var name = "dep_class_{mclass.nitdoc_id}"
+               op.append("digraph \"{name.escape_to_dot}\" \{ 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 classes = poset.to_a
                var todo = new Array[MClass]
                var done = new HashSet[MClass]
@@ -1403,18 +1389,18 @@ class NitdocClass
                        if done.has(c) then continue
                        done.add c
                        if c == mclass then
-                               op.append("\"{c.name}\"[shape=box,margin=0.03];\n")
+                               op.append("\"{c.name.escape_to_dot}\"[shape=box,margin=0.03];\n")
                        else
-                               op.append("\"{c.name}\"[URL=\"{c.nitdoc_url}\"];\n")
+                               op.append("\"{c.name.escape_to_dot}\"[URL=\"{c.nitdoc_url.escape_to_dot}\"];\n")
                        end
                        var smallers = poset[c].direct_smallers
                        if smallers.length < 10 then
                                for c2 in smallers do
-                                       op.append("\"{c2.name}\"->\"{c.name}\";\n")
+                                       op.append("\"{c2.name.escape_to_dot}\"->\"{c.name.escape_to_dot}\";\n")
                                end
                                todo.add_all smallers
                        else
-                               op.append("\"...\"->\"{c.name}\";\n")
+                               op.append("\"...\"->\"{c.name.escape_to_dot}\";\n")
                        end
                end
                op.append("\}\n")
@@ -1427,11 +1413,10 @@ class NitdocProperty
        super NitdocPage
 
        private var mproperty: MProperty
-       private var concerns: ConcernsTree
-       private var mmodules2mdefs: Map[MModule, Set[MPropDef]]
+       private var concerns: ConcernsTree is noinit
+       private var mmodules2mdefs: Map[MModule, Set[MPropDef]] is noinit
 
-       init(ctx: ToolContext, model: Model, mainmodule: MModule, mproperty: MProperty) do
-               super
+       init do
                self.mproperty = mproperty
                self.mmodules2mdefs = sort_by_mmodule(collect_mpropdefs)
                self.concerns = model.concerns_tree(mmodules2mdefs.keys)