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 # Returns the mentity name without short signature.
54 # * MClassDef: `Foo[E]`
55 # * MProperty: `foo(e)`
56 # * MPropdef: `foo(e)`
57 var html_name
: String is lazy
do return name
.html_escape
59 # A template link to the mentity `nitdoc_id`
60 fun tpl_anchor
: TplLink do
61 var tpl
= new TplLink("#{nitdoc_id}", html_name
)
62 var mdoc
= mdoc_or_fallback
64 tpl
.title
= mdoc
.short_comment
69 # A template link to the mentity `nitdoc_url`
70 fun tpl_link
: TplLink do
71 var tpl
= new TplLink(nitdoc_url
, html_name
)
72 var mdoc
= mdoc_or_fallback
74 tpl
.title
= mdoc
.short_comment
79 # A template article that briefly describe the entity
80 fun tpl_short_article
: TplArticle do
82 var mdoc
= mdoc_or_fallback
84 tpl
.content
= mdoc
.tpl_short_comment
89 # A template article that describe the entity
90 fun tpl_article
: TplArticle do
91 var tpl
= new TplArticle.with_title
(nitdoc_id
, tpl_title
)
92 tpl
.title_classes
.add
"signature"
93 tpl
.subtitle
= tpl_namespace
94 tpl
.summary_title
= html_name
98 # A template signature that contains modifiers and parameters
99 fun tpl_declaration
: Template is abstract
101 # A template namespace
102 fun tpl_namespace
: Template is abstract
104 # A template definition of the mentity
105 # include name, sysnopsys, comment and namespace
106 fun tpl_definition
: TplDefinition is abstract
108 # A li element that can go in a list
109 fun tpl_list_item
: TplListItem do
110 var lnk
= new Template
111 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
113 var mdoc
= mdoc_or_fallback
116 lnk
.add mdoc
.tpl_short_comment
118 return new TplListItem.with_content
(lnk
)
121 var tpl_css_classes
= new Array[String]
123 # Box title for this mentity
124 fun tpl_title
: Template do
125 var title
= new Template
127 title
.add tpl_namespace
131 # Icon that will be displayed before the title
132 fun tpl_icon
: TplIcon do
133 var icon
= new TplIcon.with_icon
("tag")
134 icon
.css_classes
.add_all
(tpl_css_classes
)
140 # Return a li element for `self` that can be displayed in a concern list
141 private fun tpl_concern_item
: TplListItem do
142 var lnk
= new Template
144 var mdoc
= mdoc_or_fallback
147 lnk
.add mdoc
.tpl_short_comment
149 return new TplListItem.with_content
(lnk
)
154 redef var nitdoc_id
= name
.to_cmangle
is lazy
155 redef fun nitdoc_url
do return root
.nitdoc_url
157 redef fun tpl_declaration
do
158 var tpl
= new Template
159 tpl
.add
"<span>project "
165 redef fun tpl_namespace
do return tpl_link
167 redef fun tpl_definition
do
168 var tpl
= new TplDefinition
169 var mdoc
= mdoc_or_fallback
171 tpl
.comment
= mdoc
.tpl_comment
176 redef fun tpl_css_classes
do return ["public"]
180 redef var nitdoc_id
is lazy
do
181 if parent
!= null then
182 return "{parent.nitdoc_id}__{name.to_cmangle}"
184 return name
.to_cmangle
187 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
189 redef fun tpl_namespace
do
190 var tpl
= new Template
191 tpl
.add mproject
.tpl_namespace
192 if mproject
.root
!= self then
199 redef fun tpl_declaration
do
200 var tpl
= new Template
201 tpl
.add
"<span>group "
207 redef fun tpl_definition
do
208 var tpl
= new TplDefinition
209 var mdoc
= mdoc_or_fallback
211 tpl
.comment
= mdoc
.tpl_comment
218 redef var nitdoc_id
is lazy
do
219 if mgroup
!= null then
220 if mgroup
.mmodules
.length
== 1 then
221 return "{mgroup.nitdoc_id}-"
223 return "{mgroup.nitdoc_id}__{name.to_cmangle}"
226 return name
.to_cmangle
229 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
231 redef fun tpl_declaration
do
232 var tpl
= new Template
233 tpl
.add
"<span>module "
234 tpl
.add tpl_namespace
239 redef fun tpl_namespace
do
240 var tpl
= new Template
241 if mgroup
!= null then
242 tpl
.add mgroup
.tpl_namespace
249 redef fun tpl_definition
do
250 var tpl
= new TplClassDefinition
251 var mdoc
= mdoc_or_fallback
253 tpl
.comment
= mdoc
.tpl_comment
258 redef fun tpl_css_classes
do return ["public"]
262 redef var nitdoc_id
= "{intro_mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
263 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
264 redef fun mdoc_or_fallback
do return intro
.mdoc
267 redef var html_name
is lazy
do
268 var tpl
= new Template
269 tpl
.add name
.html_escape
272 var parameter_names
= new Array[String]
273 for p
in mparameters
do
274 parameter_names
.add
(p
.html_name
)
276 tpl
.add parameter_names
.join
(", ")
279 return tpl
.write_to_string
282 redef fun tpl_declaration
do return intro
.tpl_declaration
283 redef fun tpl_definition
do return intro
.tpl_definition
285 redef fun tpl_namespace
do
286 var tpl
= new Template
287 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
294 redef fun tpl_title
do
295 var title
= new Template
301 redef fun tpl_icon
do return intro
.tpl_icon
303 fun tpl_signature
: Template do
304 var tpl
= new Template
307 var parameter_names
= new Array[String]
308 for p
in mparameters
do
309 parameter_names
.add
(p
.html_name
)
311 tpl
.add parameter_names
.join
(", ")
317 redef fun tpl_css_classes
do return intro
.tpl_css_classes
320 redef class MClassDef
321 redef var nitdoc_id
= "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
322 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
324 redef fun mdoc_or_fallback
do return mdoc
or else mclass
.mdoc_or_fallback
326 redef fun tpl_namespace
do
327 var tpl
= new Template
328 tpl
.add mmodule
.tpl_namespace
330 tpl
.add mclass
.tpl_link
335 redef fun tpl_article
do
336 var tpl
= new TplArticle(nitdoc_id
)
337 tpl
.summary_title
= "in {mmodule.html_name}"
338 tpl
.title
= tpl_declaration
339 tpl
.title_classes
.add
"signature"
340 var title
= new Template
342 title
.add mmodule
.tpl_namespace
344 var mdoc
= mdoc_or_fallback
346 tpl
.content
= mdoc
.tpl_comment
351 redef fun tpl_title
do
352 var title
= new Template
358 redef fun tpl_declaration
do
359 var tpl
= new Template
360 tpl
.add tpl_modifiers
362 tpl
.add tpl_signature
366 fun tpl_signature
: Template do
367 var tpl
= new Template
368 var mparameters
= mclass
.mparameters
369 if not mparameters
.is_empty
then
371 for i
in [0..mparameters
.length
[ do
372 tpl
.add
"{mparameters[i].html_name}: "
373 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
374 if i
< mparameters
.length
- 1 then tpl
.add
", "
381 redef fun tpl_definition
do
382 var tpl
= new TplClassDefinition
383 var mdoc
= mdoc_or_fallback
385 tpl
.comment
= mdoc
.tpl_comment
390 redef fun tpl_css_classes
do
391 var set
= new HashSet[String]
392 if is_intro
then set
.add
"intro"
393 for m
in mclass
.intro
.modifiers
do set
.add m
.to_cmangle
394 for m
in modifiers
do set
.add m
.to_cmangle
398 fun tpl_modifiers
: Template do
399 var tpl
= new Template
400 for modifier
in modifiers
do
401 if modifier
== "public" then continue
402 tpl
.add
"{modifier.html_escape} "
408 redef class MProperty
409 redef var nitdoc_id
= "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}" is lazy
410 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
412 redef fun mdoc_or_fallback
do return intro
.mdoc
414 redef fun tpl_namespace
do
415 var tpl
= new Template
416 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
418 tpl
.add intro
.tpl_link
423 redef fun tpl_declaration
do return intro
.tpl_declaration
425 fun tpl_signature
: Template do return new Template
427 redef fun tpl_title
do return intro
.tpl_title
429 redef fun tpl_icon
do return intro
.tpl_icon
431 redef fun tpl_css_classes
do return intro
.tpl_css_classes
435 redef var nitdoc_id
= "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
436 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
438 redef fun mdoc_or_fallback
do return mdoc
or else mproperty
.mdoc_or_fallback
440 redef fun tpl_namespace
do
441 var tpl
= new Template
442 tpl
.add mclassdef
.tpl_namespace
448 redef fun tpl_article
do
449 var tpl
= new TplArticle(nitdoc_id
)
450 tpl
.summary_title
= "in {mclassdef.html_name}"
451 var title
= new Template
453 title
.add mclassdef
.tpl_link
455 tpl
.subtitle
= tpl_declaration
456 var mdoc
= mdoc_or_fallback
458 tpl
.content
= mdoc
.tpl_comment
463 redef fun tpl_definition
do
464 var tpl
= new TplDefinition
465 var mdoc
= mdoc_or_fallback
467 tpl
.comment
= mdoc
.tpl_comment
472 redef fun tpl_declaration
do
473 var tpl
= new Template
474 tpl
.add tpl_modifiers
476 tpl
.add tpl_signature
480 redef fun tpl_css_classes
do
481 var set
= new HashSet[String]
482 if is_intro
then set
.add
"intro"
483 for m
in mproperty
.intro
.modifiers
do set
.add m
.to_cmangle
484 for m
in modifiers
do set
.add m
.to_cmangle
488 fun tpl_modifiers
: Template do
489 var tpl
= new Template
490 for modifier
in modifiers
do
491 if modifier
== "public" then continue
492 tpl
.add
"{modifier.html_escape} "
497 fun tpl_signature
: Template do return new Template
499 redef fun tpl_list_item
do
500 var lnk
= new Template
501 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
502 var anchor
= tpl_link
503 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
505 var mdoc
= mdoc_or_fallback
508 lnk
.add mdoc
.tpl_short_comment
510 return new TplListItem.with_content
(lnk
)
513 fun tpl_inheritance_item
: TplListItem do
514 var lnk
= new Template
515 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
516 lnk
.add mclassdef
.mmodule
.tpl_namespace
518 var anchor
= mclassdef
.tpl_link
519 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
521 var mdoc
= mdoc_or_fallback
524 lnk
.add mdoc
.tpl_short_comment
526 var li
= new TplListItem.with_content
(lnk
)
527 li
.css_classes
.add
"signature"
532 redef class MAttributeDef
533 redef fun tpl_signature
do
534 var tpl
= new Template
535 if static_mtype
!= null then
537 tpl
.add static_mtype
.tpl_signature
544 redef fun tpl_signature
do
545 var tpl
= new Template
546 var params
= new Array[String]
547 for param
in intro
.msignature
.mparameters
do
548 params
.add param
.name
.html_escape
550 if not params
.is_empty
then
552 tpl
.add params
.join
(", ")
559 redef class MMethodDef
560 redef fun tpl_signature
do return msignature
.tpl_signature
563 redef class MVirtualTypeProp
564 redef fun tpl_link
do return mvirtualtype
.tpl_link
565 redef fun tpl_signature
do return tpl_link
568 redef class MVirtualTypeDef
569 redef fun tpl_signature
do
570 var tpl
= new Template
571 if bound
== null then return tpl
573 tpl
.add bound
.tpl_signature
579 fun tpl_signature
: Template is abstract
582 redef class MClassType
583 redef fun tpl_link
do return mclass
.tpl_link
584 redef fun tpl_signature
do return tpl_link
587 redef class MNullableType
588 redef fun tpl_signature
do
589 var tpl
= new Template
591 tpl
.add mtype
.tpl_signature
596 redef class MGenericType
597 redef fun tpl_signature
do
598 var tpl
= new Template
600 lnk
.text
= mclass
.name
.html_escape
603 for i
in [0..arguments
.length
[ do
604 tpl
.add arguments
[i
].tpl_signature
605 if i
< arguments
.length
- 1 then tpl
.add
", "
612 redef class MParameterType
613 redef fun tpl_link
do
614 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name.to_cmangle}", name
, "formal type")
616 redef fun tpl_signature
do return tpl_link
619 redef class MVirtualType
620 redef fun tpl_link
do return mproperty
.intro
.tpl_link
621 redef fun tpl_signature
do return tpl_link
624 redef class MSignature
625 redef fun tpl_signature
do
626 var tpl
= new Template
627 if not mparameters
.is_empty
then
629 for i
in [0..mparameters
.length
[ do
630 tpl
.add mparameters
[i
].tpl_signature
631 if i
< mparameters
.length
- 1 then tpl
.add
", "
635 if return_mtype
!= null then
637 tpl
.add return_mtype
.tpl_signature
643 redef class MParameter
644 fun tpl_signature
: Template do
645 var tpl
= new Template
647 tpl
.add mtype
.tpl_signature
648 if is_vararg
then tpl
.add
"..."
653 redef class ConcernsTree
655 private var seen
= new HashSet[MConcern]
657 redef fun add
(p
, e
) do
658 if seen
.has
(e
) then return
663 fun to_tpl
: TplList do
664 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
666 var li
= r
.tpl_concern_item
673 private fun build_list
(e
: MConcern, li
: TplListItem) do
674 if not sub
.has_key
(e
) then return
676 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
678 if e2
isa MGroup and e2
.is_root
then
681 var sli
= e2
.tpl_concern_item
691 ################################################################################
692 # Additions to `model_ext`.
695 redef fun tpl_signature
do
696 var tpl
= new Template
699 if part
.target
!= null then
700 tpl
.add part
.target
.as(not null).tpl_link
702 tpl
.add part
.text
.html_escape
709 redef class MInnerClass
710 redef fun nitdoc_url
do return inner
.nitdoc_url
711 redef fun tpl_signature
do return inner
.tpl_signature
714 redef class MInnerClassDef
715 redef fun nitdoc_url
do return inner
.nitdoc_url
717 redef fun tpl_anchor
do return inner
.tpl_anchor
718 redef fun tpl_link
do return inner
.tpl_link
719 redef fun tpl_signature
do return inner
.tpl_signature
721 redef fun tpl_definition
do
722 var tpl
= new TplClassDefinition
723 var mdoc
= mdoc_or_fallback
725 tpl
.comment
= mdoc
.tpl_comment