src/doc/doc_down: move base MDoc services to `mdoc` module
[nit.git] / src / model / mpackage.nit
index 8309b5a..1cdde49 100644 (file)
@@ -25,14 +25,14 @@ class MPackage
        super MConcern
 
        # The name of the package
-       redef var name: String
+       redef var name
 
        redef fun full_name do return name
 
        redef var c_name = name.to_cmangle is lazy
 
        # The model of the package
-       redef var model: Model
+       redef var model
 
        redef var location
 
@@ -55,8 +55,57 @@ class MPackage
 
        redef fun mdoc_or_fallback
        do
+               var mdoc = self.mdoc
                if mdoc != null then return mdoc
-               return root.mdoc_or_fallback
+               var root = self.root
+               if root != null then return root.mdoc_or_fallback
+               return null
+       end
+
+       # Does `self` have a source file?
+       fun has_source: Bool do return location.file != null
+
+       # The path to `self`
+       fun package_path: nullable String do
+               if not has_source then return null
+               return location.file.as(not null).filename
+       end
+
+       # Is `self` in its own directory?
+       fun is_expanded: Bool do
+               var path = package_path
+               if path == null then return false
+               return not path.has_suffix(".nit")
+       end
+
+       # The path to `self` ini file
+       fun ini_path: nullable String do
+               var path = package_path
+               if path == null then return null
+               if is_expanded then return path / "package.ini"
+               return path.dirname / "{name}.ini"
+       end
+
+       # Does `self` have a ini file?
+       fun has_ini: Bool do
+               var ini_path = self.ini_path
+               if ini_path == null then return false
+               return ini_path.file_exists
+       end
+
+       # The path to `self` README.md
+       fun readme_path: nullable String do
+               var path = package_path
+               if path == null then return null
+               if not is_expanded then return null
+               return path / "README.md"
+       end
+
+       # Does `self` have a README.md file?
+       fun has_readme: Bool do
+               var readme_path = self.readme_path
+               if readme_path == null then return false
+               return readme_path.file_exists
        end
 end
 
@@ -66,7 +115,7 @@ class MGroup
 
        # The name of the group
        # empty name for a default group in a single-module package
-       redef var name: String
+       redef var name
 
        redef var location