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
176 tpl
.comment
= mdoc
.tpl_comment
181 redef fun tpl_css_classes
do return ["public"]
185 redef fun nitdoc_name
do return name
.html_escape
187 redef fun nitdoc_id
do
188 if parent
!= null then
189 return "{parent.nitdoc_id}__{nitdoc_name}"
191 return "{mproject.nitdoc_id}__{nitdoc_name}"
194 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
196 redef fun tpl_namespace
do
197 var tpl
= new Template
198 tpl
.add mproject
.tpl_namespace
199 if mproject
.root
!= self then
206 redef fun tpl_declaration
do
207 var tpl
= new Template
208 tpl
.add
"<span>group "
214 redef fun tpl_definition
do
215 var tpl
= new TplDefinition
217 tpl
.comment
= mdoc
.tpl_comment
224 redef fun nitdoc_name
do return name
.html_escape
226 redef fun nitdoc_id
do
227 if mgroup
!= null then
228 return "{mgroup.nitdoc_id}__{nitdoc_name}"
233 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
235 redef fun tpl_declaration
do
236 var tpl
= new Template
237 tpl
.add
"<span>module "
243 redef fun tpl_namespace
do
244 var tpl
= new Template
245 if mgroup
!= null then
246 tpl
.add mgroup
.tpl_namespace
253 redef fun tpl_definition
do
254 var tpl
= new TplClassDefinition
256 tpl
.comment
= mdoc
.tpl_comment
261 redef fun tpl_css_classes
do return ["public"]
265 redef fun nitdoc_name
do return name
.html_escape
266 redef fun nitdoc_id
do return "{intro_mmodule.mgroup.mproject}__{name.to_cmangle}"
267 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
268 redef fun mdoc
do return intro
.mdoc
270 redef fun tpl_declaration
do return intro
.tpl_declaration
272 redef fun tpl_namespace
do
273 var tpl
= new Template
274 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
281 redef fun tpl_title
do
282 var title
= new Template
285 title
.add tpl_signature
289 redef fun tpl_icon
do return intro
.tpl_icon
291 fun tpl_signature
: Template do
292 var tpl
= new Template
295 var parameter_names
= new Array[String]
296 for p
in mparameters
do
297 parameter_names
.add
(p
.name
)
299 tpl
.add parameter_names
.join
(", ")
305 redef fun tpl_article
do
307 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
311 redef fun tpl_css_classes
do return intro
.tpl_css_classes
314 redef class MClassDef
315 redef fun nitdoc_name
do return mclass
.nitdoc_name
316 redef fun nitdoc_id
do return "{mmodule.nitdoc_id}__{name.to_cmangle}"
317 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
319 redef fun tpl_namespace
do
320 var tpl
= new Template
321 tpl
.add mmodule
.tpl_namespace
323 tpl
.add mclass
.tpl_link
328 redef fun tpl_article
do
329 var tpl
= new TplArticle(nitdoc_id
)
330 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
331 tpl
.title
= tpl_declaration
332 tpl
.title_classes
.add
"signature"
333 var title
= new Template
335 title
.add mmodule
.tpl_namespace
338 tpl
.content
= mdoc
.tpl_comment
343 redef fun tpl_title
do
344 var title
= new Template
347 title
.add tpl_signature
351 redef fun tpl_declaration
do
352 var tpl
= new Template
353 tpl
.add tpl_modifiers
355 tpl
.add tpl_signature
359 fun tpl_signature
: Template do
360 var tpl
= new Template
361 var mparameters
= mclass
.mparameters
362 if not mparameters
.is_empty
then
364 for i
in [0..mparameters
.length
[ do
365 tpl
.add
"{mparameters[i].name}: "
366 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
367 if i
< mparameters
.length
- 1 then tpl
.add
", "
374 redef fun tpl_definition
do
375 var tpl
= new TplClassDefinition
376 tpl
.namespace
= tpl_namespace
378 tpl
.comment
= mdoc
.tpl_comment
383 redef fun tpl_css_classes
do
384 var set
= new HashSet[String]
385 if is_intro
then set
.add
"intro"
386 set
.add_all mclass
.intro
.modifiers
387 set
.add_all modifiers
391 fun tpl_modifiers
: Template do
392 var tpl
= new Template
393 for modifier
in modifiers
do
394 if modifier
== "public" then continue
395 tpl
.add
"{modifier} "
400 redef fun tpl_list_item
do
401 var lnk
= new Template
402 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
406 lnk
.add mdoc
.short_markdown
407 else if mclass
.intro
.mdoc
!= null then
409 lnk
.add mclass
.intro
.mdoc
.short_markdown
411 return new TplListItem.with_content
(lnk
)
414 redef fun tpl_anchor
: TplLink do
415 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
417 tpl
.title
= mdoc
.short_comment
418 else if mclass
.intro
.mdoc
!= null then
419 tpl
.title
= mclass
.intro
.mdoc
.short_comment
424 redef fun tpl_link
: TplLink do
425 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
427 tpl
.title
= mdoc
.short_comment
428 else if mclass
.intro
.mdoc
!= null then
429 tpl
.title
= mclass
.intro
.mdoc
.short_comment
435 redef class MProperty
436 redef fun nitdoc_name
do return name
.html_escape
437 redef fun nitdoc_id
do return "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}"
438 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
440 redef fun mdoc
do return intro
.mdoc
442 redef fun tpl_namespace
do
443 var tpl
= new Template
444 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
446 tpl
.add intro
.tpl_link
451 redef fun tpl_declaration
do return intro
.tpl_declaration
453 fun tpl_signature
: Template do return new Template
455 redef fun tpl_title
do return intro
.tpl_title
457 redef fun tpl_icon
do return intro
.tpl_icon
459 redef fun tpl_css_classes
do return intro
.tpl_css_classes
463 redef fun nitdoc_name
do return mproperty
.nitdoc_name
464 redef fun nitdoc_id
do return "{mclassdef.nitdoc_id}__{name.to_cmangle}"
465 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
467 redef fun tpl_anchor
: TplLink do
468 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
470 tpl
.title
= mdoc
.short_comment
471 else if mproperty
.intro
.mdoc
!= null then
472 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
477 redef fun tpl_link
: TplLink do
478 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
480 tpl
.title
= mdoc
.short_comment
481 else if mproperty
.intro
.mdoc
!= null then
482 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
487 redef fun tpl_namespace
do
488 var tpl
= new Template
489 tpl
.add mclassdef
.tpl_namespace
495 redef fun tpl_article
do
496 var tpl
= new TplArticle(nitdoc_id
)
497 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
498 var title
= new Template
500 title
.add mclassdef
.tpl_link
502 tpl
.subtitle
= tpl_declaration
504 tpl
.content
= mdoc
.tpl_comment
509 redef fun tpl_definition
do
510 var tpl
= new TplDefinition
511 tpl
.namespace
= mclassdef
.tpl_namespace
513 tpl
.comment
= mdoc
.tpl_comment
518 redef fun tpl_declaration
do
519 var tpl
= new Template
520 tpl
.add tpl_modifiers
522 tpl
.add tpl_signature
526 redef fun tpl_css_classes
do
527 var set
= new HashSet[String]
528 if is_intro
then set
.add
"intro"
529 set
.add_all mproperty
.intro
.modifiers
530 set
.add_all modifiers
534 fun tpl_modifiers
: Template do
535 var tpl
= new Template
536 for modifier
in modifiers
do
537 if modifier
== "public" then continue
538 tpl
.add
"{modifier} "
543 fun tpl_signature
: Template do return new Template
545 redef fun tpl_list_item
do
546 var lnk
= new Template
547 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
548 var anchor
= tpl_link
549 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
553 lnk
.add mdoc
.short_markdown
554 else if mproperty
.intro
.mdoc
!= null then
556 lnk
.add mproperty
.intro
.mdoc
.short_markdown
558 return new TplListItem.with_content
(lnk
)
561 fun tpl_inheritance_item
: TplListItem do
562 var lnk
= new Template
563 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
564 lnk
.add mclassdef
.mmodule
.tpl_namespace
566 var anchor
= mclassdef
.tpl_link
567 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
571 lnk
.add mdoc
.short_markdown
573 var li
= new TplListItem.with_content
(lnk
)
574 li
.css_classes
.add
"signature"
580 redef fun tpl_signature
do
581 var tpl
= new Template
582 var params
= new Array[String]
583 for param
in intro
.msignature
.mparameters
do
584 params
.add param
.name
586 if not params
.is_empty
then
588 tpl
.add params
.join
(", ")
595 redef class MMethodDef
596 redef fun tpl_signature
do return msignature
.tpl_signature
599 redef class MVirtualTypeProp
600 redef fun tpl_link
do return mvirtualtype
.tpl_link
601 redef fun tpl_signature
do return tpl_link
604 redef class MVirtualTypeDef
605 redef fun tpl_signature
do
606 var tpl
= new Template
608 tpl
.add bound
.tpl_signature
614 fun tpl_signature
: Template is abstract
617 redef class MClassType
618 redef fun tpl_link
do return mclass
.tpl_link
619 redef fun tpl_signature
do return tpl_link
622 redef class MNullableType
623 redef fun tpl_signature
do
624 var tpl
= new Template
626 tpl
.add mtype
.tpl_signature
631 redef class MGenericType
632 redef fun tpl_signature
do
633 var tpl
= new Template
636 for i
in [0..arguments
.length
[ do
637 tpl
.add arguments
[i
].tpl_signature
638 if i
< arguments
.length
- 1 then tpl
.add
", "
645 redef class MParameterType
646 redef fun tpl_link
do
647 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
649 redef fun tpl_signature
do return tpl_link
652 redef class MVirtualType
653 redef fun tpl_link
do return mproperty
.intro
.tpl_link
654 redef fun tpl_signature
do return tpl_link
657 redef class MSignature
658 redef fun tpl_signature
do
659 var tpl
= new Template
660 if not mparameters
.is_empty
then
662 for i
in [0..mparameters
.length
[ do
663 tpl
.add mparameters
[i
].tpl_signature
664 if i
< mparameters
.length
- 1 then tpl
.add
", "
668 if return_mtype
!= null then
670 tpl
.add return_mtype
.tpl_signature
676 redef class MParameter
677 fun tpl_signature
: Template do
678 var tpl
= new Template
680 tpl
.add mtype
.tpl_signature
681 if is_vararg
then tpl
.add
"..."
686 redef class ConcernsTree
688 private var seen
= new HashSet[MConcern]
690 redef fun add
(p
, e
) do
691 if seen
.has
(e
) then return
696 fun to_tpl
: TplList do
697 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
699 var li
= r
.tpl_concern_item
706 private fun build_list
(e
: MConcern, li
: TplListItem) do
707 if not sub
.has_key
(e
) then return
709 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
711 if e2
isa MGroup and e2
.is_root
then
714 var sli
= e2
.tpl_concern_item
724 ################################################################################
725 # Additions to `model_ext`.
728 redef fun tpl_signature
do
729 var tpl
= new Template
732 if part
.target
!= null then
733 tpl
.add part
.target
.as(not null).tpl_link
735 tpl
.add part
.text
.html_escape