end
if page isa MModulePage then is_toc_hidden = true
else if mentity isa MPropDef then
- if page isa MEntityPage and page.mentity isa MClass then
+ if page isa MClassPage then
var title = new Template
title.add mentity.html_icon
title.add mentity.html_declaration
html_title = title
html_subtitle = mentity.html_namespace
toc_title = mentity.html_name
- # TODO move in its own phase? let's see after doc_template refactoring.
- # Add linearization
- var all_defs = new HashSet[MPropDef]
- for local_def in local_defs(page.as(MClassPage), mentity.mproperty) do
- all_defs.add local_def
- var smpropdef = local_def
- while not smpropdef.is_intro do
- smpropdef = smpropdef.lookup_next_definition(
- doc.mainmodule, smpropdef.mclassdef.bound_mtype)
- all_defs.add smpropdef
- end
- end
- var lin = all_defs.to_a
- doc.mainmodule.linearize_mpropdefs(lin)
- if lin.length > 1 then
- var lin_article = new DocArticle
- lin_article.html_id = "{mentity.nitdoc_id}.lin"
- lin_article.html_title = "Inheritance"
- lin_article.is_toc_hidden = true
- var lst = new UnorderedList
- lst.css_classes.add("list-unstyled list-labeled")
- for smpropdef in lin do
- lst.add_li tpl_inheritance_item(smpropdef)
- end
- # FIXME will be moved in its own phase
- lin_article.add lst
- add_child lin_article
- end
else
var title = new Template
title.add "in "
end
super
end
-
- # Filter `page.mpropdefs` for this `mpropertie`.
- #
- # FIXME compatability with current templates.
- private fun local_defs(page: MClassPage, mproperty: MProperty): HashSet[MPropDef] do
- var mpropdefs = new HashSet[MPropDef]
- for mpropdef in page.mpropdefs do
- if mpropdef.mproperty == mproperty then
- mpropdefs.add mpropdef
- end
- end
- return mpropdefs
- end
-
- private fun tpl_inheritance_item(mpropdef: MPropDef): ListItem do
- var lnk = new Template
- lnk.add new TplLabel.with_classes(css_classes)
- lnk.add mpropdef.mclassdef.mmodule.html_namespace
- lnk.add "::"
- var atext = mpropdef.mclassdef.html_link.text
- var ahref = "{mpropdef.mclassdef.mclass.nitdoc_url}#{mpropdef.mproperty.nitdoc_id}"
- var atitle = mpropdef.mclassdef.html_link.title
- var anchor = new Link.with_title(ahref, atext, atitle)
- lnk.add anchor
- var comment = mpropdef.html_short_comment
- if comment != null then
- lnk.add ": "
- lnk.add comment
- end
- var li = new ListItem(lnk)
- li.css_classes.add "signature"
- return li
- end
end
redef class HomeArticle
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Add linearization lists to DefinitionArticle found in MClass pages.
+module doc_lin
+
+import doc_structure
+
+# LinPhase populates the DocPage content with linearization data.
+class LinListPhase
+ super DocPhase
+
+ # Used to sort list by linearization order
+ private var lin_sorter = new MEntityNameSorter
+
+ redef fun apply do
+ for page in doc.pages do page.apply_linearization(self, doc)
+ end
+end
+
+redef class DocPage
+
+ # Populates `self` with linearization data.
+ #
+ # See `LinListPhase`.
+ fun apply_linearization(v: LinListPhase, doc: DocModel) do end
+end
+
+redef class MClassPage
+ redef fun apply_linearization(v, doc) do
+ root.apply_linearization(v, doc, self)
+ end
+end
+
+redef class DocComposite
+
+ # Populates `self` with linearization data.
+ #
+ # For now, it's only used for mpropdefs linearization in MClassPage.
+ #
+ # See `LinListPhase`.
+ private fun apply_linearization(v: LinListPhase, doc: DocModel, page: DocPage) do
+ for child in children do child.apply_linearization(v, doc, page)
+ end
+end
+
+redef class DefinitionArticle
+ redef fun apply_linearization(v, doc, page) do
+ var mentity = self.mentity
+ if not mentity isa MPropDef then return
+ # Add linearization
+ var all_defs = new HashSet[MPropDef]
+ for local_def in local_defs(page.as(MClassPage), mentity.mproperty) do
+ all_defs.add local_def
+ var smpropdef = local_def
+ while not smpropdef.is_intro do
+ smpropdef = smpropdef.lookup_next_definition(
+ doc.mainmodule, smpropdef.mclassdef.bound_mtype)
+ all_defs.add smpropdef
+ end
+ end
+ var lin = all_defs.to_a
+ doc.mainmodule.linearize_mpropdefs(lin)
+ if lin.length > 1 then
+ add_child new DefinitionLinArticle(mentity, lin)
+ end
+ end
+
+ # Filter `page.mpropdefs` for this `mpropertie`.
+ #
+ # FIXME compatability with current templates.
+ private fun local_defs(page: MClassPage, mproperty: MProperty): HashSet[MPropDef] do
+ var mpropdefs = new HashSet[MPropDef]
+ for mpropdef in page.mpropdefs do
+ if mpropdef.mproperty == mproperty then
+ mpropdefs.add mpropdef
+ end
+ end
+ return mpropdefs
+ end
+end
+
+# Display a linearized list of definitions.
+class DefinitionLinArticle
+ super MEntityArticle
+
+ # The linearized list to display.
+ var mentities: Array[MEntity]
+end
import doc_phases::doc_hierarchies
import doc_phases::doc_graphs
import doc_phases::doc_intros_redefs
+import doc_phases::doc_lin
# Renders the page as HTML.
redef class DocPage
end
end
+redef class DefinitionLinArticle
+ redef var html_id is lazy do return "article_lin_{mentity.nitdoc_id}"
+ redef var html_title is lazy do return "Linearization"
+ redef fun is_hidden do return mentities.is_empty
+ redef var is_toc_hidden = true
+
+ redef fun render_body do
+ var lst = new UnorderedList
+ lst.css_classes.add "list-unstyled list-labeled"
+ for mentity in mentities do
+ if not mentity isa MPropDef then continue # TODO handle all mentities
+ var tpl = new Template
+ tpl.add mentity.mclassdef.html_namespace
+ var comment = mentity.mclassdef.html_short_comment
+ if comment != null then
+ tpl.add ": "
+ tpl.add comment
+ end
+ var li = new ListItem(tpl)
+ li.css_classes.add "signature"
+ lst.add_li li
+ end
+ add lst
+ end
+end
+
redef class GraphArticle
redef var html_id is lazy do return "article_graph_{mentity.nitdoc_id}"
redef var html_title = null
new StructurePhase(toolcontext, doc),
new InheritanceListsPhase(toolcontext, doc),
new IntroRedefListPhase(toolcontext, doc),
+ new LinListPhase(toolcontext, doc),
new GraphPhase(toolcontext, doc),
new RenderHTMLPhase(toolcontext, doc): DocPhase]