Merge: Nitdoc: HTML templates related cleaning
authorJean Privat <jean@pryen.org>
Thu, 26 Feb 2015 02:23:27 +0000 (09:23 +0700)
committerJean Privat <jean@pryen.org>
Thu, 26 Feb 2015 02:23:27 +0000 (09:23 +0700)
This PR reorganizes Nitdoc modules importation for HTML templates.

The main objective is to dissociate `doc_model` from html related things.
This is the last step before template migration from old model templates to `DocComposite`.

Pull-Request: #1172
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

src/doc/doc_base.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_indexing.nit
src/doc/doc_phases/doc_intros_redefs.nit
src/doc/doc_phases/doc_pages.nit
src/doc/doc_phases/doc_structure.nit
src/doc/html_templates/html_components.nit [moved from src/doc/doc_templates.nit with 83% similarity]
src/doc/html_templates/html_model.nit [moved from src/doc/doc_model.nit with 98% similarity]
src/doc/html_templates/html_templates.nit [new file with mode: 0644]

index 56b57c2..e947ee2 100644 (file)
@@ -16,7 +16,8 @@
 module doc_base
 
 import toolcontext
-import doc_model # FIXME maintain compatibility with old templates.
+import model_utils
+import model_ext
 
 # The model of a Nitdoc documentation.
 #
@@ -83,7 +84,9 @@ abstract class DocComposite
        # Add a `child` to `self`.
        #
        # Shortcut for `children.add`.
-       fun add(child: DocComposite) do children.add child
+       fun add_child(child: DocComposite) do
+               children.add child
+       end
 end
 
 # The `DocComposite` element that contains all the other.
@@ -217,3 +220,16 @@ class PropertyGroup[E: MProperty]
        # The title of the group, as displayed to the user.
        var title: String
 end
+
+redef class MEntity
+       # Name displayed in console for debug and tests.
+       fun nitdoc_name: String do return name.html_escape
+end
+
+redef class MClassDef
+       redef fun nitdoc_name do return mclass.nitdoc_name
+end
+
+redef class MPropDef
+       redef fun nitdoc_name do return mproperty.nitdoc_name
+end
index 6013088..aff25d4 100644 (file)
@@ -15,7 +15,9 @@
 # Adds importation and class hierarchy graphs.
 module doc_graphs
 
+import doc_structure
 import doc_poset
+import html_templates::html_model # FIXME maybe this phase should depend on `html_render`
 
 redef class ToolContext
 
@@ -70,7 +72,7 @@ redef class MModulePage
                        end
                end
                op.append("\}\n")
-               return new GraphArticle(name, op)
+               return new GraphArticle(mentity, name, op)
        end
 end
 
@@ -104,7 +106,7 @@ redef class MClassPage
                        end
                end
                op.append("\}\n")
-               return new GraphArticle(name, op)
+               return new GraphArticle(mentity, name, op)
        end
 end
 
@@ -113,7 +115,7 @@ end
 # The graph is stored in dot format.
 # The final output is delayed untill rendering.
 class GraphArticle
-       super DocComposite
+       super MEntityComposite
 
        # Graph ID (used for outputing file with names).
        var id: String
index ba98ee4..39ad273 100644 (file)
@@ -40,32 +40,32 @@ end
 
 redef class MModulePage
        redef fun build_inh_list(v, doc) do
-               var section = new ImportationListSection
+               var section = new ImportationListSection(mentity)
                var imports = self.imports.to_a
                v.name_sorter.sort(imports)
-               section.children.add new HierarchyListArticle(mentity, "Imports", imports)
+               section.add_child new HierarchyListArticle(mentity, "Imports", imports)
                var clients = self.clients.to_a
                v.name_sorter.sort(clients)
-               section.children.add new HierarchyListArticle(mentity, "Clients", clients)
+               section.add_child 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 section = new InheritanceListSection(mentity)
                var parents = self.parents.to_a
                v.name_sorter.sort(parents)
-               section.children.add new HierarchyListArticle(mentity, "Parents", parents)
+               section.add_child new HierarchyListArticle(mentity, "Parents", parents)
                var ancestors = self.ancestors.to_a
                v.name_sorter.sort(ancestors)
-               section.children.add new HierarchyListArticle(mentity, "Ancestors", ancestors)
+               section.add_child new HierarchyListArticle(mentity, "Ancestors", ancestors)
                var children = self.children.to_a
                v.name_sorter.sort(children)
-               section.children.add new HierarchyListArticle(mentity, "Children", children)
+               section.add_child new HierarchyListArticle(mentity, "Children", children)
                var descendants = self.descendants.to_a
                v.name_sorter.sort(descendants)
