3882eb060e07c92d26ed1c93dcc7ab16947add02
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 # Returns a Link to the mentity `nitdoc_id`.
74 # Example: `<a href="#nitdoc_id" title="mdoc.short_comment">html_short_name</a>
75 fun html_link_to_anchor
: Link do
76 var tpl
= new Link("#{nitdoc_id}", html_name
)
77 var mdoc
= mdoc_or_fallback
79 tpl
.title
= mdoc
.short_comment
84 # A template article that briefly describe the entity
85 fun tpl_short_article
: TplArticle do
87 var mdoc
= mdoc_or_fallback
89 tpl
.content
= mdoc
.tpl_short_comment
94 # A template article that describe the entity
95 fun tpl_article
: TplArticle do
96 var tpl
= new TplArticle.with_title
(nitdoc_id
, tpl_title
)
97 tpl
.title_classes
.add
"signature"
98 tpl
.subtitle
= tpl_namespace
99 tpl
.summary_title
= html_name
103 # A template signature that contains modifiers and parameters
104 fun tpl_declaration
: Template is abstract
106 # A template namespace
107 fun tpl_namespace
: Template is abstract
109 # A template definition of the mentity
110 # include name, sysnopsys, comment and namespace
111 fun tpl_definition
: TplDefinition is abstract
113 # A li element that can go in a list
114 fun tpl_list_item
: TplListItem do
115 var lnk
= new Template
116 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
118 var mdoc
= mdoc_or_fallback
121 lnk
.add mdoc
.tpl_short_comment
123 return new TplListItem.with_content
(lnk
)
126 var tpl_css_classes
= new Array[String]
128 # Box title for this mentity
129 fun tpl_title
: Template do
130 var title
= new Template
132 title
.add tpl_namespace
136 # Icon that will be displayed before the title
137 fun tpl_icon
: TplIcon do
138 var icon
= new TplIcon.with_icon
("tag")
139 icon
.css_classes
.add_all
(tpl_css_classes
)
145 # Return a li element for `self` that can be displayed in a concern list
146 private fun tpl_concern_item
: TplListItem do
147 var lnk
= new Template
148 lnk
.add html_link_to_anchor
149 var mdoc
= mdoc_or_fallback
152 lnk
.add mdoc
.tpl_short_comment
154 return new TplListItem.with_content
(lnk
)
159 redef var nitdoc_id
= name
.to_cmangle
is lazy
160 redef fun nitdoc_url
do return root
.nitdoc_url
162 redef fun tpl_declaration
do
163 var tpl
= new Template
164 tpl
.add
"<span>project "
170 redef fun tpl_namespace
do return html_link
172 redef fun tpl_definition
do
173 var tpl
= new TplDefinition
174 var mdoc
= mdoc_or_fallback
176 tpl
.comment
= mdoc
.tpl_comment
181 redef fun tpl_css_classes
do return ["public"]
185 redef var nitdoc_id
is lazy
do
186 if parent
!= null then
187 return "{parent.nitdoc_id}__{name.to_cmangle}"
189 return name
.to_cmangle
192 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
194 redef fun tpl_namespace
do
195 var tpl
= new Template
196 tpl
.add mproject
.tpl_namespace
197 if mproject
.root
!= self then
204 redef fun tpl_declaration
do
205 var tpl
= new Template
206 tpl
.add
"<span>group "
212 redef fun tpl_definition
do
213 var tpl
= new TplDefinition
214 var mdoc
= mdoc_or_fallback
216 tpl
.comment
= mdoc
.tpl_comment
223 redef var nitdoc_id
is lazy
do
224 if mgroup
!= null then
225 if mgroup
.mmodules
.length
== 1 then
226 return "{mgroup.nitdoc_id}-"
228 return "{mgroup.nitdoc_id}__{name.to_cmangle}"
231 return name
.to_cmangle
234 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
236 redef fun tpl_declaration
do
237 var tpl
= new Template
238 tpl
.add
"<span>module "
239 tpl
.add tpl_namespace
244 redef fun tpl_namespace
do
245 var tpl
= new Template
246 if mgroup
!= null then
247 tpl
.add mgroup
.tpl_namespace
254 redef fun tpl_definition
do
255 var tpl
= new TplClassDefinition
256 var mdoc
= mdoc_or_fallback
258 tpl
.comment
= mdoc
.tpl_comment
263 redef fun tpl_css_classes
do return ["public"]
267 redef var nitdoc_id
= "{intro_mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
268 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
269 redef fun mdoc_or_fallback
do return intro
.mdoc
272 redef var html_name
is lazy
do
273 var tpl
= new Template
274 tpl
.add name
.html_escape
277 var parameter_names
= new Array[String]
278 for p
in mparameters
do
279 parameter_names
.add
(p
.html_name
)
281 tpl
.add parameter_names
.join
(", ")
284 return tpl
.write_to_string
287 redef fun tpl_declaration
do return intro
.tpl_declaration
288 redef fun tpl_definition
do return intro
.tpl_definition
290 redef fun tpl_namespace
do
291 var tpl
= new Template
292 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
299 redef fun tpl_title
do
300 var title
= new Template
306 redef fun tpl_icon
do return intro
.tpl_icon
308 fun tpl_signature
: Template do
309 var tpl
= new Template
312 var parameter_names
= new Array[String]
313 for p
in mparameters
do
314 parameter_names
.add
(p
.html_name
)
316 tpl
.add parameter_names
.join
(", ")
322 redef fun tpl_css_classes
do return intro
.tpl_css_classes
325 redef class MClassDef
326 redef var nitdoc_id
= "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
327 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
329 redef fun mdoc_or_fallback
do return mdoc
or else mclass
.mdoc_or_fallback
331 redef fun tpl_namespace
do
332 var tpl
= new Template
333 tpl
.add mmodule
.tpl_namespace
335 tpl
.add mclass
.html_link
340 redef fun tpl_article
do
341 var tpl
= new TplArticle(nitdoc_id
)
342 tpl
.summary_title
= "in {mmodule.html_name}"
343 tpl
.title
= tpl_declaration
344 tpl
.title_classes
.add
"signature"
345 var title
= new Template
347 title
.add mmodule
.tpl_namespace
349 var mdoc
= mdoc_or_fallback
351 tpl
.content
= mdoc
.tpl_comment
356 redef fun tpl_title
do
357 var title
= new Template
363 redef fun tpl_declaration
do
364 var tpl
= new Template
365 tpl
.add tpl_modifiers
367 tpl
.add tpl_signature
371 fun tpl_signature
: Template do
372 var tpl
= new Template
373 var mparameters
= mclass
.mparameters
374 if not mparameters
.is_empty
then
376 for i
in [0..mparameters
.length
[ do
377 tpl
.add
"{mparameters[i].html_name}: "
378 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
379 if i
< mparameters
.length
- 1 then tpl
.add
", "
386 redef fun tpl_definition
do
387 var tpl
= new TplClassDefinition
388 var mdoc
= mdoc_or_fallback
390 tpl
.comment
= mdoc
.tpl_comment
395 redef fun tpl_css_classes
do
396 var set
= new HashSet[String]
397 if is_intro
then set
.add
"intro"
398 for m
in mclass
.intro
.modifiers
do set
.add m
.to_cmangle
399 for m
in modifiers
do set
.add m
.to_cmangle
403 fun tpl_modifiers
: Template do
404 var tpl
= new Template
405 for modifier
in modifiers
do
406 if modifier
== "public" then continue
407 tpl
.add
"{modifier.html_escape} "
413 redef class MProperty
414 redef var nitdoc_id
= "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}" is lazy
415 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
417 redef fun mdoc_or_fallback
do return intro
.mdoc
419 redef fun tpl_namespace
do
420 var tpl
= new Template
421 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
423 tpl
.add intro
.html_link
428 redef fun tpl_declaration
do return intro
.tpl_declaration
430 fun tpl_signature
: Template do return new Template
432 redef fun tpl_title
do return intro
.tpl_title
434 redef fun tpl_icon
do return intro
.tpl_icon
436 redef fun tpl_css_classes
do return intro
.tpl_css_classes
440 redef var nitdoc_id
= "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
441 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
443 redef fun mdoc_or_fallback
do return mdoc
or else mproperty
.mdoc_or_fallback
445 redef fun tpl_namespace
do
446 var tpl
= new Template
447 tpl
.add mclassdef
.tpl_namespace
453 redef fun tpl_article
do
454 var tpl
= new TplArticle(nitdoc_id
)
455 tpl
.summary_title
= "in {mclassdef.html_name}"
456 var title
= new Template
458 title
.add mclassdef
.html_link
460 tpl
.subtitle
= tpl_declaration
461 var mdoc
= mdoc_or_fallback
463 tpl
.content
= mdoc
.tpl_comment
468 redef fun tpl_definition
do
469 var tpl
= new TplDefinition
470 var mdoc
= mdoc_or_fallback
472 tpl
.comment
= mdoc
.tpl_comment
477 redef fun tpl_declaration
do
478 var tpl
= new Template
479 tpl
.add tpl_modifiers
481 tpl
.add tpl_signature
485 redef fun tpl_css_classes
do
486 var set
= new HashSet[String]
487 if is_intro
then set
.add
"intro"
488 for m
in mproperty
.intro
.modifiers
do set
.add m
.to_cmangle
489 for m
in modifiers
do set
.add m
.to_cmangle
493 fun tpl_modifiers
: Template do
494 var tpl
= new Template
495 for modifier
in modifiers
do
496 if modifier
== "public" then continue
497 tpl
.add
"{modifier.html_escape} "
502 fun tpl_signature
: Template do return new Template
504 redef fun tpl_list_item
do
505 var lnk
= new Template
506 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
507 var atext
= html_link
.text
508 var ahref
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
509 var atitle
= html_link
.title
510 var anchor
= new Link.with_title
(ahref
, atext
, atitle
)
512 var mdoc
= mdoc_or_fallback
515 lnk
.add mdoc
.tpl_short_comment
517 return new TplListItem.with_content
(lnk
)
520 fun tpl_inheritance_item
: TplListItem do
521 var lnk
= new Template
522 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
523 lnk
.add mclassdef
.mmodule
.tpl_namespace
525 var atext
= mclassdef
.html_link
.text
526 var ahref
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
527 var atitle
= mclassdef
.html_link
.title
528 var anchor
= new Link.with_title
(ahref
, atext
, atitle
)
530 var mdoc
= mdoc_or_fallback
533 lnk
.add mdoc
.tpl_short_comment
535 var li
= new TplListItem.with_content
(lnk
)
536 li
.css_classes
.add
"signature"
541 redef class MAttributeDef
542 redef fun tpl_signature
do
543 var tpl
= new Template
544 if static_mtype
!= null then
546 tpl
.add static_mtype
.tpl_signature
553 redef fun tpl_signature
do
554 var tpl
= new Template
555 var params
= new Array[String]
556 for param
in intro
.msignature
.mparameters
do
557 params
.add param
.name
.html_escape
559 if not params
.is_empty
then
561 tpl
.add params
.join
(", ")
568 redef class MMethodDef
569 redef fun tpl_signature
do return msignature
.tpl_signature
572 redef class MVirtualTypeProp
573 redef fun html_link
do return mvirtualtype
.html_link
574 redef fun tpl_signature
do return html_link
577 redef class MVirtualTypeDef
578 redef fun tpl_signature
do
579 var tpl
= new Template
580 if bound
== null then return tpl
582 tpl
.add bound
.tpl_signature
588 fun tpl_signature
: Template is abstract
591 redef class MClassType
592 redef fun html_link
do return mclass
.html_link
593 redef fun tpl_signature
do return html_link
596 redef class MNullableType
597 redef fun tpl_signature
do
598 var tpl
= new Template
600 tpl
.add mtype
.tpl_signature
605 redef class MGenericType
606 redef fun tpl_signature
do
608 var tpl
= new Template
609 tpl
.add
new Link.with_title
(lnk
.href
, mclass
.name
.html_escape
, lnk
.title
)
611 for i
in [0..arguments
.length
[ do
612 tpl
.add arguments
[i
].tpl_signature
613 if i
< arguments
.length
- 1 then tpl
.add
", "
620 redef class MParameterType
621 redef fun html_link
do
622 return new Link.with_title
("{mclass.nitdoc_url}#FT_{name.to_cmangle}", name
, "formal type")
624 redef fun tpl_signature
do return html_link
627 redef class MVirtualType
628 redef fun html_link
do return mproperty
.intro
.html_link
629 redef fun tpl_signature
do return html_link
632 redef class MSignature
633 redef fun tpl_signature
do
634 var tpl
= new Template
635 if not mparameters
.is_empty
then
637 for i
in [0..mparameters
.length
[ do
638 tpl
.add mparameters
[i
].tpl_signature
639 if i
< mparameters
.length
- 1 then tpl
.add
", "
643 if return_mtype
!= null then
645 tpl
.add return_mtype
.tpl_signature
651 redef class MParameter
652 fun tpl_signature
: Template do
653 var tpl
= new Template
655 tpl
.add mtype
.tpl_signature
656 if is_vararg
then tpl
.add
"..."
661 redef class ConcernsTree
663 private var seen
= new HashSet[MConcern]
665 redef fun add
(p
, e
) do
666 if seen
.has
(e
) then return
671 fun to_tpl
: TplList do
672 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
674 var li
= r
.tpl_concern_item
681 private fun build_list
(e
: MConcern, li
: TplListItem) do
682 if not sub
.has_key
(e
) then return
684 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
686 if e2
isa MGroup and e2
.is_root
then
689 var sli
= e2
.tpl_concern_item
699 ################################################################################
700 # Additions to `model_ext`.
703 redef fun tpl_signature
do
704 var tpl
= new Template
707 if part
.target
!= null then
708 tpl
.add part
.target
.as(not null).html_link
710 tpl
.add part
.text
.html_escape
717 redef class MInnerClass
718 redef fun nitdoc_url
do return inner
.nitdoc_url
719 redef fun tpl_signature
do return inner
.tpl_signature
722 redef class MInnerClassDef
723 redef fun nitdoc_url
do return inner
.nitdoc_url
725 redef fun html_link_to_anchor
do return inner
.html_link_to_anchor
726 redef fun html_link
do return inner
.html_link
727 redef fun tpl_signature
do return inner
.tpl_signature
729 redef fun tpl_definition
do
730 var tpl
= new TplClassDefinition
731 var mdoc
= mdoc_or_fallback
733 tpl
.comment
= mdoc
.tpl_comment