X-Git-Url: http://nitlanguage.org diff --git a/src/doc/doc_model.nit b/src/doc/doc_model.nit index d460f07..b9d6b48 100644 --- a/src/doc/doc_model.nit +++ b/src/doc/doc_model.nit @@ -16,24 +16,10 @@ module doc_model import model_utils -import modelize_property -import markdown +import doc_down import doc_templates import ordered_tree - -redef class MDoc - # Comment synopsys HTML escaped - fun short_comment: String do return content.first.html_escape - - # Full comment HTML escaped - fun full_comment: String do return content.join("\n").html_escape - - # Synopsys in a template - fun tpl_short_comment: Streamable do return short_markdown - - # Full comment in a template - fun tpl_comment: Streamable do return full_markdown -end +import model_ext redef class Location # Github url based on this location @@ -52,10 +38,10 @@ redef class MEntity # Used as HTML unique ids fun nitdoc_id: String is abstract - # URL of this entity Nitdoc page + # URL of this entity’s 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 @@ -108,7 +94,7 @@ redef class MEntity lnk.add tpl_link if mdoc != null then lnk.add ": " - lnk.add mdoc.short_comment + lnk.add mdoc.tpl_short_comment end return new TplListItem.with_content(lnk) end @@ -138,7 +124,7 @@ redef class MConcern lnk.add tpl_anchor if mdoc != null then lnk.add ": " - lnk.add mdoc.short_comment + lnk.add mdoc.tpl_short_comment end return new TplListItem.with_content(lnk) end @@ -147,7 +133,7 @@ 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 @@ -168,6 +154,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 @@ -187,16 +174,12 @@ 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 - if mproject != null then - tpl.add mproject.tpl_namespace - else if parent != null then - tpl.add parent.tpl_namespace - end - if mproject != null and mproject.root != self then + tpl.add mproject.tpl_namespace + if mproject.root != self then tpl.add "::" tpl.add tpl_link end @@ -213,19 +196,15 @@ 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 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,21 +214,12 @@ 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 tpl.add "module " - tpl.add tpl_link + tpl.add tpl_namespace tpl.add "" return tpl end @@ -272,21 +242,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 @@ -314,7 +276,11 @@ redef class MClass var tpl = new Template if arity > 0 then tpl.add "[" - tpl.add intro.parameter_names.join(", ") + var parameter_names = new Array[String] + for p in mparameters do + parameter_names.add(p.name) + end + tpl.add parameter_names.join(", ") tpl.add "]" end return tpl @@ -376,12 +342,13 @@ redef class MClassDef fun tpl_signature: Template do var tpl = new Template - if not parameter_names.is_empty then + var mparameters = mclass.mparameters + if not mparameters.is_empty then tpl.add "[" - for i in [0..parameter_names.length[ do - tpl.add "{parameter_names[i]}: " + for i in [0..mparameters.length[ do + tpl.add "{mparameters[i].name}: " tpl.add bound_mtype.arguments[i].tpl_signature - if i < parameter_names.length - 1 then tpl.add ", " + if i < mparameters.length - 1 then tpl.add ", " end tpl.add "]" end @@ -420,10 +387,10 @@ redef class MClassDef lnk.add tpl_link if mdoc != null then lnk.add ": " - lnk.add mdoc.short_comment + lnk.add mdoc.tpl_short_comment else if mclass.intro.mdoc != null then lnk.add ": " - lnk.add mclass.intro.mdoc.short_comment + lnk.add mclass.intro.mdoc.tpl_short_comment end return new TplListItem.with_content(lnk) end @@ -452,7 +419,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 +472,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 +490,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 +529,46 @@ 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.tpl_short_comment else if mproperty.intro.mdoc != null then lnk.add ": " - lnk.add mproperty.intro.mdoc.short_comment + lnk.add mproperty.intro.mdoc.tpl_short_comment 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.tpl_short_comment + end + var li = new TplListItem.with_content(lnk) + li.css_classes.add "signature" + return li + end +end + +redef class MAttributeDef + redef fun tpl_signature do + var tpl = new Template + if static_mtype != null then + tpl.add ": " + tpl.add static_mtype.tpl_signature + end + return tpl + end end redef class MMethod @@ -616,6 +605,28 @@ redef class MVirtualTypeDef end end +redef class MInnerClass + redef fun nitdoc_url do return inner.nitdoc_url + redef fun tpl_signature do return inner.tpl_signature +end + +redef class MInnerClassDef + redef fun nitdoc_url do return inner.nitdoc_url + + redef fun tpl_anchor do return inner.tpl_anchor + redef fun tpl_link do return inner.tpl_link + redef fun tpl_signature do return inner.tpl_signature + + redef fun tpl_definition do + var tpl = new TplClassDefinition + tpl.namespace = mclassdef.tpl_namespace + if mdoc != null then + tpl.comment = mdoc.tpl_comment + end + return tpl + end +end + redef class MType fun tpl_signature: Template is abstract end @@ -650,7 +661,6 @@ end redef class MParameterType redef fun tpl_link do - var name = mclass.intro.parameter_names[rank] return new TplLink.with_title("{mclass.nitdoc_url}#FT_{name}", name, "formal type") end redef fun tpl_signature do return tpl_link @@ -726,3 +736,22 @@ redef class ConcernsTree li.append lst end end + + +################################################################################ +# Additions to `model_ext`. + +redef class MRawType + redef fun tpl_signature do + var tpl = new Template + + for part in parts do + if part.target != null then + tpl.add part.target.as(not null).tpl_link + else + tpl.add part.text.html_escape + end + end + return tpl + end +end