-               section.children.add new HierarchyListArticle(mentity, "Descendants", descendants)
+               section.add_child new HierarchyListArticle(mentity, "Descendants", descendants)
                root.children.insert(section, 1)
        end
 end
@@ -73,11 +73,13 @@ end
 # FIXME diff hack
 class ImportationListSection
        super DocSection
+       super MEntityComposite
 end
 
 # FIXME diff hack
 class InheritanceListSection
        super DocSection
+       super MEntityComposite
 end
 
 # Dislay a hierarchical list of mentities.
index e4865e5..a11e187 100644 (file)
@@ -23,6 +23,7 @@ import doc_structure
 import doc_hierarchies
 import doc_intros_redefs
 import doc_graphs
+import html_templates
 
 redef class ToolContext
 
@@ -104,7 +105,7 @@ class RenderHTMLPhase
        redef fun apply do
                init_output_dir
                for page in doc.pages do
-                       page.render(self, doc).write_to_file("{ctx.output_dir.to_s}/{page.page_url}")
+                       page.render(self, doc).write_to_file("{ctx.output_dir.to_s}/{page.html_url}")
                end
        end
 
@@ -156,52 +157,41 @@ end
 redef class DocPage
 
        # Render the page as a html template.
-       private fun render(v: RenderHTMLPhase, doc: DocModel): TplPage do
+       private fun render(v: RenderHTMLPhase, doc: DocModel): Writable do
                var shareurl = "."
                if v.ctx.opt_shareurl.value != null then
                        shareurl = v.ctx.opt_shareurl.value.as(not null)
                end
 
+               # init page options
+               self.shareurl = shareurl
+               self.footer = v.ctx.opt_custom_footer.value
+               self.body_attrs.add(new TagAttribute("data-bootstrap-share", shareurl))
+
                # build page
-               var tpl = new TplPage
-               tpl.title = tpl_title(v, doc)
-               tpl.url = page_url
-               tpl.shareurl = shareurl
-               tpl.topmenu = tpl_topmenu(v, doc)
-               tpl.add_section tpl_content(v, doc)
-               tpl.footer = v.ctx.opt_custom_footer.value
-               tpl.body_attrs.add(new TagAttribute("data-bootstrap-share", shareurl))
-               tpl.sidebar = tpl_sidebar(v, doc)
+               init_title(v, doc)
+               init_sidebar(v, doc)
+               init_topmenu(v, doc)
+               init_content(v, doc)
 
                # piwik tracking
                var tracker_url = v.ctx.opt_piwik_tracker.value
                var site_id = v.ctx.opt_piwik_site_id.value
                if tracker_url != null and site_id != null then
-                       tpl.scripts.add new TplPiwikScript(tracker_url, site_id)
+                       self.scripts.add new TplPiwikScript(tracker_url, site_id)
                end
-               return tpl
+               return self
        end
 
        # FIXME diff hack
        # all properties below are roughly copied from `doc_pages`
 
-       # URL to this page.
-       fun page_url: String is abstract
-
-       # Build page sidebar if any
-       fun tpl_sidebar(v: RenderHTMLPhase, doc: DocModel): nullable TplSidebar do return null
-
        # Build page title string
-       fun tpl_title(v: RenderHTMLPhase, doc: DocModel): String do
-               if v.ctx.opt_custom_title.value != null then
-                       return v.ctx.opt_custom_title.value.to_s
-               end
-               return "Nitdoc"
-       end
+       fun init_title(v: RenderHTMLPhase, doc: DocModel) is abstract
 
-       # Build top menu template
-       fun tpl_topmenu(v: RenderHTMLPhase, doc: DocModel): TplTopMenu do
-               var topmenu = new TplTopMenu(page_url)
+       # Build top menu template if any.
+       fun init_topmenu(v: RenderHTMLPhase, doc: DocModel) do
+               topmenu = new TplTopMenu(html_url)
                var brand = v.ctx.opt_custom_brand.value
                if brand != null then
                        var tpl = new Template
@@ -212,28 +202,31 @@ redef class DocPage
                end
                topmenu.add_link new TplLink("index.html", "Overview")
                topmenu.add_link new TplLink("search.html", "Index")
-               return topmenu
        end
 
-       # Build page content template
-       fun tpl_content(v: RenderHTMLPhase, doc: DocModel): TplSection is abstract
+       # Build page sidebar if any.
+       fun init_sidebar(v: RenderHTMLPhase, doc: DocModel) do
+               sidebar = new TplSidebar
+       end
+
+       # Build page content template.
+       fun init_content(v: RenderHTMLPhase, doc: DocModel) do end
 end
 
 redef class OverviewPage
