nitdoc: check multiple page with same id
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 22 May 2015 01:39:03 +0000 (21:39 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 28 May 2015 13:51:31 +0000 (09:51 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/doc_base.nit
src/doc/doc_phases/doc_concerns.nit
src/doc/doc_phases/doc_console.nit
src/doc/doc_phases/doc_graphs.nit
src/doc/doc_phases/doc_hierarchies.nit
src/doc/doc_phases/doc_html.nit
src/doc/doc_phases/doc_intros_redefs.nit
src/doc/doc_phases/doc_lin.nit
src/doc/doc_phases/doc_pages.nit
src/doc/doc_phases/doc_poset.nit
src/doc/doc_phases/doc_structure.nit

index b8af28b..8f0467d 100644 (file)
@@ -27,16 +27,26 @@ import model_ext
 # It is a placeholder to share data between each phase.
 class DocModel
 
-       # `DocPage` composing the documentation.
+       # `DocPage` composing the documentation associated to their ids.
        #
        # This is where `DocPhase` store and access pages to produce documentation.
-       var pages = new Array[DocPage]
+       #
+       # See `add_page`.
+       var pages: Map[String, DocPage] = new HashMap[String, DocPage]
 
        # Nit `Model` from which we extract the documentation.
        var model: Model is writable
 
        # The entry point of the `model`.
        var mainmodule: MModule is writable
+
+       # Add a `page` to this documentation.
+       fun add_page(page: DocPage) do
+               if pages.has_key(page.id) then
+                       print "Warning: multiple page with the same id `{page.id}`"
+               end
+               pages[page.id] = page
+       end
 end
 
 # A documentation page abstraction.
index d1ada76..cca6346 100644 (file)
@@ -23,7 +23,7 @@ class ConcernsPhase
 
        # Populates the given DocModel.
        redef fun apply do
-               for page in doc.pages do page.build_concerns(doc)
+               for page in doc.pages.values do page.build_concerns(doc)
        end
 end
 
index b1f80f5..f927fd9 100644 (file)
@@ -19,6 +19,7 @@
 module doc_console
 
 import semantize
+import doc_extract
 import doc::console_templates
 
 # Nitx handles console I/O.
@@ -214,7 +215,7 @@ class CommentQuery
                if len == 1 then
                        var res = results.first.as(MEntityMatch)
                        var mentity = res.mentity
-                       var page = new DocPage("Results")
+                       var page = new DocPage("resultats", "Results")
                        var article = new DefinitionArticle(mentity)
                        article.cs_title = mentity.name
                        article.cs_subtitle = mentity.cs_declaration
@@ -317,7 +318,7 @@ class DocQuery
        redef fun perform(nitx, doc) do
                var res = new Array[NitxMatch]
                var name = args.first
-               for page in doc.pages do
+               for page in doc.pages.values do
                        if name == "*" then # FIXME dev only
                                res.add new PageMatch(self, page)
                        else if page.title == name then
index 07b7c99..1339d09 100644 (file)
@@ -36,7 +36,7 @@ class GraphPhase
 
        redef fun apply do
                if ctx.opt_nodot.value then return
-               for page in doc.pages do
+               for page in doc.pages.values do
                        var article = page.build_graph(self, doc)
                        if article == null then continue
                        # FIXME avoid diff
index 5bfbfb1..eecc95b 100644 (file)
@@ -26,7 +26,7 @@ class InheritanceListsPhase
        var name_sorter = new MEntityNameSorter
 
        redef fun apply do
-               for page in doc.pages do
+               for page in doc.pages.values do
                        if page isa MEntityPage then page.build_inh_list(self, doc)
                end
        end
index a8612d0..0c843bb 100644 (file)
@@ -104,7 +104,7 @@ class RenderHTMLPhase
 
        redef fun apply do
                init_output_dir
-               for page in doc.pages do
+               for page in doc.pages.values do
                        page.render(self, doc).write_to_file("{ctx.output_dir.to_s}/{page.html_url}")
                end
        end
index 54f7c18..5ed6f78 100644 (file)
@@ -24,7 +24,7 @@ class IntroRedefListPhase
        super DocPhase
 
        redef fun apply do
-               for page in doc.pages do
+               for page in doc.pages.values do
                        if not page isa MEntityPage then continue
                        page.root.build_intro_redef_list(self, doc, page)
                end
index eda76ba..c36756c 100644 (file)
@@ -25,7 +25,7 @@ class LinListPhase
        private var lin_sorter = new MEntityNameSorter
 
        redef fun apply do
-               for page in doc.pages do page.apply_linearization(self, doc)
+               for page in doc.pages.values do page.apply_linearization(self, doc)
        end
 end
 
index f255e42..3f83001 100644 (file)
@@ -23,19 +23,19 @@ class MakePagePhase
 
        # Instanciates documentation pages for the given DocModel.
        redef fun apply do
-               doc.pages.add new OverviewPage("overview", "Overview")
-               doc.pages.add new SearchPage("search", "Index")
+               doc.add_page new OverviewPage("overview", "Overview")
+               doc.add_page new SearchPage("search", "Index")
                for mgroup in doc.mgroups do
-                       doc.pages.add new MGroupPage(mgroup)
+                       doc.add_page new MGroupPage(mgroup)
                end
                for mmodule in doc.mmodules do
-                       doc.pages.add new MModulePage(mmodule)
+                       doc.add_page new MModulePage(mmodule)
                end
                for mclass in doc.mclasses do
-                       doc.pages.add new MClassPage(mclass)
+                       doc.add_page new MClassPage(mclass)
                end
                for mproperty in doc.mproperties do
-                       doc.pages.add new MPropertyPage(mproperty)
+                       doc.add_page new MPropertyPage(mproperty)
                end
        end
 end
index fd38e0f..0c610d4 100644 (file)
@@ -23,7 +23,7 @@ class POSetPhase
 
        # Populates the given DocModel.
        redef fun apply do
-               for page in doc.pages do
+               for page in doc.pages.values do
                        if page isa MEntityPage then page.build_poset(self, doc)
                end
        end
index 507a0a4..7491e4b 100644 (file)
@@ -33,7 +33,7 @@ class StructurePhase
 
        # Populates the given DocModel.
        redef fun apply do
-               for page in doc.pages do page.apply_structure(self, doc)
+               for page in doc.pages.values do page.apply_structure(self, doc)
        end
 end