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 # 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}"
36 fun nitdoc_name
: String is abstract
38 # Used as HTML unique ids
39 fun nitdoc_id
: String is abstract
41 # URL of this entity Nitdoc page
42 fun nitdoc_url
: String is abstract
44 # A template link to the mentity `nitdoc_id`
45 fun tpl_anchor
: TplLink do
46 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
48 tpl
.title
= mdoc
.short_comment
53 # A template link to the mentity `nitdoc_url`
54 fun tpl_link
: TplLink do
55 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
57 tpl
.title
= mdoc
.short_comment
62 # A template article that briefly describe the entity
63 fun tpl_short_article
: TplArticle do
66 tpl
.content
= mdoc
.tpl_short_comment
71 # A template article that describe the entity
72 fun tpl_article
: TplArticle do
73 var tpl
= new TplArticle.with_title
(nitdoc_id
, tpl_title
)
74 tpl
.title_classes
.add
"signature"
75 tpl
.subtitle
= tpl_namespace
76 tpl
.summary_title
= nitdoc_name
80 # A template signature that contains modifiers and parameters
81 fun tpl_declaration
: Template is abstract
83 # A template namespace
84 fun tpl_namespace
: Template is abstract
86 # A template definition of the mentity
87 # include name, sysnopsys, comment and namespace
88 fun tpl_definition
: TplDefinition is abstract
90 # A li element that can go in a list
91 fun tpl_list_item
: TplListItem do
92 var lnk
= new Template
93 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
97 lnk
.add mdoc
.tpl_short_comment
99 return new TplListItem.with_content
(lnk
)
102 fun tpl_css_classes
: Array[String] is abstract
104 # Box title for this mentity
105 fun tpl_title
: Template do
106 var title
= new Template
108 title
.add tpl_namespace
112 # Icon that will be displayed before the title
113 fun tpl_icon
: TplIcon do
114 var icon
= new TplIcon.with_icon
("tag")
115 icon
.css_classes
.add_all
(tpl_css_classes
)
121 # Return a li element for `self` that can be displayed in a concern list
122 private fun tpl_concern_item
: TplListItem do
123 var lnk
= new Template
127 lnk
.add mdoc
.tpl_short_comment
129 return new TplListItem.with_content
(lnk
)
134 redef fun nitdoc_name
do return name
.html_escape
135 redef fun nitdoc_id
do return nitdoc_name
136 redef fun nitdoc_url
do return root
.nitdoc_url
145 redef fun tpl_declaration
do
146 var tpl
= new Template
147 tpl
.add
"<span>project "
153 redef fun tpl_namespace
do return tpl_link
155 redef fun tpl_definition
do
156 var tpl
= new TplDefinition
157 var mdoc
= mdoc_or_fallback
159 tpl
.comment
= mdoc
.tpl_comment
164 redef fun tpl_css_classes
do return ["public"]
168 redef fun nitdoc_name
do return name
.html_escape
170 redef fun nitdoc_id
do
171 if parent
!= null then
172 return "{parent.nitdoc_id}__{nitdoc_name}"
174 return "{mproject.nitdoc_id}__{nitdoc_name}"
177 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
179 redef fun tpl_namespace
do
180 var tpl
= new Template
181 tpl
.add mproject
.tpl_namespace
182 if mproject
.root
!= self then
189 redef fun tpl_declaration
do
190 var tpl
= new Template
191 tpl
.add
"<span>group "
197 redef fun tpl_definition
do
198 var tpl
= new TplDefinition
199 var mdoc
= mdoc_or_fallback
201 tpl
.comment
= mdoc
.tpl_comment
208 redef fun nitdoc_name
do return name
.html_escape
210 redef fun nitdoc_id
do
211 if mgroup
!= null then
212 return "{mgroup.nitdoc_id}__{nitdoc_name}"
217 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
219 redef fun tpl_declaration
do
220 var tpl
= new Template
221 tpl
.add
"<span>module "
222 tpl
.add tpl_namespace
227 redef fun tpl_namespace
do
228 var tpl
= new Template
229 if mgroup
!= null then
230 tpl
.add mgroup
.tpl_namespace
237 redef fun tpl_definition
do
238 var tpl
= new TplClassDefinition
240 tpl
.comment
= mdoc
.tpl_comment
245 redef fun tpl_css_classes
do return ["public"]
249 redef fun nitdoc_name
do return name
.html_escape
250 redef fun nitdoc_id
do return "{intro_mmodule.mgroup.mproject}__{name.to_cmangle}"
251 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
252 redef fun mdoc
do return intro
.mdoc
254 redef fun tpl_declaration
do return intro
.tpl_declaration
256 redef fun tpl_namespace
do
257 var tpl
= new Template
258 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
265 redef fun tpl_title
do
266 var title
= new Template
269 title
.add tpl_signature
273 redef fun tpl_icon
do return intro
.tpl_icon
275 fun tpl_signature
: Template do
276 var tpl
= new Template
279 var parameter_names
= new Array[String]
280 for p
in mparameters
do
281 parameter_names
.add
(p
.name
)
283 tpl
.add parameter_names
.join
(", ")
289 redef fun tpl_article
do
291 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
295 redef fun tpl_css_classes
do return intro
.tpl_css_classes
298 redef class MClassDef
299 redef fun nitdoc_name
do return mclass
.nitdoc_name
300 redef fun nitdoc_id
do return "{mmodule.nitdoc_id}__{name.to_cmangle}"
301 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
303 redef fun tpl_namespace
do
304 var tpl
= new Template
305 tpl
.add mmodule
.tpl_namespace
307 tpl
.add mclass
.tpl_link
312 redef fun tpl_article
do
313 var tpl
= new TplArticle(nitdoc_id
)
314 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
315 tpl
.title
= tpl_declaration
316 tpl
.title_classes
.add
"signature"
317 var title
= new Template
319 title
.add mmodule
.tpl_namespace
322 tpl
.content
= mdoc
.tpl_comment
327 redef fun tpl_title
do
328 var title
= new Template
331 title
.add tpl_signature
335 redef fun tpl_declaration
do
336 var tpl
= new Template
337 tpl
.add tpl_modifiers
339 tpl
.add tpl_signature
343 fun tpl_signature
: Template do
344 var tpl
= new Template
345 var mparameters
= mclass
.mparameters
346 if not mparameters
.is_empty
then
348 for i
in [0..mparameters
.length
[ do
349 tpl
.add
"{mparameters[i].name}: "
350 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
351 if i
< mparameters
.length
- 1 then tpl
.add
", "
358 redef fun tpl_definition
do
359 var tpl
= new TplClassDefinition
360 tpl
.namespace
= tpl_namespace
362 tpl
.comment
= mdoc
.tpl_comment
367 redef fun tpl_css_classes
do
368 var set
= new HashSet[String]
369 if is_intro
then set
.add
"intro"
370 set
.add_all mclass
.intro
.modifiers
371 set
.add_all modifiers
375 fun tpl_modifiers
: Template do
376 var tpl
= new Template
377 for modifier
in modifiers
do
378 if modifier
== "public" then continue
379 tpl
.add
"{modifier} "
384 redef fun tpl_list_item
do
385 var lnk
= new Template
386 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
390 lnk
.add mdoc
.tpl_short_comment
391 else if mclass
.intro
.mdoc
!= null then
393 lnk
.add mclass
.intro
.mdoc
.tpl_short_comment
395 return new TplListItem.with_content
(lnk
)
398 redef fun tpl_anchor
: TplLink do
399 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
401 tpl
.title
= mdoc
.short_comment
402 else if mclass
.intro
.mdoc
!= null then
403 tpl
.title
= mclass
.intro
.mdoc
.short_comment
408 redef fun tpl_link
: TplLink do
409 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
411 tpl
.title
= mdoc
.short_comment
412 else if mclass
.intro
.mdoc
!= null then
413 tpl
.title
= mclass
.intro
.mdoc
.short_comment
419 redef class MProperty
420 redef fun nitdoc_name
do return name
.html_escape
421 redef fun nitdoc_id
do return "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}"
422 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
424 redef fun mdoc
do return intro
.mdoc
426 redef fun tpl_namespace
do
427 var tpl
= new Template
428 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
430 tpl
.add intro
.tpl_link
435 redef fun tpl_declaration
do return intro
.tpl_declaration
437 fun tpl_signature
: Template do return new Template
439 redef fun tpl_title
do return intro
.tpl_title
441 redef fun tpl_icon
do return intro
.tpl_icon
443 redef fun tpl_css_classes
do return intro
.tpl_css_classes
447 redef fun nitdoc_name
do return mproperty
.nitdoc_name
448 redef fun nitdoc_id
do return "{mclassdef.nitdoc_id}__{name.to_cmangle}"
449 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
451 redef fun tpl_anchor
: TplLink do
452 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
454 tpl
.title
= mdoc
.short_comment
455 else if mproperty
.intro
.mdoc
!= null then
456 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
461 redef fun tpl_link
: TplLink do
462 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
464 tpl
.title
= mdoc
.short_comment
465 else if mproperty
.intro
.mdoc
!= null then
466 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
471 redef fun tpl_namespace
do
472 var tpl
= new Template
473 tpl
.add mclassdef
.tpl_namespace
479 redef fun tpl_article
do
480 var tpl
= new TplArticle(nitdoc_id
)
481 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
482 var title
= new Template
484 title
.add mclassdef
.tpl_link
486 tpl
.subtitle
= tpl_declaration
488 tpl
.content
= mdoc
.tpl_comment
493 redef fun tpl_definition
do
494 var tpl
= new TplDefinition
495 tpl
.namespace
= mclassdef
.tpl_namespace
497 tpl
.comment
= mdoc
.tpl_comment
502 redef fun tpl_declaration
do
503 var tpl
= new Template
504 tpl
.add tpl_modifiers
506 tpl
.add tpl_signature
510 redef fun tpl_css_classes
do
511 var set
= new HashSet[String]
512 if is_intro
then set
.add
"intro"
513 set
.add_all mproperty
.intro
.modifiers
514 set
.add_all modifiers
518 fun tpl_modifiers
: Template do
519 var tpl
= new Template
520 for modifier
in modifiers
do
521 if modifier
== "public" then continue
522 tpl
.add
"{modifier} "
527 fun tpl_signature
: Template do return new Template
529 redef fun tpl_list_item
do
530 var lnk
= new Template
531 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
532 var anchor
= tpl_link
533 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
537 lnk
.add mdoc
.tpl_short_comment
538 else if mproperty
.intro
.mdoc
!= null then
540 lnk
.add mproperty
.intro
.mdoc
.tpl_short_comment
542 return new TplListItem.with_content
(lnk
)
545 fun tpl_inheritance_item
: TplListItem do
546 var lnk
= new Template
547 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
548 lnk
.add mclassdef
.mmodule
.tpl_namespace
550 var anchor
= mclassdef
.tpl_link
551 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
555 lnk
.add mdoc
.tpl_short_comment
557 var li
= new TplListItem.with_content
(lnk
)
558 li
.css_classes
.add
"signature"
563 redef class MAttributeDef
564 redef fun tpl_signature
do
565 var tpl
= new Template
566 if static_mtype
!= null then
568 tpl
.add static_mtype
.tpl_signature
575 redef fun tpl_signature
do
576 var tpl
= new Template
577 var params
= new Array[String]
578 for param
in intro
.msignature
.mparameters
do
579 params
.add param
.name
581 if not params
.is_empty
then
583 tpl
.add params
.join
(", ")
590 redef class MMethodDef
591 redef fun tpl_signature
do return msignature
.tpl_signature
594 redef class MVirtualTypeProp
595 redef fun tpl_link
do return mvirtualtype
.tpl_link
596 redef fun tpl_signature
do return tpl_link
599 redef class MVirtualTypeDef
600 redef fun tpl_signature
do
601 var tpl
= new Template
603 tpl
.add bound
.tpl_signature
608 redef class MInnerClass
609 redef fun nitdoc_url
do return inner
.nitdoc_url
610 redef fun tpl_signature
do return inner
.tpl_signature
613 redef class MInnerClassDef
614 redef fun nitdoc_url
do return inner
.nitdoc_url
616 redef fun tpl_anchor
do return inner
.tpl_anchor
617 redef fun tpl_link
do return inner
.tpl_link
618 redef fun tpl_signature
do return inner
.tpl_signature
620 redef fun tpl_definition
do
621 var tpl
= new TplClassDefinition
622 tpl
.namespace
= mclassdef
.tpl_namespace
624 tpl
.comment
= mdoc
.tpl_comment
631 fun tpl_signature
: Template is abstract
634 redef class MClassType
635 redef fun tpl_link
do return mclass
.tpl_link
636 redef fun tpl_signature
do return tpl_link
639 redef class MNullableType
640 redef fun tpl_signature
do
641 var tpl
= new Template
643 tpl
.add mtype
.tpl_signature
648 redef class MGenericType
649 redef fun tpl_signature
do
650 var tpl
= new Template
653 for i
in [0..arguments
.length
[ do
654 tpl
.add arguments
[i
].tpl_signature
655 if i
< arguments
.length
- 1 then tpl
.add
", "
662 redef class MParameterType
663 redef fun tpl_link
do
664 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
666 redef fun tpl_signature
do return tpl_link
669 redef class MVirtualType
670 redef fun tpl_link
do return mproperty
.intro
.tpl_link
671 redef fun tpl_signature
do return tpl_link
674 redef class MSignature
675 redef fun tpl_signature
do
676 var tpl
= new Template
677 if not mparameters
.is_empty
then
679 for i
in [0..mparameters
.length
[ do
680 tpl
.add mparameters
[i
].tpl_signature
681 if i
< mparameters
.length
- 1 then tpl
.add
", "
685 if return_mtype
!= null then
687 tpl
.add return_mtype
.tpl_signature
693 redef class MParameter
694 fun tpl_signature
: Template do
695 var tpl
= new Template
697 tpl
.add mtype
.tpl_signature
698 if is_vararg
then tpl
.add
"..."
703 redef class ConcernsTree
705 private var seen
= new HashSet[MConcern]
707 redef fun add
(p
, e
) do
708 if seen
.has
(e
) then return
713 fun to_tpl
: TplList do
714 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
716 var li
= r
.tpl_concern_item
723 private fun build_list
(e
: MConcern, li
: TplListItem) do
724 if not sub
.has_key
(e
) then return
726 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
728 if e2
isa MGroup and e2
.is_root
then
731 var sli
= e2
.tpl_concern_item
741 ################################################################################
742 # Additions to `model_ext`.
745 redef fun tpl_signature
do
746 var tpl
= new Template
749 if part
.target
!= null then
750 tpl
.add part
.target
.as(not null).tpl_link
752 tpl
.add part
.text
.html_escape