f13d69f5cf48fcc2b7670ac6b9e7b0bf8eb61e45
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 var parameter_names
= new Array[String]
295 for p
in mparameters
do
296 parameter_names
.add
(p
.name
)
298 tpl
.add parameter_names
.join
(", ")
304 redef fun tpl_article
do
306 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
310 redef fun tpl_css_classes
do return intro
.tpl_css_classes
313 redef class MClassDef
314 redef fun nitdoc_name
do return mclass
.nitdoc_name
315 redef fun nitdoc_id
do return "{mmodule.nitdoc_id}__{name.to_cmangle}"
316 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
318 redef fun tpl_namespace
do
319 var tpl
= new Template
320 tpl
.add mmodule
.tpl_namespace
322 tpl
.add mclass
.tpl_link
327 redef fun tpl_article
do
328 var tpl
= new TplArticle(nitdoc_id
)
329 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
330 tpl
.title
= tpl_declaration
331 tpl
.title_classes
.add
"signature"
332 var title
= new Template
334 title
.add mmodule
.tpl_namespace
337 tpl
.content
= mdoc
.tpl_comment
342 redef fun tpl_title
do
343 var title
= new Template
346 title
.add tpl_signature
350 redef fun tpl_declaration
do
351 var tpl
= new Template
352 tpl
.add tpl_modifiers
354 tpl
.add tpl_signature
358 fun tpl_signature
: Template do
359 var tpl
= new Template
360 var mparameters
= mclass
.mparameters
361 if not mparameters
.is_empty
then
363 for i
in [0..mparameters
.length
[ do
364 tpl
.add
"{mparameters[i].name}: "
365 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
366 if i
< mparameters
.length
- 1 then tpl
.add
", "
373 redef fun tpl_definition
do
374 var tpl
= new TplClassDefinition
375 tpl
.namespace
= tpl_namespace
377 tpl
.comment
= mdoc
.tpl_comment
382 redef fun tpl_css_classes
do
383 var set
= new HashSet[String]
384 if is_intro
then set
.add
"intro"
385 set
.add_all mclass
.intro
.modifiers
386 set
.add_all modifiers
390 fun tpl_modifiers
: Template do
391 var tpl
= new Template
392 for modifier
in modifiers
do
393 if modifier
== "public" then continue
394 tpl
.add
"{modifier} "
399 redef fun tpl_list_item
do
400 var lnk
= new Template
401 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
405 lnk
.add mdoc
.short_markdown
406 else if mclass
.intro
.mdoc
!= null then
408 lnk
.add mclass
.intro
.mdoc
.short_markdown
410 return new TplListItem.with_content
(lnk
)
413 redef fun tpl_anchor
: TplLink do
414 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
416 tpl
.title
= mdoc
.short_comment
417 else if mclass
.intro
.mdoc
!= null then
418 tpl
.title
= mclass
.intro
.mdoc
.short_comment
423 redef fun tpl_link
: TplLink do
424 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
426 tpl
.title
= mdoc
.short_comment
427 else if mclass
.intro
.mdoc
!= null then
428 tpl
.title
= mclass
.intro
.mdoc
.short_comment
434 redef class MProperty
435 redef fun nitdoc_name
do return name
.html_escape
436 redef fun nitdoc_id
do return "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}"
437 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
439 redef fun mdoc
do return intro
.mdoc
441 redef fun tpl_namespace
do
442 var tpl
= new Template
443 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
445 tpl
.add intro
.tpl_link
450 redef fun tpl_declaration
do return intro
.tpl_declaration
452 fun tpl_signature
: Template do return new Template
454 redef fun tpl_title
do return intro
.tpl_title
456 redef fun tpl_icon
do return intro
.tpl_icon
458 redef fun tpl_css_classes
do return intro
.tpl_css_classes
462 redef fun nitdoc_name
do return mproperty
.nitdoc_name
463 redef fun nitdoc_id
do return "{mclassdef.nitdoc_id}__{name.to_cmangle}"
464 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
466 redef fun tpl_anchor
: TplLink do
467 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
469 tpl
.title
= mdoc
.short_comment
470 else if mproperty
.intro
.mdoc
!= null then
471 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
476 redef fun tpl_link
: TplLink do
477 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
479 tpl
.title
= mdoc
.short_comment
480 else if mproperty
.intro
.mdoc
!= null then
481 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
486 redef fun tpl_namespace
do
487 var tpl
= new Template
488 tpl
.add mclassdef
.tpl_namespace
494 redef fun tpl_article
do
495 var tpl
= new TplArticle(nitdoc_id
)
496 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
497 var title
= new Template
499 title
.add mclassdef
.tpl_link
501 tpl
.subtitle
= tpl_declaration
503 tpl
.content
= mdoc
.tpl_comment
508 redef fun tpl_definition
do
509 var tpl
= new TplDefinition
510 tpl
.namespace
= mclassdef
.tpl_namespace
512 tpl
.comment
= mdoc
.tpl_comment
517 redef fun tpl_declaration
do
518 var tpl
= new Template
519 tpl
.add tpl_modifiers
521 tpl
.add tpl_signature
525 redef fun tpl_css_classes
do
526 var set
= new HashSet[String]
527 if is_intro
then set
.add
"intro"
528 set
.add_all mproperty
.intro
.modifiers
529 set
.add_all modifiers
533 fun tpl_modifiers
: Template do
534 var tpl
= new Template
535 for modifier
in modifiers
do
536 if modifier
== "public" then continue
537 tpl
.add
"{modifier} "
542 fun tpl_signature
: Template do return new Template
544 redef fun tpl_list_item
do
545 var lnk
= new Template
546 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
547 var anchor
= tpl_link
548 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
552 lnk
.add mdoc
.short_markdown
553 else if mproperty
.intro
.mdoc
!= null then
555 lnk
.add mproperty
.intro
.mdoc
.short_markdown
557 return new TplListItem.with_content
(lnk
)
560 fun tpl_inheritance_item
: TplListItem do
561 var lnk
= new Template
562 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
563 lnk
.add mclassdef
.mmodule
.tpl_namespace
565 var anchor
= mclassdef
.tpl_link
566 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
570 lnk
.add mdoc
.short_markdown
572 var li
= new TplListItem.with_content
(lnk
)
573 li
.css_classes
.add
"signature"
579 redef fun tpl_signature
do
580 var tpl
= new Template
581 var params
= new Array[String]
582 for param
in intro
.msignature
.mparameters
do
583 params
.add param
.name
585 if not params
.is_empty
then
587 tpl
.add params
.join
(", ")
594 redef class MMethodDef
595 redef fun tpl_signature
do return msignature
.tpl_signature
598 redef class MVirtualTypeProp
599 redef fun tpl_link
do return mvirtualtype
.tpl_link
600 redef fun tpl_signature
do return tpl_link
603 redef class MVirtualTypeDef
604 redef fun tpl_signature
do
605 var tpl
= new Template
607 tpl
.add bound
.tpl_signature
613 fun tpl_signature
: Template is abstract
616 redef class MClassType
617 redef fun tpl_link
do return mclass
.tpl_link
618 redef fun tpl_signature
do return tpl_link
621 redef class MNullableType
622 redef fun tpl_signature
do
623 var tpl
= new Template
625 tpl
.add mtype
.tpl_signature
630 redef class MGenericType
631 redef fun tpl_signature
do
632 var tpl
= new Template
635 for i
in [0..arguments
.length
[ do
636 tpl
.add arguments
[i
].tpl_signature
637 if i
< arguments
.length
- 1 then tpl
.add
", "
644 redef class MParameterType
645 redef fun tpl_link
do
646 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
648 redef fun tpl_signature
do return tpl_link
651 redef class MVirtualType
652 redef fun tpl_link
do return mproperty
.intro
.tpl_link
653 redef fun tpl_signature
do return tpl_link
656 redef class MSignature
657 redef fun tpl_signature
do
658 var tpl
= new Template
659 if not mparameters
.is_empty
then
661 for i
in [0..mparameters
.length
[ do
662 tpl
.add mparameters
[i
].tpl_signature
663 if i
< mparameters
.length
- 1 then tpl
.add
", "
667 if return_mtype
!= null then
669 tpl
.add return_mtype
.tpl_signature
675 redef class MParameter
676 fun tpl_signature
: Template do
677 var tpl
= new Template
679 tpl
.add mtype
.tpl_signature
680 if is_vararg
then tpl
.add
"..."
685 redef class ConcernsTree
687 private var seen
= new HashSet[MConcern]
689 redef fun add
(p
, e
) do
690 if seen
.has
(e
) then return
695 fun to_tpl
: TplList do
696 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
698 var li
= r
.tpl_concern_item
705 private fun build_list
(e
: MConcern, li
: TplListItem) do
706 if not sub
.has_key
(e
) then return
708 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
710 if e2
isa MGroup and e2
.is_root
then
713 var sli
= e2
.tpl_concern_item