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.
20 import html_components
21 import html
::bootstrap
25 # Github url based on this location
26 fun github
(gitdir
: String): String do
27 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
28 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
29 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
30 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
35 # ID used as a HTML unique ID and in file names.
37 # **Must** match the following (POSIX ERE) regular expression:
40 # ^[A-Za-z_][A-Za-z0-9._-]*$
43 # That way, the ID is always a valid URI component and a valid XML name.
44 fun nitdoc_id
: String is abstract
46 # URL of this entity’s Nitdoc page.
47 fun nitdoc_url
: String is abstract
49 # Returns the mentity name without short signature.
55 # * MClassDef: `Foo[E]`
56 # * MProperty: `foo(e)`
57 # * MPropdef: `foo(e)`
58 var html_name
: String is lazy
do return name
.html_escape
60 # Returns a Link to the mentity `html_url`.
62 # Example: `<a href="html_url" title="mdoc.short_comment">html_short_name</a>
63 var html_link
: Link is lazy
do
64 var tpl
= new Link(nitdoc_url
, html_name
)
65 var mdoc
= mdoc_or_fallback
67 tpl
.title
= mdoc
.short_comment
72 # A template link to the mentity `nitdoc_id`
73 fun tpl_anchor
: TplLink do
74 var tpl
= new TplLink("#{nitdoc_id}", html_name
)
75 var mdoc
= mdoc_or_fallback
77 tpl
.title
= mdoc
.short_comment
82 # A template article that briefly describe the entity
83 fun tpl_short_article
: TplArticle do
85 var mdoc
= mdoc_or_fallback
87 tpl
.content
= mdoc
.tpl_short_comment
92 # A template article that describe the entity
93 fun tpl_article
: TplArticle do
94 var tpl
= new TplArticle.with_title
(nitdoc_id
, tpl_title
)
95 tpl
.title_classes
.add
"signature"
96 tpl
.subtitle
= tpl_namespace
97 tpl
.summary_title
= html_name
101 # A template signature that contains modifiers and parameters
102 fun tpl_declaration
: Template is abstract
104 # A template namespace
105 fun tpl_namespace
: Template is abstract
107 # A template definition of the mentity
108 # include name, sysnopsys, comment and namespace
109 fun tpl_definition
: TplDefinition is abstract
111 # A li element that can go in a list
112 fun tpl_list_item
: TplListItem do
113 var lnk
= new Template
114 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
116 var mdoc
= mdoc_or_fallback
119 lnk
.add mdoc
.tpl_short_comment
121 return new TplListItem.with_content
(lnk
)
124 var tpl_css_classes
= new Array[String]
126 # Box title for this mentity
127 fun tpl_title
: Template do
128 var title
= new Template
130 title
.add tpl_namespace
134 # Icon that will be displayed before the title
135 fun tpl_icon
: TplIcon do
136 var icon
= new TplIcon.with_icon
("tag")
137 icon
.css_classes
.add_all
(tpl_css_classes
)
143 # Return a li element for `self` that can be displayed in a concern list
144 private fun tpl_concern_item
: TplListItem do
145 var lnk
= new Template
147 var mdoc
= mdoc_or_fallback
150 lnk
.add mdoc
.tpl_short_comment
152 return new TplListItem.with_content
(lnk
)
157 redef var nitdoc_id
= name
.to_cmangle
is lazy
158 redef fun nitdoc_url
do return root
.nitdoc_url
160 redef fun tpl_declaration
do
161 var tpl
= new Template
162 tpl
.add
"<span>project "
168 redef fun tpl_namespace
do return html_link
170 redef fun tpl_definition
do
171 var tpl
= new TplDefinition
172 var mdoc
= mdoc_or_fallback
174 tpl
.comment
= mdoc
.tpl_comment
179 redef fun tpl_css_classes
do return ["public"]
183 redef var nitdoc_id
is lazy
do
184 if parent
!= null then
185 return "{parent.nitdoc_id}__{name.to_cmangle}"
187 return name
.to_cmangle
190 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
192 redef fun tpl_namespace
do
193 var tpl
= new Template
194 tpl
.add mproject
.tpl_namespace
195 if mproject
.root
!= self then
202 redef fun tpl_declaration
do
203 var tpl
= new Template
204 tpl
.add
"<span>group "
210 redef fun tpl_definition
do
211 var tpl
= new TplDefinition
212 var mdoc
= mdoc_or_fallback
214 tpl
.comment
= mdoc
.tpl_comment
221 redef var nitdoc_id
is lazy
do
222 if mgroup
!= null then
223 if mgroup
.mmodules
.length
== 1 then
224 return "{mgroup.nitdoc_id}-"
226 return "{mgroup.nitdoc_id}__{name.to_cmangle}"
229 return name
.to_cmangle
232 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
234 redef fun tpl_declaration
do
235 var tpl
= new Template
236 tpl
.add
"<span>module "
237 tpl
.add tpl_namespace
242 redef fun tpl_namespace
do
243 var tpl
= new Template
244 if mgroup
!= null then
245 tpl
.add mgroup
.tpl_namespace
252 redef fun tpl_definition
do
253 var tpl
= new TplClassDefinition
254 var mdoc
= mdoc_or_fallback
256 tpl
.comment
= mdoc
.tpl_comment
261 redef fun tpl_css_classes
do return ["public"]
265 redef var nitdoc_id
= "{intro_mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
266 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
267 redef fun mdoc_or_fallback
do return intro
.mdoc
270 redef var html_name
is lazy
do
271 var tpl
= new Template
272 tpl
.add name
.html_escape
275 var parameter_names
= new Array[String]
276 for p
in mparameters
do
277 parameter_names
.add
(p
.html_name
)
279 tpl
.add parameter_names
.join
(", ")
282 return tpl
.write_to_string
285 redef fun tpl_declaration
do return intro
.tpl_declaration
286 redef fun tpl_definition
do return intro
.tpl_definition
288 redef fun tpl_namespace
do
289 var tpl
= new Template
290 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
297 redef fun tpl_title
do
298 var title
= new Template
304 redef fun tpl_icon
do return intro
.tpl_icon
306 fun tpl_signature
: Template do
307 var tpl
= new Template
310 var parameter_names
= new Array[String]
311 for p
in mparameters
do
312 parameter_names
.add
(p
.html_name
)
314 tpl
.add parameter_names
.join
(", ")
320 redef fun tpl_css_classes
do return intro
.tpl_css_classes
323 redef class MClassDef
324 redef var nitdoc_id
= "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
325 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
327 redef fun mdoc_or_fallback
do return mdoc
or else mclass
.mdoc_or_fallback
329 redef fun tpl_namespace
do
330 var tpl
= new Template
331 tpl
.add mmodule
.tpl_namespace
333 tpl
.add mclass
.html_link
338 redef fun tpl_article
do
339 var tpl
= new TplArticle(nitdoc_id
)
340 tpl
.summary_title
= "in {mmodule.html_name}"
341 tpl
.title
= tpl_declaration
342 tpl
.title_classes
.add
"signature"
343 var title
= new Template
345 title
.add mmodule
.tpl_namespace
347 var mdoc
= mdoc_or_fallback
349 tpl
.content
= mdoc
.tpl_comment
354 redef fun tpl_title
do
355 var title
= new Template
361 redef fun tpl_declaration
do
362 var tpl
= new Template
363 tpl
.add tpl_modifiers
365 tpl
.add tpl_signature
369 fun tpl_signature
: Template do
370 var tpl
= new Template
371 var mparameters
= mclass
.mparameters
372 if not mparameters
.is_empty
then
374 for i
in [0..mparameters
.length
[ do
375 tpl
.add
"{mparameters[i].html_name}: "
376 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
377 if i
< mparameters
.length
- 1 then tpl
.add
", "
384 redef fun tpl_definition
do
385 var tpl
= new TplClassDefinition
386 var mdoc
= mdoc_or_fallback
388 tpl
.comment
= mdoc
.tpl_comment
393 redef fun tpl_css_classes
do
394 var set
= new HashSet[String]
395 if is_intro
then set
.add
"intro"
396 for m
in mclass
.intro
.modifiers
do set
.add m
.to_cmangle
397 for m
in modifiers
do set
.add m
.to_cmangle
401 fun tpl_modifiers
: Template do
402 var tpl
= new Template
403 for modifier
in modifiers
do
404 if modifier
== "public" then continue
405 tpl
.add
"{modifier.html_escape} "
411 redef class MProperty
412 redef var nitdoc_id
= "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}" is lazy
413 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
415 redef fun mdoc_or_fallback
do return intro
.mdoc
417 redef fun tpl_namespace
do
418 var tpl
= new Template
419 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
421 tpl
.add intro
.html_link
426 redef fun tpl_declaration
do return intro
.tpl_declaration
428 fun tpl_signature
: Template do return new Template
430 redef fun tpl_title
do return intro
.tpl_title
432 redef fun tpl_icon
do return intro
.tpl_icon
434 redef fun tpl_css_classes
do return intro
.tpl_css_classes
438 redef var nitdoc_id
= "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
439 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
441 redef fun mdoc_or_fallback
do return mdoc
or else mproperty
.mdoc_or_fallback
443 redef fun tpl_namespace
do
444 var tpl
= new Template
445 tpl
.add mclassdef
.tpl_namespace
451 redef fun tpl_article
do
452 var tpl
= new TplArticle(nitdoc_id
)
453 tpl
.summary_title
= "in {mclassdef.html_name}"
454 var title
= new Template
456 title
.add mclassdef
.html_link
458 tpl
.subtitle
= tpl_declaration
459 var mdoc
= mdoc_or_fallback
461 tpl
.content
= mdoc
.tpl_comment
466 redef fun tpl_definition
do
467 var tpl
= new TplDefinition
468 var mdoc
= mdoc_or_fallback
470 tpl
.comment
= mdoc
.tpl_comment
475 redef fun tpl_declaration
do
476 var tpl
= new Template
477 tpl
.add tpl_modifiers
479 tpl
.add tpl_signature
483 redef fun tpl_css_classes
do
484 var set
= new HashSet[String]
485 if is_intro
then set
.add
"intro"
486 for m
in mproperty
.intro
.modifiers
do set
.add m
.to_cmangle
487 for m
in modifiers
do set
.add m
.to_cmangle
491 fun tpl_modifiers
: Template do
492 var tpl
= new Template
493 for modifier
in modifiers
do
494 if modifier
== "public" then continue
495 tpl
.add
"{modifier.html_escape} "
500 fun tpl_signature
: Template do return new Template
502 redef fun tpl_list_item
do
503 var lnk
= new Template
504 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
505 var atext
= html_link
.text
506 var ahref
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
507 var atitle
= html_link
.title
508 var anchor
= new Link.with_title
(ahref
, atext
, atitle
)
510 var mdoc
= mdoc_or_fallback
513 lnk
.add mdoc
.tpl_short_comment
515 return new TplListItem.with_content
(lnk
)
518 fun tpl_inheritance_item
: TplListItem do
519 var lnk
= new Template
520 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
521 lnk
.add mclassdef
.mmodule
.tpl_namespace
523 var atext
= mclassdef
.html_link
.text
524 var ahref
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
525 var atitle
= mclassdef
.html_link
.title
526 var anchor
= new Link.with_title
(ahref
, atext
, atitle
)
528 var mdoc
= mdoc_or_fallback
531 lnk
.add mdoc
.tpl_short_comment
533 var li
= new TplListItem.with_content
(lnk
)
534 li
.css_classes
.add
"signature"
539 redef class MAttributeDef
540 redef fun tpl_signature
do
541 var tpl
= new Template
542 if static_mtype
!= null then
544 tpl
.add static_mtype
.tpl_signature
551 redef fun tpl_signature
do
552 var tpl
= new Template
553 var params
= new Array[String]
554 for param
in intro
.msignature
.mparameters
do
555 params
.add param
.name
.html_escape
557 if not params
.is_empty
then
559 tpl
.add params
.join
(", ")
566 redef class MMethodDef
567 redef fun tpl_signature
do return msignature
.tpl_signature
570 redef class MVirtualTypeProp
571 redef fun html_link
do return mvirtualtype
.html_link
572 redef fun tpl_signature
do return html_link
575 redef class MVirtualTypeDef
576 redef fun tpl_signature
do
577 var tpl
= new Template
578 if bound
== null then return tpl
580 tpl
.add bound
.tpl_signature
586 fun tpl_signature
: Template is abstract
589 redef class MClassType
590 redef fun html_link
do return mclass
.html_link
591 redef fun tpl_signature
do return html_link
594 redef class MNullableType
595 redef fun tpl_signature
do
596 var tpl
= new Template
598 tpl
.add mtype
.tpl_signature
603 redef class MGenericType
604 redef fun tpl_signature
do
606 var tpl
= new Template
607 tpl
.add
new Link.with_title
(lnk
.href
, mclass
.name
.html_escape
, lnk
.title
)
609 for i
in [0..arguments
.length
[ do
610 tpl
.add arguments
[i
].tpl_signature
611 if i
< arguments
.length
- 1 then tpl
.add
", "
618 redef class MParameterType
619 redef fun html_link
do
620 return new Link.with_title
("{mclass.nitdoc_url}#FT_{name.to_cmangle}", name
, "formal type")
622 redef fun tpl_signature
do return html_link
625 redef class MVirtualType
626 redef fun html_link
do return mproperty
.intro
.html_link
627 redef fun tpl_signature
do return html_link
630 redef class MSignature
631 redef fun tpl_signature
do
632 var tpl
= new Template
633 if not mparameters
.is_empty
then
635 for i
in [0..mparameters
.length
[ do
636 tpl
.add mparameters
[i
].tpl_signature
637 if i
< mparameters
.length
- 1 then tpl
.add
", "
641 if return_mtype
!= null then
643 tpl
.add return_mtype
.tpl_signature
649 redef class MParameter
650 fun tpl_signature
: Template do
651 var tpl
= new Template
653 tpl
.add mtype
.tpl_signature
654 if is_vararg
then tpl
.add
"..."
659 redef class ConcernsTree
661 private var seen
= new HashSet[MConcern]
663 redef fun add
(p
, e
) do
664 if seen
.has
(e
) then return
669 fun to_tpl
: TplList do
670 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
672 var li
= r
.tpl_concern_item
679 private fun build_list
(e
: MConcern, li
: TplListItem) do
680 if not sub
.has_key
(e
) then return
682 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
684 if e2
isa MGroup and e2
.is_root
then
687 var sli
= e2
.tpl_concern_item
697 ################################################################################
698 # Additions to `model_ext`.
701 redef fun tpl_signature
do
702 var tpl
= new Template
705 if part
.target
!= null then
706 tpl
.add part
.target
.as(not null).html_link
708 tpl
.add part
.text
.html_escape
715 redef class MInnerClass
716 redef fun nitdoc_url
do return inner
.nitdoc_url
717 redef fun tpl_signature
do return inner
.tpl_signature
720 redef class MInnerClassDef
721 redef fun nitdoc_url
do return inner
.nitdoc_url
723 redef fun tpl_anchor
do return inner
.tpl_anchor
724 redef fun html_link
do return inner
.html_link
725 redef fun tpl_signature
do return inner
.tpl_signature
727 redef fun tpl_definition
do
728 var tpl
= new TplClassDefinition
729 var mdoc
= mdoc_or_fallback
731 tpl
.comment
= mdoc
.tpl_comment