-       redef fun page_url do return "index.html"
+       redef var html_url = "index.html"
 
-       redef fun tpl_title(v, doc) do
+       redef fun init_title(v, doc) do
+               title = "Overview"
                if v.ctx.opt_custom_title.value != null then
-                       return v.ctx.opt_custom_title.value.to_s
-               else
-                       return "Overview"
+                       title = v.ctx.opt_custom_title.value.to_s
                end
        end
 
        # TODO this should be done in StructurePhase.
-       redef fun tpl_content(v, doc) do
+       redef fun init_content(v, doc) do
                # intro text
-               var section = new TplSection.with_title("overview", tpl_title(v, doc))
+               var section = new TplSection.with_title("overview", title)
                var article = new TplArticle("intro")
                if v.ctx.opt_custom_intro.value != null then
                        article.content = v.ctx.opt_custom_intro.value.to_s
@@ -255,18 +248,19 @@ redef class OverviewPage
                        ssection.add_child sarticle
                end
                section.add_child ssection
-               return section
+               self.add_section section
        end
 
-       redef fun tpl_sidebar(v, doc) do return new TplSidebar
+       redef fun init_sidebar(v, doc) do sidebar = new TplSidebar
 end
 
 redef class SearchPage
-       redef fun page_url do return "search.html"
-       redef fun tpl_title(v, doc) do return "Index"
+       redef var html_url = "search.html"
+       redef fun init_title(v, doc) do title = "Index"
+       redef fun init_sidebar(v, doc) do end
 
        # TODO this should be done in StructurePhase.
-       redef fun tpl_content(v, doc) do
+       redef fun init_content(v, doc) do
                var tpl = new TplSearchPage("search_all")
                var section = new TplSection("search")
                # title
@@ -289,7 +283,7 @@ redef class SearchPage
                        tpl.props.add m
                end
                section.add_child tpl
-               return section
+               self.add_section section
        end
 
        # Extract mmodule list to display (sorted by name)
@@ -319,9 +313,9 @@ redef class SearchPage
 end
 
 redef class MEntityPage
-       redef fun page_url do return mentity.nitdoc_url
-       redef fun tpl_title(v, doc) do return mentity.nitdoc_name
-       redef fun tpl_content(v, doc) do return root.start_rendering(v, doc, self)
+       redef var html_url is lazy do return mentity.nitdoc_url
+       redef fun init_title(v, doc) do title = mentity.nitdoc_name
+       redef fun init_content(v, doc) do add_section root.start_rendering(v, doc, self)
 end
 
 # FIXME all clases below are roughly copied from `doc_pages` and adapted to new
@@ -329,22 +323,21 @@ end
 # `doc_templates` module.
 
 redef class MGroupPage
-       redef fun tpl_topmenu(v, doc) do
-               var topmenu = super
+       redef fun init_topmenu(v, doc) do
+               super
                var mproject = mentity.mproject
                if not mentity.is_root then
                        topmenu.add_link new TplLink(mproject.nitdoc_url, mproject.nitdoc_name)
                end
-               topmenu.add_link new TplLink(page_url, mproject.nitdoc_name)
-               return topmenu
+               topmenu.add_link new TplLink(html_url, mproject.nitdoc_name)
        end
 
-       redef fun tpl_sidebar(v, doc) do
-               var sidebar = new TplSidebar
+       redef fun init_sidebar(v, doc) do
+               super
                var mclasses = new HashSet[MClass]
                mclasses.add_all intros
                mclasses.add_all redefs
-               if mclasses.is_empty then return sidebar
+               if mclasses.is_empty then return
                var list = new TplList.with_classes(["list-unstyled", "list-labeled"])
 
                var sorted = mclasses.to_a
@@ -353,7 +346,6 @@ redef class MGroupPage
                        list.add_li tpl_sidebar_item(mclass)
                end
                sidebar.boxes.add new TplSideBox.with_content("All classes", list)
-               return sidebar
        end
 
        private fun tpl_sidebar_item(def: MClass): TplListItem do
@@ -371,22 +363,21 @@ redef class MGroupPage
 end
 
 redef class MModulePage
-       redef fun tpl_topmenu(v, doc) do
-               var topmenu = super
+       redef fun init_topmenu(v, doc) do
+               super
                var mproject = mentity.mproject
                topmenu.add_link new TplLink(mproject.nitdoc_url, mproject.nitdoc_name)
                topmenu.add_link new TplLink(mentity.nitdoc_url, mentity.nitdoc_name)
-               return topmenu
        end
 
        # Class list to display in sidebar
-       redef fun tpl_sidebar(v, doc) do
+       redef fun init_sidebar(v, doc) do
                # TODO filter here?
