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 # A documentation page
25 # Page title in HTML header
26 var title
: String is writable, noinit
29 var url
: String is writable, noinit
31 # Directory where css, js and other assets can be found
32 var shareurl
: String is writable, noinit
34 # Attributes of the body tag element
35 var body_attrs
= new Array[TagAttribute]
37 # Top menu template if any
38 var topmenu
: TplTopMenu is writable, noinit
40 # Sidebar template if any
41 var sidebar
: nullable TplSidebar = null is writable
43 # Content of the page in form a TplSection
44 var sections
= new Array[TplSection]
46 # Footer content if any
47 var footer
: nullable Streamable = null is writable
49 # JS scripts to append at the end of the body
50 var scripts
= new Array[TplScript]
54 # Add a section to this page
55 fun add_section
(section
: TplSection) do
59 # Render the html header
60 private fun render_head
do
63 add
" <meta charset='utf-8'/>"
64 add
" <!--link rel='stylesheet' href='{shareurl}/css/Nitdoc.UI.css' type='text/css'/-->"
65 add
" <link rel='stylesheet' href='{shareurl}/vendors/bootstrap/css/bootstrap.min.css'/>"
66 add
" <link rel='stylesheet' href='{shareurl}/css/nitdoc.bootstrap.css'/>"
67 add
" <link rel='stylesheet' href='{shareurl}/css/nitdoc.css'/>"
68 add
" <link rel='stylesheet' href='{shareurl}/css/Nitdoc.QuickSearch.css'/>"
69 add
" <link rel='stylesheet' href='{shareurl}/css/Nitdoc.ModalBox.css'/>"
70 add
" <link rel='stylesheet' href='{shareurl}/css/Nitdoc.GitHub.css'/>"
71 add
" <title>{title}</title>"
74 for attr
in body_attrs
do add attr
78 # Render the topmenu template
79 private fun render_topmenu
do
80 add
" <div class='row'>"
86 # Sidebar is automatically populated with a summary of all sections
88 if sidebar
== null then return
89 var summary
= new TplSummary.with_order
(0)
90 for section
in sections
do
91 section
.render_summary summary
93 sidebar
.boxes
.add summary
94 add sidebar
.as(not null)
96 # Render the footer and content
97 private fun render_content
do
98 for section
in sections
do add section
99 if footer
!= null then
100 add
"<div class='well footer'>"
101 add footer
.as(not null)
107 private fun render_footer
do
108 add
"<script src='{shareurl}/vendors/jquery/jquery-1.11.1.min.js'></script>"
109 add
"<script src='{shareurl}/vendors/jquery/jquery-ui-1.10.4.custom.min.js'></script>"
110 add
"<script src='{shareurl}/vendors/bootstrap/js/bootstrap.min.js'></script>"
111 add
"<script data-main='{shareurl}/js/nitdoc' src='{shareurl}/js/lib/require.js'</script>"
112 for script
in scripts
do add script
115 $("[data-toggle='tooltip']").tooltip();
116 $("[data-toggle='popover']").popover();
123 # Render the whole page
124 redef fun rendering
do
126 add
"<div class='container-fluid'>"
128 add
" <div class='row' id='content'>"
129 if sidebar
!= null then
130 add
"<div class='col col-xs-3 col-lg-2'>"
133 add
"<div class='col col-xs-9 col-lg-10' data-spy='scroll' data-target='.summary'>"
137 add
"<div class='col col-xs-12'>"
147 #########################
148 # general layout elements
149 #########################
151 # Top menu bar template
155 # Brand link to display in first position of the top menu
156 private var brand
: nullable Streamable = null is writable
157 # Elements of the topmenu
158 private var elts
= new Array[Streamable]
162 # Add a content between `<li>` tags
163 fun add_item
(content
: Streamable, is_active
: Bool) do
164 var tpl
= new Template
167 tpl
.add
" class='active'"
175 # Add a raw content to the menu
176 fun add_raw
(content
: Streamable) do
180 redef fun rendering
do
181 if brand
== null and elts
.is_empty
then return
182 add
"<nav id='topmenu' class='navbar navbar-default navbar-fixed-top' role='navigation'>"
183 add
" <div class='container-fluid'>"
184 add
" <div class='navbar-header'>"
185 add
" <button type='button' class='navbar-toggle' "
186 add
" data-toggle='collapse' data-target='#topmenu-collapse'>"
187 add
" <span class='sr-only'>Toggle menu</span>"
188 add
" <span class='icon-bar'></span>"
189 add
" <span class='icon-bar'></span>"
190 add
" <span class='icon-bar'></span>"
192 if brand
!= null then add brand
.as(not null)
194 add
" <div class='collapse navbar-collapse' id='topmenu-collapse'>"
195 if not elts
.is_empty
then
196 add
"<ul class='nav navbar-nav'>"
197 for elt
in elts
do add elt
210 # Sidebar contains sidebar element templates called boxes
211 var boxes
= new Array[TplSidebarElt]
213 # Sort boxes by order priority
214 private fun order_boxes
do
215 var sorter
= new OrderComparator
219 redef fun rendering
do
220 if boxes
.is_empty
then return
222 add
"<div id='sidebar'>"
223 for box
in boxes
do add box
228 # Comparator used to sort boxes by order
229 private class OrderComparator
230 super Comparator[TplSidebarElt]
232 redef fun compare
(a
, b
) do
233 if a
.order
< b
.order
then return -1
234 if a
.order
> b
.order
then return 1
239 # Something that can be put in the sidebar
243 # Order of the box in the sidebar
246 init with_order
(order
: Int) do self.order
= order
249 # Agenericbox that can be added to sidebar
253 # Title of the box to display
254 # Title is also a placeholder for the collapse link
258 # equals to `title.to_cmangle` by default
259 # Used for collapsing
262 # Content to display in the box
263 # box will not be rendered if the content is null
264 var content
: nullable Streamable writable
266 # Is the box opened by default
267 # otherwise, the user will have to clic on the title to display the content
268 var is_open
writable = false
270 init(title
: String) do
272 self.id
= title
.to_cmangle
275 init with_content
(title
: String, content
: Streamable) do
277 self.content
= content
280 redef fun rendering
do
281 if content
== null then return
283 if is_open
then open
= "in"
284 add
"<div class='panel'>"
285 add
" <div class='panel-heading'>"
286 add
" <a data-toggle='collapse' data-parent='#sidebar' data-target='#box_{id}' href='#'>"
290 add
" <div id='box_{id}' class='panel-body collapse {open}'>"
291 add content
.as(not null)
297 # Something that can go on a summary template
301 # Add an element to the summary
302 fun add_child
(child
: TplSummaryElt) is abstract
305 # A summary that can go on the sidebar
306 # If the page contains a sidebar, the summary is automatically placed
307 # on top of the sidebarauto-generated
308 # summary contains anchors to all sections displayed in the page
313 # Summary elements to display
314 var children
= new Array[TplSummaryElt]
316 redef fun add_child
(child
) do children
.add child
318 redef fun rendering
do
319 if children
.is_empty
then return
320 add
"<div class='panel'>"
321 add
" <div class='panel-heading'>"
322 add
" <a data-toggle='collapse' data-parent='#sidebar' data-target='#box-sum' href='#'>"
326 add
" <div id='box-sum' class='summary collapse in'>"
327 add
" <ul class='nav'>"
328 for entry
in children
do add entry
336 class TplSummaryEntry
342 # Children of this entry
343 # Will be displayed as a tree
344 var children
= new Array[TplSummaryElt]
346 init(text
: Streamable) do self.text
= text
348 redef fun add_child
(child
) do children
.add child
350 redef fun rendering
do
353 if not children
.is_empty
then
354 add
"<ul class='nav'>"
355 for entry
in children
do add entry
362 # Something that can go in a section
363 # Sections are automatically collected to populate the menu
370 # Title to display if any
371 # if both `title` and `summary_title` are null then
372 # the section will not appear in the summary
373 var title
: nullable Streamable writable
375 # Subtitle to display if any
376 var subtitle
: nullable Streamable writable
378 # Title that appear in the summary
379 # if null use `title` instead
380 var summary_title
: nullable String writable
382 # CSS classes to apply on the section element
383 var css_classes
= new Array[String]
385 # CSS classes to apply on the title heading element
386 var title_classes
= new Array[String]
388 # Parent article/section if any
389 var parent
: nullable TplSectionElt
391 init(id
: String) do self.id
= id
393 init with_title
(id
: String, title
: Streamable) do
398 # Level <hX> for HTML heading
399 protected fun hlvl
: Int do
400 if parent
== null then return 1
401 return parent
.hlvl
+ 1
404 # Elements contained by this section
405 var children
= new Array[TplSectionElt]
407 # Add an element in this section
408 fun add_child
(child
: TplSectionElt) do
413 # Is the section empty (no content at all)
414 fun is_empty
: Bool do return children
.is_empty
416 # Render this section in the summary
417 fun render_summary
(parent
: TplSummaryElt) do
418 if is_empty
then return
419 var title
= summary_title
420 if title
== null and self.title
!= null then title
= self.title
.write_to_string
421 if title
== null then return
422 var lnk
= new TplLink("#{id}", title
)
423 var entry
= new TplSummaryEntry(lnk
)
424 for child
in children
do
425 child
.render_summary
(entry
)
427 parent
.add_child entry
431 # A HTML <section> element
435 redef fun rendering
do
436 add
"<section id='{id}' class='{css_classes.join(" ")}'>"
437 if title
!= null then
439 if lvl
== 2 then title_classes
.add
"well well-sm"
440 add
"<h{lvl} class='{title_classes.join(" ")}'>"
441 add title
.as(not null)
444 if subtitle
!= null then
445 add
"<div class='info subtitle'>"
446 add subtitle
.as(not null)
449 for child
in children
do
456 # A page article that can go in a section
460 # Content for this article
461 var content
: nullable Streamable writable = null
462 var source_link
: nullable Streamable writable = null
464 init with_content
(id
: String, title
: Streamable, content
: Streamable) do
465 with_title
(id
, title
)
466 self.content
= content
469 redef fun render_summary
(parent
) do
470 if is_empty
then return
471 var title
= summary_title
472 if title
== null and self.title
!= null then title
= self.title
.write_to_string
473 if title
== null then return
474 var lnk
= new TplLink("#{id}", title
)
475 parent
.add_child
new TplSummaryEntry(lnk
)
478 redef fun rendering
do
479 if is_empty
then return
480 add
"<article id='{id}' class='{css_classes.join(" ")}'>"
481 if source_link
!= null then
482 add
"<div class='source-link'>"
483 add source_link
.as(not null)
486 if title
!= null then
488 if lvl
== 2 then title_classes
.add
"well well-sm"
489 add
"<h{lvl} class='{title_classes.join(" ")}'>"
490 add title
.as(not null)
493 if subtitle
!= null then
494 add
"<div class='info subtitle'>"
495 add subtitle
.as(not null)
498 if content
!= null then
499 add content
.as(not null)
501 for child
in children
do
507 redef fun is_empty
: Bool do
508 return title
== null and subtitle
== null and content
== null
512 # A module / class / prop definition
517 var comment
: nullable Streamable = null is writable
519 # Namespace for this definition
520 var namespace
: nullable Streamable = null is writable
522 # Location link to display
523 var location
: nullable Streamable = null is writable
525 private fun render_info
do
526 add
"<div class='info text-right'>"
527 if namespace
!= null then
528 if comment
== null then
529 add
"<span class=\"noComment\
">no comment for </span>"
531 add namespace
.as(not null)
533 if location
!= null then
535 add location
.as(not null)
540 private fun render_comment
do
541 if comment
!= null then add comment
.as(not null)
544 redef fun rendering
do
545 add
"<div class='definition'>"
553 class TplClassDefinition
556 var intros
= new Array[TplListElt]
557 var redefs
= new Array[TplListElt]
561 redef fun rendering
do
562 add
"<div class='definition'>"
565 render_list
("Introduces", intros
)
566 render_list
("Redefines", redefs
)
570 private fun render_list
(name
: String, elts
: Array[TplListElt]) do
571 if elts
.is_empty
then return
572 add
"<h5>{name}</h5>"
573 add
"<ul class='list-unstyled list-definition'>"
574 for elt
in elts
do add elt
579 # Layout for Search page
583 var modules
= new Array[Streamable]
584 var classes
= new Array[Streamable]
585 var props
= new Array[Streamable]
587 redef fun rendering
do
588 var title
= self.title
589 if title
!= null then add
"<h1>{title}</h1>"
590 add
"<div class='container-fluid'>"
591 add
" <div class='row'>"
592 if not modules
.is_empty
then
593 add
"<div class='col-xs-4'>"
594 add
"<h3>Modules</h3>"
604 if not classes
.is_empty
then
605 add
"<div class='col-xs-4'>"
606 add
"<h3>Classes</h3>"
616 if not props
.is_empty
then
617 add
"<div class='col-xs-4'>"
618 add
"<h3>Properties</h3>"
633 #####################
634 # Basiv HTML elements
635 #####################
642 var href
: String writable
644 # Text to display in the link
645 var text
: String writable
648 var title
: nullable String writable
650 init(href
, text
: String) do
655 init with_title
(href
, text
, title
: String) do
660 redef fun rendering
do
664 if title
!= null then
666 add title.as(not null)
679 # Elements contained in this list
680 # can be <li> or <ul> elements
681 var elts
= new Array[TplListElt]
683 # CSS classes of the <ul> element
684 var css_classes
= new Array[String]
686 # Add content wrapped in a <li> element
687 fun add_li
(content
: Streamable) do elts
.add
new TplListItem.with_content
(content
)
691 init with_classes
(classes
: Array[String]) do self.css_classes
= classes
693 fun is_empty
: Bool do return elts
.is_empty
695 redef fun rendering
do
696 if elts
.is_empty
then return
697 add
"<ul class='{css_classes.join(" ")}'>"
698 for elt
in elts
do add elt
703 # Something that can be added to a TplList
712 # Content of the list item
713 var content
= new Template
715 # CSS classes of the <li> element
716 var css_classes
= new Array[String]
720 init with_content
(content
: Streamable) do append
(content
)
722 init with_classes
(content
: Streamable, classes
: Array[String]) do
723 with_content
(content
)
724 css_classes
= classes
727 # Append `content` to the item
728 # similar to `self.content.add`
729 fun append
(content
: Streamable) do self.content
.add content
731 redef fun rendering
do
733 for cls
in css_classes
do add
" {cls}"
740 # A label with a text content
744 # Content of the label if any
745 var content
: nullable Streamable
747 # CSS classes of the <span> element
748 var css_classes
= new Array[String]
751 init with_content
(content
: Streamable) do self.content
= content
752 init with_classes
(classes
: Array[String]) do self.css_classes
= classes
754 redef fun rendering
do
755 add
"<span class='label {css_classes.join(" ")}'>"
756 if content
!= null then add content
.as(not null)
761 # A label with an icon
766 # see: http://getbootstrap.com/components/#glyphicons
769 init with_icon
(icon
: String) do self.icon
= icon
771 redef fun rendering
do
772 add
"<span class='glyphicon glyphicon-{icon} {css_classes.join(" ")}'>"
773 if content
!= null then add content
.as(not null)
778 # A HTML tag attribute
779 # `<tag attr="value">`
784 var value
: nullable String
786 init(name
: String, value
: nullable String) do
791 redef fun rendering
do
792 var value
= self.value
793 if value
== null then
796 add
(" {name}=\"{value}\
"")
805 var attrs
= new Array[TagAttribute]
806 var content
: nullable Streamable = null is writable
809 attrs
.add
(new TagAttribute("type", "text/javascript"))
812 protected fun render_content
do
813 if content
!= null then add content
.as(not null)
816 redef fun rendering
do
818 for attr
in attrs
do add attr
825 # JS script for Piwik Tracker
829 var tracker_url
: String
832 init(tracker_url
, site_id
: String) do
834 self.tracker_url
= tracker_url
835 self.site_id
= site_id
838 redef fun render_content
do
840 add
"var _paq = _paq || [];"
841 add
" _paq.push([\"trackPageView\
"]);"
842 add
" _paq.push([\"enableLinkTracking\
"]);"
844 add
" var u=((\"https
:\
" == document.location.protocol) ? \"https\
" : \"http\
") + \"://{tracker_url}\
";"
845 add
" _paq.push([\"setTrackerUrl\
", u+\"piwik
.php\
"]);"
846 add
" _paq.push([\"setSiteId\
", \"{site_id}\
"]);"
847 add
" var d=document, g=d.createElement(\"script\
"), s=d.getElementsByTagName(\"script\
")[0]; g.type=\"text
/javascript\
";"
848 add
" g.defer=true; g.async=true; g.src=u+\"piwik
.js\
"; s.parentNode.insertBefore(g,s);"