Merge: concurrent_collections: Add implementation of has method
[nit.git] / contrib / nitrpg / src / templates / templates.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014-2015 Alexandre Terrasa <alexandre@moz-code.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Templates that compose the `nitrpg` site.
18 module templates
19
20 import panels
21
22 # A page in the nitrp site.
23 class NitRpgPage
24 super Template
25
26 # URL used as prefix for all the links generated in this page.
27 var root_url: String
28
29 # Breadcrumbs to this page if any.
30 var breadcrumbs: nullable Breadcrumbs = null is public writable
31
32 # Panels to display in the sidebar.
33 var side_panels = new Array[Panel]
34
35 # Panels to display in the page main container.
36 var flow_panels = new Array[Panel]
37
38 redef fun rendering do
39 render_header
40 render_footer
41 end
42
43 # Render the header shared by all pages.
44 fun render_header do
45 add """
46 <!DOCTYPE html>
47 <html>
48 <head>
49 <meta charset="UTF-8">
50 <title>Github RPG</title>
51 <link rel="stylesheet"
52 href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
53 <link rel="stylesheet" href="{{{root_url}}}/styles/main.css">
54 </head>
55 <body>
56 <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
57 <a class="navbar-brand" href="{{{root_url}}}/">Github RPG</a>"""
58 if not breadcrumbs == null then
59 add breadcrumbs.as(not null)
60 end
61 add """
62 </nav>
63 <div class="container-fluid">
64 <div class="row">"""
65 if not side_panels.is_empty then
66 add """<div class="col-xs-3" id="side">"""
67 for panel in side_panels do add panel
68 add """</div>
69 <div class="col-xs-9" id="flow">"""
70 else
71 add """<div class="col-xs-12" id="flow">"""
72 end
73 for panel in flow_panels do add panel
74 add """ </div>
75 </div>
76 </div>
77 """
78 end
79
80 # Render the footer shared by all pages.
81 fun render_footer do
82 add """
83 <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
84 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
85 </body>
86 </html>
87 """
88 end
89 end
90
91 # A Bootstrap breadcrumbs component.
92 class Breadcrumbs
93 super Template
94
95 # Items to display in this breadcrumb.
96 var entries = new Array[String]
97
98 redef fun rendering do
99 add "<ol class=\"breadcrumb\">"
100 for entry in entries do
101 add "<li>{entry}</li>"
102 end
103 add "</ol>"
104 end
105
106 # Add a link to the breadcrumbs.
107 fun add_link(href, name: String) do
108 entries.add "<a href=\"{href}\">{name}</a>"
109 end
110 end