-               var sidebar = new TplSidebar
+               super
                var mclasses = new HashSet[MClass]
                mclasses.add_all mentity.filter_intro_mclasses(v.ctx.min_visibility)
                mclasses.add_all mentity.filter_redef_mclasses(v.ctx.min_visibility)
-               if mclasses.is_empty then return sidebar
+               if mclasses.is_empty then return
                var list = new TplList.with_classes(["list-unstyled", "list-labeled"])
 
                var sorted = mclasses.to_a
@@ -395,7 +386,6 @@ redef class MModulePage
                        list.add_li tpl_sidebar_item(mclass)
                end
                sidebar.boxes.add new TplSideBox.with_content("All classes", list)
-               return sidebar
        end
 
        private fun tpl_sidebar_item(def: MClass): TplListItem do
@@ -414,27 +404,25 @@ end
 
 redef class MClassPage
 
-       redef fun tpl_title(v, doc) do
-               return "{mentity.nitdoc_name}{mentity.tpl_signature.write_to_string}"
+       redef fun init_title(v, doc) do
+               title = "{mentity.nitdoc_name}{mentity.tpl_signature.write_to_string}"
        end
 
-       redef fun tpl_topmenu(v, doc) do
-               var topmenu = super
+       redef fun init_topmenu(v, doc) do
+               super
                var mproject = mentity.intro_mmodule.mgroup.mproject
                topmenu.add_link new TplLink("{mproject.nitdoc_url}", "{mproject.nitdoc_name}")
-               topmenu.add_link new TplLink(page_url, mentity.nitdoc_name)
-               return topmenu
+               topmenu.add_link new TplLink(html_url, mentity.nitdoc_name)
        end
 
-       redef fun tpl_sidebar(v, doc) do
-               var sidebar = new TplSidebar
+       redef fun init_sidebar(v, doc) do
+               super
                var by_kind = new PropertiesByKind.with_elements(mclass_inherited_mprops(v, doc))
                var summary = new TplList.with_classes(["list-unstyled"])
 
                by_kind.sort_groups(v.name_sorter)
                for g in by_kind.groups do tpl_sidebar_list(g, summary)
                sidebar.boxes.add new TplSideBox.with_content("All properties", summary)
-               return sidebar
        end
 
        private fun tpl_sidebar_list(mprops: PropertyGroup[MProperty], summary: TplList) do
@@ -497,22 +485,19 @@ redef class MClassPage
 end
 
 redef class MPropertyPage
-       redef fun tpl_topmenu(v, doc) do
-               var topmenu = super
+       redef fun init_title(v, doc) do
+               title = "{mentity.nitdoc_name}{mentity.tpl_signature.write_to_string}"
+       end
+
+       redef fun init_topmenu(v, doc) do
+               super
                var mmodule = mentity.intro_mclassdef.mmodule
                var mproject = mmodule.mgroup.mproject
                var mclass = mentity.intro_mclassdef.mclass
                topmenu.add_link new TplLink("{mproject.nitdoc_url}", "{mproject.nitdoc_name}")
                topmenu.add_link new TplLink("{mclass.nitdoc_url}", "{mclass.nitdoc_name}")
-               topmenu.add_link new TplLink(page_url, mentity.nitdoc_name)
-               return topmenu
+               topmenu.add_link new TplLink(html_url, mentity.nitdoc_name)
        end
-
-       redef fun tpl_title(v, doc) do
-               return "{mentity.nitdoc_name}{mentity.tpl_signature.write_to_string}"
-       end
-
-       redef fun tpl_sidebar(v, doc) do return new TplSidebar
 end
 
 redef class DocComposite
index 9e9ef3c..2f1151f 100644 (file)
@@ -16,6 +16,7 @@
 module doc_indexing
 
 import doc_extract
+import html_templates::html_model # FIXME maybe this phase should depend on `html_render`
 private import json::static
 
 # Generate the index for then Nitdoc QuickSearch field.
index 85c2c80..afd8e55 100644 (file)
@@ -56,10 +56,10 @@ redef class DefinitionArticle
        private fun build_mmodule_list(v: IntroRedefListPhase, doc: DocModel, mmodule: MModule) do
                var intros = mmodule.intro_mclassdefs(v.ctx.min_visibility).to_a
                doc.mainmodule.linearize_mclassdefs(intros)
-               children.add new IntrosRedefsListArticle(mentity, "Introduces", intros)
+               add_child new IntrosRedefsListArticle(mentity, "Introduces", intros)
                var redefs = mmodule.redef_mclassdefs(v.ctx.min_visibility).to_a
                doc.mainmodule.linearize_mclassdefs(redefs)
