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
19 import modelize_property
25 # Comment synopsys HTML escaped
26 fun short_comment
: String do return content
.first
.html_escape
28 # Full comment HTML escaped
29 fun full_comment
: String do return content
.join
("\n").html_escape
31 # Synopsys in a template
32 fun tpl_short_comment
: Streamable do return short_markdown
34 # Full comment in a template
35 fun tpl_comment
: Streamable do return full_markdown
39 # Github url based on this location
40 fun github
(gitdir
: String): String do
41 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
42 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
43 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
44 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
50 fun nitdoc_name
: String is abstract
52 # Used as HTML unique ids
53 fun nitdoc_id
: String is abstract
55 # URL of this entity Nitdoc page
56 fun nitdoc_url
: String is abstract
58 # A template link to the mentity `nitdoc_anchor`
59 fun tpl_anchor
: TplLink do
60 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
62 tpl
.title
= mdoc
.short_comment
67 # A template link to the mentity `nitdoc_url`
68 fun tpl_link
: TplLink do
69 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
71 tpl
.title
= mdoc
.short_comment
76 # A template article that briefly describe the entity
77 fun tpl_short_article
: TplArticle do
80 tpl
.content
= mdoc
.tpl_short_comment
85 # A template article that describe the entity
86 fun tpl_article
: TplArticle do
87 var tpl
= new TplArticle.with_title
(nitdoc_id
, tpl_title
)
88 tpl
.title_classes
.add
"signature"
89 tpl
.subtitle
= tpl_namespace
90 tpl
.summary_title
= nitdoc_name
94 # A template signature that contains modifiers and parameters
95 fun tpl_declaration
: Template is abstract
97 # A template namespace
98 fun tpl_namespace
: Template is abstract
100 # A template definition of the mentity
101 # include name, sysnopsys, comment and namespace
102 fun tpl_definition
: TplDefinition is abstract
104 # A li element that can go in a list
105 fun tpl_list_item
: TplListItem do
106 var lnk
= new Template
107 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
111 lnk
.add mdoc
.short_comment
113 return new TplListItem.with_content
(lnk
)
116 fun tpl_css_classes
: Array[String] is abstract
118 # Box title for this mentity
119 fun tpl_title
: Template do
120 var title
= new Template
122 title
.add tpl_namespace
126 # Icon that will be displayed before the title
127 fun tpl_icon
: TplIcon do
128 var icon
= new TplIcon.with_icon
("tag")
129 icon
.css_classes
.add_all
(tpl_css_classes
)
135 # Return a li element for `self` that can be displayed in a concern list
136 private fun tpl_concern_item
: TplListItem do
137 var lnk
= new Template
141 lnk
.add mdoc
.short_comment
143 return new TplListItem.with_content
(lnk
)
148 redef fun nitdoc_name
do return name
.html_escape
149 redef fun nitdoc_id
do return nitdoc_name
150 redef fun nitdoc_url
do return "project_{name}.html"
159 redef fun tpl_declaration
do
160 var tpl
= new Template
161 tpl
.add
"<span>project "
167 redef fun tpl_namespace
do return tpl_link
169 redef fun tpl_definition
do
170 var tpl
= new TplDefinition
172 tpl
.comment
= mdoc
.tpl_comment
177 redef fun tpl_css_classes
do return ["public"]
181 redef fun nitdoc_name
do return name
.html_escape
183 redef fun nitdoc_id
do
184 if parent
!= null then
185 return "{parent.nitdoc_id}__{nitdoc_name}"
187 return "{mproject.nitdoc_id}__{nitdoc_name}"
190 redef fun nitdoc_url
do return "group_{name}.html"
192 redef fun tpl_namespace
do
193 var tpl
= new Template
194 if mproject
!= null then
195 tpl
.add mproject
.tpl_namespace
196 else if parent
!= null then
197 tpl
.add parent
.tpl_namespace
199 if mproject
!= null and 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
222 redef fun tpl_css_classes
do return ["public"]
226 # Is the mmodule created by nitdoc for internal purpose?
227 var is_fictive
: Bool writable = false
229 redef fun nitdoc_name
do return name
.html_escape
231 redef fun nitdoc_id
do
232 if mgroup
!= null then
233 return "{mgroup.nitdoc_id}__{nitdoc_name}"
238 redef fun nitdoc_url
do
239 var res
= new FlatBuffer
240 res
.append
("module_")
241 var mowner
= public_owner
242 if mowner
!= null then
243 res
.append
("{public_owner.name}_")
245 res
.append
("{self.name}.html")
249 redef fun tpl_declaration
do
250 var tpl
= new Template
251 tpl
.add
"<span>module "
257 redef fun tpl_namespace
do
258 var tpl
= new Template
259 if mgroup
!= null then
260 tpl
.add mgroup
.tpl_namespace
267 redef fun tpl_definition
do
268 var tpl
= new TplClassDefinition
270 tpl
.comment
= mdoc
.tpl_comment
275 redef fun tpl_title
do
276 var title
= new Template
278 title
.add tpl_namespace
282 redef fun tpl_css_classes
do return ["public"]
286 redef fun nitdoc_name
do return name
.html_escape
287 redef fun nitdoc_id
do return "{intro_mmodule.mgroup.mproject}__{name.to_cmangle}"
288 redef fun nitdoc_url
do return "class_{public_owner}_{name}.html"
290 redef fun mdoc
do return intro
.mdoc
292 redef fun tpl_declaration
do return intro
.tpl_declaration
294 redef fun tpl_namespace
do
295 var tpl
= new Template
296 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
303 redef fun tpl_title
do
304 var title
= new Template
307 title
.add tpl_signature
311 redef fun tpl_icon
do return intro
.tpl_icon
313 fun tpl_signature
: Template do
314 var tpl
= new Template
317 tpl
.add intro
.parameter_names
.join
(", ")
323 redef fun tpl_article
do
325 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
329 redef fun tpl_css_classes
do return intro
.tpl_css_classes
332 redef class MClassDef
333 redef fun nitdoc_name
do return mclass
.nitdoc_name
334 redef fun nitdoc_id
do return "{mmodule.nitdoc_id}__{name.to_cmangle}"
335 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
337 redef fun tpl_namespace
do
338 var tpl
= new Template
339 tpl
.add mmodule
.tpl_namespace
341 tpl
.add mclass
.tpl_link
346 redef fun tpl_article
do
347 var tpl
= new TplArticle(nitdoc_id
)
348 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
349 tpl
.title
= tpl_declaration
350 tpl
.title_classes
.add
"signature"
351 var title
= new Template
353 title
.add mmodule
.tpl_namespace
356 tpl
.content
= mdoc
.tpl_comment
361 redef fun tpl_title
do
362 var title
= new Template
365 title
.add tpl_signature
369 redef fun tpl_declaration
do
370 var tpl
= new Template
371 tpl
.add tpl_modifiers
373 tpl
.add tpl_signature
377 fun tpl_signature
: Template do
378 var tpl
= new Template
379 if not parameter_names
.is_empty
then
381 for i
in [0..parameter_names
.length
[ do
382 tpl
.add
"{parameter_names[i]}: "
383 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
384 if i
< parameter_names
.length
- 1 then tpl
.add
", "
391 redef fun tpl_definition
do
392 var tpl
= new TplClassDefinition
393 tpl
.namespace
= tpl_namespace
395 tpl
.comment
= mdoc
.tpl_comment
400 redef fun tpl_css_classes
do
401 var set
= new HashSet[String]
402 if is_intro
then set
.add
"intro"
403 set
.add_all mclass
.intro
.modifiers
404 set
.add_all modifiers
408 fun tpl_modifiers
: Template do
409 var tpl
= new Template
410 for modifier
in modifiers
do
411 if modifier
== "public" then continue
412 tpl
.add
"{modifier} "
417 redef fun tpl_list_item
do
418 var lnk
= new Template
419 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
423 lnk
.add mdoc
.short_comment
424 else if mclass
.intro
.mdoc
!= null then
426 lnk
.add mclass
.intro
.mdoc
.short_comment
428 return new TplListItem.with_content
(lnk
)
431 redef fun tpl_anchor
: TplLink do
432 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
434 tpl
.title
= mdoc
.short_comment
435 else if mclass
.intro
.mdoc
!= null then
436 tpl
.title
= mclass
.intro
.mdoc
.short_comment
441 redef fun tpl_link
: TplLink do
442 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
444 tpl
.title
= mdoc
.short_comment
445 else if mclass
.intro
.mdoc
!= null then
446 tpl
.title
= mclass
.intro
.mdoc
.short_comment
452 redef class MProperty
453 redef fun nitdoc_name
do return name
.html_escape
454 redef fun nitdoc_id
do return "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}"
455 redef fun nitdoc_url
do return "proprety_{nitdoc_id}.html"
457 redef fun mdoc
do return intro
.mdoc
459 redef fun tpl_namespace
do
460 var tpl
= new Template
461 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
463 tpl
.add intro
.tpl_link
468 redef fun tpl_declaration
do return intro
.tpl_declaration
470 fun tpl_signature
: Template do return new Template
472 redef fun tpl_title
do return intro
.tpl_title
474 redef fun tpl_icon
do return intro
.tpl_icon
476 redef fun tpl_css_classes
do return intro
.tpl_css_classes
480 redef fun nitdoc_name
do return mproperty
.nitdoc_name
481 redef fun nitdoc_id
do return "{mclassdef.nitdoc_id}__{name.to_cmangle}"
482 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
484 redef fun tpl_anchor
: TplLink do
485 var tpl
= new TplLink("#{nitdoc_id}", 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_link
: TplLink do
495 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
497 tpl
.title
= mdoc
.short_comment
498 else if mproperty
.intro
.mdoc
!= null then
499 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
504 redef fun tpl_namespace
do
505 var tpl
= new Template
506 tpl
.add mclassdef
.tpl_namespace
508 tpl
.add mproperty
.name
512 redef fun tpl_article
do
513 var tpl
= new TplArticle(nitdoc_id
)
514 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
515 var title
= new Template
517 title
.add mclassdef
.tpl_link
519 tpl
.subtitle
= tpl_declaration
521 tpl
.content
= mdoc
.tpl_comment
526 redef fun tpl_title
do
527 var title
= new Template
530 title
.add tpl_signature
534 redef fun tpl_definition
do
535 var tpl
= new TplDefinition
536 tpl
.namespace
= mclassdef
.tpl_namespace
538 tpl
.comment
= mdoc
.tpl_comment
543 redef fun tpl_declaration
do
544 var tpl
= new Template
545 tpl
.add tpl_modifiers
547 tpl
.add tpl_signature
551 redef fun tpl_css_classes
do
552 var set
= new HashSet[String]
553 if is_intro
then set
.add
"intro"
554 set
.add_all mproperty
.intro
.modifiers
555 set
.add_all modifiers
559 fun tpl_modifiers
: Template do
560 var tpl
= new Template
561 for modifier
in modifiers
do
562 if modifier
== "public" then continue
563 tpl
.add
"{modifier} "
568 fun tpl_signature
: Template do return new Template
570 redef fun tpl_list_item
do
571 var lnk
= new Template
572 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
576 lnk
.add mdoc
.short_comment
577 else if mproperty
.intro
.mdoc
!= null then
579 lnk
.add mproperty
.intro
.mdoc
.short_comment
581 return new TplListItem.with_content
(lnk
)
586 redef fun tpl_signature
do
587 var tpl
= new Template
588 var params
= new Array[String]
589 for param
in intro
.msignature
.mparameters
do
590 params
.add param
.name
592 if not params
.is_empty
then
594 tpl
.add params
.join
(", ")
601 redef class MMethodDef
602 redef fun tpl_signature
do return msignature
.tpl_signature
605 redef class MVirtualTypeProp
606 redef fun tpl_link
do return mvirtualtype
.tpl_link
607 redef fun tpl_signature
do return tpl_link
610 redef class MVirtualTypeDef
611 redef fun tpl_signature
do
612 var tpl
= new Template
614 tpl
.add bound
.tpl_signature
620 fun tpl_signature
: Template is abstract
623 redef class MClassType
624 redef fun tpl_link
do return mclass
.tpl_link
625 redef fun tpl_signature
do return tpl_link
628 redef class MNullableType
629 redef fun tpl_signature
do
630 var tpl
= new Template
632 tpl
.add mtype
.tpl_signature
637 redef class MGenericType
638 redef fun tpl_signature
do
639 var tpl
= new Template
642 for i
in [0..arguments
.length
[ do
643 tpl
.add arguments
[i
].tpl_signature
644 if i
< arguments
.length
- 1 then tpl
.add
", "
651 redef class MParameterType
652 redef fun tpl_link
do
653 var name
= mclass
.intro
.parameter_names
[rank
]
654 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
656 redef fun tpl_signature
do return tpl_link
659 redef class MVirtualType
660 redef fun tpl_link
do return mproperty
.intro
.tpl_link
661 redef fun tpl_signature
do return tpl_link
664 redef class MSignature
665 redef fun tpl_signature
do
666 var tpl
= new Template
667 if not mparameters
.is_empty
then
669 for i
in [0..mparameters
.length
[ do
670 tpl
.add mparameters
[i
].tpl_signature
671 if i
< mparameters
.length
- 1 then tpl
.add
", "
675 if return_mtype
!= null then
677 tpl
.add return_mtype
.tpl_signature
683 redef class MParameter
684 fun tpl_signature
: Template do
685 var tpl
= new Template
687 tpl
.add mtype
.tpl_signature
688 if is_vararg
then tpl
.add
"..."
693 redef class ConcernsTree
695 private var seen
= new HashSet[MConcern]
697 redef fun add
(p
, e
) do
698 if seen
.has
(e
) then return
703 fun to_tpl
: TplList do
704 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
706 var li
= r
.tpl_concern_item
713 private fun build_list
(e
: MConcern, li
: TplListItem) do
714 if not sub
.has_key
(e
) then return
716 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
718 if e2
isa MGroup and e2
.is_root
then
721 var sli
= e2
.tpl_concern_item