From: Alexandre Terrasa Date: Wed, 4 Feb 2015 20:09:27 +0000 (+0100) Subject: nitdoc: introduce InheritanceListsPhase X-Git-Tag: v0.7.2~30^2~5 X-Git-Url: http://nitlanguage.org nitdoc: introduce InheritanceListsPhase Signed-off-by: Alexandre Terrasa --- diff --git a/src/doc/doc_pages.nit b/src/doc/doc_pages.nit index 4239532..aca9ea7 100644 --- a/src/doc/doc_pages.nit +++ b/src/doc/doc_pages.nit @@ -593,36 +593,6 @@ class NitdocModule lnk.add def.tpl_link return new TplListItem.with_content(lnk) end - - # inheritance section - private fun tpl_inheritance(parent: TplSection) do - # Display lists - var section = new TplSection.with_title("dependencies", "Dependencies") - - # Imports - var lst = new Array[MModule] - if not lst.is_empty then - name_sorter.sort lst - section.add_child tpl_list("imports", "Imports", lst) - end - - # Clients - lst = new Array[MModule] - if not lst.is_empty then - name_sorter.sort lst - section.add_child tpl_list("clients", "Clients", lst) - end - - parent.add_child section - end - - private fun tpl_list(id: String, title: String, mmodules: Array[MModule]): TplArticle do - var article = new TplArticle.with_title(id, title) - var list = new TplList.with_classes(["list-unstyled", "list-definition"]) - for mmodule in mmodules do list.elts.add mmodule.tpl_list_item - article.content = list - return article - end end # A class page @@ -695,58 +665,6 @@ class NitdocClass lnk.add mprop.tpl_anchor return new TplListItem.with_content(lnk) end - - private fun tpl_inheritance(parent: TplSection) do - # Display lists - var section = new TplSection.with_title("inheritance", "Inheritance") - - # parents - if not hparents.is_empty then - var lst = hparents.to_a - name_sorter.sort lst - section.add_child tpl_list("parents", "Parents", lst) - end - - # ancestors - if not hancestors.is_empty then - var lst = hancestors.to_a - name_sorter.sort lst - section.add_child tpl_list("ancestors", "Ancestors", lst) - end - - # children - if not hchildren.is_empty then - var lst = hchildren.to_a - name_sorter.sort lst - section.add_child tpl_list("children", "Children", lst) - end - - # descendants - if not hdescendants.is_empty then - var lst = hdescendants.to_a - name_sorter.sort lst - section.add_child tpl_list("descendants", "Descendants", lst) - end - - parent.add_child section - end - - private fun tpl_list(id: String, title: String, elts: Array[MClass]): TplArticle do - var article = new TplArticle.with_title(id, title) - if elts.length > 20 then - var tpl = new Template - for e in elts do - tpl.add e.tpl_link - if e != elts.last then tpl.add ", " - end - article.content = tpl - else - var list = new TplList.with_classes(["list-unstyled", "list-definition"]) - for elt in elts do list.elts.add elt.tpl_list_item - article.content = list - end - return article - end end # A MProperty page diff --git a/src/doc/doc_phases/doc_hierarchies.nit b/src/doc/doc_phases/doc_hierarchies.nit new file mode 100644 index 0000000..ba98ee4 --- /dev/null +++ b/src/doc/doc_phases/doc_hierarchies.nit @@ -0,0 +1,92 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Computes importation and class hierarchy lists. +module doc_hierarchies + +import doc_structure +import doc_poset + +# Insert inheritance / importation lists in the page. +class InheritanceListsPhase + super DocPhase + + # Used to sort list by name. + var name_sorter = new MEntityNameSorter + + redef fun apply do + for page in doc.pages do + if page isa MEntityPage then page.build_inh_list(self, doc) + end + end +end + +redef class MEntityPage + + # Build importation / inheritance list for this page. + fun build_inh_list(v: InheritanceListsPhase, doc: DocModel) do end +end + +redef class MModulePage + redef fun build_inh_list(v, doc) do + var section = new ImportationListSection + var imports = self.imports.to_a + v.name_sorter.sort(imports) + section.children.add new HierarchyListArticle(mentity, "Imports", imports) + var clients = self.clients.to_a + v.name_sorter.sort(clients) + section.children.add new HierarchyListArticle(mentity, "Clients", clients) + root.children.insert(section, 1) + end +end + +redef class MClassPage + redef fun build_inh_list(v, doc) do + var section = new InheritanceListSection + var parents = self.parents.to_a + v.name_sorter.sort(parents) + section.children.add new HierarchyListArticle(mentity, "Parents", parents) + var ancestors = self.ancestors.to_a + v.name_sorter.sort(ancestors) + section.children.add new HierarchyListArticle(mentity, "Ancestors", ancestors) + var children = self.children.to_a + v.name_sorter.sort(children) + section.children.add new HierarchyListArticle(mentity, "Children", children) + var descendants = self.descendants.to_a + v.name_sorter.sort(descendants) + section.children.add new HierarchyListArticle(mentity, "Descendants", descendants) + root.children.insert(section, 1) + end +end + +# FIXME diff hack +class ImportationListSection + super DocSection +end + +# FIXME diff hack +class InheritanceListSection + super DocSection +end + +# Dislay a hierarchical list of mentities. +class HierarchyListArticle + super MEntityArticle + + # Title displayed in the top of this list. + var list_title: String + + # MEntities to display in this list. + var mentities: Array[MEntity] +end diff --git a/src/doc/doc_phases/doc_phases.nit b/src/doc/doc_phases/doc_phases.nit index 5719856..6005237 100644 --- a/src/doc/doc_phases/doc_phases.nit +++ b/src/doc/doc_phases/doc_phases.nit @@ -18,5 +18,5 @@ module doc_phases import doc_structure -import doc_poset +import doc_hierarchies import doc_graphs diff --git a/src/nitdoc.nit b/src/nitdoc.nit index 8d37650..3423cbf 100644 --- a/src/nitdoc.nit +++ b/src/nitdoc.nit @@ -38,6 +38,7 @@ private class Nitdoc new POSetPhase(toolcontext, doc), new ConcernsPhase(toolcontext, doc), new StructurePhase(toolcontext, doc), + new InheritanceListsPhase(toolcontext, doc), new GraphPhase(toolcontext, doc): DocPhase] for phase in phases do