-               children.add new IntrosRedefsListArticle(mentity, "Redefines", redefs)
+               add_child new IntrosRedefsListArticle(mentity, "Redefines", redefs)
        end
 
        # TODO this should move to MEntity?
@@ -67,11 +67,11 @@ redef class DefinitionArticle
                var intros = mclassdef.collect_intro_mpropdefs(v.ctx.min_visibility).to_a
                # FIXME avoid diff changes
                # v.ctx.mainmodule.linearize_mpropdefs(intros)
-               children.add new IntrosRedefsListArticle(mentity, "Introduces", intros)
+               add_child new IntrosRedefsListArticle(mentity, "Introduces", intros)
                var redefs = mclassdef.collect_redef_mpropdefs(v.ctx.min_visibility).to_a
                # FIXME avoid diff changes
                # v.ctx.mainmodule.linearize_mpropdefs(redefs)
-               children.add new IntrosRedefsListArticle(mentity, "Redefines", redefs)
+               add_child new IntrosRedefsListArticle(mentity, "Redefines", redefs)
        end
 
 end
index 2594d4b..e468cb6 100644 (file)
@@ -26,16 +26,16 @@ class MakePagePhase
                doc.pages.add new OverviewPage("Overview")
                doc.pages.add new SearchPage("Index")
                for mgroup in doc.mgroups do
-                       doc.pages.add new MGroupPage(mgroup.nitdoc_id, mgroup)
+                       doc.pages.add new MGroupPage(mgroup.nitdoc_name, mgroup)
                end
                for mmodule in doc.mmodules do
-                       doc.pages.add new MModulePage(mmodule.nitdoc_id, mmodule)
+                       doc.pages.add new MModulePage(mmodule.nitdoc_name, mmodule)
                end
                for mclass in doc.mclasses do
-                       doc.pages.add new MClassPage(mclass.nitdoc_id, mclass)
+                       doc.pages.add new MClassPage(mclass.nitdoc_name, mclass)
                end
                for mproperty in doc.mproperties do
-                       doc.pages.add new MPropertyPage(mproperty.nitdoc_id, mproperty)
+                       doc.pages.add new MPropertyPage(mproperty.nitdoc_name, mproperty)
                end
        end
 end
index 6fc7468..1e0d773 100644 (file)
@@ -51,9 +51,9 @@ end
 redef class MGroupPage
        redef fun apply_structure(v, doc) do
                if mentity.is_root then
-                       root.add new IntroArticle(mentity.mproject)
+                       root.add_child new IntroArticle(mentity.mproject)
                else
-                       root.add new IntroArticle(mentity)
+                       root.add_child new IntroArticle(mentity)
                end
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
@@ -63,12 +63,12 @@ redef class MGroupPage
                concerns.sort_with(v.concerns_sorter)
                mentity.mproject.booster_rank = 0
                mentity.booster_rank = 0
-               root.add new ConcernsArticle(mentity, concerns)
+               root.add_child new ConcernsArticle(mentity, concerns)
                for mentity in concerns do
                        if mentity isa MModule then
-                               root.add new DefinitionArticle(mentity)
+                               root.add_child new DefinitionArticle(mentity)
                        else
-                               root.add new ConcernSection(mentity)
+                               root.add_child new ConcernSection(mentity)
                        end
                end
        end
@@ -76,7 +76,7 @@ end
 
 redef class MModulePage
        redef fun apply_structure(v, doc) do
-               root.add new IntroArticle(mentity)
+               root.add_child new IntroArticle(mentity)
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
                # FIXME avoid diff
@@ -87,7 +87,7 @@ redef class MModulePage
                mentity.mgroup.mproject.booster_rank = 0
                mentity.mgroup.booster_rank = 0
                mentity.booster_rank = 0
-               root.add new ConcernsArticle(mentity, concerns)
+               root.add_child new ConcernsArticle(mentity, concerns)
                # reference list
                for mentity in concerns do
                        var section = new ConcernSection(mentity)
@@ -98,16 +98,16 @@ redef class MModulePage
                                        var article = new DefinitionArticle(mclass)
                                        var mclassdefs = mclassdefs_for(mclass).to_a
                                        if not mclassdefs.has(mclass.intro) then
-                                               article.add(new DefinitionArticle(mclass.intro))
+                                               article.add_child(new DefinitionArticle(mclass.intro))
                                        end
                                        doc.mainmodule.linearize_mclassdefs(mclassdefs)
                                        for mclassdef in mclassdefs do
-                                               article.add(new DefinitionArticle(mclassdef))
+                                               article.add_child(new DefinitionArticle(mclassdef))
                                        end
-                                       section.add article
+                                       section.add_child article
                                end
                        end
