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 if mproject
!= null then
194 tpl
.add mproject
.tpl_namespace
195 else if parent
!= null then
196 tpl
.add parent
.tpl_namespace
198 if mproject
!= null and mproject
.root
!= self then
205 redef fun tpl_declaration
do
206 var tpl
= new Template
207 tpl
.add
"<span>group "
213 redef fun tpl_definition
do
214 var tpl
= new TplDefinition
216 tpl
.comment
= mdoc
.tpl_comment
223 redef fun nitdoc_name
do return name
.html_escape
225 redef fun nitdoc_id
do
226 if mgroup
!= null then
227 return "{mgroup.nitdoc_id}__{nitdoc_name}"
232 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
234 redef fun tpl_declaration
do
235 var tpl
= new Template
236 tpl
.add
"<span>module "
242 redef fun tpl_namespace
do
243 var tpl
= new Template
244 if mgroup
!= null then
245 tpl
.add mgroup
.tpl_namespace
252 redef fun tpl_definition
do
253 var tpl
= new TplClassDefinition
255 tpl
.comment
= mdoc
.tpl_comment
260 redef fun tpl_css_classes
do return ["public"]
264 redef fun nitdoc_name
do return name
.html_escape
265 redef fun nitdoc_id
do return "{intro_mmodule.mgroup.mproject}__{name.to_cmangle}"
266 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
267 redef fun mdoc
do return intro
.mdoc
269 redef fun tpl_declaration
do return intro
.tpl_declaration
271 redef fun tpl_namespace
do
272 var tpl
= new Template
273 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
280 redef fun tpl_title
do
281 var title
= new Template
284 title
.add tpl_signature
288 redef fun tpl_icon
do return intro
.tpl_icon
290 fun tpl_signature
: Template do
291 var tpl
= new Template
294 tpl
.add intro
.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 if not parameter_names
.is_empty
then
358 for i
in [0..parameter_names
.length
[ do
359 tpl
.add
"{parameter_names[i]}: "
360 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
361 if i
< parameter_names
.length
- 1 then tpl
.add
", "
368 redef fun tpl_definition
do
369 var tpl
= new TplClassDefinition
370 tpl
.namespace
= tpl_namespace
372 tpl
.comment
= mdoc
.tpl_comment
377 redef fun tpl_css_classes
do
378 var set
= new HashSet[String]
379 if is_intro
then set
.add
"intro"
380 set
.add_all mclass
.intro
.modifiers
381 set
.add_all modifiers
385 fun tpl_modifiers
: Template do
386 var tpl
= new Template
387 for modifier
in modifiers
do
388 if modifier
== "public" then continue
389 tpl
.add
"{modifier} "
394 redef fun tpl_list_item
do
395 var lnk
= new Template
396 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
400 lnk
.add mdoc
.short_markdown
401 else if mclass
.intro
.mdoc
!= null then
403 lnk
.add mclass
.intro
.mdoc
.short_markdown
405 return new TplListItem.with_content
(lnk
)
408 redef fun tpl_anchor
: TplLink do
409 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
411 tpl
.title
= mdoc
.short_comment
412 else if mclass
.intro
.mdoc
!= null then
413 tpl
.title
= mclass
.intro
.mdoc
.short_comment
418 redef fun tpl_link
: TplLink do
419 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
421 tpl
.title
= mdoc
.short_comment
422 else if mclass
.intro
.mdoc
!= null then
423 tpl
.title
= mclass
.intro
.mdoc
.short_comment
429 redef class MProperty
430 redef fun nitdoc_name
do return name
.html_escape
431 redef fun nitdoc_id
do return "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}"
432 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
434 redef fun mdoc
do return intro
.mdoc
436 redef fun tpl_namespace
do
437 var tpl
= new Template
438 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
440 tpl
.add intro
.tpl_link
445 redef fun tpl_declaration
do return intro
.tpl_declaration
447 fun tpl_signature
: Template do return new Template
449 redef fun tpl_title
do return intro
.tpl_title
451 redef fun tpl_icon
do return intro
.tpl_icon
453 redef fun tpl_css_classes
do return intro
.tpl_css_classes
457 redef fun nitdoc_name
do return mproperty
.nitdoc_name
458 redef fun nitdoc_id
do return "{mclassdef.nitdoc_id}__{name.to_cmangle}"
459 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
461 redef fun tpl_anchor
: TplLink do
462 var tpl
= new TplLink("#{nitdoc_id}", 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_link
: TplLink do
472 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
474 tpl
.title
= mdoc
.short_comment
475 else if mproperty
.intro
.mdoc
!= null then
476 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
481 redef fun tpl_namespace
do
482 var tpl
= new Template
483 tpl
.add mclassdef
.tpl_namespace
489 redef fun tpl_article
do
490 var tpl
= new TplArticle(nitdoc_id
)
491 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
492 var title
= new Template
494 title
.add mclassdef
.tpl_link
496 tpl
.subtitle
= tpl_declaration
498 tpl
.content
= mdoc
.tpl_comment
503 redef fun tpl_definition
do
504 var tpl
= new TplDefinition
505 tpl
.namespace
= mclassdef
.tpl_namespace
507 tpl
.comment
= mdoc
.tpl_comment
512 redef fun tpl_declaration
do
513 var tpl
= new Template
514 tpl
.add tpl_modifiers
516 tpl
.add tpl_signature
520 redef fun tpl_css_classes
do
521 var set
= new HashSet[String]
522 if is_intro
then set
.add
"intro"
523 set
.add_all mproperty
.intro
.modifiers
524 set
.add_all modifiers
528 fun tpl_modifiers
: Template do
529 var tpl
= new Template
530 for modifier
in modifiers
do
531 if modifier
== "public" then continue
532 tpl
.add
"{modifier} "
537 fun tpl_signature
: Template do return new Template
539 redef fun tpl_list_item
do
540 var lnk
= new Template
541 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
542 var anchor
= tpl_link
543 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
547 lnk
.add mdoc
.short_markdown
548 else if mproperty
.intro
.mdoc
!= null then
550 lnk
.add mproperty
.intro
.mdoc
.short_markdown
552 return new TplListItem.with_content
(lnk
)
555 fun tpl_inheritance_item
: TplListItem do
556 var lnk
= new Template
557 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
558 lnk
.add mclassdef
.mmodule
.tpl_namespace
560 var anchor
= mclassdef
.tpl_link
561 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
565 lnk
.add mdoc
.short_markdown
567 var li
= new TplListItem.with_content
(lnk
)
568 li
.css_classes
.add
"signature"
574 redef fun tpl_signature
do
575 var tpl
= new Template
576 var params
= new Array[String]
577 for param
in intro
.msignature
.mparameters
do
578 params
.add param
.name
580 if not params
.is_empty
then
582 tpl
.add params
.join
(", ")
589 redef class MMethodDef
590 redef fun tpl_signature
do return msignature
.tpl_signature
593 redef class MVirtualTypeProp
594 redef fun tpl_link
do return mvirtualtype
.tpl_link
595 redef fun tpl_signature
do return tpl_link
598 redef class MVirtualTypeDef
599 redef fun tpl_signature
do
600 var tpl
= new Template
602 tpl
.add bound
.tpl_signature
608 fun tpl_signature
: Template is abstract
611 redef class MClassType
612 redef fun tpl_link
do return mclass
.tpl_link
613 redef fun tpl_signature
do return tpl_link
616 redef class MNullableType
617 redef fun tpl_signature
do
618 var tpl
= new Template
620 tpl
.add mtype
.tpl_signature
625 redef class MGenericType
626 redef fun tpl_signature
do
627 var tpl
= new Template
630 for i
in [0..arguments
.length
[ do
631 tpl
.add arguments
[i
].tpl_signature
632 if i
< arguments
.length
- 1 then tpl
.add
", "
639 redef class MParameterType
640 redef fun tpl_link
do
641 var name
= mclass
.intro
.parameter_names
[rank
]
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