nitdoc: show mpropdefs redef chain in MClass page.
[nit.git] / src / doc / doc_model.nit
index 023290d..5d666c8 100644 (file)
@@ -16,9 +16,9 @@
 module doc_model
 
 import model_utils
-import modelize_property
 import markdown
 import doc_templates
+import ordered_tree
 
 redef class MDoc
        # Comment synopsys HTML escaped
@@ -54,7 +54,7 @@ redef class MEntity
        # URL of this entity Nitdoc page
        fun nitdoc_url: String is abstract
 
-       # A template link to the mentity `nitdoc_anchor`
+       # A template link to the mentity `nitdoc_id`
        fun tpl_anchor: TplLink do
                var tpl = new TplLink("#{nitdoc_id}", nitdoc_name)
                if mdoc != null then
@@ -107,7 +107,7 @@ redef class MEntity
                lnk.add tpl_link
                if mdoc != null then
                        lnk.add ": "
-                       lnk.add mdoc.short_comment
+                       lnk.add mdoc.short_markdown
                end
                return new TplListItem.with_content(lnk)
        end
@@ -137,17 +137,16 @@ redef class MConcern
                lnk.add tpl_anchor
                if mdoc != null then
                        lnk.add ": "
-                       lnk.add mdoc.short_comment
+                       lnk.add mdoc.short_markdown
                end
                return new TplListItem.with_content(lnk)
        end
 end
 
 redef class MProject
-
        redef fun nitdoc_name do return name.html_escape
        redef fun nitdoc_id do return nitdoc_name
-       redef fun nitdoc_url do return "project_{name}.html"
+       redef fun nitdoc_url do return root.nitdoc_url
 
        redef fun mdoc do
                if root != null then
@@ -187,7 +186,7 @@ redef class MGroup
                return "{mproject.nitdoc_id}__{nitdoc_name}"
        end
 
-       redef fun nitdoc_url do return "group_{name}.html"
+       redef fun nitdoc_url do return "group_{nitdoc_id}.html"
 
        redef fun tpl_namespace do
                var tpl = new Template
@@ -218,14 +217,9 @@ redef class MGroup
                end
                return tpl
        end
-
-       redef fun tpl_css_classes do return ["public"]
 end
 
 redef class MModule
-       # Is the mmodule created by nitdoc for internal purpose?
-       var is_fictive: Bool writable = false
-
        redef fun nitdoc_name do return name.html_escape
 
        redef fun nitdoc_id do
@@ -235,16 +229,7 @@ redef class MModule
                return nitdoc_name
        end
 
-       redef fun nitdoc_url do
-               var res = new FlatBuffer
-               res.append("module_")
-               var mowner = public_owner
-               if mowner != null then
-                       res.append("{public_owner.name}_")
-               end
-               res.append("{self.name}.html")
-               return res.to_s
-       end
+       redef fun nitdoc_url do return "module_{nitdoc_id}.html"
 
        redef fun tpl_declaration do
                var tpl = new Template
@@ -272,21 +257,13 @@ redef class MModule
                return tpl
        end
 
-       redef fun tpl_title do
-               var title = new Template
-               title.add tpl_icon
-               title.add tpl_namespace
-               return title
-       end
-
        redef fun tpl_css_classes do return ["public"]
 end
 
 redef class MClass
        redef fun nitdoc_name do return name.html_escape
        redef fun nitdoc_id do return "{intro_mmodule.mgroup.mproject}__{name.to_cmangle}"
-       redef fun nitdoc_url do return "class_{public_owner}_{name}.html"
-
+       redef fun nitdoc_url do return "class_{nitdoc_id}.html"
        redef fun mdoc do return intro.mdoc
 
        redef fun tpl_declaration do return intro.tpl_declaration
@@ -420,10 +397,10 @@ redef class MClassDef
                lnk.add tpl_link
                if mdoc != null then
                        lnk.add ": "
-                       lnk.add mdoc.short_comment
+                       lnk.add mdoc.short_markdown
                else if mclass.intro.mdoc != null then
                        lnk.add ": "
-                       lnk.add mclass.intro.mdoc.short_comment
+                       lnk.add mclass.intro.mdoc.short_markdown
                end
                return new TplListItem.with_content(lnk)
        end
@@ -452,7 +429,7 @@ end
 redef class MProperty
        redef fun nitdoc_name do return name.html_escape
        redef fun nitdoc_id do return "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}"
-       redef fun nitdoc_url do return "proprety_{nitdoc_id}.html"
+       redef fun nitdoc_url do return "property_{nitdoc_id}.html"
 
        redef fun mdoc do return intro.mdoc
 
@@ -505,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
 
@@ -523,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
@@ -570,16 +539,35 @@ 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_comment
+                       lnk.add mdoc.short_markdown
                else if mproperty.intro.mdoc != null then
                        lnk.add ": "
-                       lnk.add mproperty.intro.mdoc.short_comment
+                       lnk.add mproperty.intro.mdoc.short_markdown
                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
@@ -690,3 +678,39 @@ redef class MParameter
        end
 end
 
+redef class ConcernsTree
+
+       private var seen = new HashSet[MConcern]
+
+       redef fun add(p, e) do
+               if seen.has(e) then return
+               seen.add e
+               super(p, e)
+       end
+
+       fun to_tpl: TplList do
+               var lst = new TplList.with_classes(["list-unstyled", "list-definition"])
+               for r in roots do
+                       var li = r.tpl_concern_item
+                       lst.add_li li
+                       build_list(r, li)
+               end
+               return lst
+       end
+
+       private fun build_list(e: MConcern, li: TplListItem) do
+               if not sub.has_key(e) then return
+               var subs = sub[e]
+               var lst = new TplList.with_classes(["list-unstyled", "list-definition"])
+               for e2 in subs do
+                       if e2 isa MGroup and e2.is_root then
+                               build_list(e2, li)
+                       else
+                               var sli = e2.tpl_concern_item
+                               lst.add_li sli
+                               build_list(e2, sli)
+                       end
+               end
+               li.append lst
+       end
+end