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 # HTML templates used by Nitdoc to generate API documentation
16 # Pages are assembled using `Template`
21 # Full Nitdoc page template
25 var head
: TplHead writable
26 var body_attrs
= new Array[TagAttribute] # attributes for body tag element
27 var topmenu
: TplTopMenu writable
28 var sidebar
: nullable TplSidebar writable
29 var content
: Streamable writable
30 var footer
: nullable TplFooter writable
31 var scripts
= new Array[TplScript] # js scripts appended to body
34 redef fun rendering
do
40 for attr
in body_attrs
do add attr
43 if footer
!= null then
44 add
"<div class='page footed'>"
46 add
"<div class='page'>"
48 if sidebar
!= null then
49 add sidebar
.as(not null)
53 if footer
!= null then
54 add footer
.as(not null)
56 for script
in scripts
do
64 # general layout elements
73 init(title
, shareurl
: String) do
75 self.shareurl
= shareurl
78 redef fun rendering
do
80 <meta charset="utf-8"/>
81 <link rel="stylesheet" href="{{{shareurl}}}/css/main.css" type="text/css"/>
82 <link rel="stylesheet" href="{{{shareurl}}}/css/Nitdoc.UI.css" type="text/css"/>
83 <link rel="stylesheet" href="{{{shareurl}}}/css/Nitdoc.QuickSearch.css" type="text/css"/>
84 <link rel="stylesheet" href="{{{shareurl}}}/css/Nitdoc.GitHub.css" type="text/css"/>
85 <link rel="stylesheet" href="{{{shareurl}}}/css/Nitdoc.ModalBox.css" type="text/css"/>
86 <title>{{{title}}}</title>"""
94 private var elts
= new Array[Streamable]
96 redef fun rendering
do
98 add
"<nav class='main'>"
99 if not elts
.is_empty
then
101 for elt
in elts
do add
(elt
)
108 fun add_elt
(href
, name
: String, is_active
: Bool) do
109 elts
.add
(new TplTopMenuElt(href
, name
, is_active
))
112 fun add_raw
(content
: Streamable) do
118 private class TplTopMenuElt
125 init(href
, name
: String, is_active
: Bool) do
128 self.is_active
= is_active
131 redef fun rendering
do
133 add
"""<li class="current">{{{name}}}</li>"""
135 add
"""<li><a href="{{{href}}}">{{{name}}}</a></li>"""
144 var content
: Streamable writable
146 init(content
: Streamable) do self.content
= content
148 redef fun rendering
do
161 var boxes
= new Array[TplSidebarBox]
163 redef fun rendering
do
164 add
""""<div class="sidebar">"""
165 for box
in boxes
do add box
170 # A box that can be added to sidebar
175 var elts
= new Array[TplSidebarGroup]
177 init(name
: String) do self.name
= name
179 redef fun rendering
do
180 add
"""<nav class"properties filterable">"""
181 add
""" <h3>{{{name}}}</h3>"""
182 for elt
in elts
do add elt
187 # A sidebar box group
188 class TplSidebarGroup
192 private var elts
= new Array[Template]
194 init(name
: String) do self.name
= name
196 redef fun rendering
do
197 if elts
.is_empty
then return
198 add
"<h4>{name}</h4>"
200 for elt
in elts
do add elt
204 fun add_elt
(content
: Streamable, classes
: Array[Streamable]) do
205 var tpl
= new Template
206 tpl
.add
"<li {classes.join(" ")}>"
212 fun add_bullet
(text
, title
, content
: Streamable, classes
: Array[Streamable]) do
213 var tpl
= new Template
214 tpl
.add
"<span title='{title}'>{text}</span>"
216 add_elt
(tpl
, classes
)
222 # Layout for Overview page
223 class TplOverviewPage
226 var title
: nullable Streamable writable
227 var text
: nullable Streamable writable
228 var graph
: nullable TplGraph writable
229 var modules
= new Array[Streamable]
232 redef fun rendering
do
233 add
"<div class='content fullpage'>"
234 if title
!= null then add
"<h1>{title}</h1>"
235 if text
!= null then add
"<article class='overview'>{text}</article>"
237 if not modules
.is_empty
then
238 add
"<article class='overview'>"
239 add
"<h2>Modules</h2>"
248 if not graph
== null then add graph
.as(not null)
254 # Layout for Search page
258 var title
: nullable Streamable writable
259 var modules
= new Array[Streamable]
260 var classes
= new Array[Streamable]
261 var props
= new Array[Streamable]
264 redef fun rendering
do
265 add
"<div class='content fullpage'>"
266 if title
!= null then add
"<h1>{title}</h1>"
267 if not modules
.is_empty
then
268 add
"<article class='modules filterable'>"
269 add
"<h2>Modules</h2>"
279 if not classes
.is_empty
then
280 add
"<article class='classes filterable'>"
281 add
"<h2>Classes</h2>"
291 if not props
.is_empty
then
292 add
"<article class='properties filterable'>"
293 add
"<h2>Properties</h2>"
307 # Layout for Module page
311 var title
: nullable Streamable writable
312 var subtitle
: nullable Streamable writable
313 var definition
: nullable TplDefinition writable
314 var graph
: nullable TplGraph writable
315 var intros
= new Array[TplArticle]
316 var redefs
= new Array[TplArticle]
319 redef fun rendering
do
320 add
"<div class='content'>"
321 if title
!= null then
323 add title
.as(not null)
326 if subtitle
!= null then
327 add
"<div class='subtitle info'>"
328 add subtitle
.as(not null)
331 if definition
!= null then add definition
.as(not null)
332 if graph
!= null then add graph
.as(not null)
333 if not intros
.is_empty
then
334 add
"<section class='classes'>"
335 add
"<h2 class='section-header'>Introduced classes</h2>"
336 for intro
in intros
do add intro
339 if not redefs
.is_empty
then
340 add
"<section class='classes'>"
341 add
"<h2 class='section-header'>Refined classes</h2>"
342 for rdef
in redefs
do add rdef
349 # Layout for Class page
353 var title
: nullable Streamable writable
354 var subtitle
: nullable Streamable writable
355 var definition
: nullable TplDefinition writable
356 var graph
: nullable TplGraph writable
357 var concerns
: nullable TplConcernList writable
358 var types
= new Array[TplArticle]
359 var inits
= new Array[TplArticle]
360 var methods
= new Array[Streamable]
364 redef fun rendering
do
365 add
"<div class='content'>"
366 if title
!= null then
368 add title
.as(not null)
371 if subtitle
!= null then
372 add
"<div class='subtitle info'>"
373 add subtitle
.as(not null)
376 if definition
!= null then add definition
.as(not null)
377 if graph
!= null then add graph
.as(not null)
379 if concerns
!= null then
380 add
"<section class='concerns'>"
381 add
"<h2 class='section-header'>Concerns</h2>"
382 add concerns
.as(not null)
385 if not types
.is_empty
then
386 add
"<section class='types'>"
387 add
"<h2>Virtual Types</h2>"
388 for t
in types
do add t
391 if not inits
.is_empty
then
392 add
"<section class='constructors'>"
393 add
"<h2>Constructors</h2>"
394 for i
in inits
do add i
397 if not methods
.is_empty
then
398 add
"<section class='methods'>"
399 add
"<h2>Methods</h2>"
400 for m
in methods
do add m
409 # A HTML tag attribute
410 # `<tag attr="value">`
415 var value
: nullable String
417 init(name
: String, value
: nullable String) do
422 redef fun rendering
do
423 if value
== null then
426 add
(" {name}=\"{value}\
"")
435 var attrs
= new Array[TagAttribute]
436 var content
: nullable Streamable writable
439 attrs
.add
(new TagAttribute("type", "text/javascript"))
442 redef fun rendering
do
444 for attr
in attrs
do add attr
446 if content
!= null then add content
.as(not null)
451 # JS script for Piwik Tracker
455 var tracker_url
: String
458 init(tracker_url
, site_id
: String) do
460 self.tracker_url
= tracker_url
461 self.site_id
= site_id
464 redef fun rendering
do
465 var tpl
= new Template
466 tpl
.add
"<!-- Piwik -->"
467 tpl
.add
"var _paq = _paq || [];"
468 tpl
.add
" _paq.push([\"trackPageView\
"]);"
469 tpl
.add
" _paq.push([\"enableLinkTracking\
"]);"
470 tpl
.add
"(function() \{"
471 tpl
.add
" var u=((\"https
:\
" == document.location.protocol) ? \"https\
" : \"http\
") + \"://{tracker_url}\
";"
472 tpl
.add
" _paq.push([\"setTrackerUrl\
", u+\"piwik
.php\
"]);"
473 tpl
.add
" _paq.push([\"setSiteId\
", \"{site_id}\
"]);"
474 tpl
.add
" var d=document, g=d.createElement(\"script\
"), s=d.getElementsByTagName(\"script\
")[0]; g.type=\"text
/javascript\
";"
475 tpl
.add
" g.defer=true; g.async=true; g.src=u+\"piwik
.js\
"; s.parentNode.insertBefore(g,s);"
482 # Graph image with clicable map
490 init(name
, alt
, map
: String) do
496 redef fun rendering
do
497 add
"<article class='graph'>"
498 add
"<img src='{name}.png' usemap='#{name}' style='margin:auto' alt='{alt}'/>"
504 # A page article (used for module, class, prop description)
508 var id
: String writable
509 var classes
= new HashSet[String]
510 var title
: Template writable
511 var subtitle
: Template writable
512 var content
: nullable Template writable
516 redef fun rendering
do
517 add
"<article class='{classes.join(" ")}' id='{id}'>"
518 add
"<h3 class='signature'>"
521 add
"<div class='info'>"
524 if content
!= null then
525 add content
.as(not null)
531 # A module / class / prop definition
533 # * namespace of the definition
539 var comment
: nullable TplComment writable
540 var namespace
: Streamable writable
541 var location
: nullable Streamable writable
542 var github_area
: nullable TplGithubArea writable
546 redef fun rendering
do
547 add
"<div class='description'>"
548 if github_area
!= null then
549 add github_area
.as(not null)
551 if comment
== null then
552 add
"<p class='info inheritance'>"
553 add
"<span class=\"noComment\
">no comment for </span>"
555 add comment
.as(not null)
556 add
"<p class='info inheritance'>"
560 if location
!= null then
562 add location
.as(not null)
569 # Textarea used by Github comment edition plugin to store comments
573 var raw_comment
: String writable
574 var raw_namespace
: String writable
575 var location
: String writable
577 init(raw_comment
, raw_namespace
, location
: String) do
578 self.raw_comment
= raw_comment
579 self.raw_namespace
= raw_namespace
580 self.location
= location
583 redef fun rendering
do
585 add
" class='baseComment'"
586 add
" data-comment-namespace='{raw_namespace}'"
587 add
" data-comment-location='{location}'>"
597 var comment
: Streamable writable
599 init(comment
: Streamable) do self.comment
= comment
601 redef fun rendering
do
602 add
"<div class='comment'>"
608 # Comment box (for synopsys)
609 class TplShortComment
612 redef fun rendering
do
613 add
"<div class='comment'>"
614 add
"<div class='nitdoc'>"
621 # A html link (with optional title)
625 var href
: String writable
626 var text
: String writable
627 var title
: nullable String writable
631 redef fun rendering
do
635 if title
!= null then
637 add title.as(not null)
646 # Element to display in concerns list
655 var elts
= new Array[TplConcernElt]
657 redef fun rendering
do
658 if elts
.is_empty
then return
667 # Element of a list of concerns
668 class TplConcernListElt
671 var anchor
: String writable
672 var name
: String writable
673 var comment
: nullable String writable
677 redef fun rendering
do
679 add
"<a href=\"{anchor}\
">{name}</a>"
680 if comment
!= null then
681 add
": {comment.as(not null)}"
687 # Section for topconcern
691 var anchor
: String writable
692 var concern
: TplLink writable
696 redef fun rendering
do
697 add
"<a id=\"{anchor}\
"></a>"
698 add
"<h3 class=\"concern-toplevel\
">Methods refined in "
704 # Section for subconcern
708 var anchor
: String writable
709 var concern
: TplLink writable
710 var comment
: nullable String writable
714 redef fun rendering
do
715 add
"<a id=\"{anchor}\
"></a>"
716 add
"<p class=\"concern-doc\
">"
718 if comment
!= null then
720 add comment
.as(not null)