1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Introduces templates that compose the documentation HTML rendering.
19 import html
::bootstrap
21 # Renders the page as HTML.
26 var html_url
: String is writable, noinit
28 # Directory where css, js and other assets can be found.
29 var shareurl
: String is writable, noinit
31 # Attributes of the body tag element.
32 var body_attrs
= new Array[TagAttribute]
34 # Top menu template if any.
35 var topmenu
: DocTopMenu is writable, noinit
37 # Sidebar template if any.
38 var sidebar
: nullable TplSidebar = null is writable
40 # Content of the page in form a TplSection.
41 # TODO remove when other templates are migrated.
42 var sections
= new Array[TplSection]
44 # Footer content if any.
45 var footer
: nullable Writable = null is writable
47 # JS scripts to append at the end of the body
48 var scripts
= new Array[TplScript]
50 # Adds a section to this page.
51 # TODO remove when other templates are migrated.
52 fun add_section
(section
: TplSection) do
56 # Renders the html `<head>`.
57 private fun render_head
do
58 var css
= (self.shareurl
/ "css").html_escape
59 var vendors
= (self.shareurl
/ "vendors").html_escape
61 addn
"<!DOCTYPE html>"
63 addn
" <meta charset='utf-8'/>"
64 addn
" <!--link rel='stylesheet' href='{css}/Nitdoc.UI.css' type='text/css'/-->"
65 addn
" <link rel='stylesheet' href='{vendors}/bootstrap/css/bootstrap.min.css'/>"
66 addn
" <link rel='stylesheet' href='{css}/nitdoc.bootstrap.css'/>"
67 addn
" <link rel='stylesheet' href='{css}/nitdoc.css'/>"
68 addn
" <link rel='stylesheet' href='{css}/Nitdoc.QuickSearch.css'/>"
69 addn
" <link rel='stylesheet' href='{css}/Nitdoc.ModalBox.css'/>"
70 addn
" <link rel='stylesheet' href='{css}/Nitdoc.GitHub.css'/>"
71 addn
" <title>{title.html_escape}</title>"
74 for attr
in body_attrs
do add attr
78 # Renders the sidebar template.
80 # Sidebar is automatically populated with a summary of all sections
81 # TODO remove summary generation when other templates are migrated.
82 private fun render_sidebar
do
83 if sidebar
== null then return
84 var summary
= new TplSummary.with_order
(0)
85 for section
in sections
do
86 section
.render_summary summary
88 sidebar
.boxes
.add summary
89 add sidebar
.as(not null)
92 # Renders the footer and content.
93 private fun render_content
do
94 for section
in sections
do add section
95 if footer
!= null then
96 addn
"<div class='well footer'>"
97 add footer
.as(not null)
103 private fun render_footer
do
104 var vendors
= (self.shareurl
/ "vendors").html_escape
105 var js
= (self.shareurl
/ "js").html_escape
107 addn
"<script src='{vendors}/jquery/jquery-1.11.1.min.js'></script>"
108 addn
"<script src='{vendors}/jquery/jquery-ui-1.10.4.custom.min.js'></script>"
109 addn
"<script src='{vendors}/bootstrap/js/bootstrap.min.js'></script>"
110 addn
"<script data-main='{js}/nitdoc' src='{js}/lib/require.js'></script>"
111 for script
in scripts
do add script
114 $("[data-toggle='tooltip']").tooltip();
115 $("[data-toggle='popover']").popover();
122 # Render the whole page
123 redef fun rendering
do
125 addn
"<div class='container-fluid'>"
126 addn
" <div class='row'>"
129 addn
" <div class='row' id='content'>"
130 if sidebar
!= null then
131 addn
"<div class='col col-xs-3 col-lg-2'>"
134 addn
"<div class='col col-xs-9 col-lg-10' data-spy='scroll' data-target='.summary'>"
138 addn
"<div class='col col-xs-12'>"
148 # Top menu bar template.
150 # FIXME should be a Bootstrap component template
151 # At this moment, the topmenu structure stills to specific to Nitdoc to use the
156 # Brand link to display in first position of the top menu.
158 # This is where you want to put your logo.
159 var brand
: nullable Writable is noinit
, writable
163 # Depends on the current page, this allows to hilighted the current item.
165 # FIXME should be using Boostrap breadcrumbs component.
166 # This will still like this to avoid diff and be changed in further fixes
167 # when we will modify the output.
168 var active_item
: nullable ListItem is noinit
, writable
170 redef fun rendering
do
171 addn
"<nav id='topmenu' class='navbar navbar-default navbar-fixed-top' role='navigation'>"
172 addn
" <div class='container-fluid'>"
173 addn
" <div class='navbar-header'>"
174 add
" <button type='button' class='navbar-toggle' "
175 addn
" data-toggle='collapse' data-target='#topmenu-collapse'>"
176 addn
" <span class='sr-only'>Toggle menu</span>"
177 addn
" <span class='icon-bar'></span>"
178 addn
" <span class='icon-bar'></span>"
179 addn
" <span class='icon-bar'></span>"
181 if brand
!= null then
182 add
"<span class='navbar-brand'>"
183 add brand
.write_to_string
187 addn
" <div class='collapse navbar-collapse' id='topmenu-collapse'>"
188 addn
" <ul class='nav navbar-nav'>"
190 if item
== active_item
then item
.css_classes
.add
"active"
191 add item
.write_to_string