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
24 # Github url based on this location
25 fun github
(gitdir
: String): String do
26 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
27 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
28 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
29 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
34 # ID used as a HTML unique ID and in file names.
36 # **Must** match the following (POSIX ERE) regular expression:
39 # ^[A-Za-z_][A-Za-z0-9._-]*$
42 # That way, the ID is always a valid URI component and a valid XML name.
43 fun nitdoc_id
: String is abstract
45 # URL of this entity’s Nitdoc page.
46 fun nitdoc_url
: String is abstract
48 # A template link to the mentity `nitdoc_id`
49 fun tpl_anchor
: TplLink do
50 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
51 var mdoc
= mdoc_or_fallback
53 tpl
.title
= mdoc
.short_comment
58 # A template link to the mentity `nitdoc_url`
59 fun tpl_link
: TplLink do
60 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
61 var mdoc
= mdoc_or_fallback
63 tpl
.title
= mdoc
.short_comment
68 # A template article that briefly describe the entity
69 fun tpl_short_article
: TplArticle do
71 var mdoc
= mdoc_or_fallback
73 tpl
.content
= mdoc
.tpl_short_comment
78 # A template article that describe the entity
79 fun tpl_article
: TplArticle do
80 var tpl
= new TplArticle.with_title
(nitdoc_id
, tpl_title
)
81 tpl
.title_classes
.add
"signature"
82 tpl
.subtitle
= tpl_namespace
83 tpl
.summary_title
= nitdoc_name
87 # A template signature that contains modifiers and parameters
88 fun tpl_declaration
: Template is abstract
90 # A template namespace
91 fun tpl_namespace
: Template is abstract
93 # A template definition of the mentity
94 # include name, sysnopsys, comment and namespace
95 fun tpl_definition
: TplDefinition is abstract
97 # A li element that can go in a list
98 fun tpl_list_item
: TplListItem do
99 var lnk
= new Template
100 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
102 var mdoc
= mdoc_or_fallback
105 lnk
.add mdoc
.tpl_short_comment
107 return new TplListItem.with_content
(lnk
)
110 var tpl_css_classes
= new Array[String]
112 # Box title for this mentity
113 fun tpl_title
: Template do
114 var title
= new Template
116 title
.add tpl_namespace
120 # Icon that will be displayed before the title
121 fun tpl_icon
: TplIcon do
122 var icon
= new TplIcon.with_icon
("tag")
123 icon
.css_classes
.add_all
(tpl_css_classes
)
129 # Return a li element for `self` that can be displayed in a concern list
130 private fun tpl_concern_item
: TplListItem do
131 var lnk
= new Template
133 var mdoc
= mdoc_or_fallback
136 lnk
.add mdoc
.tpl_short_comment
138 return new TplListItem.with_content
(lnk
)
143 redef var nitdoc_id
= name
.to_cmangle
is lazy
144 redef fun nitdoc_url
do return root
.nitdoc_url
146 redef fun tpl_declaration
do
147 var tpl
= new Template
148 tpl
.add
"<span>project "
154 redef fun tpl_namespace
do return tpl_link
156 redef fun tpl_definition
do
157 var tpl
= new TplDefinition
158 var mdoc
= mdoc_or_fallback
160 tpl
.comment
= mdoc
.tpl_comment
165 redef fun tpl_css_classes
do return ["public"]
169 redef var nitdoc_id
is lazy
do
170 if parent
!= null then
171 return "{parent.nitdoc_id}__{name.to_cmangle}"
173 return name
.to_cmangle
176 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
178 redef fun tpl_namespace
do
179 var tpl
= new Template
180 tpl
.add mproject
.tpl_namespace
181 if mproject
.root
!= self then
188 redef fun tpl_declaration
do
189 var tpl
= new Template
190 tpl
.add
"<span>group "
196 redef fun tpl_definition
do
197 var tpl
= new TplDefinition
198 var mdoc
= mdoc_or_fallback
200 tpl
.comment
= mdoc
.tpl_comment
207 redef var nitdoc_id
is lazy
do
208 if mgroup
!= null then
209 if mgroup
.mmodules
.length
== 1 then
210 return "{mgroup.nitdoc_id}-"
212 return "{mgroup.nitdoc_id}__{name.to_cmangle}"
215 return name
.to_cmangle
218 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
220 redef fun tpl_declaration
do
221 var tpl
= new Template
222 tpl
.add
"<span>module "
223 tpl
.add tpl_namespace
228 redef fun tpl_namespace
do
229 var tpl
= new Template
230 if mgroup
!= null then
231 tpl
.add mgroup
.tpl_namespace
238 redef fun tpl_definition
do
239 var tpl
= new TplClassDefinition
240 var mdoc
= mdoc_or_fallback
242 tpl
.comment
= mdoc
.tpl_comment
247 redef fun tpl_css_classes
do return ["public"]
251 redef var nitdoc_id
= "{intro_mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
252 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
253 redef fun mdoc_or_fallback
do return intro
.mdoc
255 redef fun tpl_declaration
do return intro
.tpl_declaration
256 redef fun tpl_definition
do return intro
.tpl_definition
258 redef fun tpl_namespace
do
259 var tpl
= new Template
260 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
267 redef fun tpl_title
do
268 var title
= new Template
271 title
.add tpl_signature
275 redef fun tpl_icon
do return intro
.tpl_icon
277 fun tpl_signature
: Template do
278 var tpl
= new Template
281 var parameter_names
= new Array[String]
282 for p
in mparameters
do
283 parameter_names
.add
(p
.nitdoc_name
)
285 tpl
.add parameter_names
.join
(", ")
291 redef fun tpl_article
do
293 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
297 redef fun tpl_css_classes
do return intro
.tpl_css_classes
300 redef class MClassDef
301 redef var nitdoc_id
= "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
302 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
304 redef fun mdoc_or_fallback
do return mdoc
or else mclass
.mdoc_or_fallback
306 redef fun tpl_namespace
do
307 var tpl
= new Template
308 tpl
.add mmodule
.tpl_namespace
310 tpl
.add mclass
.tpl_link
315 redef fun tpl_article
do
316 var tpl
= new TplArticle(nitdoc_id
)
317 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
318 tpl
.title
= tpl_declaration
319 tpl
.title_classes
.add
"signature"
320 var title
= new Template
322 title
.add mmodule
.tpl_namespace
324 var mdoc
= mdoc_or_fallback
326 tpl
.content
= mdoc
.tpl_comment
331 redef fun tpl_title
do
332 var title
= new Template
335 title
.add tpl_signature
339 redef fun tpl_declaration
do
340 var tpl
= new Template
341 tpl
.add tpl_modifiers
343 tpl
.add tpl_signature
347 fun tpl_signature
: Template do
348 var tpl
= new Template
349 var mparameters
= mclass
.mparameters
350 if not mparameters
.is_empty
then
352 for i
in [0..mparameters
.length
[ do
353 tpl
.add
"{mparameters[i].nitdoc_name}: "
354 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
355 if i
< mparameters
.length
- 1 then tpl
.add
", "
362 redef fun tpl_definition
do
363 var tpl
= new TplClassDefinition
364 var mdoc
= mdoc_or_fallback
366 tpl
.comment
= mdoc
.tpl_comment
371 redef fun tpl_css_classes
do
372 var set
= new HashSet[String]
373 if is_intro
then set
.add
"intro"
374 for m
in mclass
.intro
.modifiers
do set
.add m
.to_cmangle
375 for m
in modifiers
do set
.add m
.to_cmangle
379 fun tpl_modifiers
: Template do
380 var tpl
= new Template
381 for modifier
in modifiers
do
382 if modifier
== "public" then continue
383 tpl
.add
"{modifier.html_escape} "
389 redef class MProperty
390 redef var nitdoc_id
= "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}" is lazy
391 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
393 redef fun mdoc_or_fallback
do return intro
.mdoc
395 redef fun tpl_namespace
do
396 var tpl
= new Template
397 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
399 tpl
.add intro
.tpl_link
404 redef fun tpl_declaration
do return intro
.tpl_declaration
406 fun tpl_signature
: Template do return new Template
408 redef fun tpl_title
do return intro
.tpl_title
410 redef fun tpl_icon
do return intro
.tpl_icon
412 redef fun tpl_css_classes
do return intro
.tpl_css_classes
416 redef var nitdoc_id
= "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
417 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
419 redef fun mdoc_or_fallback
do return mdoc
or else mproperty
.mdoc_or_fallback
421 redef fun tpl_namespace
do
422 var tpl
= new Template
423 tpl
.add mclassdef
.tpl_namespace
429 redef fun tpl_article
do
430 var tpl
= new TplArticle(nitdoc_id
)
431 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
432 var title
= new Template
434 title
.add mclassdef
.tpl_link
436 tpl
.subtitle
= tpl_declaration
437 var mdoc
= mdoc_or_fallback
439 tpl
.content
= mdoc
.tpl_comment
444 redef fun tpl_definition
do
445 var tpl
= new TplDefinition
446 var mdoc
= mdoc_or_fallback
448 tpl
.comment
= mdoc
.tpl_comment
453 redef fun tpl_declaration
do
454 var tpl
= new Template
455 tpl
.add tpl_modifiers
457 tpl
.add tpl_signature
461 redef fun tpl_css_classes
do
462 var set
= new HashSet[String]
463 if is_intro
then set
.add
"intro"
464 for m
in mproperty
.intro
.modifiers
do set
.add m
.to_cmangle
465 for m
in modifiers
do set
.add m
.to_cmangle
469 fun tpl_modifiers
: Template do
470 var tpl
= new Template
471 for modifier
in modifiers
do
472 if modifier
== "public" then continue
473 tpl
.add
"{modifier.html_escape} "
478 fun tpl_signature
: Template do return new Template
480 redef fun tpl_list_item
do
481 var lnk
= new Template
482 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
483 var anchor
= tpl_link
484 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
486 var mdoc
= mdoc_or_fallback
489 lnk
.add mdoc
.tpl_short_comment
491 return new TplListItem.with_content
(lnk
)
494 fun tpl_inheritance_item
: TplListItem do
495 var lnk
= new Template
496 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
497 lnk
.add mclassdef
.mmodule
.tpl_namespace
499 var anchor
= mclassdef
.tpl_link
500 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
502 var mdoc
= mdoc_or_fallback
505 lnk
.add mdoc
.tpl_short_comment
507 var li
= new TplListItem.with_content
(lnk
)
508 li
.css_classes
.add
"signature"
513 redef class MAttributeDef
514 redef fun tpl_signature
do
515 var tpl
= new Template
516 if static_mtype
!= null then
518 tpl
.add static_mtype
.tpl_signature
525 redef fun tpl_signature
do
526 var tpl
= new Template
527 var params
= new Array[String]
528 for param
in intro
.msignature
.mparameters
do
529 params
.add param
.name
.html_escape
531 if not params
.is_empty
then
533 tpl
.add params
.join
(", ")
540 redef class MMethodDef
541 redef fun tpl_signature
do return msignature
.tpl_signature
544 redef class MVirtualTypeProp
545 redef fun tpl_link
do return mvirtualtype
.tpl_link
546 redef fun tpl_signature
do return tpl_link
549 redef class MVirtualTypeDef
550 redef fun tpl_signature
do
551 var tpl
= new Template
552 if bound
== null then return tpl
554 tpl
.add bound
.tpl_signature
560 fun tpl_signature
: Template is abstract
563 redef class MClassType
564 redef fun tpl_link
do return mclass
.tpl_link
565 redef fun tpl_signature
do return tpl_link
568 redef class MNullableType
569 redef fun tpl_signature
do
570 var tpl
= new Template
572 tpl
.add mtype
.tpl_signature
577 redef class MGenericType
578 redef fun tpl_signature
do
579 var tpl
= new Template
582 for i
in [0..arguments
.length
[ do
583 tpl
.add arguments
[i
].tpl_signature
584 if i
< arguments
.length
- 1 then tpl
.add
", "
591 redef class MParameterType
592 redef fun tpl_link
do
593 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name.to_cmangle}", name
, "formal type")
595 redef fun tpl_signature
do return tpl_link
598 redef class MVirtualType
599 redef fun tpl_link
do return mproperty
.intro
.tpl_link
600 redef fun tpl_signature
do return tpl_link
603 redef class MSignature
604 redef fun tpl_signature
do
605 var tpl
= new Template
606 if not mparameters
.is_empty
then
608 for i
in [0..mparameters
.length
[ do
609 tpl
.add mparameters
[i
].tpl_signature
610 if i
< mparameters
.length
- 1 then tpl
.add
", "
614 if return_mtype
!= null then
616 tpl
.add return_mtype
.tpl_signature
622 redef class MParameter
623 fun tpl_signature
: Template do
624 var tpl
= new Template
626 tpl
.add mtype
.tpl_signature
627 if is_vararg
then tpl
.add
"..."
632 redef class ConcernsTree
634 private var seen
= new HashSet[MConcern]
636 redef fun add
(p
, e
) do
637 if seen
.has
(e
) then return
642 fun to_tpl
: TplList do
643 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
645 var li
= r
.tpl_concern_item
652 private fun build_list
(e
: MConcern, li
: TplListItem) do
653 if not sub
.has_key
(e
) then return
655 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
657 if e2
isa MGroup and e2
.is_root
then
660 var sli
= e2
.tpl_concern_item
670 ################################################################################
671 # Additions to `model_ext`.
674 redef fun tpl_signature
do
675 var tpl
= new Template
678 if part
.target
!= null then
679 tpl
.add part
.target
.as(not null).tpl_link
681 tpl
.add part
.text
.html_escape
688 redef class MInnerClass
689 redef fun nitdoc_url
do return inner
.nitdoc_url
690 redef fun tpl_signature
do return inner
.tpl_signature
693 redef class MInnerClassDef
694 redef fun nitdoc_url
do return inner
.nitdoc_url
696 redef fun tpl_anchor
do return inner
.tpl_anchor
697 redef fun tpl_link
do return inner
.tpl_link
698 redef fun tpl_signature
do return inner
.tpl_signature
700 redef fun tpl_definition
do
701 var tpl
= new TplClassDefinition
702 var mdoc
= mdoc_or_fallback
704 tpl
.comment
= mdoc
.tpl_comment