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 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
233 var res
= new FlatBuffer
234 res
.append
("module_")
235 var mowner
= public_owner
236 if mowner
!= null then
237 res
.append
("{public_owner.name}_")
239 res
.append
("{self.name}.html")
243 redef fun tpl_declaration
do
244 var tpl
= new Template
245 tpl
.add
"<span>module "
251 redef fun tpl_namespace
do
252 var tpl
= new Template
253 if mgroup
!= null then
254 tpl
.add mgroup
.tpl_namespace
261 redef fun tpl_definition
do
262 var tpl
= new TplClassDefinition
264 tpl
.comment
= mdoc
.tpl_comment
269 redef fun tpl_css_classes
do return ["public"]
273 redef fun nitdoc_name
do return name
.html_escape
274 redef fun nitdoc_id
do return "{intro_mmodule.mgroup.mproject}__{name.to_cmangle}"
275 redef fun nitdoc_url
do return "class_{public_owner}_{name}.html"
277 redef fun mdoc
do return intro
.mdoc
279 redef fun tpl_declaration
do return intro
.tpl_declaration
281 redef fun tpl_namespace
do
282 var tpl
= new Template
283 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
290 redef fun tpl_title
do
291 var title
= new Template
294 title
.add tpl_signature
298 redef fun tpl_icon
do return intro
.tpl_icon
300 fun tpl_signature
: Template do
301 var tpl
= new Template
304 tpl
.add intro
.parameter_names
.join
(", ")
310 redef fun tpl_article
do
312 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
316 redef fun tpl_css_classes
do return intro
.tpl_css_classes
319 redef class MClassDef
320 redef fun nitdoc_name
do return mclass
.nitdoc_name
321 redef fun nitdoc_id
do return "{mmodule.nitdoc_id}__{name.to_cmangle}"
322 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
324 redef fun tpl_namespace
do
325 var tpl
= new Template
326 tpl
.add mmodule
.tpl_namespace
328 tpl
.add mclass
.tpl_link
333 redef fun tpl_article
do
334 var tpl
= new TplArticle(nitdoc_id
)
335 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
336 tpl
.title
= tpl_declaration
337 tpl
.title_classes
.add
"signature"
338 var title
= new Template
340 title
.add mmodule
.tpl_namespace
343 tpl
.content
= mdoc
.tpl_comment
348 redef fun tpl_title
do
349 var title
= new Template
352 title
.add tpl_signature
356 redef fun tpl_declaration
do
357 var tpl
= new Template
358 tpl
.add tpl_modifiers
360 tpl
.add tpl_signature
364 fun tpl_signature
: Template do
365 var tpl
= new Template
366 if not parameter_names
.is_empty
then
368 for i
in [0..parameter_names
.length
[ do
369 tpl
.add
"{parameter_names[i]}: "
370 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
371 if i
< parameter_names
.length
- 1 then tpl
.add
", "
378 redef fun tpl_definition
do
379 var tpl
= new TplClassDefinition
380 tpl
.namespace
= tpl_namespace
382 tpl
.comment
= mdoc
.tpl_comment
387 redef fun tpl_css_classes
do
388 var set
= new HashSet[String]
389 if is_intro
then set
.add
"intro"
390 set
.add_all mclass
.intro
.modifiers
391 set
.add_all modifiers
395 fun tpl_modifiers
: Template do
396 var tpl
= new Template
397 for modifier
in modifiers
do
398 if modifier
== "public" then continue
399 tpl
.add
"{modifier} "
404 redef fun tpl_list_item
do
405 var lnk
= new Template
406 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
410 lnk
.add mdoc
.short_comment
411 else if mclass
.intro
.mdoc
!= null then
413 lnk
.add mclass
.intro
.mdoc
.short_comment
415 return new TplListItem.with_content
(lnk
)
418 redef fun tpl_anchor
: TplLink do
419 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
421 tpl
.title
= mdoc
.short_comment
422 else if mclass
.intro
.mdoc
!= null then
423 tpl
.title
= mclass
.intro
.mdoc
.short_comment
428 redef fun tpl_link
: TplLink do
429 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
431 tpl
.title
= mdoc
.short_comment
432 else if mclass
.intro
.mdoc
!= null then
433 tpl
.title
= mclass
.intro
.mdoc
.short_comment
439 redef class MProperty
440 redef fun nitdoc_name
do return name
.html_escape
441 redef fun nitdoc_id
do return "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}"
442 redef fun nitdoc_url
do return "proprety_{nitdoc_id}.html"
444 redef fun mdoc
do return intro
.mdoc
446 redef fun tpl_namespace
do
447 var tpl
= new Template
448 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
450 tpl
.add intro
.tpl_link
455 redef fun tpl_declaration
do return intro
.tpl_declaration
457 fun tpl_signature
: Template do return new Template
459 redef fun tpl_title
do return intro
.tpl_title
461 redef fun tpl_icon
do return intro
.tpl_icon
463 redef fun tpl_css_classes
do return intro
.tpl_css_classes
467 redef fun nitdoc_name
do return mproperty
.nitdoc_name
468 redef fun nitdoc_id
do return "{mclassdef.nitdoc_id}__{name.to_cmangle}"
469 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
471 redef fun tpl_anchor
: TplLink do
472 var tpl
= new TplLink("#{nitdoc_id}", 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_link
: TplLink do
482 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
484 tpl
.title
= mdoc
.short_comment
485 else if mproperty
.intro
.mdoc
!= null then
486 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
491 redef fun tpl_namespace
do
492 var tpl
= new Template
493 tpl
.add mclassdef
.tpl_namespace
495 tpl
.add mproperty
.name
499 redef fun tpl_article
do
500 var tpl
= new TplArticle(nitdoc_id
)
501 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
502 var title
= new Template
504 title
.add mclassdef
.tpl_link
506 tpl
.subtitle
= tpl_declaration
508 tpl
.content
= mdoc
.tpl_comment
513 redef fun tpl_title
do
514 var title
= new Template
517 title
.add tpl_signature
521 redef fun tpl_definition
do
522 var tpl
= new TplDefinition
523 tpl
.namespace
= mclassdef
.tpl_namespace
525 tpl
.comment
= mdoc
.tpl_comment
530 redef fun tpl_declaration
do
531 var tpl
= new Template
532 tpl
.add tpl_modifiers
534 tpl
.add tpl_signature
538 redef fun tpl_css_classes
do
539 var set
= new HashSet[String]
540 if is_intro
then set
.add
"intro"
541 set
.add_all mproperty
.intro
.modifiers
542 set
.add_all modifiers
546 fun tpl_modifiers
: Template do
547 var tpl
= new Template
548 for modifier
in modifiers
do
549 if modifier
== "public" then continue
550 tpl
.add
"{modifier} "
555 fun tpl_signature
: Template do return new Template
557 redef fun tpl_list_item
do
558 var lnk
= new Template
559 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
563 lnk
.add mdoc
.short_comment
564 else if mproperty
.intro
.mdoc
!= null then
566 lnk
.add mproperty
.intro
.mdoc
.short_comment
568 return new TplListItem.with_content
(lnk
)
573 redef fun tpl_signature
do
574 var tpl
= new Template
575 var params
= new Array[String]
576 for param
in intro
.msignature
.mparameters
do
577 params
.add param
.name
579 if not params
.is_empty
then
581 tpl
.add params
.join
(", ")
588 redef class MMethodDef
589 redef fun tpl_signature
do return msignature
.tpl_signature
592 redef class MVirtualTypeProp
593 redef fun tpl_link
do return mvirtualtype
.tpl_link
594 redef fun tpl_signature
do return tpl_link
597 redef class MVirtualTypeDef
598 redef fun tpl_signature
do
599 var tpl
= new Template
601 tpl
.add bound
.tpl_signature
607 fun tpl_signature
: Template is abstract
610 redef class MClassType
611 redef fun tpl_link
do return mclass
.tpl_link
612 redef fun tpl_signature
do return tpl_link
615 redef class MNullableType
616 redef fun tpl_signature
do
617 var tpl
= new Template
619 tpl
.add mtype
.tpl_signature
624 redef class MGenericType
625 redef fun tpl_signature
do
626 var tpl
= new Template
629 for i
in [0..arguments
.length
[ do
630 tpl
.add arguments
[i
].tpl_signature
631 if i
< arguments
.length
- 1 then tpl
.add
", "
638 redef class MParameterType
639 redef fun tpl_link
do
640 var name
= mclass
.intro
.parameter_names
[rank
]
641 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
643 redef fun tpl_signature
do return tpl_link
646 redef class MVirtualType
647 redef fun tpl_link
do return mproperty
.intro
.tpl_link
648 redef fun tpl_signature
do return tpl_link
651 redef class MSignature
652 redef fun tpl_signature
do
653 var tpl
= new Template
654 if not mparameters
.is_empty
then
656 for i
in [0..mparameters
.length
[ do
657 tpl
.add mparameters
[i
].tpl_signature
658 if i
< mparameters
.length
- 1 then tpl
.add
", "
662 if return_mtype
!= null then
664 tpl
.add return_mtype
.tpl_signature
670 redef class MParameter
671 fun tpl_signature
: Template do
672 var tpl
= new Template
674 tpl
.add mtype
.tpl_signature
675 if is_vararg
then tpl
.add
"..."
680 redef class ConcernsTree
682 private var seen
= new HashSet[MConcern]
684 redef fun add
(p
, e
) do
685 if seen
.has
(e
) then return
690 fun to_tpl
: TplList do
691 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
693 var li
= r
.tpl_concern_item
700 private fun build_list
(e
: MConcern, li
: TplListItem) do
701 if not sub
.has_key
(e
) then return
703 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
705 if e2
isa MGroup and e2
.is_root
then
708 var sli
= e2
.tpl_concern_item