nitdoc: Always use `mdoc_or_fallback`.
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Fri, 12 Dec 2014 19:32:24 +0000 (14:32 -0500)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Fri, 19 Dec 2014 16:43:57 +0000 (11:43 -0500)
Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

src/doc/doc_model.nit
src/doc/doc_pages.nit

index c25c7dc..c8bcc3a 100644 (file)
@@ -52,6 +52,7 @@ redef class MEntity
        # A template link to the mentity `nitdoc_id`
        fun tpl_anchor: TplLink do
                var tpl = new TplLink("#{nitdoc_id}", nitdoc_name)
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        tpl.title = mdoc.short_comment
                end
@@ -61,6 +62,7 @@ redef class MEntity
        # A template link to the mentity `nitdoc_url`
        fun tpl_link: TplLink do
                var tpl = new TplLink(nitdoc_url, nitdoc_name)
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        tpl.title = mdoc.short_comment
                end
@@ -70,6 +72,7 @@ redef class MEntity
        # A template article that briefly describe the entity
        fun tpl_short_article: TplArticle do
                var tpl = tpl_article
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        tpl.content = mdoc.tpl_short_comment
                end
@@ -100,6 +103,7 @@ redef class MEntity
                var lnk = new Template
                lnk.add new TplLabel.with_classes(tpl_css_classes)
                lnk.add tpl_link
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        lnk.add ": "
                        lnk.add mdoc.tpl_short_comment
@@ -130,6 +134,7 @@ redef class MConcern
        private fun tpl_concern_item: TplListItem do
                var lnk = new Template
                lnk.add tpl_anchor
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        lnk.add ": "
                        lnk.add mdoc.tpl_short_comment
@@ -143,13 +148,6 @@ redef class MProject
        redef fun nitdoc_name do return name.html_escape
        redef fun nitdoc_url do return root.nitdoc_url
 
-       redef fun mdoc do
-               if root != null then
-                       return root.mdoc
-               end
-               return super
-       end
-
        redef fun tpl_declaration do
                var tpl = new Template
                tpl.add "<span>project "
@@ -248,6 +246,7 @@ redef class MModule
 
        redef fun tpl_definition do
                var tpl = new TplClassDefinition
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        tpl.comment = mdoc.tpl_comment
                end
@@ -261,7 +260,7 @@ redef class MClass
        redef fun nitdoc_name do return name.html_escape
        redef var nitdoc_id = "{intro_mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
        redef fun nitdoc_url do return "class_{nitdoc_id}.html"
-       redef fun mdoc do return intro.mdoc
+       redef fun mdoc_or_fallback do return intro.mdoc
 
        redef fun tpl_declaration do return intro.tpl_declaration
 
@@ -312,6 +311,8 @@ redef class MClassDef
        redef var nitdoc_id = "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
        redef fun nitdoc_url do return "{mclass.nitdoc_url}#{nitdoc_id}"
 
+       redef fun mdoc_or_fallback do return mdoc or else mclass.mdoc_or_fallback
+
        redef fun tpl_namespace do
                var tpl = new Template
                tpl.add mmodule.tpl_namespace
@@ -330,6 +331,7 @@ redef class MClassDef
                title.add "in "
                title.add mmodule.tpl_namespace
                tpl.subtitle = title
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        tpl.content = mdoc.tpl_comment
                end
@@ -370,6 +372,7 @@ redef class MClassDef
        redef fun tpl_definition do
                var tpl = new TplClassDefinition
                tpl.namespace = tpl_namespace
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        tpl.comment = mdoc.tpl_comment
                end
@@ -392,40 +395,6 @@ redef class MClassDef
                end
                return tpl
        end
-
-       redef fun tpl_list_item do
-               var lnk = new Template
-               lnk.add new TplLabel.with_classes(tpl_css_classes)
-               lnk.add tpl_link
-               if mdoc != null then
-                       lnk.add ": "
-                       lnk.add mdoc.tpl_short_comment
-               else if mclass.intro.mdoc != null then
-                       lnk.add ": "
-                       lnk.add mclass.intro.mdoc.tpl_short_comment
-               end
-               return new TplListItem.with_content(lnk)
-       end
-
-       redef fun tpl_anchor: TplLink do
-               var tpl = new TplLink("#{nitdoc_id}", nitdoc_name)
-               if mdoc != null then
-                       tpl.title = mdoc.short_comment
-               else if mclass.intro.mdoc != null then
-                       tpl.title = mclass.intro.mdoc.short_comment
-               end
-               return tpl
-       end
-
-       redef fun tpl_link: TplLink do
-               var tpl = new TplLink(nitdoc_url, nitdoc_name)
-               if mdoc != null then
-                       tpl.title = mdoc.short_comment
-               else if mclass.intro.mdoc != null then
-                       tpl.title = mclass.intro.mdoc.short_comment
-               end
-               return tpl
-       end
 end
 
 redef class MProperty
@@ -433,7 +402,7 @@ redef class MProperty
        redef fun nitdoc_name do return name.html_escape
        redef fun nitdoc_url do return "property_{nitdoc_id}.html"
 
-       redef fun mdoc do return intro.mdoc
+       redef fun mdoc_or_fallback do return intro.mdoc
 
        redef fun tpl_namespace do
                var tpl = new Template
