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
24 # Comment synopsys HTML escaped
25 fun short_comment
: String do return content
.first
.html_escape
27 # Full comment HTML escaped
28 fun full_comment
: String do return content
.join
("\n").html_escape
30 # Synopsys in a template
31 fun tpl_short_comment
: Streamable do return short_markdown
33 # Full comment in a template
34 fun tpl_comment
: Streamable do return full_markdown
38 # Github url based on this location
39 fun github
(gitdir
: String): String do
40 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
41 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
42 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
43 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
49 fun nitdoc_name
: String is abstract
51 # Used as HTML unique ids
52 fun nitdoc_id
: String is abstract
54 # URL of this entity Nitdoc page
55 fun nitdoc_url
: String is abstract
57 # A template link to the mentity `nitdoc_id`
58 fun tpl_anchor
: TplLink do
59 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
61 tpl
.title
= mdoc
.short_comment
66 # A template link to the mentity `nitdoc_url`
67 fun tpl_link
: TplLink do
68 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
70 tpl
.title
= mdoc
.short_comment
75 # A template article that briefly describe the entity
76 fun tpl_short_article
: TplArticle do
79 tpl
.content
= mdoc
.tpl_short_comment
84 # A template article that describe the entity
85 fun tpl_article
: TplArticle do
86 var tpl
= new TplArticle.with_title
(nitdoc_id
, tpl_title
)
87 tpl
.title_classes
.add
"signature"
88 tpl
.subtitle
= tpl_namespace
89 tpl
.summary_title
= nitdoc_name
93 # A template signature that contains modifiers and parameters
94 fun tpl_declaration
: Template is abstract
96 # A template namespace
97 fun tpl_namespace
: Template is abstract
99 # A template definition of the mentity
100 # include name, sysnopsys, comment and namespace
101 fun tpl_definition
: TplDefinition is abstract
103 # A li element that can go in a list
104 fun tpl_list_item
: TplListItem do
105 var lnk
= new Template
106 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
110 lnk
.add mdoc
.short_markdown
112 return new TplListItem.with_content
(lnk
)
115 fun tpl_css_classes
: Array[String] is abstract
117 # Box title for this mentity
118 fun tpl_title
: Template do
119 var title
= new Template
121 title
.add tpl_namespace
125 # Icon that will be displayed before the title
126 fun tpl_icon
: TplIcon do
127 var icon
= new TplIcon.with_icon
("tag")
128 icon
.css_classes
.add_all
(tpl_css_classes
)
134 # Return a li element for `self` that can be displayed in a concern list
135 private fun tpl_concern_item
: TplListItem do
136 var lnk
= new Template
140 lnk
.add mdoc
.short_markdown
142 return new TplListItem.with_content
(lnk
)
147 redef fun nitdoc_name
do return name
.html_escape
148 redef fun nitdoc_id
do return nitdoc_name
149 redef fun nitdoc_url
do return root
.nitdoc_url
158 redef fun tpl_declaration
do
159 var tpl
= new Template
160 tpl
.add
"<span>project "
166 redef fun tpl_namespace
do return tpl_link
168 redef fun tpl_definition
do
169 var tpl
= new TplDefinition
171 tpl
.comment
= mdoc
.tpl_comment
176 redef fun tpl_css_classes
do return ["public"]
180 redef fun nitdoc_name
do return name
.html_escape
182 redef fun nitdoc_id
do
183 if parent
!= null then
184 return "{parent.nitdoc_id}__{nitdoc_name}"
186 return "{mproject.nitdoc_id}__{nitdoc_name}"
189 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
191 redef fun tpl_namespace
do
192 var tpl
= new Template
193 tpl
.add mproject
.tpl_namespace
194 if mproject
.root
!= self then
201 redef fun tpl_declaration
do
202 var tpl
= new Template
203 tpl
.add
"<span>group "
209 redef fun tpl_definition
do
210 var tpl
= new TplDefinition
212 tpl
.comment
= mdoc
.tpl_comment
219 redef fun nitdoc_name
do return name
.html_escape
221 redef fun nitdoc_id
do
222 if mgroup
!= null then
223 return "{mgroup.nitdoc_id}__{nitdoc_name}"
228 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
230 redef fun tpl_declaration
do
231 var tpl
= new Template
232 tpl
.add
"<span>module "
238 redef fun tpl_namespace
do
239 var tpl
= new Template
240 if mgroup
!= null then
241 tpl
.add mgroup
.tpl_namespace
248 redef fun tpl_definition
do
249 var tpl
= new TplClassDefinition
251 tpl
.comment
= mdoc
.tpl_comment
256 redef fun tpl_css_classes
do return ["public"]
260 redef fun nitdoc_name
do return name
.html_escape
261 redef fun nitdoc_id
do return "{intro_mmodule.mgroup.mproject}__{name.to_cmangle}"
262 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
263 redef fun mdoc
do return intro
.mdoc
265 redef fun tpl_declaration
do return intro
.tpl_declaration
267 redef fun tpl_namespace
do
268 var tpl
= new Template
269 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
276 redef fun tpl_title
do
277 var title
= new Template
280 title
.add tpl_signature
284 redef fun tpl_icon
do return intro
.tpl_icon
286 fun tpl_signature
: Template do
287 var tpl
= new Template
290 var parameter_names
= new Array[String]
291 for p
in mparameters
do
292 parameter_names
.add
(p
.name
)
294 tpl
.add parameter_names
.join
(", ")
300 redef fun tpl_article
do
302 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
306 redef fun tpl_css_classes
do return intro
.tpl_css_classes
309 redef class MClassDef
310 redef fun nitdoc_name
do return mclass
.nitdoc_name
311 redef fun nitdoc_id
do return "{mmodule.nitdoc_id}__{name.to_cmangle}"
312 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
314 redef fun tpl_namespace
do
315 var tpl
= new Template
316 tpl
.add mmodule
.tpl_namespace
318 tpl
.add mclass
.tpl_link
323 redef fun tpl_article
do
324 var tpl
= new TplArticle(nitdoc_id
)
325 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
326 tpl
.title
= tpl_declaration
327 tpl
.title_classes
.add
"signature"
328 var title
= new Template
330 title
.add mmodule
.tpl_namespace
333 tpl
.content
= mdoc
.tpl_comment
338 redef fun tpl_title
do
339 var title
= new Template
342 title
.add tpl_signature
346 redef fun tpl_declaration
do
347 var tpl
= new Template
348 tpl
.add tpl_modifiers
350 tpl
.add tpl_signature
354 fun tpl_signature
: Template do
355 var tpl
= new Template
356 var mparameters
= mclass
.mparameters
357 if not mparameters
.is_empty
then
359 for i
in [0..mparameters
.length
[ do
360 tpl
.add
"{mparameters[i].name}: "
361 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
362 if i
< mparameters
.length
- 1 then tpl
.add
", "
369 redef fun tpl_definition
do
370 var tpl
= new TplClassDefinition
371 tpl
.namespace
= tpl_namespace
373 tpl
.comment
= mdoc
.tpl_comment
378 redef fun tpl_css_classes
do
379 var set
= new HashSet[String]
380 if is_intro
then set
.add
"intro"
381 set
.add_all mclass
.intro
.modifiers
382 set
.add_all modifiers
386 fun tpl_modifiers
: Template do
387 var tpl
= new Template
388 for modifier
in modifiers
do
389 if modifier
== "public" then continue
390 tpl
.add
"{modifier} "
395 redef fun tpl_list_item
do
396 var lnk
= new Template
397 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
401 lnk
.add mdoc
.short_markdown
402 else if mclass
.intro
.mdoc
!= null then
404 lnk
.add mclass
.intro
.mdoc
.short_markdown
406 return new TplListItem.with_content
(lnk
)
409 redef fun tpl_anchor
: TplLink do
410 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
412 tpl
.title
= mdoc
.short_comment
413 else if mclass
.intro
.mdoc
!= null then
414 tpl
.title
= mclass
.intro
.mdoc
.short_comment
419 redef fun tpl_link
: TplLink do
420 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
422 tpl
.title
= mdoc
.short_comment
423 else if mclass
.intro
.mdoc
!= null then
424 tpl
.title
= mclass
.intro
.mdoc
.short_comment
430 redef class MProperty
431 redef fun nitdoc_name
do return name
.html_escape
432 redef fun nitdoc_id
do return "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}"
433 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
435 redef fun mdoc
do return intro
.mdoc
437 redef fun tpl_namespace
do
438 var tpl
= new Template
439 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
441 tpl
.add intro
.tpl_link
446 redef fun tpl_declaration
do return intro
.tpl_declaration
448 fun tpl_signature
: Template do return new Template
450 redef fun tpl_title
do return intro
.tpl_title
452 redef fun tpl_icon
do return intro
.tpl_icon
454 redef fun tpl_css_classes
do return intro
.tpl_css_classes
458 redef fun nitdoc_name
do return mproperty
.nitdoc_name
459 redef fun nitdoc_id
do return "{mclassdef.nitdoc_id}__{name.to_cmangle}"
460 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
462 redef fun tpl_anchor
: TplLink do
463 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
465 tpl
.title
= mdoc
.short_comment
466 else if mproperty
.intro
.mdoc
!= null then
467 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
472 redef fun tpl_link
: TplLink do
473 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
475 tpl
.title
= mdoc
.short_comment
476 else if mproperty
.intro
.mdoc
!= null then
477 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
482 redef fun tpl_namespace
do
483 var tpl
= new Template
484 tpl
.add mclassdef
.tpl_namespace
490 redef fun tpl_article
do
491 var tpl
= new TplArticle(nitdoc_id
)
492 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
493 var title
= new Template
495 title
.add mclassdef
.tpl_link
497 tpl
.subtitle
= tpl_declaration
499 tpl
.content
= mdoc
.tpl_comment
504 redef fun tpl_definition
do
505 var tpl
= new TplDefinition
506 tpl
.namespace
= mclassdef
.tpl_namespace
508 tpl
.comment
= mdoc
.tpl_comment
513 redef fun tpl_declaration
do
514 var tpl
= new Template
515 tpl
.add tpl_modifiers
517 tpl
.add tpl_signature
521 redef fun tpl_css_classes
do
522 var set
= new HashSet[String]
523 if is_intro
then set
.add
"intro"
524 set
.add_all mproperty
.intro
.modifiers
525 set
.add_all modifiers
529 fun tpl_modifiers
: Template do
530 var tpl
= new Template
531 for modifier
in modifiers
do
532 if modifier
== "public" then continue
533 tpl
.add
"{modifier} "
538 fun tpl_signature
: Template do return new Template
540 redef fun tpl_list_item
do
541 var lnk
= new Template
542 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
543 var anchor
= tpl_link
544 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
548 lnk
.add mdoc
.short_markdown
549 else if mproperty
.intro
.mdoc
!= null then
551 lnk
.add mproperty
.intro
.mdoc
.short_markdown
553 return new TplListItem.with_content
(lnk
)
556 fun tpl_inheritance_item
: TplListItem do
557 var lnk
= new Template
558 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
559 lnk
.add mclassdef
.mmodule
.tpl_namespace
561 var anchor
= mclassdef
.tpl_link
562 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
566 lnk
.add mdoc
.short_markdown
568 var li
= new TplListItem.with_content
(lnk
)
569 li
.css_classes
.add
"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
609 fun tpl_signature
: Template is abstract
612 redef class MClassType
613 redef fun tpl_link
do return mclass
.tpl_link
614 redef fun tpl_signature
do return tpl_link
617 redef class MNullableType
618 redef fun tpl_signature
do
619 var tpl
= new Template
621 tpl
.add mtype
.tpl_signature
626 redef class MGenericType
627 redef fun tpl_signature
do
628 var tpl
= new Template
631 for i
in [0..arguments
.length
[ do
632 tpl
.add arguments
[i
].tpl_signature
633 if i
< arguments
.length
- 1 then tpl
.add
", "
640 redef class MParameterType
641 redef fun tpl_link
do
642 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
644 redef fun tpl_signature
do return tpl_link
647 redef class MVirtualType
648 redef fun tpl_link
do return mproperty
.intro
.tpl_link
649 redef fun tpl_signature
do return tpl_link
652 redef class MSignature
653 redef fun tpl_signature
do
654 var tpl
= new Template
655 if not mparameters
.is_empty
then
657 for i
in [0..mparameters
.length
[ do
658 tpl
.add mparameters
[i
].tpl_signature
659 if i
< mparameters
.length
- 1 then tpl
.add
", "
663 if return_mtype
!= null then
665 tpl
.add return_mtype
.tpl_signature
671 redef class MParameter
672 fun tpl_signature
: Template do
673 var tpl
= new Template
675 tpl
.add mtype
.tpl_signature
676 if is_vararg
then tpl
.add
"..."
681 redef class ConcernsTree
683 private var seen
= new HashSet[MConcern]
685 redef fun add
(p
, e
) do
686 if seen
.has
(e
) then return
691 fun to_tpl
: TplList do
692 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
694 var li
= r
.tpl_concern_item
701 private fun build_list
(e
: MConcern, li
: TplListItem) do
702 if not sub
.has_key
(e
) then return
704 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
706 if e2
isa MGroup and e2
.is_root
then
709 var sli
= e2
.tpl_concern_item