nitdoc: show mpropdefs redef chain in MClass page.
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 23 Sep 2014 03:12:50 +0000 (23:12 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 23 Sep 2014 03:12:50 +0000 (23:12 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

share/nitdoc/css/nitdoc.css
src/doc/doc_model.nit
src/doc/doc_pages.nit

index 2daf48f..a6084f7 100644 (file)
@@ -33,6 +33,15 @@ h3 {
        margin: 10px 0;
 }
 
+article {
+       padding: 10px 0px;
+}
+
+article.nospace {
+       padding: 0;
+       margin: 0;
+}
+
 /*
  * Sidebar
  */
@@ -178,10 +187,6 @@ h3 {
        display: none;
 }
 
-#content article {
-       padding: 10px 0px;
-}
-
 #content article:target {
        padding-left: 10px;
        margin-left: -10px;
@@ -221,7 +226,7 @@ h3 {
        vertical-align: middle;
 }
 
-.signature a, .list-definition a {
+.signature a, .list-definition a, .info.signature a {
        color: #0d8921;
 }
 
index dea9682..5d666c8 100644 (file)
@@ -482,7 +482,7 @@ redef class MPropDef
                var tpl = new Template
                tpl.add mclassdef.tpl_namespace
                tpl.add "::"
-               tpl.add mproperty.name
+               tpl.add tpl_link
                return tpl
        end
 
@@ -500,14 +500,6 @@ redef class MPropDef
                return tpl
        end
 
-       redef fun tpl_title do
-               var title = new Template
-               title.add tpl_icon
-               title.add tpl_link
-               title.add tpl_signature
-               return title
-       end
-
        redef fun tpl_definition do
                var tpl = new TplDefinition
                tpl.namespace = mclassdef.tpl_namespace
@@ -547,7 +539,9 @@ redef class MPropDef
        redef fun tpl_list_item do
                var lnk = new Template
                lnk.add new TplLabel.with_classes(tpl_css_classes.to_a)
-               lnk.add tpl_link
+               var anchor = tpl_link
+               anchor.href = "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
+               lnk.add anchor
                if mdoc != null then
                        lnk.add ": "
                        lnk.add mdoc.short_markdown
@@ -557,6 +551,23 @@ redef class MPropDef
                end
                return new TplListItem.with_content(lnk)
        end
+
+       fun tpl_inheritance_item: TplListItem do
+               var lnk = new Template
+               lnk.add new TplLabel.with_classes(tpl_css_classes.to_a)
+               lnk.add mclassdef.mmodule.tpl_namespace
+               lnk.add "::"
+               var anchor = mclassdef.tpl_link
+               anchor.href = "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
+               lnk.add anchor
+               if mdoc != null then
+                       lnk.add ": "
+                       lnk.add mdoc.short_markdown
+               end
+               var li = new TplListItem.with_content(lnk)
+               li.css_classes.add "signature"
+               return li
+       end
 end
 
 redef class MMethod
index 2af39be..c0a1b2f 100644 (file)
@@ -468,28 +468,72 @@ abstract class NitdocPage
        end
 
        # MProp description template
-       fun tpl_mprop_article(mproperty: MProperty, mpropdefs: Array[MPropDef]): TplArticle do
-               var article = mproperty.tpl_article
-               if not mpropdefs.has(mproperty.intro) then
-                       # add intro synopsys
-                       var intro_article = mproperty.intro.tpl_short_article
-                       intro_article.source_link = tpl_showsource(mproperty.intro.location)
-                       article.add_child intro_article
+       #
+       # `main_mpropdef`: The most important mpropdef to display
+       # `local_mpropdefs`: List of other locally defined mpropdefs to display
+       # `lin`: full linearization from local_mpropdefs to intro (displayed in redef tree)
+       fun tpl_mprop_article(main_mpropdef: MPropDef, local_mpropdefs: Array[MPropDef],
+          lin: Array[MPropDef]): TplArticle do
+               var mprop = main_mpropdef.mproperty
+               var article = new TplArticle(mprop.nitdoc_id)
+               var title = new Template
+               title.add mprop.tpl_icon
+               title.add "<span id='{main_mpropdef.nitdoc_id}'></span>"
+               if main_mpropdef.is_intro then
+                       title.add mprop.tpl_link
+                       title.add mprop.intro.tpl_signature
+               else
+                       var cls_url = mprop.intro.mclassdef.mclass.nitdoc_url
+                       var def_url = "{cls_url}#{mprop.nitdoc_id}"
+                       var lnk = new TplLink.with_title(def_url, mprop.name, "Go to introduction")
+                       title.add "redef "
+                       title.add lnk
+               end
+               article.title = title
+               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
+               end
+               var subarticle = new TplArticle("{main_mpropdef.nitdoc_id}_redefs")
+               # Add redef in same `MClass`
+               if local_mpropdefs.length > 1 then
+                       for mpropdef in local_mpropdefs do
+                               if mpropdef == main_mpropdef then continue
+                               var redef_article = new TplArticle("{mpropdef.nitdoc_id}")
+                               var redef_title = new Template
+                               redef_title.add "also redef in "
+                               redef_title.add mpropdef.tpl_namespace
+                               redef_article.title = redef_title
+                               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
+                               end
+                               redef_article.content = redef_content
+                               subarticle.add_child redef_article
+                       end
                end
-               mainmodule.linearize_mpropdefs(mpropdefs)
-               for mpropdef in mpropdefs do
-                       # add mpropdef description
-                       var redef_article = mpropdef.tpl_article
-                       redef_article.source_link = tpl_showsource(mpropdef.location)
-                       article.add_child redef_article
+               # Add linearization
+               if lin.length > 1 then
+                       var lin_article = new TplArticle("{main_mpropdef.nitdoc_id}_lin")
+                       lin_article.title = "Inheritance"
+                       var lst = new TplList.with_classes(["list-unstyled", "list-labeled"])
+                       for mpropdef in lin do
+                               lst.add_li mpropdef.tpl_inheritance_item
+                       end
+                       lin_article.content = lst
+                       subarticle.add_child lin_article
                end
+               article.add_child subarticle
                return article
        end
 
        # MProperty description template
        fun tpl_mpropdef_article(mpropdef: MPropDef): TplArticle do
                var article = mpropdef.tpl_article
-               if mpropdef.is_intro then article.content = null
                article.source_link = tpl_showsource(mpropdef.location)
                return article
        end
@@ -1057,10 +1101,14 @@ class NitdocClass
                var classes = mprop.intro.tpl_css_classes.to_a
                if not mprops2mdefs.has_key(mprop) then
                        classes.add "inherit"
-                       var lnk = new Template
-                       lnk.add new TplLabel.with_classes(classes)
-                       lnk.add mprop.intro.tpl_link
-                       return new TplListItem.with_content(lnk)
+                       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 item = new Template
+                       item.add new TplLabel.with_classes(classes)
+                       item.add lnk
+                       return new TplListItem.with_content(item)
                end
                var defs = mprops2mdefs[mprop]
                if defs.has(mprop.intro) then
@@ -1070,7 +1118,7 @@ class NitdocClass
                end
                var lnk = new Template
                lnk.add new TplLabel.with_classes(classes)
-               lnk.add mprop.intro.tpl_anchor
+               lnk.add mprop.tpl_anchor
                return new TplListItem.with_content(lnk)
        end
 
@@ -1210,33 +1258,48 @@ class NitdocClass
                                var kind_map = sort_by_kind(mprops)
 
                                # virtual types
-                               var elts = kind_map["type"].to_a
-                               name_sorter.sort(elts)
-                               for elt in elts do
-                                       var defs = mprops2mdefs[elt].to_a
-                                       section.add_child tpl_mprop_article(elt, defs)
+                               for article in tpl_mproperty_articles(kind_map, "type") do
+                                       section.add_child article
                                end
-
                                # constructors
-                               elts = kind_map["init"].to_a
-                               name_sorter.sort(elts)
-                               for elt in elts do
-                                       var defs = mprops2mdefs[elt].to_a
-                                       section.add_child tpl_mprop_article(elt, defs)
+                               for article in tpl_mproperty_articles(kind_map, "init") do
+                                       section.add_child article
                                end
-
                                # methods
-                               elts = kind_map["fun"].to_a
-                               name_sorter.sort(elts)
-                               for elt in elts do
-                                       var defs = mprops2mdefs[elt].to_a
-                                       section.add_child tpl_mprop_article(elt, defs)
+                               for article in tpl_mproperty_articles(kind_map, "fun") do
+                                       section.add_child article
                                end
                                parent.add_child section
                        end
                end
        end
 
+       private fun tpl_mproperty_articles(kind_map: Map[String, Set[MProperty]],
+               kind_name: String): Sequence[TplArticle] do
+               var articles = new List[TplArticle]
+               var elts = kind_map[kind_name].to_a
+               name_sorter.sort(elts)
+               for elt in elts do
+                       var local_defs = mprops2mdefs[elt]
+                       # var all_defs = elt.mpropdefs
+                       var all_defs = new HashSet[MPropDef]
+                       for local_def in local_defs do
+                               all_defs.add local_def
+                               var mpropdef = local_def
+                               while not mpropdef.is_intro do
+                                       mpropdef = mpropdef.lookup_next_definition(mainmodule, mpropdef.mclassdef.bound_mtype)
+                                       all_defs.add mpropdef
+                               end
+                       end
+                       var loc_lin = local_defs.to_a
+                       mainmodule.linearize_mpropdefs(loc_lin)
+                       var all_lin = all_defs.to_a
+                       mainmodule.linearize_mpropdefs(all_lin)
+                       articles.add tpl_mprop_article(loc_lin.first, loc_lin, all_lin)
+               end
+               return articles
+       end
+
        redef fun tpl_content do
                tpl_sidebar_properties
                var top = tpl_intro
@@ -1407,13 +1470,12 @@ class NitdocProperty
        end
 
        private fun tpl_intro: TplSection do
-               var section = new TplSection.with_title("top", tpl_title)
-               section.subtitle = mproperty.tpl_declaration
-               var article = new TplArticle("comment")
-               if mproperty.intro.mdoc != null then
-                       article.content = mproperty.intro.mdoc.tpl_comment
-               end
-               section.add_child article
+               var title = new Template
+               title.add mproperty.nitdoc_name
+               title.add mproperty.intro.tpl_signature
+               var section = new TplSection.with_title("top", title)
+               section.subtitle = mproperty.tpl_namespace
+               section.summary_title = mproperty.nitdoc_name
                return section
        end