@@ -460,25 +429,7 @@ redef class MPropDef
        redef var nitdoc_id = "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
        redef fun nitdoc_url do return "{mproperty.nitdoc_url}#{nitdoc_id}"
 
-       redef fun tpl_anchor: TplLink do
-               var tpl = new TplLink("#{nitdoc_id}", nitdoc_name)
-               if mdoc != null then
-                       tpl.title = mdoc.short_comment
-               else if mproperty.intro.mdoc != null then
-                       tpl.title = mproperty.intro.mdoc.short_comment
-               end
-               return tpl
-       end
-
-       redef fun tpl_link: TplLink do
-               var tpl = new TplLink(nitdoc_url, nitdoc_name)
-               if mdoc != null then
-                       tpl.title = mdoc.short_comment
-               else if mproperty.intro.mdoc != null then
-                       tpl.title = mproperty.intro.mdoc.short_comment
-               end
-               return tpl
-       end
+       redef fun mdoc_or_fallback do return mdoc or else mproperty.mdoc_or_fallback
 
        redef fun tpl_namespace do
                var tpl = new Template
@@ -496,6 +447,7 @@ redef class MPropDef
                title.add mclassdef.tpl_link
                tpl.title = title
                tpl.subtitle = tpl_declaration
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        tpl.content = mdoc.tpl_comment
                end
@@ -505,6 +457,7 @@ redef class MPropDef
        redef fun tpl_definition do
                var tpl = new TplDefinition
                tpl.namespace = mclassdef.tpl_namespace
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        tpl.comment = mdoc.tpl_comment
                end
@@ -544,12 +497,10 @@ redef class MPropDef
                var anchor = tpl_link
                anchor.href = "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
                lnk.add anchor
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        lnk.add ": "
                        lnk.add mdoc.tpl_short_comment
-               else if mproperty.intro.mdoc != null then
-                       lnk.add ": "
-                       lnk.add mproperty.intro.mdoc.tpl_short_comment
                end
                return new TplListItem.with_content(lnk)
        end
@@ -562,6 +513,7 @@ redef class MPropDef
                var anchor = mclassdef.tpl_link
                anchor.href = "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
                lnk.add anchor
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        lnk.add ": "
                        lnk.add mdoc.tpl_short_comment
@@ -761,6 +713,7 @@ redef class MInnerClassDef
        redef fun tpl_definition do
                var tpl = new TplClassDefinition
                tpl.namespace = mclassdef.tpl_namespace
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        tpl.comment = mdoc.tpl_comment
                end
index b400c6d..ae2dde5 100644 (file)
@@ -404,8 +404,9 @@ abstract class NitdocPage
                var article = mproject.tpl_article
                article.subtitle = mproject.tpl_declaration
                article.content = mproject.tpl_definition
-               if mproject.mdoc != null then
-                       article.content = mproject.mdoc.tpl_short_comment
+               var mdoc = mproject.mdoc_or_fallback
+               if mdoc != null then
+                       article.content = mdoc.tpl_short_comment
                end
                return article
        end
@@ -525,8 +526,8 @@ abstract class NitdocPage
                article.title_classes.add "signature"
                article.summary_title = "{mprop.nitdoc_name}"
                article.subtitle = main_mpropdef.tpl_namespace
-               if main_mpropdef.mdoc != null then
-                       article.content = main_mpropdef.mdoc.tpl_comment
+               if main_mpropdef.mdoc_or_fallback != null then
+                       article.content = main_mpropdef.mdoc_or_fallback.tpl_comment
                end
                var subarticle = new TplArticle("{main_mpropdef.nitdoc_id}.redefs")
                # Add redef in same `MClass`
@@ -541,8 +542,8 @@ abstract class NitdocPage
                                redef_article.title_classes.add "signature info"
                                redef_article.css_classes.add "nospace"
                                var redef_content = new Template
-                               if mpropdef.mdoc != null then
-                                       redef_content.add mpropdef.mdoc.tpl_comment
+                               if mpropdef.mdoc_or_fallback != null then
+                                       redef_content.add mpropdef.mdoc_or_fallback.tpl_comment
                                end
                                redef_article.content = redef_content
                                subarticle.add_child redef_article
@@ -1126,7 +1127,8 @@ class NitdocClass
                        var cls_url = mprop.intro.mclassdef.mclass.nitdoc_url
                        var def_url = "{cls_url}#{mprop.nitdoc_id}"
                        var lnk = new TplLink(def_url, mprop.name)
-                       if mprop.intro.mdoc != null then lnk.title = mprop.intro.mdoc.short_comment
+                       var mdoc = mprop.intro.mdoc_or_fallback
+                       if mdoc != null then lnk.title = mdoc.short_comment
                        var item = new Template
                        item.add new TplLabel.with_classes(classes)
                        item.add lnk
@@ -1148,8 +1150,9 @@ class NitdocClass
                var section = new TplSection.with_title("top", tpl_title)
                section.subtitle = mclass.intro.tpl_declaration
                var article = new TplArticle("comment")
-               if mclass.mdoc != null then
-                       article.content = mclass.mdoc.tpl_comment
+               var mdoc = mclass.mdoc_or_fallback
+               if mdoc != null then
+                       article.content = mdoc.tpl_comment
                end
                section.add_child article
                return section