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_anchor`
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_comment
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_comment
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_{name}.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 # Is the mmodule created by nitdoc for internal purpose?
224 var is_fictive
: Bool writable = false
226 redef fun nitdoc_name
do return name
.html_escape
228 redef fun nitdoc_id
do
229 if mgroup
!= null then
230 return "{mgroup.nitdoc_id}__{nitdoc_name}"
235 redef fun nitdoc_url
do
236 var res
= new FlatBuffer
237 res
.append
("module_")
238 var mowner
= public_owner
239 if mowner
!= null then
240 res
.append
("{public_owner.name}_")
242 res
.append
("{self.name}.html")
246 redef fun tpl_declaration
do
247 var tpl
= new Template
248 tpl
.add
"<span>module "
254 redef fun tpl_namespace
do
255 var tpl
= new Template
256 if mgroup
!= null then
257 tpl
.add mgroup
.tpl_namespace
264 redef fun tpl_definition
do
265 var tpl
= new TplClassDefinition
267 tpl
.comment
= mdoc
.tpl_comment
272 redef fun tpl_css_classes
do return ["public"]
276 redef fun nitdoc_name
do return name
.html_escape
277 redef fun nitdoc_id
do return "{intro_mmodule.mgroup.mproject}__{name.to_cmangle}"
278 redef fun nitdoc_url
do return "class_{public_owner}_{name}.html"
280 redef fun mdoc
do return intro
.mdoc
282 redef fun tpl_declaration
do return intro
.tpl_declaration
284 redef fun tpl_namespace
do
285 var tpl
= new Template
286 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
293 redef fun tpl_title
do
294 var title
= new Template
297 title
.add tpl_signature
301 redef fun tpl_icon
do return intro
.tpl_icon
303 fun tpl_signature
: Template do
304 var tpl
= new Template
307 tpl
.add intro
.parameter_names
.join
(", ")
313 redef fun tpl_article
do
315 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
319 redef fun tpl_css_classes
do return intro
.tpl_css_classes
322 redef class MClassDef
323 redef fun nitdoc_name
do return mclass
.nitdoc_name
324 redef fun nitdoc_id
do return "{mmodule.nitdoc_id}__{name.to_cmangle}"
325 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
327 redef fun tpl_namespace
do
328 var tpl
= new Template
329 tpl
.add mmodule
.tpl_namespace
331 tpl
.add mclass
.tpl_link
336 redef fun tpl_article
do
337 var tpl
= new TplArticle(nitdoc_id
)
338 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
339 tpl
.title
= tpl_declaration
340 tpl
.title_classes
.add
"signature"
341 var title
= new Template
343 title
.add mmodule
.tpl_namespace
346 tpl
.content
= mdoc
.tpl_comment
351 redef fun tpl_title
do
352 var title
= new Template
355 title
.add tpl_signature
359 redef fun tpl_declaration
do
360 var tpl
= new Template
361 tpl
.add tpl_modifiers
363 tpl
.add tpl_signature
367 fun tpl_signature
: Template do
368 var tpl
= new Template
369 if not parameter_names
.is_empty
then
371 for i
in [0..parameter_names
.length
[ do
372 tpl
.add
"{parameter_names[i]}: "
373 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
374 if i
< parameter_names
.length
- 1 then tpl
.add
", "
381 redef fun tpl_definition
do
382 var tpl
= new TplClassDefinition
383 tpl
.namespace
= tpl_namespace
385 tpl
.comment
= mdoc
.tpl_comment
390 redef fun tpl_css_classes
do
391 var set
= new HashSet[String]
392 if is_intro
then set
.add
"intro"
393 set
.add_all mclass
.intro
.modifiers
394 set
.add_all modifiers
398 fun tpl_modifiers
: Template do
399 var tpl
= new Template
400 for modifier
in modifiers
do
401 if modifier
== "public" then continue
402 tpl
.add
"{modifier} "
407 redef fun tpl_list_item
do
408 var lnk
= new Template
409 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
413 lnk
.add mdoc
.short_comment
414 else if mclass
.intro
.mdoc
!= null then
416 lnk
.add mclass
.intro
.mdoc
.short_comment
418 return new TplListItem.with_content
(lnk
)
421 redef fun tpl_anchor
: TplLink do
422 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
424 tpl
.title
= mdoc
.short_comment
425 else if mclass
.intro
.mdoc
!= null then
426 tpl
.title
= mclass
.intro
.mdoc
.short_comment
431 redef fun tpl_link
: TplLink do
432 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
434 tpl
.title
= mdoc
.short_comment
435 else if mclass
.intro
.mdoc
!= null then
436 tpl
.title
= mclass
.intro
.mdoc
.short_comment
442 redef class MProperty
443 redef fun nitdoc_name
do return name
.html_escape
444 redef fun nitdoc_id
do return "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}"
445 redef fun nitdoc_url
do return "proprety_{nitdoc_id}.html"
447 redef fun mdoc
do return intro
.mdoc
449 redef fun tpl_namespace
do
450 var tpl
= new Template
451 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
453 tpl
.add intro
.tpl_link
458 redef fun tpl_declaration
do return intro
.tpl_declaration
460 fun tpl_signature
: Template do return new Template
462 redef fun tpl_title
do return intro
.tpl_title
464 redef fun tpl_icon
do return intro
.tpl_icon
466 redef fun tpl_css_classes
do return intro
.tpl_css_classes
470 redef fun nitdoc_name
do return mproperty
.nitdoc_name
471 redef fun nitdoc_id
do return "{mclassdef.nitdoc_id}__{name.to_cmangle}"
472 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
474 redef fun tpl_anchor
: TplLink do
475 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
477 tpl
.title
= mdoc
.short_comment
478 else if mproperty
.intro
.mdoc
!= null then
479 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
484 redef fun tpl_link
: TplLink do
485 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
487 tpl
.title
= mdoc
.short_comment
488 else if mproperty
.intro
.mdoc
!= null then
489 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
494 redef fun tpl_namespace
do
495 var tpl
= new Template
496 tpl
.add mclassdef
.tpl_namespace
498 tpl
.add mproperty
.name
502 redef fun tpl_article
do
503 var tpl
= new TplArticle(nitdoc_id
)
504 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
505 var title
= new Template
507 title
.add mclassdef
.tpl_link
509 tpl
.subtitle
= tpl_declaration
511 tpl
.content
= mdoc
.tpl_comment
516 redef fun tpl_title
do
517 var title
= new Template
520 title
.add tpl_signature
524 redef fun tpl_definition
do
525 var tpl
= new TplDefinition
526 tpl
.namespace
= mclassdef
.tpl_namespace
528 tpl
.comment
= mdoc
.tpl_comment
533 redef fun tpl_declaration
do
534 var tpl
= new Template
535 tpl
.add tpl_modifiers
537 tpl
.add tpl_signature
541 redef fun tpl_css_classes
do
542 var set
= new HashSet[String]
543 if is_intro
then set
.add
"intro"
544 set
.add_all mproperty
.intro
.modifiers
545 set
.add_all modifiers
549 fun tpl_modifiers
: Template do
550 var tpl
= new Template
551 for modifier
in modifiers
do
552 if modifier
== "public" then continue
553 tpl
.add
"{modifier} "
558 fun tpl_signature
: Template do return new Template
560 redef fun tpl_list_item
do
561 var lnk
= new Template
562 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
566 lnk
.add mdoc
.short_comment
567 else if mproperty
.intro
.mdoc
!= null then
569 lnk
.add mproperty
.intro
.mdoc
.short_comment
571 return new TplListItem.with_content
(lnk
)
576 redef fun tpl_signature
do
577 var tpl
= new Template
578 var params
= new Array[String]
579 for param
in intro
.msignature
.mparameters
do
580 params
.add param
.name
582 if not params
.is_empty
then
584 tpl
.add params
.join
(", ")
591 redef class MMethodDef
592 redef fun tpl_signature
do return msignature
.tpl_signature
595 redef class MVirtualTypeProp
596 redef fun tpl_link
do return mvirtualtype
.tpl_link
597 redef fun tpl_signature
do return tpl_link
600 redef class MVirtualTypeDef
601 redef fun tpl_signature
do
602 var tpl
= new Template
604 tpl
.add bound
.tpl_signature
610 fun tpl_signature
: Template is abstract
613 redef class MClassType
614 redef fun tpl_link
do return mclass
.tpl_link
615 redef fun tpl_signature
do return tpl_link
618 redef class MNullableType
619 redef fun tpl_signature
do
620 var tpl
= new Template
622 tpl
.add mtype
.tpl_signature
627 redef class MGenericType
628 redef fun tpl_signature
do
629 var tpl
= new Template
632 for i
in [0..arguments
.length
[ do
633 tpl
.add arguments
[i
].tpl_signature
634 if i
< arguments
.length
- 1 then tpl
.add
", "
641 redef class MParameterType
642 redef fun tpl_link
do
643 var name
= mclass
.intro
.parameter_names
[rank
]
644 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
646 redef fun tpl_signature
do return tpl_link
649 redef class MVirtualType
650 redef fun tpl_link
do return mproperty
.intro
.tpl_link
651 redef fun tpl_signature
do return tpl_link
654 redef class MSignature
655 redef fun tpl_signature
do
656 var tpl
= new Template
657 if not mparameters
.is_empty
then
659 for i
in [0..mparameters
.length
[ do
660 tpl
.add mparameters
[i
].tpl_signature
661 if i
< mparameters
.length
- 1 then tpl
.add
", "
665 if return_mtype
!= null then
667 tpl
.add return_mtype
.tpl_signature
673 redef class MParameter
674 fun tpl_signature
: Template do
675 var tpl
= new Template
677 tpl
.add mtype
.tpl_signature
678 if is_vararg
then tpl
.add
"..."
683 redef class ConcernsTree
685 private var seen
= new HashSet[MConcern]
687 redef fun add
(p
, e
) do
688 if seen
.has
(e
) then return
693 fun to_tpl
: TplList do
694 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
696 var li
= r
.tpl_concern_item
703 private fun build_list
(e
: MConcern, li
: TplListItem) do
704 if not sub
.has_key
(e
) then return
706 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
708 if e2
isa MGroup and e2
.is_root
then
711 var sli
= e2
.tpl_concern_item