tests: add base_with.nit
[nit.git] / src / doc / html_templates / html_templates.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # Introduces templates that compose the documentation HTML rendering.
16 module html_templates
17
18 import html_model
19
20 # Renders the page as HTML.
21 redef class DocPage
22 super Template
23
24 # Page url.
25 var html_url: String is writable, noinit
26
27 # Directory where css, js and other assets can be found.
28 var shareurl: String is writable, noinit
29
30 # Attributes of the body tag element.
31 var body_attrs = new Array[TagAttribute]
32
33 # Top menu template if any.
34 var topmenu: TplTopMenu is writable, noinit
35
36 # Sidebar template if any.
37 var sidebar: nullable TplSidebar = null is writable
38
39 # Content of the page in form a TplSection.
40 # TODO remove when other templates are migrated.
41 var sections = new Array[TplSection]
42
43 # Footer content if any.
44 var footer: nullable Writable = null is writable
45
46 # JS scripts to append at the end of the body
47 var scripts = new Array[TplScript]
48
49 # Adds a section to this page.
50 # TODO remove when other templates are migrated.
51 fun add_section(section: TplSection) do
52 sections.add section
53 end
54
55 # Renders the html `<head>`.
56 private fun render_head do
57 var css = (self.shareurl / "css").html_escape
58 var vendors = (self.shareurl / "vendors").html_escape
59
60 addn "<!DOCTYPE html>"
61 addn "<head>"
62 addn " <meta charset='utf-8'/>"
63 addn " <!--link rel='stylesheet' href='{css}/Nitdoc.UI.css' type='text/css'/-->"
64 addn " <link rel='stylesheet' href='{vendors}/bootstrap/css/bootstrap.min.css'/>"
65 addn " <link rel='stylesheet' href='{css}/nitdoc.bootstrap.css'/>"
66 addn " <link rel='stylesheet' href='{css}/nitdoc.css'/>"
67 addn " <link rel='stylesheet' href='{css}/Nitdoc.QuickSearch.css'/>"
68 addn " <link rel='stylesheet' href='{css}/Nitdoc.ModalBox.css'/>"
69 addn " <link rel='stylesheet' href='{css}/Nitdoc.GitHub.css'/>"
70 addn " <title>{title.html_escape}</title>"
71 addn "</head>"
72 add "<body"
73 for attr in body_attrs do add attr
74 addn ">"
75 end
76
77 # Renders the topmenu template.
78 private fun render_topmenu do
79 addn " <div class='row'>"
80 add topmenu
81 addn " </div>"
82 end
83
84 # Renders the sidebar template.
85 #
86 # Sidebar is automatically populated with a summary of all sections
87 # TODO remove summary generation when other templates are migrated.
88 private fun render_sidebar do
89 if sidebar == null then return
90 var summary = new TplSummary.with_order(0)
91 for section in sections do
92 section.render_summary summary
93 end
94 sidebar.boxes.add summary
95 add sidebar.as(not null)
96 end
97
98 # Renders the footer and content.
99 private fun render_content do
100 for section in sections do add section
101 if footer != null then
102 addn "<div class='well footer'>"
103 add footer.as(not null)
104 addn "</div>"
105 end
106 end
107
108 # Render JS scripts
109 private fun render_footer do
110 var vendors = (self.shareurl / "vendors").html_escape
111 var js = (self.shareurl / "js").html_escape
112
113 addn "<script src='{vendors}/jquery/jquery-1.11.1.min.js'></script>"
114 addn "<script src='{vendors}/jquery/jquery-ui-1.10.4.custom.min.js'></script>"
115 addn "<script src='{vendors}/bootstrap/js/bootstrap.min.js'></script>"
116 addn "<script data-main='{js}/nitdoc' src='{js}/lib/require.js'></script>"
117 for script in scripts do add script
118 addn """<script>
119 $(function () {
120 $("[data-toggle='tooltip']").tooltip();
121 $("[data-toggle='popover']").popover();
122 });
123 </script>"""
124 addn "</body>"
125 addn "</html>"
126 end
127
128 # Render the whole page
129 redef fun rendering do
130 render_head
131 addn "<div class='container-fluid'>"
132 render_topmenu
133 addn " <div class='row' id='content'>"
134 if sidebar != null then
135 addn "<div class='col col-xs-3 col-lg-2'>"
136 render_sidebar
137 addn "</div>"
138 addn "<div class='col col-xs-9 col-lg-10' data-spy='scroll' data-target='.summary'>"
139 render_content
140 addn "</div>"
141 else
142 addn "<div class='col col-xs-12'>"
143 render_content
144 addn "</div>"
145 end
146 addn " </div>"
147 addn "</div>"
148 render_footer
149 end
150 end