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]
160 # The page url where the top menu is displayed.
162 # Used to select the active link.
163 private var current_url
: String
165 init(current_url
: String) do
166 self.current_url
= current_url
169 # Add a new link to the menu.
170 fun add_link
(content
: TplLink) do
171 var is_active
= content
.href
== current_url
172 add_item
(content
, is_active
)
175 # Add a content between `<li>` tags
176 fun add_item
(content
: Streamable, is_active
: Bool) do
177 var tpl
= new Template
180 tpl
.add
" class='active'"
188 # Add a raw content to the menu
189 fun add_raw
(content
: Streamable) do
193 redef fun rendering
do
194 if brand
== null and elts
.is_empty
then return
195 add
"<nav id='topmenu' class='navbar navbar-default navbar-fixed-top' role='navigation'>"
196 add
" <div class='container-fluid'>"
197 add
" <div class='navbar-header'>"
198 add
" <button type='button' class='navbar-toggle' "
199 add
" data-toggle='collapse' data-target='#topmenu-collapse'>"
200 add
" <span class='sr-only'>Toggle menu</span>"
201 add
" <span class='icon-bar'></span>"
202 add
" <span class='icon-bar'></span>"
203 add
" <span class='icon-bar'></span>"
205 if brand
!= null then add brand
.as(not null)
207 add
" <div class='collapse navbar-collapse' id='topmenu-collapse'>"
208 if not elts
.is_empty
then
209 add
"<ul class='nav navbar-nav'>"
210 for elt
in elts
do add elt
223 # Sidebar contains sidebar element templates called boxes
224 var boxes
= new Array[TplSidebarElt]
226 # Sort boxes by order priority
227 private fun order_boxes
do
228 var sorter
= new OrderComparator
232 redef fun rendering
do
233 if boxes
.is_empty
then return
235 add
"<div id='sidebar'>"
236 for box
in boxes
do add box
241 # Comparator used to sort boxes by order
242 private class OrderComparator
243 super Comparator[TplSidebarElt]
245 redef fun compare
(a
, b
) do
246 if a
.order
< b
.order
then return -1
247 if a
.order
> b
.order
then return 1
252 # Something that can be put in the sidebar
256 # Order of the box in the sidebar
259 init with_order
(order
: Int) do self.order
= order
262 # Agenericbox that can be added to sidebar
266 # Title of the box to display
267 # Title is also a placeholder for the collapse link
271 # equals to `title.to_cmangle` by default
272 # Used for collapsing
275 # Content to display in the box
276 # box will not be rendered if the content is null
277 var content
: nullable Streamable is writable
279 # Is the box opened by default
280 # otherwise, the user will have to clic on the title to display the content
281 var is_open
= false is writable
283 init(title
: String) do
285 self.id
= title
.to_cmangle
288 init with_content
(title
: String, content
: Streamable) do
290 self.content
= content
293 redef fun rendering
do
294 if content
== null then return
296 if is_open
then open
= "in"
297 add
"<div class='panel'>"
298 add
" <div class='panel-heading'>"
299 add
" <a data-toggle='collapse' data-parent='#sidebar' data-target='#box_{id}' href='#'>"
303 add
" <div id='box_{id}' class='panel-body collapse {open}'>"
304 add content
.as(not null)
310 # Something that can go on a summary template
314 # Add an element to the summary
315 fun add_child
(child
: TplSummaryElt) is abstract
318 # A summary that can go on the sidebar
319 # If the page contains a sidebar, the summary is automatically placed
320 # on top of the sidebarauto-generated
321 # summary contains anchors to all sections displayed in the page
326 # Summary elements to display
327 var children
= new Array[TplSummaryElt]
329 redef fun add_child
(child
) do children
.add child
331 redef fun rendering
do
332 if children
.is_empty
then return
333 add
"<div class='panel'>"
334 add
" <div class='panel-heading'>"
335 add
" <a data-toggle='collapse' data-parent='#sidebar' data-target='#box-sum' href='#'>"
339 add
" <div id='box-sum' class='summary collapse in'>"
340 add
" <ul class='nav'>"
341 for entry
in children
do add entry
349 class TplSummaryEntry
355 # Children of this entry
356 # Will be displayed as a tree
357 var children
= new Array[TplSummaryElt]
359 init(text
: Streamable) do self.text
= text
361 redef fun add_child
(child
) do children
.add child
363 redef fun rendering
do
366 if not children
.is_empty
then
367 add
"<ul class='nav'>"
368 for entry
in children
do add entry
375 # Something that can go in a section
376 # Sections are automatically collected to populate the menu
383 # Title to display if any
384 # if both `title` and `summary_title` are null then
385 # the section will not appear in the summary
386 var title
: nullable Streamable is writable
388 # Subtitle to display if any
389 var subtitle
: nullable Streamable is writable
391 # Title that appear in the summary
392 # if null use `title` instead
393 var summary_title
: nullable String is writable
395 # CSS classes to apply on the section element
396 var css_classes
= new Array[String]
398 # CSS classes to apply on the title heading element
399 var title_classes
= new Array[String]
401 # Parent article/section if any
402 var parent
: nullable TplSectionElt
404 init(id
: String) do self.id
= id
406 init with_title
(id
: String, title
: Streamable) do
411 # Level <hX> for HTML heading
412 protected fun hlvl
: Int do
413 if parent
== null then return 1
414 return parent
.hlvl
+ 1
417 # Elements contained by this section
418 var children
= new Array[TplSectionElt]
420 # Add an element in this section
421 fun add_child
(child
: TplSectionElt) do
426 # Is the section empty (no content at all)
427 fun is_empty
: Bool do return children
.is_empty
429 # Render this section in the summary
430 fun render_summary
(parent
: TplSummaryElt) do
431 if is_empty
then return
432 var title
= summary_title
433 if title
== null and self.title
!= null then title
= self.title
.write_to_string
434 if title
== null then return
435 var lnk
= new TplLink("#{id}", title
)
436 var entry
= new TplSummaryEntry(lnk
)
437 for child
in children
do
438 child
.render_summary
(entry
)
440 parent
.add_child entry
444 # A HTML <section> element
448 redef fun rendering
do
449 add
"<section id='{id}' class='{css_classes.join(" ")}'>"
450 if title
!= null then
452 if lvl
== 2 then title_classes
.add
"well well-sm"
453 add
"<h{lvl} class='{title_classes.join(" ")}'>"
454 add title
.as(not null)
457 if subtitle
!= null then
458 add
"<div class='info subtitle'>"
459 add subtitle
.as(not null)
462 for child
in children
do
469 # A page article that can go in a section
473 # Content for this article
474 var content
: nullable Streamable = null is writable
475 var source_link
: nullable Streamable = null is writable
477 init with_content
(id
: String, title
: Streamable, content
: Streamable) do
478 with_title
(id
, title
)
479 self.content
= content
482 redef fun render_summary
(parent
) do
483 if is_empty
then return
484 var title
= summary_title
485 if title
== null and self.title
!= null then title
= self.title
.write_to_string
486 if title
== null then return
487 var lnk
= new TplLink("#{id}", title
)
488 parent
.add_child
new TplSummaryEntry(lnk
)
491 redef fun rendering
do
492 if is_empty
then return
493 add
"<article id='{id}' class='{css_classes.join(" ")}'>"
494 if source_link
!= null then
495 add
"<div class='source-link'>"
496 add source_link
.as(not null)
499 if title
!= null then
501 if lvl
== 2 then title_classes
.add
"well well-sm"
502 add
"<h{lvl} class='{title_classes.join(" ")}'>"
503 add title
.as(not null)
506 if subtitle
!= null then
507 add
"<div class='info subtitle'>"
508 add subtitle
.as(not null)
511 if content
!= null then
512 add content
.as(not null)
514 for child
in children
do
520 redef fun is_empty
: Bool do
521 return title
== null and subtitle
== null and content
== null and children
.is_empty
525 # A module / class / prop definition
530 var comment
: nullable Streamable = null is writable
532 # Namespace for this definition
533 var namespace
: nullable Streamable = null is writable
535 # Location link to display
536 var location
: nullable Streamable = null is writable
538 private fun render_info
do
539 add
"<div class='info text-right'>"
540 if namespace
!= null then
541 if comment
== null then
542 add
"<span class=\"noComment\
">no comment for </span>"
544 add namespace
.as(not null)
546 if location
!= null then
548 add location
.as(not null)
553 private fun render_comment
do
554 if comment
!= null then add comment
.as(not null)
557 redef fun rendering
do
558 add
"<div class='definition'>"
566 class TplClassDefinition
569 var intros
= new Array[TplListElt]
570 var redefs
= new Array[TplListElt]
574 redef fun rendering
do
575 add
"<div class='definition'>"
578 render_list
("Introduces", intros
)
579 render_list
("Redefines", redefs
)
583 private fun render_list
(name
: String, elts
: Array[TplListElt]) do
584 if elts
.is_empty
then return
585 add
"<h5>{name}</h5>"
586 add
"<ul class='list-unstyled list-definition'>"
587 for elt
in elts
do add elt
592 # Layout for Search page
596 var modules
= new Array[Streamable]
597 var classes
= new Array[Streamable]
598 var props
= new Array[Streamable]
600 redef fun rendering
do
601 var title
= self.title
602 if title
!= null then add
"<h1>{title}</h1>"
603 add
"<div class='container-fluid'>"
604 add
" <div class='row'>"
605 if not modules
.is_empty
then
606 add
"<div class='col-xs-4'>"
607 add
"<h3>Modules</h3>"
617 if not classes
.is_empty
then
618 add
"<div class='col-xs-4'>"
619 add
"<h3>Classes</h3>"
629 if not props
.is_empty
then
630 add
"<div class='col-xs-4'>"
631 add
"<h3>Properties</h3>"
646 #####################
647 # Basiv HTML elements
648 #####################
655 var href
: String is writable
657 # Text to display in the link
658 var text
: Streamable is writable
661 var title
: nullable String is writable
663 init(href
, text
: String) do
668 init with_title
(href
, text
, title
: String) do
673 redef fun rendering
do
677 if title
!= null then
679 add title.as(not null)
692 # Elements contained in this list
693 # can be <li> or <ul> elements
694 var elts
= new Array[TplListElt]
696 # CSS classes of the <ul> element
697 var css_classes
= new Array[String]
699 # Add content wrapped in a <li> element
700 fun add_li
(item
: TplListItem) do elts
.add item
704 init with_classes
(classes
: Array[String]) do self.css_classes
= classes
706 fun is_empty
: Bool do return elts
.is_empty
708 redef fun rendering
do
709 if elts
.is_empty
then return
710 add
"<ul class='{css_classes.join(" ")}'>"
711 for elt
in elts
do add elt
716 # Something that can be added to a TplList
725 # Content of the list item
726 var content
= new Template
728 # CSS classes of the <li> element
729 var css_classes
= new Array[String]
733 init with_content
(content
: Streamable) do append
(content
)
735 init with_classes
(content
: Streamable, classes
: Array[String]) do
736 with_content
(content
)
737 css_classes
= classes
740 # Append `content` to the item
741 # similar to `self.content.add`
742 fun append
(content
: Streamable) do self.content
.add content
744 redef fun rendering
do
745 add
"<li class='{css_classes.join(" ")}'>"
751 # A Bootstrap tab component that contains `TplTabPanel`.
755 # Panels contained in the tab.
756 var panels
= new Array[TplTabPanel]
759 fun add_panel
(panel
: TplTabPanel) do panels
.add panel
761 # CSS classes of the tab component.
762 var css_classes
= new Array[String]
764 redef fun rendering
do
765 add
"<div class='tab-content'>"
766 for panel
in panels
do add panel
771 # A panel that goes in a `TplTab`.
775 # CSS classes of the pane element.
776 var css_classes
= new Array[String]
780 # Used to show/hide panel.
785 # Displayed in the tab header or in the pointing link.
788 # Is the panel visible by default?
789 var is_active
= false is writable
792 var content
: nullable Streamable = null is writable
794 # Get a link pointing to this panel.
795 fun tpl_link_to
: Streamable do
796 var lnk
= new Template
797 lnk
.add
"<a data-target='#{id}' data-toggle='pill'>"
803 redef fun rendering
do
804 add
"<div class='tab-pane {css_classes.join(" ")}"
805 if is_active
then add
"active"
807 if content
!= null then add content
.as(not null)
812 # A label with a text content
816 # Content of the label if any
817 var content
: nullable Streamable = null is writable
819 # CSS classes of the <span> element
820 var css_classes
= new Array[String]
822 init with_content
(content
: Streamable) do self.content
= content
823 init with_classes
(classes
: Array[String]) do self.css_classes
= classes
825 redef fun rendering
do
826 add
"<span class='label {css_classes.join(" ")}'>"
827 if content
!= null then add content
.as(not null)
832 # A label with an icon
837 # see: http://getbootstrap.com/components/#glyphicons
840 init with_icon
(icon
: String) do self.icon
= icon
842 redef fun rendering
do
843 add
"<span class='glyphicon glyphicon-{icon} {css_classes.join(" ")}'>"
844 if content
!= null then add content
.as(not null)
849 # A HTML tag attribute
850 # `<tag attr="value">`
855 var value
: nullable String
857 init(name
: String, value
: nullable String) do
862 redef fun rendering
do
863 var value
= self.value
864 if value
== null then
867 add
(" {name}=\"{value}\
"")
876 var attrs
= new Array[TagAttribute]
877 var content
: nullable Streamable = null is writable
880 attrs
.add
(new TagAttribute("type", "text/javascript"))
883 protected fun render_content
do
884 if content
!= null then add content
.as(not null)
887 redef fun rendering
do
889 for attr
in attrs
do add attr
896 # JS script for Piwik Tracker
900 var tracker_url
: String
903 init(tracker_url
, site_id
: String) do
905 self.tracker_url
= tracker_url
906 self.site_id
= site_id
909 redef fun render_content
do
911 add
"var _paq = _paq || [];"
912 add
" _paq.push([\"trackPageView\
"]);"
913 add
" _paq.push([\"enableLinkTracking\
"]);"
915 add
" var u=((\"https
:\
" == document.location.protocol) ? \"https\
" : \"http\
") + \"://{tracker_url}\
";"
916 add
" _paq.push([\"setTrackerUrl\
", u+\"piwik
.php\
"]);"
917 add
" _paq.push([\"setSiteId\
", \"{site_id}\
"]);"
918 add
" var d=document, g=d.createElement(\"script\
"), s=d.getElementsByTagName(\"script\
")[0]; g.type=\"text
/javascript\
";"
919 add
" g.defer=true; g.async=true; g.src=u+\"piwik
.js\
"; s.parentNode.insertBefore(g,s);"