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`
17 module html_components
20 import html
::bootstrap
23 # A label with a text content.
29 css_classes
.add
"label"
32 # Init this label from css classes.
33 init with_classes
(classes
: Array[String]) do
35 css_classes
.add_all classes
39 # A HTML tag attribute
40 # `<tag attr="value">`
43 # var attr: TagAttribute
45 # attr = new TagAttribute("foo", null)
46 # assert attr.write_to_string == " foo=\"\""
48 # attr = new TagAttribute("foo", "bar<>")
49 # assert attr.write_to_string == " foo=\"bar<>\""
55 var value
: nullable String
57 redef fun rendering
do
58 var value
= self.value
60 # SEE: http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes
61 add
" {name.html_escape}=\"\
""
63 add
" {name.html_escape}=\"{value.html_escape}\
""
68 # Javacript template that can be added into a DocPage.
72 # HTML attributes to add in this tag.
73 var attrs
= new Array[TagAttribute]
75 # Text content of this script tag.
76 var content
: nullable Writable = null is writable
79 attrs
.add
(new TagAttribute("type", "text/javascript"))
82 # Render the content of this script.
83 protected fun render_content
do
84 if content
!= null then add content
.as(not null)
87 redef fun rendering
do
89 for attr
in attrs
do add attr
96 # JS script for Piwik Tracker
100 # Piwik URL to use for this tracker.
101 var tracker_url
: String
103 # Site ID used on Piwik system.
106 redef fun render_content
do
107 var site_id
= self.site_id
.to_json
108 var tracker_url
= self.tracker_url
.trim
109 if tracker_url
.chars
.last
!= '/' then tracker_url
+= "/"
110 tracker_url
= "://{tracker_url}".to_json
112 addn
"<!-- Piwik -->"
113 addn
"var _paq = _paq || [];"
114 addn
" _paq.push([\"trackPageView\
"]);"
115 addn
" _paq.push([\"enableLinkTracking\
"]);"
116 addn
"(function() \{"
117 addn
" var u=((\"https
:\
" == document.location.protocol) ? \"https\
" : \"http\
") + {tracker_url};"
118 addn
" _paq.push([\"setTrackerUrl\
", u+\"piwik
.php\
"]);"
119 addn
" _paq.push([\"setSiteId\
", {site_id}]);"
120 addn
" var d=document, g=d.createElement(\"script\
"), s=d.getElementsByTagName(\"script\
")[0]; g.type=\"text
/javascript\
";"
121 addn
" g.defer=true; g.async=true; g.src=u+\"piwik
.js\
"; s.parentNode.insertBefore(g,s);"