# 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. # Introduces templates that compose the documentation HTML rendering. module html_templates import html_model import html::bootstrap # Renders the page as HTML. redef class DocPage super Template # Page url. var html_url: String is writable, noinit # Directory where css, js and other assets can be found. var shareurl: String is writable, noinit # Attributes of the body tag element. var body_attrs = new Array[TagAttribute] # Top menu template if any. var topmenu: DocTopMenu is writable, noinit # Sidebar template if any. var sidebar: nullable TplSidebar = null is writable # Content of the page in form a TplSection. # TODO remove when other templates are migrated. var sections = new Array[TplSection] # Footer content if any. var footer: nullable Writable = null is writable # JS scripts to append at the end of the body var scripts = new Array[TplScript] # Adds a section to this page. # TODO remove when other templates are migrated. fun add_section(section: TplSection) do sections.add section end # Renders the html ``. private fun render_head do var css = (self.shareurl / "css").html_escape var vendors = (self.shareurl / "vendors").html_escape addn "" addn "" addn " " addn " " addn " " addn " " addn " " addn " " addn " " addn " " addn " {title.html_escape}" addn "" add "" 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 if footer != null then addn "" end end # Render JS scripts private fun render_footer do var vendors = (self.shareurl / "vendors").html_escape var js = (self.shareurl / "js").html_escape addn "" addn "" addn "" addn "" for script in scripts do add script addn """""" addn "" addn "" end # Render the whole page redef fun rendering do render_head addn "
" addn "
" add topmenu addn "
" addn "
" if sidebar != null then addn "
" render_sidebar addn "
" addn "
" render_content addn "
" else addn "
" render_content addn "
" end addn "
" addn "
" render_footer end end # Top menu bar template. # # FIXME should be a Bootstrap component template # At this moment, the topmenu structure stills to specific to Nitdoc to use the # generic component. class DocTopMenu super UnorderedList # Brand link to display in first position of the top menu. # # This is where you want to put your logo. var brand: nullable Writable is noinit, writable # Active menu item. # # Depends on the current page, this allows to hilighted the current item. # # FIXME should be using Boostrap breadcrumbs component. # This will still like this to avoid diff and be changed in further fixes # when we will modify the output. var active_item: nullable ListItem is noinit, writable redef fun rendering do addn "" end end