- # 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
- super Template
-
- # HTML anchor id
- var id: String
-
- # Title to display if any
- # if both `title` and `summary_title` are null then
- # the section will not appear in the summary
- var title: nullable Writable = null is writable
-
- # Subtitle to display if any
- var subtitle: nullable Writable = null is writable
-
- # Title that appear in the summary
- # if null use `title` instead
- var summary_title: nullable String = null is writable
-
- # CSS classes to apply on the section element
- var css_classes = new Array[String]
-
- # CSS classes to apply on the title heading element
- var title_classes = new Array[String]
-
- # Parent article/section if any
- var parent: nullable TplSectionElt = null
-
- init with_title(id: String, title: Writable) do
- init(id)
- self.title = title
- end
-
- # Level <hX> for HTML heading
- protected fun hlvl: Int do
- if parent == null then return 1
- return parent.hlvl + 1
- end
-
- # Elements contained by this section
- var children = new Array[TplSectionElt]
-
- # Add an element in this section
- fun add_child(child: TplSectionElt) do
- child.parent = self
- children.add child
- end