-                       root.add section
+                       root.add_child section
                end
        end
 
@@ -136,7 +136,7 @@ end
 
 redef class MClassPage
        redef fun apply_structure(v, doc) do
-               root.add new IntroArticle(mentity)
+               root.add_child new IntroArticle(mentity)
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
                # FIXME diff hack
@@ -147,7 +147,7 @@ redef class MClassPage
                mentity.intro_mmodule.mgroup.mproject.booster_rank = 0
                mentity.intro_mmodule.mgroup.booster_rank = 0
                mentity.intro_mmodule.booster_rank = 0
-               root.add new ConcernsArticle(mentity, concerns)
+               root.add_child new ConcernsArticle(mentity, concerns)
                for mentity in concerns do
                        var section = new ConcernSection(mentity)
                        if mentity isa MModule then
@@ -157,12 +157,12 @@ redef class MClassPage
                                        v.name_sorter.sort(group)
                                        for mprop in group do
                                                for mpropdef in mpropdefs_for(mprop, mentity) do
-                                                       section.add new DefinitionArticle(mpropdef)
+                                                       section.add_child new DefinitionArticle(mpropdef)
                                                end
                                        end
                                end
                        end
-                       root.add section
+                       root.add_child section
                end
        end
 
@@ -196,7 +196,7 @@ end
 
 redef class MPropertyPage
        redef fun apply_structure(v, doc) do
-               root.add new IntroArticle(mentity)
+               root.add_child new IntroArticle(mentity)
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
                # FIXME diff hack
@@ -207,7 +207,7 @@ redef class MPropertyPage
                mentity.intro.mclassdef.mmodule.mgroup.mproject.booster_rank = 0
                mentity.intro.mclassdef.mmodule.mgroup.booster_rank = 0
                mentity.intro.mclassdef.mmodule.booster_rank = 0
-               root.add new ConcernsArticle(mentity, concerns)
+               root.add_child new ConcernsArticle(mentity, concerns)
                for mentity in concerns do
                        var section = new ConcernSection(mentity)
                        if mentity isa MModule then
@@ -215,10 +215,10 @@ redef class MPropertyPage
                                var mpropdefs = mpropdefs_for(mentity).to_a
                                v.name_sorter.sort(mpropdefs)
                                for mpropdef in mpropdefs do
-                                       section.add new DefinitionArticle(mpropdef)
+                                       section.add_child new DefinitionArticle(mpropdef)
                                end
                        end
-                       root.add section
+                       root.add_child section
                end
        end
 
similarity index 83%
rename from src/doc/doc_templates.nit
rename to src/doc/html_templates/html_components.nit
index c23e880..c3126f7 100644 (file)
 
 # HTML templates used by Nitdoc to generate API documentation
 # Pages are assembled using `Template`
-module doc_templates
+module html_components
 
+import doc_base
 import template
 import json::static
 
