# build page
init_title(v, doc)
- init_sidebar(v, doc)
init_topmenu(v, doc)
init_content(v, doc)
+ init_sidebar(v, doc)
# piwik tracking
var tracker_url = v.ctx.opt_piwik_tracker.value
# Build page sidebar if any.
fun init_sidebar(v: RenderHTMLPhase, doc: DocModel) do
- sidebar = new TplSidebar
+ sidebar = new DocSideBar
+ sidebar.boxes.add new DocSideBox("Summary", html_toc)
end
# Build page content template.
section.add_child ssection
self.add_section section
end
-
- redef fun init_sidebar(v, doc) do sidebar = new TplSidebar
end
redef class SearchPage
for mclass in sorted do
list.add_li tpl_sidebar_item(mclass)
end
- sidebar.boxes.add new TplSideBox.with_content("All classes", list)
+ sidebar.boxes.add new DocSideBox("All classes", list)
+ sidebar.boxes.last.is_open = false
end
private fun tpl_sidebar_item(def: MClass): TplListItem do
for mclass in sorted do
list.add_li tpl_sidebar_item(mclass)
end
- sidebar.boxes.add new TplSideBox.with_content("All classes", list)
+ sidebar.boxes.add new DocSideBox("All classes", list)
+ sidebar.boxes.last.is_open = false
end
private fun tpl_sidebar_item(def: MClass): TplListItem do
by_kind.sort_groups(v.name_sorter)
for g in by_kind.groups do tpl_sidebar_list(g, summary)
- sidebar.boxes.add new TplSideBox.with_content("All properties", summary)
+ sidebar.boxes.add new DocSideBox("All properties", summary)
+ sidebar.boxes.last.is_open = false
end
private fun tpl_sidebar_list(mprops: PropertyGroup[MProperty], summary: TplList) do
if mentity.is_intro and mentity.mmodule != page.mentity then
article.content = mentity.html_short_comment
end
+ if page isa MModulePage then is_toc_hidden = true
else if mentity isa MPropDef then
if page.mentity isa MClass then
title = new Template
title.add "in "
title.add mentity.mclassdef.html_link
article.title = title
- article.summary_title = "in {mentity.mclassdef.html_name}"
+ toc_title = "in {mentity.mclassdef.html_name}"
end
article.source_link = v.tpl_showsource(mentity.location)
end
# general layout elements
#########################
-# A sidebar template
-class TplSidebar
- super Template
-
- # Sidebar contains sidebar element templates called boxes
- var boxes = new Array[TplSidebarElt]
-
- # Sort boxes by order priority
- private fun order_boxes do
- var sorter = new OrderComparator
- sorter.sort(boxes)
- end
-
- redef fun rendering do
- if boxes.is_empty then return
- order_boxes
- addn "<div id='sidebar'>"
- for box in boxes do add box
- addn "</div>"
- end
-end
-
-# Comparator used to sort boxes by order
-private class OrderComparator
- super Comparator
-
- redef type COMPARED: TplSidebarElt
-
- redef fun compare(a, b) do
- if a.order < b.order then return -1
- if a.order > b.order then return 1
- return 0
- end
-end
-
-# Something that can be put in the sidebar
-class TplSidebarElt
- super Template
-
- # Order of the box in the sidebar
- var order: Int = 1
-
- init with_order(order: Int) do self.order = order
-end
-
-# Agenericbox that can be added to sidebar
-class TplSideBox
- super TplSidebarElt
-
- # Title of the box to display
- # Title is also a placeholder for the collapse link
- var title: String
-
- # Box HTML id
- # equals to `title.to_cmangle` by default
- # Used for collapsing
- var id: String is noinit
-
- # Content to display in the box
- # box will not be rendered if the content is null
- var content: nullable Writable = null is writable
-
- # Is the box opened by default
- # otherwise, the user will have to clic on the title to display the content
- var is_open = false is writable
-
- init do
- self.id = title.to_cmangle
- end
-
- init with_content(title: String, content: Writable) do
- init(title)
- self.content = content
- end
-
- redef fun rendering do
- if content == null then return
- var open = ""
- if is_open then open = "in"
- addn "<div class='panel'>"
- addn " <div class='panel-heading'>"
- add " <a data-toggle='collapse' data-parent='#sidebar' data-target='#box_{id}' href='#'>"
- add title
- addn " </a>"
- addn " </div>"
- addn " <div id='box_{id}' class='panel-body collapse {open}'>"
- add content.as(not null)
- addn " </div>"
- addn "</div>"
- end
-end
-
-# Something that can go on a summary template
-class TplSummaryElt
- super Template
-
- # Add an element to the summary
- fun add_child(child: TplSummaryElt) is abstract
-end
-
-# A summary that can go on the sidebar
-# If the page contains a sidebar, the summary is automatically placed
-# on top of the sidebarauto-generated
-# summary contains anchors to all sections displayed in the page
-class TplSummary
- super TplSidebarElt
- super TplSummaryElt
-
- # Summary elements to display
- var children = new Array[TplSummaryElt]
-
- redef fun add_child(child) do children.add child
-
- redef fun rendering do
- if children.is_empty then return
- addn "<div class='panel'>"
- addn " <div class='panel-heading'>"
- add " <a data-toggle='collapse' data-parent='#sidebar' data-target='#box-sum' href='#'>"
- add "Summary"
- addn " </a>"
- addn " </div>"
- addn " <div id='box-sum' class='summary collapse in'>"
- addn " <ul class='nav'>"
- for entry in children do add entry
- addn " </ul>"
- addn " </div>"
- addn "</div>"
- end
-end
-
-# A summary entry
-class TplSummaryEntry
- super TplSummaryElt
-
- # Text to display
- var text: Writable
-
- # Children of this entry
- # Will be displayed as a tree
- var children = new Array[TplSummaryElt]
-
- redef fun add_child(child) do children.add child
-
- redef fun rendering do
- add "<li>"
- add text
- if not children.is_empty then
- addn "\n<ul class='nav'>"
- for entry in children do add entry
- addn "</ul>"
- end
- addn "</li>"
- end
-end
-
# Something that can go in a section
# Sections are automatically collected to populate the menu
class TplSectionElt
# Is the section empty (no content at all)
fun is_empty: Bool do return children.is_empty
-
- # Render this section in the summary
- fun render_summary(parent: TplSummaryElt) do
- if is_empty then return
- var title = summary_title
- if title == null and self.title != null then title = self.title.write_to_string
- if title == null then return
- var lnk = new TplLink("#{id}", title)
- var entry = new TplSummaryEntry(lnk)
- for child in children do
- child.render_summary(entry)
- end
- parent.add_child entry
- end
end
# A HTML <section> element
self.content = content
end
- redef fun render_summary(parent) do
- if is_empty then return
- var title = summary_title
- if title == null and self.title != null then title = self.title.write_to_string
- if title == null then return
- var lnk = new TplLink("#{id}", title)
- parent.add_child new TplSummaryEntry(lnk)
- end
-
redef fun rendering do
if is_empty then return
addn "<article id='{id}' class='{css_classes.join(" ")}'>"
var topmenu: DocTopMenu is writable, noinit
# Sidebar template if any.
- var sidebar: nullable TplSidebar = null is writable
+ var sidebar: nullable DocSideBar = null is writable
# Content of the page in form a TplSection.
# TODO remove when other templates are migrated.
addn ">"
end
- # Renders the sidebar template.
- #
- # Sidebar is automatically populated with a summary of all sections
- # TODO remove summary generation when other templates are migrated.
- private fun render_sidebar do
- if sidebar == null then return
- var summary = new TplSummary.with_order(0)
- for section in sections do
- section.render_summary summary
- end
- sidebar.boxes.add summary
- add sidebar.as(not null)
- end
-
# Renders the footer and content.
private fun render_content do
for section in sections do add section
add topmenu
addn " </div>"
addn " <div class='row' id='content'>"
+ var sidebar = self.sidebar
if sidebar != null then
addn "<div class='col col-xs-3 col-lg-2'>"
- render_sidebar
+ add sidebar
addn "</div>"
addn "<div class='col col-xs-9 col-lg-10' data-spy='scroll' data-target='.summary'>"
render_content
addn "</div>"
render_footer
end
+
+ # Render table of content for this page.
+ fun html_toc: UnorderedList do
+ var lst = new UnorderedList
+ lst.css_classes.add "nav"
+ for child in root.children do
+ child.render_toc_item(lst)
+ end
+ return lst
+ end
end
# Top menu bar template.
end
end
+# Nitdoc sidebar template.
+class DocSideBar
+ super Template
+
+ # Sidebar contains `DocSideBox`.
+ var boxes = new Array[DocSideBox]
+
+ redef fun rendering do
+ if boxes.is_empty then return
+ addn "<div id='sidebar'>"
+ for box in boxes do add box
+ addn "</div>"
+ end
+end
+
+# Something that can be put in a DocSideBar.
+class DocSideBox
+ super Template
+
+ # Box HTML id, used for Bootstrap collapsing feature.
+ #
+ # Use `html_title.to_cmangle` by default.
+ var id: String is lazy do return title.write_to_string.to_cmangle
+
+ # Title of the box to display.
+ var title: Writable
+
+ # Content to display in the box.
+ var content: Writable
+
+ # Is the box opened by default?
+ #
+ # Otherwise, the user will have to clic on the title to display the content.
+ #
+ # Default is `true`.
+ var is_open = true is writable
+
+ redef fun rendering do
+ var open = ""
+ if is_open then open = "in"
+ addn "<div class='panel'>"
+ addn " <div class='panel-heading'>"
+ add " <a data-toggle='collapse' data-parent='#sidebar'"
+ add " data-target='#box_{id}' href='#'>"
+ add title
+ addn " </a>"
+ addn " </div>"
+ addn " <div id='box_{id}' class='summary panel-body collapse {open}'>"
+ add content
+ addn " </div>"
+ addn "</div>"
+ end
+end
+
redef class DocComposite
super Template
#
# By default, empty elements are hidden.
fun is_hidden: Bool do return is_empty
+
+ # A short, undecorated title that goes in the table of contents.
+ #
+ # By default, returns `html_title.to_s`, subclasses should redefine it.
+ var toc_title: String is lazy, writable do return html_title.to_s
+
+ # Is `self` hidden in the table of content?
+ var is_toc_hidden = false is writable
+
+ # Render this element in a table of contents.
+ private fun render_toc_item(lst: UnorderedList) do
+ if is_toc_hidden then return
+
+ var content = new Template
+ content.add new Link("#{html_id}", toc_title)
+
+ if not children.is_empty then
+ var sublst = new UnorderedList
+ sublst.css_classes.add "nav"
+ for child in children do
+ child.render_toc_item(sublst)
+ end
+ content.add sublst
+ end
+ lst.add_li new ListItem(content)
+ end
end
redef class DocSection
redef fun render_title do end
end
+redef class MEntityComposite
+ redef var html_id is lazy do return mentity.nitdoc_id
+ redef var html_title is lazy do return mentity.nitdoc_name
+end
+
+redef class ConcernSection
+ redef var html_id is lazy do return "section_concerns_{mentity.nitdoc_id}"
+ redef var html_title is lazy do return "in {mentity.nitdoc_name}"
+ redef fun is_toc_hidden do return is_empty
+end
+
+redef class ImportationListSection
+ redef var html_id is lazy do return "section_dependancies_{mentity.nitdoc_id}"
+ redef var html_title is lazy do return "Dependencies"
+end
+
+redef class InheritanceListSection
+ redef var html_id is lazy do return "section_inheritance_{mentity.nitdoc_id}"
+ redef var html_title is lazy do return "Inheritance"
+end
+
redef class IntroArticle
redef var html_id is lazy do return "article_intro_{mentity.nitdoc_id}"
redef var html_title is lazy do return null
redef var is_hidden = false
+ redef var is_toc_hidden = true
redef fun render_body do
var comment = mentity.html_comment
redef var html_id is lazy do return "article_concerns_{mentity.nitdoc_id}"
redef var html_title = "Concerns"
redef fun is_hidden do return concerns.is_empty
-
redef fun render_body do add concerns.html_list
end
redef var html_id is lazy do return "article_hierarchy_{list_title}_{mentity.nitdoc_id}"
redef var html_title is lazy do return list_title
redef fun is_empty do return mentities.is_empty
+ redef fun is_toc_hidden do return mentities.is_empty
redef fun render_body do
var lst = new UnorderedList
redef var html_id is lazy do return "article_intros_redefs_{mentity.nitdoc_id}"
redef var html_title is lazy do return list_title
redef fun is_hidden do return mentities.is_empty
+ redef var is_toc_hidden = true
redef fun render_body do
var lst = new UnorderedList
redef class GraphArticle
redef var html_id is lazy do return "article_graph_{mentity.nitdoc_id}"
+ redef var html_title = null
+ redef var toc_title do return "Graph"
redef var is_hidden = false
+ redef var is_toc_hidden = true
# HTML map used to display link.
#