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 for Nit model MEntities.
19 import html_components
24 # URL of this entity’s Nitdoc page.
25 fun nitdoc_url
: String is abstract
27 # Returns a Link to the mentity `html_url`.
29 # Example: `<a href="html_url" title="mdoc.short_comment">html_short_name</a>
30 redef var html_link
is lazy
do
31 var tpl
= new Link(nitdoc_url
, html_name
)
32 var mdoc
= mdoc_or_fallback
34 tpl
.title
= mdoc
.synopsis
39 # Returns a Link to the mentity `nitdoc_id`.
41 # Example: `<a href="#nitdoc_id" title="mdoc.short_comment">html_short_name</a>
42 fun html_link_to_anchor
: Link do
43 var tpl
= new Link("#{nitdoc_id}", html_name
)
44 var mdoc
= mdoc_or_fallback
46 tpl
.title
= mdoc
.synopsis
51 # A li element that can go in a `HTMLList`.
52 fun html_list_item
: ListItem do
53 var tpl
= new Template
54 tpl
.add
new DocHTMLLabel.with_classes
(css_classes
)
56 var comment
= html_synopsis
57 if comment
!= null then
61 return new ListItem(tpl
)
66 redef var nitdoc_id
= name
.to_cmangle
is lazy
68 redef fun nitdoc_url
do
70 if root
== null then return super
71 return root
.nitdoc_url
76 redef var nitdoc_id
is lazy
do
77 var parent
= self.parent
78 if parent
!= null then
79 return "{parent.nitdoc_id}__{name.to_cmangle}"
81 return name
.to_cmangle
84 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
88 redef var nitdoc_id
is lazy
do
89 var mgroup
= self.mgroup
90 if mgroup
!= null then
91 if mgroup
.mmodules
.length
== 1 then
92 return "{mgroup.nitdoc_id}-"
94 return "{mgroup.nitdoc_id}__{name.to_cmangle}"
97 return name
.to_cmangle
100 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
104 redef var nitdoc_id
= "{intro_mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
105 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
108 redef class MClassDef
109 redef var nitdoc_id
= "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
110 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
113 redef class MProperty
114 redef var nitdoc_id
= "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}" is lazy
115 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
119 redef var nitdoc_id
= "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
120 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
123 redef class MAttributeDef
125 redef fun html_modifiers
do
131 redef fun html_short_signature
do return new Template
133 redef fun html_signature
do
134 var static_mtype
= self.static_mtype
135 var tpl
= new Template
136 if static_mtype
!= null then
138 tpl
.add static_mtype
.html_signature
144 redef class MParameterType
145 redef fun html_link
do
146 return new Link("{mclass.nitdoc_url}#FT_{name.to_cmangle}", name
, "formal type")
150 redef class MVirtualType
151 redef fun html_link
do return mproperty
.intro
.html_link
154 redef class ConcernsTree
155 # Render `self` as a hierarchical UnorderedList.
156 fun html_list
: UnorderedList do
157 var lst
= new UnorderedList
158 lst
.css_classes
.add
"list-unstyled list-definition"
160 var li
= r
.html_concern_item
162 build_html_list
(r
, li
)
167 # Build the html list recursively.
168 private fun build_html_list
(e
: MConcern, li
: ListItem) do
169 if not sub
.has_key
(e
) then return
171 var lst
= new UnorderedList
172 lst
.css_classes
.add
"list-unstyled list-definition"
174 if e2
isa MGroup and e2
.is_root
then
175 build_html_list
(e2
, li
)
177 var sli
= e2
.html_concern_item
179 build_html_list
(e2
, sli
)
182 var text
= new Template
184 if not lst
.is_empty
then text
.add lst
190 # Return a li element for `self` that can be displayed in a concern list
191 private fun html_concern_item
: ListItem do
193 var tpl
= new Template
194 tpl
.add
new Link("#{nitdoc_id}.concern", lnk
.text
, lnk
.title
)
195 var comment
= html_synopsis
196 if comment
!= null then
200 return new ListItem(tpl
)
204 ################################################################################
205 # Additions to `model_ext`.
208 redef fun html_signature
do
209 var tpl
= new Template
212 if part
.target
!= null then
213 tpl
.add part
.target
.as(not null).html_link
215 tpl
.add part
.text
.html_escape
222 redef class MInnerClass
223 redef fun nitdoc_url
do return inner
.nitdoc_url
224 redef fun html_signature
do return inner
.html_signature
227 redef class MInnerClassDef
228 redef fun nitdoc_url
do return inner
.nitdoc_url
230 redef fun html_link_to_anchor
do return inner
.html_link_to_anchor
231 redef fun html_link
do return inner
.html_link
232 redef fun html_signature
do return inner
.html_signature