-# A documentation page
-class TplPage
-       super Template
-
-       # The unescaped page title to put in the HTML header.
-       var title: String is writable, noinit
-
-       # Page url
-       var url: String is writable, noinit
-
-       # Directory where css, js and other assets can be found
-       var shareurl: String is writable, noinit
-
-       # Attributes of the body tag element
-       var body_attrs = new Array[TagAttribute]
-
-       # Top menu template if any
-       var topmenu: TplTopMenu is writable, noinit
-
-       # Sidebar template if any
-       var sidebar: nullable TplSidebar = null is writable
-
-       # Content of the page in form a TplSection
-       var sections = new Array[TplSection]
-
-       # Footer content if any
-       var footer: nullable Writable = null is writable
-
-       # JS scripts to append at the end of the body
-       var scripts = new Array[TplScript]
-
-       # Add a section to this page
-       fun add_section(section: TplSection) do
-               sections.add section
-       end
-
-       # Render the html header
-       private fun render_head do
-               var css = (self.shareurl / "css").html_escape
-               var vendors = (self.shareurl / "vendors").html_escape
-
-               addn "<!DOCTYPE html>"
-               addn "<head>"
-               addn " <meta charset='utf-8'/>"
-               addn " <!--link rel='stylesheet' href='{css}/Nitdoc.UI.css' type='text/css'/-->"
-               addn " <link rel='stylesheet' href='{vendors}/bootstrap/css/bootstrap.min.css'/>"
-               addn " <link rel='stylesheet' href='{css}/nitdoc.bootstrap.css'/>"
-               addn " <link rel='stylesheet' href='{css}/nitdoc.css'/>"
-               addn " <link rel='stylesheet' href='{css}/Nitdoc.QuickSearch.css'/>"
-               addn " <link rel='stylesheet' href='{css}/Nitdoc.ModalBox.css'/>"
-               addn " <link rel='stylesheet' href='{css}/Nitdoc.GitHub.css'/>"
-               addn " <title>{title.html_escape}</title>"
-               addn "</head>"
-               add "<body"
-               for attr in body_attrs do add attr
-               addn ">"
-       end
-
-       # Render the topmenu template
-       private fun render_topmenu do
-               addn " <div class='row'>"
-               add topmenu
-               addn " </div>"
-       end
-
-       # Render the sidebar
-       # Sidebar is automatically populated with a summary of all sections
-       fun render_sidebar do
-               if sidebar == null then return
-               var summary = new TplSummary.with_order(0)
-               for section in sections do
-                       section.render_summary summary
-               end
-               sidebar.boxes.add summary
-               add sidebar.as(not null)
-       end
-       # Render the footer and content
-       private fun render_content do
-               for section in sections do add section
-               if footer != null then
-                       addn "<div class='well footer'>"
-                       add footer.as(not null)
-                       addn "</div>"
-               end
-       end
-
-       # Render JS scripts
-       private fun render_footer do
-               var vendors = (self.shareurl / "vendors").html_escape
-               var js = (self.shareurl / "js").html_escape
-
-               addn "<script src='{vendors}/jquery/jquery-1.11.1.min.js'></script>"
-               addn "<script src='{vendors}/jquery/jquery-ui-1.10.4.custom.min.js'></script>"
-               addn "<script src='{vendors}/bootstrap/js/bootstrap.min.js'></script>"
-               addn "<script data-main='{js}/nitdoc' src='{js}/lib/require.js'></script>"
-               for script in scripts do add script
-               addn """<script>
-                       $(function () {
-                               $("[data-toggle='tooltip']").tooltip();
-                               $("[data-toggle='popover']").popover();
-                       });
-               </script>"""
-               addn "</body>"
-               addn "</html>"
-       end
-
-       # Render the whole page
-       redef fun rendering do
-               render_head
-               addn "<div class='container-fluid'>"
-               render_topmenu
-               addn " <div class='row' id='content'>"
-               if sidebar != null then
-                       addn "<div class='col col-xs-3 col-lg-2'>"
-                       render_sidebar
-                       addn "</div>"
-                       addn "<div class='col col-xs-9 col-lg-10' data-spy='scroll' data-target='.summary'>"
-                       render_content
-                       addn "</div>"
-               else
-                       addn "<div class='col col-xs-12'>"
-                       render_content
-                       addn "</div>"
-               end
-               addn " </div>"
-               addn "</div>"
-               render_footer
-       end
-end
-
 #########################
 # general layout elements
 #########################
@@ -178,7 +49,7 @@ class TplTopMenu
                var tpl = new Template
                tpl.add "<li"
                if is_active then
-                       tpl.add " class='active'"
+                       tpl.add " class=\"active\""
                end
                tpl.add ">"
                tpl.add content
@@ -912,4 +783,3 @@ class TplPiwikScript
                addn "\})();"
        end
 end
-
similarity index 98%
rename from src/doc/doc_model.nit
rename to src/doc/html_templates/html_model.nit
index 99691d1..15b2963 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Nitdoc model template parts generation
-module doc_model
+# HTML templates for Nit model MEntities.
+module html_model
 
-import model_utils
+import doc_base
 import doc_down
-import doc_templates
+import html_components
 import ordered_tree
-import model_ext
 
 redef class Location
        # Github url based on this location
@@ -32,9 +31,6 @@ redef class Location
 end
 
 redef class MEntity
-       # HTML-escaped name.
-       fun nitdoc_name: String do return name.html_escape
-
        # ID used as a HTML unique ID and in file names.
        #
        # **Must** match the following (POSIX ERE) regular expression:
@@ -302,7 +298,6 @@ redef class MClass
 end
 
 redef class MClassDef
-       redef fun nitdoc_name do return mclass.nitdoc_name
        redef var nitdoc_id = "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
        redef fun nitdoc_url do return "{mclass.nitdoc_url}#{nitdoc_id}"
 
@@ -418,7 +413,6 @@ redef class MProperty
 end
 
 redef class MPropDef
-       redef fun nitdoc_name do return mproperty.nitdoc_name
        redef var nitdoc_id = "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
        redef fun nitdoc_url do return "{mproperty.nitdoc_url}#{nitdoc_id}"
 
