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 # Nitdoc model template parts generation
25 ################################################################################
26 # Additions to Nit entities.
29 # Comment synopsys HTML escaped
30 fun short_comment
: String do return content
.first
.html_escape
32 # Full comment HTML escaped
33 fun full_comment
: String do return content
.join
("\n").html_escape
35 # Synopsys in a template
36 fun tpl_short_comment
: Streamable do return short_markdown
38 # Full comment in a template
39 fun tpl_comment
: Streamable do return full_markdown
43 # Github url based on this location
44 fun github
(gitdir
: String): String do
45 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
46 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
47 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
48 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
54 fun nitdoc_name
: String is abstract
56 # Used as HTML unique ids
57 fun nitdoc_id
: String is abstract
59 # URL of this entity Nitdoc page
60 fun nitdoc_url
: String is abstract
62 # A template link to the mentity `nitdoc_id`
63 fun tpl_anchor
: TplLink do
64 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
66 tpl
.title
= mdoc
.short_comment
71 # A template link to the mentity `nitdoc_url`
72 fun tpl_link
: TplLink do
73 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
75 tpl
.title
= mdoc
.short_comment
80 # A template article that briefly describe the entity
81 fun tpl_short_article
: TplArticle do
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
= nitdoc_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
)
115 lnk
.add mdoc
.short_markdown
117 return new TplListItem.with_content
(lnk
)
120 fun tpl_css_classes
: Array[String] is abstract
122 # Box title for this mentity
123 fun tpl_title
: Template do
124 var title
= new Template
126 title
.add tpl_namespace
130 # Icon that will be displayed before the title
131 fun tpl_icon
: TplIcon do
132 var icon
= new TplIcon.with_icon
("tag")
133 icon
.css_classes
.add_all
(tpl_css_classes
)
139 # Return a li element for `self` that can be displayed in a concern list
140 private fun tpl_concern_item
: TplListItem do
141 var lnk
= new Template
145 lnk
.add mdoc
.short_markdown
147 return new TplListItem.with_content
(lnk
)
152 redef fun nitdoc_name
do return name
.html_escape
153 redef fun nitdoc_id
do return nitdoc_name
154 redef fun nitdoc_url
do return root
.nitdoc_url
163 redef fun tpl_declaration
do
164 var tpl
= new Template
165 tpl
.add
"<span>project "
171 redef fun tpl_namespace
do return tpl_link
173 redef fun tpl_definition
do
174 var tpl
= new TplDefinition
175 var mdoc
= mdoc_or_fallback
177 tpl
.comment
= mdoc
.tpl_comment
182 redef fun tpl_css_classes
do return ["public"]
186 redef fun nitdoc_name
do return name
.html_escape
188 redef fun nitdoc_id
do
189 if parent
!= null then
190 return "{parent.nitdoc_id}__{nitdoc_name}"
192 return "{mproject.nitdoc_id}__{nitdoc_name}"
195 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
197 redef fun tpl_namespace
do
198 var tpl
= new Template
199 tpl
.add mproject
.tpl_namespace
200 if mproject
.root
!= self then
207 redef fun tpl_declaration
do
208 var tpl
= new Template
209 tpl
.add
"<span>group "
215 redef fun tpl_definition
do
216 var tpl
= new TplDefinition
217 var mdoc
= mdoc_or_fallback
219 tpl
.comment
= mdoc
.tpl_comment
226 redef fun nitdoc_name
do return name
.html_escape
228 redef fun nitdoc_id
do
229 if mgroup
!= null then
230 return "{mgroup.nitdoc_id}__{nitdoc_name}"
235 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
237 redef fun tpl_declaration
do
238 var tpl
= new Template
239 tpl
.add
"<span>module "
240 tpl
.add tpl_namespace
245 redef fun tpl_namespace
do
246 var tpl
= new Template
247 if mgroup
!= null then
248 tpl
.add mgroup
.tpl_namespace
255 redef fun tpl_definition
do
256 var tpl
= new TplClassDefinition
258 tpl
.comment
= mdoc
.tpl_comment
263 redef fun tpl_css_classes
do return ["public"]
267 redef fun nitdoc_name
do return name
.html_escape
268 redef fun nitdoc_id
do return "{intro_mmodule.mgroup.mproject}__{name.to_cmangle}"
269 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
270 redef fun mdoc
do return intro
.mdoc
272 redef fun tpl_declaration
do return intro
.tpl_declaration
274 redef fun tpl_namespace
do
275 var tpl
= new Template
276 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
283 redef fun tpl_title
do
284 var title
= new Template
287 title
.add tpl_signature
291 redef fun tpl_icon
do return intro
.tpl_icon
293 fun tpl_signature
: Template do
294 var tpl
= new Template
297 var parameter_names
= new Array[String]
298 for p
in mparameters
do
299 parameter_names
.add
(p
.name
)
301 tpl
.add parameter_names
.join
(", ")
307 redef fun tpl_article
do
309 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
313 redef fun tpl_css_classes
do return intro
.tpl_css_classes
316 redef class MClassDef
317 redef fun nitdoc_name
do return mclass
.nitdoc_name
318 redef fun nitdoc_id
do return "{mmodule.nitdoc_id}__{name.to_cmangle}"
319 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
321 redef fun tpl_namespace
do
322 var tpl
= new Template
323 tpl
.add mmodule
.tpl_namespace
325 tpl
.add mclass
.tpl_link
330 redef fun tpl_article
do
331 var tpl
= new TplArticle(nitdoc_id
)
332 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
333 tpl
.title
= tpl_declaration
334 tpl
.title_classes
.add
"signature"
335 var title
= new Template
337 title
.add mmodule
.tpl_namespace
340 tpl
.content
= mdoc
.tpl_comment
345 redef fun tpl_title
do
346 var title
= new Template
349 title
.add tpl_signature
353 redef fun tpl_declaration
do
354 var tpl
= new Template
355 tpl
.add tpl_modifiers
357 tpl
.add tpl_signature
361 fun tpl_signature
: Template do
362 var tpl
= new Template
363 var mparameters
= mclass
.mparameters
364 if not mparameters
.is_empty
then
366 for i
in [0..mparameters
.length
[ do
367 tpl
.add
"{mparameters[i].name}: "
368 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
369 if i
< mparameters
.length
- 1 then tpl
.add
", "
376 redef fun tpl_definition
do
377 var tpl
= new TplClassDefinition
378 tpl
.namespace
= tpl_namespace
380 tpl
.comment
= mdoc
.tpl_comment
385 redef fun tpl_css_classes
do
386 var set
= new HashSet[String]
387 if is_intro
then set
.add
"intro"
388 set
.add_all mclass
.intro
.modifiers
389 set
.add_all modifiers
393 fun tpl_modifiers
: Template do
394 var tpl
= new Template
395 for modifier
in modifiers
do
396 if modifier
== "public" then continue
397 tpl
.add
"{modifier} "
402 redef fun tpl_list_item
do
403 var lnk
= new Template
404 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
408 lnk
.add mdoc
.short_markdown
409 else if mclass
.intro
.mdoc
!= null then
411 lnk
.add mclass
.intro
.mdoc
.short_markdown
413 return new TplListItem.with_content
(lnk
)
416 redef fun tpl_anchor
: TplLink do
417 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
419 tpl
.title
= mdoc
.short_comment
420 else if mclass
.intro
.mdoc
!= null then
421 tpl
.title
= mclass
.intro
.mdoc
.short_comment
426 redef fun tpl_link
: TplLink do
427 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
429 tpl
.title
= mdoc
.short_comment
430 else if mclass
.intro
.mdoc
!= null then
431 tpl
.title
= mclass
.intro
.mdoc
.short_comment
437 redef class MProperty
438 redef fun nitdoc_name
do return name
.html_escape
439 redef fun nitdoc_id
do return "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}"
440 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
442 redef fun mdoc
do return intro
.mdoc
444 redef fun tpl_namespace
do
445 var tpl
= new Template
446 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
448 tpl
.add intro
.tpl_link
453 redef fun tpl_declaration
do return intro
.tpl_declaration
455 fun tpl_signature
: Template do return new Template
457 redef fun tpl_title
do return intro
.tpl_title
459 redef fun tpl_icon
do return intro
.tpl_icon
461 redef fun tpl_css_classes
do return intro
.tpl_css_classes
465 redef fun nitdoc_name
do return mproperty
.nitdoc_name
466 redef fun nitdoc_id
do return "{mclassdef.nitdoc_id}__{name.to_cmangle}"
467 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
469 redef fun tpl_anchor
: TplLink do
470 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
472 tpl
.title
= mdoc
.short_comment
473 else if mproperty
.intro
.mdoc
!= null then
474 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
479 redef fun tpl_link
: TplLink do
480 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
482 tpl
.title
= mdoc
.short_comment
483 else if mproperty
.intro
.mdoc
!= null then
484 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
489 redef fun tpl_namespace
do
490 var tpl
= new Template
491 tpl
.add mclassdef
.tpl_namespace
497 redef fun tpl_article
do
498 var tpl
= new TplArticle(nitdoc_id
)
499 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
500 var title
= new Template
502 title
.add mclassdef
.tpl_link
504 tpl
.subtitle
= tpl_declaration
506 tpl
.content
= mdoc
.tpl_comment
511 redef fun tpl_definition
do
512 var tpl
= new TplDefinition
513 tpl
.namespace
= mclassdef
.tpl_namespace
515 tpl
.comment
= mdoc
.tpl_comment
520 redef fun tpl_declaration
do
521 var tpl
= new Template
522 tpl
.add tpl_modifiers
524 tpl
.add tpl_signature
528 redef fun tpl_css_classes
do
529 var set
= new HashSet[String]
530 if is_intro
then set
.add
"intro"
531 set
.add_all mproperty
.intro
.modifiers
532 set
.add_all modifiers
536 fun tpl_modifiers
: Template do
537 var tpl
= new Template
538 for modifier
in modifiers
do
539 if modifier
== "public" then continue
540 tpl
.add
"{modifier} "
545 fun tpl_signature
: Template do return new Template
547 redef fun tpl_list_item
do
548 var lnk
= new Template
549 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
550 var anchor
= tpl_link
551 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
555 lnk
.add mdoc
.short_markdown
556 else if mproperty
.intro
.mdoc
!= null then
558 lnk
.add mproperty
.intro
.mdoc
.short_markdown
560 return new TplListItem.with_content
(lnk
)
563 fun tpl_inheritance_item
: TplListItem do
564 var lnk
= new Template
565 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
566 lnk
.add mclassdef
.mmodule
.tpl_namespace
568 var anchor
= mclassdef
.tpl_link
569 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
573 lnk
.add mdoc
.short_markdown
575 var li
= new TplListItem.with_content
(lnk
)
576 li
.css_classes
.add
"signature"
581 redef class MAttributeDef
582 redef fun tpl_signature
do
583 var tpl
= new Template
584 if static_mtype
!= null then
586 tpl
.add static_mtype
.tpl_signature
593 redef fun tpl_signature
do
594 var tpl
= new Template
595 var params
= new Array[String]
596 for param
in intro
.msignature
.mparameters
do
597 params
.add param
.name
599 if not params
.is_empty
then
601 tpl
.add params
.join
(", ")
608 redef class MMethodDef
609 redef fun tpl_signature
do return msignature
.tpl_signature
612 redef class MVirtualTypeProp
613 redef fun tpl_link
do return mvirtualtype
.tpl_link
614 redef fun tpl_signature
do return tpl_link
617 redef class MVirtualTypeDef
618 redef fun tpl_signature
do
619 var tpl
= new Template
621 tpl
.add bound
.tpl_signature
626 redef class MInnerClass
627 redef fun nitdoc_url
do return inner
.nitdoc_url
628 redef fun tpl_signature
do return inner
.tpl_signature
631 redef class MInnerClassDef
632 redef fun nitdoc_url
do return inner
.nitdoc_url
634 redef fun tpl_anchor
do return inner
.tpl_anchor
635 redef fun tpl_link
do return inner
.tpl_link
636 redef fun tpl_signature
do return inner
.tpl_signature
638 redef fun tpl_definition
do
639 var tpl
= new TplClassDefinition
640 tpl
.namespace
= mclassdef
.tpl_namespace
642 tpl
.comment
= mdoc
.tpl_comment
649 fun tpl_signature
: Template is abstract
652 redef class MClassType
653 redef fun tpl_link
do return mclass
.tpl_link
654 redef fun tpl_signature
do return tpl_link
657 redef class MNullableType
658 redef fun tpl_signature
do
659 var tpl
= new Template
661 tpl
.add mtype
.tpl_signature
666 redef class MGenericType
667 redef fun tpl_signature
do
668 var tpl
= new Template
671 for i
in [0..arguments
.length
[ do
672 tpl
.add arguments
[i
].tpl_signature
673 if i
< arguments
.length
- 1 then tpl
.add
", "
680 redef class MParameterType
681 redef fun tpl_link
do
682 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
684 redef fun tpl_signature
do return tpl_link
687 redef class MVirtualType
688 redef fun tpl_link
do return mproperty
.intro
.tpl_link
689 redef fun tpl_signature
do return tpl_link
692 redef class MSignature
693 redef fun tpl_signature
do
694 var tpl
= new Template
695 if not mparameters
.is_empty
then
697 for i
in [0..mparameters
.length
[ do
698 tpl
.add mparameters
[i
].tpl_signature
699 if i
< mparameters
.length
- 1 then tpl
.add
", "
703 if return_mtype
!= null then
705 tpl
.add return_mtype
.tpl_signature
711 redef class MParameter
712 fun tpl_signature
: Template do
713 var tpl
= new Template
715 tpl
.add mtype
.tpl_signature
716 if is_vararg
then tpl
.add
"..."
721 redef class ConcernsTree
723 private var seen
= new HashSet[MConcern]
725 redef fun add
(p
, e
) do
726 if seen
.has
(e
) then return
731 fun to_tpl
: TplList do
732 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
734 var li
= r
.tpl_concern_item
741 private fun build_list
(e
: MConcern, li
: TplListItem) do
742 if not sub
.has_key
(e
) then return
744 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
746 if e2
isa MGroup and e2
.is_root
then
749 var sli
= e2
.tpl_concern_item
759 ################################################################################
760 # Additions to `model_ext`.
763 redef fun tpl_signature
do
764 var tpl
= new Template
767 if part
.target
!= null then
768 tpl
.add part
.target
.as(not null).tpl_link
770 tpl
.add part
.text
.html_escape