Merge: Fallback doc
authorJean Privat <jean@pryen.org>
Thu, 4 Dec 2014 03:29:15 +0000 (22:29 -0500)
committerJean Privat <jean@pryen.org>
Thu, 4 Dec 2014 03:29:15 +0000 (22:29 -0500)
In order to fill the descriptions on the [overview page], add a way for a mproject or a mgroup to use the mdoc of other entities.

  [overview page]: http://nitlanguage.org/doc/stdlib/

Pull-Request: #954
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/doc_model.nit
src/model/mdoc.nit
src/model/mmodule.nit
src/model/mproject.nit

index 4523ec3..9794beb 100644 (file)
@@ -172,6 +172,7 @@ redef class MProject
 
        redef fun tpl_definition do
                var tpl = new TplDefinition
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        tpl.comment = mdoc.tpl_comment
                end
@@ -213,6 +214,7 @@ redef class MGroup
 
        redef fun tpl_definition do
                var tpl = new TplDefinition
+               var mdoc = mdoc_or_fallback
                if mdoc != null then
                        tpl.comment = mdoc.tpl_comment
                end
index abc733a..2f8d045 100644 (file)
@@ -33,6 +33,16 @@ redef class MEntity
        # The documentation associated to the entity
        var mdoc: nullable MDoc is writable
 
+       # The documentation associated to the entity or their main nested entity.
+       #
+       # MProject fall-back to their root MGroup
+       # MGroup fall-back to their default_mmodule
+       # Other entities do not fall-back
+       #
+       # One may use `MDoc::original_mentity` to retrieve the original
+       # source of the documentation.
+       fun mdoc_or_fallback: nullable MDoc do return mdoc
+
        # Is the entity deprecated?
        #
        # Used for warnings and in documentation.
index f2c11a6..a92d065 100644 (file)
@@ -63,6 +63,13 @@ redef class MGroup
        # Return `null` if the group has no default module or if the default
        # module is not loaded.
        var default_mmodule: nullable MModule = null
+
+       redef fun mdoc_or_fallback
+       do
+               if mdoc != null then return mdoc
+               if default_mmodule == null then return null
+               return default_mmodule.mdoc_or_fallback
+       end
 end
 
 # A Nit module is usually associated with a Nit source file.
index c23e5cb..b89eced 100644 (file)
@@ -18,6 +18,7 @@ module mproject
 import model_base
 private import more_collections
 import poset
+import mdoc
 
 # A Nit project, that encompass a product
 class MProject
@@ -45,6 +46,12 @@ class MProject
 
        # MProject are always roots of the concerns hierarchy
        redef fun parent_concern do return null
+
+       redef fun mdoc_or_fallback
+       do
+               if mdoc != null then return mdoc
+               return root.mdoc_or_fallback
+       end
 end
 
 # A group of modules in a project