diff --git a/src/doc/html_templates/html_templates.nit b/src/doc/html_templates/html_templates.nit
new file mode 100644 (file)
index 0000000..83c1842
--- /dev/null
@@ -0,0 +1,150 @@
+# 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.
+
+# Introduces templates that compose the documentation HTML rendering.
+module html_templates
+
+import html_model
+
+# Renders the page as HTML.
+redef class DocPage
+       super Template
+
+       # Page url.
+       var html_url: String is writable, noinit
+
+       # Directory where css, js and other assets can be found.
+       var shareurl: String is writable, noinit
+
+       # Attributes of the body tag element.
+       var body_attrs = new Array[TagAttribute]
+
+       # Top menu template if any.
+       var topmenu: TplTopMenu is writable, noinit
+
+       # Sidebar template if any.
+       var sidebar: nullable TplSidebar = null is writable
+
+       # Content of the page in form a TplSection.
+       # TODO remove when other templates are migrated.
+       var sections = new Array[TplSection]
+
+       # Footer content if any.
+       var footer: nullable Writable = null is writable
+
+       # JS scripts to append at the end of the body
+       var scripts = new Array[TplScript]
+
+       # Adds a section to this page.
+       # TODO remove when other templates are migrated.
+       fun add_section(section: TplSection) do
+               sections.add section
+       end
+
+       # Renders the html `<head>`.
+       private fun render_head do
+               var css = (self.shareurl / "css").html_escape
+               var vendors = (self.shareurl / "vendors").html_escape
+
+               addn "<!DOCTYPE html>"
+               addn "<head>"
+               addn " <meta charset='utf-8'/>"
+               addn " <!--link rel='stylesheet' href='{css}/Nitdoc.UI.css' type='text/css'/-->"
+               addn " <link rel='stylesheet' href='{vendors}/bootstrap/css/bootstrap.min.css'/>"
+               addn " <link rel='stylesheet' href='{css}/nitdoc.bootstrap.css'/>"
+               addn " <link rel='stylesheet' href='{css}/nitdoc.css'/>"
+               addn " <link rel='stylesheet' href='{css}/Nitdoc.QuickSearch.css'/>"
+               addn " <link rel='stylesheet' href='{css}/Nitdoc.ModalBox.css'/>"
+               addn " <link rel='stylesheet' href='{css}/Nitdoc.GitHub.css'/>"
+               addn " <title>{title.html_escape}</title>"
+               addn "</head>"
+               add "<body"
+               for attr in body_attrs do add attr
+               addn ">"
+       end
+
+       # Renders the topmenu template.
+       private fun render_topmenu do
+               addn " <div class='row'>"
+               add topmenu
+               addn " </div>"
+       end
+
+       # Renders the sidebar template.
+       #
+       # Sidebar is automatically populated with a summary of all sections
+       # TODO remove summary generation when other templates are migrated.
+       private fun render_sidebar do
+               if sidebar == null then return
+               var summary = new TplSummary.with_order(0)
+               for section in sections do
+                       section.render_summary summary
+               end
+               sidebar.boxes.add summary
+               add sidebar.as(not null)
+       end
+
+       # Renders the footer and content.
+       private fun render_content do
+               for section in sections do add section
+               if footer != null then
+                       addn "<div class='well footer'>"
+                       add footer.as(not null)
+                       addn "</div>"
+               end
+       end
+
+       # Render JS scripts
+       private fun render_footer do
+               var vendors = (self.shareurl / "vendors").html_escape
+               var js = (self.shareurl / "js").html_escape
+
+               addn "<script src='{vendors}/jquery/jquery-1.11.1.min.js'></script>"
+               addn "<script src='{vendors}/jquery/jquery-ui-1.10.4.custom.min.js'></script>"
+               addn "<script src='{vendors}/bootstrap/js/bootstrap.min.js'></script>"
+               addn "<script data-main='{js}/nitdoc' src='{js}/lib/require.js'></script>"
+               for script in scripts do add script
+               addn """<script>
+                       $(function () {
+                               $("[data-toggle='tooltip']").tooltip();
+                               $("[data-toggle='popover']").popover();
+                       });
+               </script>"""
+               addn "</body>"
+               addn "</html>"
+       end
+
+       # Render the whole page
+       redef fun rendering do
+               render_head
+               addn "<div class='container-fluid'>"
+               render_topmenu
+               addn " <div class='row' id='content'>"
+               if sidebar != null then
+                       addn "<div class='col col-xs-3 col-lg-2'>"
+                       render_sidebar
+                       addn "</div>"
+                       addn "<div class='col col-xs-9 col-lg-10' data-spy='scroll' data-target='.summary'>"
+                       render_content
+                       addn "</div>"
+               else
+                       addn "<div class='col col-xs-12'>"
+                       render_content
+                       addn "</div>"
+               end
+               addn " </div>"
+               addn "</div>"
+               render_footer
+       end
+end