9f5043cace628bd446ea88ac7a916eb44d94b980
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
25 # Github url based on this location
26 fun github
(gitdir
: String): String do
27 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
28 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
29 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
30 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
36 fun nitdoc_name
: String is abstract
38 # ID used as a HTML unique ID and in file names.
40 # **Must** match the following (POSIX ERE) regular expression:
43 # ^[A-Za-z_][A-Za-z0-9._-]*$
46 # That way, the ID is always a valid URI component and a valid XML name.
47 fun nitdoc_id
: String is abstract
49 # URL of this entity’s Nitdoc page.
50 fun nitdoc_url
: String is abstract
52 # A template link to the mentity `nitdoc_id`
53 fun tpl_anchor
: TplLink do
54 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
56 tpl
.title
= mdoc
.short_comment
61 # A template link to the mentity `nitdoc_url`
62 fun tpl_link
: TplLink do
63 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
65 tpl
.title
= mdoc
.short_comment
70 # A template article that briefly describe the entity
71 fun tpl_short_article
: TplArticle do
74 tpl
.content
= mdoc
.tpl_short_comment
79 # A template article that describe the entity
80 fun tpl_article
: TplArticle do
81 var tpl
= new TplArticle.with_title
(nitdoc_id
, tpl_title
)
82 tpl
.title_classes
.add
"signature"
83 tpl
.subtitle
= tpl_namespace
84 tpl
.summary_title
= nitdoc_name
88 # A template signature that contains modifiers and parameters
89 fun tpl_declaration
: Template is abstract
91 # A template namespace
92 fun tpl_namespace
: Template is abstract
94 # A template definition of the mentity
95 # include name, sysnopsys, comment and namespace
96 fun tpl_definition
: TplDefinition is abstract
98 # A li element that can go in a list
99 fun tpl_list_item
: TplListItem do
100 var lnk
= new Template
101 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
105 lnk
.add mdoc
.tpl_short_comment
107 return new TplListItem.with_content
(lnk
)
110 fun tpl_css_classes
: Array[String] is abstract
112 # Box title for this mentity
113 fun tpl_title
: Template do
114 var title
= new Template
116 title
.add tpl_namespace
120 # Icon that will be displayed before the title
121 fun tpl_icon
: TplIcon do
122 var icon
= new TplIcon.with_icon
("tag")
123 icon
.css_classes
.add_all
(tpl_css_classes
)
129 # Return a li element for `self` that can be displayed in a concern list
130 private fun tpl_concern_item
: TplListItem do
131 var lnk
= new Template
135 lnk
.add mdoc
.tpl_short_comment
137 return new TplListItem.with_content
(lnk
)
142 redef var nitdoc_id
= name
.to_cmangle
is lazy
143 redef fun nitdoc_name
do return name
.html_escape
144 redef fun nitdoc_url
do return root
.nitdoc_url
153 redef fun tpl_declaration
do
154 var tpl
= new Template
155 tpl
.add
"<span>project "
161 redef fun tpl_namespace
do return tpl_link
163 redef fun tpl_definition
do
164 var tpl
= new TplDefinition
165 var mdoc
= mdoc_or_fallback
167 tpl
.comment
= mdoc
.tpl_comment
172 redef fun tpl_css_classes
do return ["public"]
176 redef fun nitdoc_name
do return name
.html_escape
178 redef var nitdoc_id
is lazy
do
179 if parent
!= null then
180 return "{parent.nitdoc_id}__{name.to_cmangle}"
182 return "{mproject.nitdoc_id}__{name.to_cmangle}"
185 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
187 redef fun tpl_namespace
do
188 var tpl
= new Template
189 tpl
.add mproject
.tpl_namespace
190 if mproject
.root
!= self then
197 redef fun tpl_declaration
do
198 var tpl
= new Template
199 tpl
.add
"<span>group "
205 redef fun tpl_definition
do
206 var tpl
= new TplDefinition
207 var mdoc
= mdoc_or_fallback
209 tpl
.comment
= mdoc
.tpl_comment
216 redef fun nitdoc_name
do return name
.html_escape
218 redef var nitdoc_id
is lazy
do
219 if mgroup
!= null then
220 return "{mgroup.nitdoc_id}__{name.to_cmangle}"
222 return name
.to_cmangle
225 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
227 redef fun tpl_declaration
do
228 var tpl
= new Template
229 tpl
.add
"<span>module "
230 tpl
.add tpl_namespace
235 redef fun tpl_namespace
do
236 var tpl
= new Template
237 if mgroup
!= null then
238 tpl
.add mgroup
.tpl_namespace
245 redef fun tpl_definition
do
246 var tpl
= new TplClassDefinition
248 tpl
.comment
= mdoc
.tpl_comment
253 redef fun tpl_css_classes
do return ["public"]
257 redef fun nitdoc_name
do return name
.html_escape
258 redef var nitdoc_id
= "{intro_mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
259 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
260 redef fun mdoc
do return intro
.mdoc
262 redef fun tpl_declaration
do return intro
.tpl_declaration
264 redef fun tpl_namespace
do
265 var tpl
= new Template
266 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
273 redef fun tpl_title
do
274 var title
= new Template
277 title
.add tpl_signature
281 redef fun tpl_icon
do return intro
.tpl_icon
283 fun tpl_signature
: Template do
284 var tpl
= new Template
287 var parameter_names
= new Array[String]
288 for p
in mparameters
do
289 parameter_names
.add
(p
.name
)
291 tpl
.add parameter_names
.join
(", ")
297 redef fun tpl_article
do
299 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
303 redef fun tpl_css_classes
do return intro
.tpl_css_classes
306 redef class MClassDef
307 redef fun nitdoc_name
do return mclass
.nitdoc_name
308 redef var nitdoc_id
= "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
309 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
311 redef fun tpl_namespace
do
312 var tpl
= new Template
313 tpl
.add mmodule
.tpl_namespace
315 tpl
.add mclass
.tpl_link
320 redef fun tpl_article
do
321 var tpl
= new TplArticle(nitdoc_id
)
322 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
323 tpl
.title
= tpl_declaration
324 tpl
.title_classes
.add
"signature"
325 var title
= new Template
327 title
.add mmodule
.tpl_namespace
330 tpl
.content
= mdoc
.tpl_comment
335 redef fun tpl_title
do
336 var title
= new Template
339 title
.add tpl_signature
343 redef fun tpl_declaration
do
344 var tpl
= new Template
345 tpl
.add tpl_modifiers
347 tpl
.add tpl_signature
351 fun tpl_signature
: Template do
352 var tpl
= new Template
353 var mparameters
= mclass
.mparameters
354 if not mparameters
.is_empty
then
356 for i
in [0..mparameters
.length
[ do
357 tpl
.add
"{mparameters[i].name}: "
358 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
359 if i
< mparameters
.length
- 1 then tpl
.add
", "
366 redef fun tpl_definition
do
367 var tpl
= new TplClassDefinition
368 tpl
.namespace
= tpl_namespace
370 tpl
.comment
= mdoc
.tpl_comment
375 redef fun tpl_css_classes
do
376 var set
= new HashSet[String]
377 if is_intro
then set
.add
"intro"
378 set
.add_all mclass
.intro
.modifiers
379 set
.add_all modifiers
383 fun tpl_modifiers
: Template do
384 var tpl
= new Template
385 for modifier
in modifiers
do
386 if modifier
== "public" then continue
387 tpl
.add
"{modifier} "
392 redef fun tpl_list_item
do
393 var lnk
= new Template
394 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
398 lnk
.add mdoc
.tpl_short_comment
399 else if mclass
.intro
.mdoc
!= null then
401 lnk
.add mclass
.intro
.mdoc
.tpl_short_comment
403 return new TplListItem.with_content
(lnk
)
406 redef fun tpl_anchor
: TplLink do
407 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
409 tpl
.title
= mdoc
.short_comment
410 else if mclass
.intro
.mdoc
!= null then
411 tpl
.title
= mclass
.intro
.mdoc
.short_comment
416 redef fun tpl_link
: TplLink do
417 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
419 tpl
.title
= mdoc
.short_comment
420 else if mclass
.intro
.mdoc
!= null then
421 tpl
.title
= mclass
.intro
.mdoc
.short_comment
427 redef class MProperty
428 redef var nitdoc_id
= "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}" is lazy
429 redef fun nitdoc_name
do return name
.html_escape
430 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
432 redef fun mdoc
do return intro
.mdoc
434 redef fun tpl_namespace
do
435 var tpl
= new Template
436 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
438 tpl
.add intro
.tpl_link
443 redef fun tpl_declaration
do return intro
.tpl_declaration
445 fun tpl_signature
: Template do return new Template
447 redef fun tpl_title
do return intro
.tpl_title
449 redef fun tpl_icon
do return intro
.tpl_icon
451 redef fun tpl_css_classes
do return intro
.tpl_css_classes
455 redef fun nitdoc_name
do return mproperty
.nitdoc_name
456 redef var nitdoc_id
= "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
457 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
459 redef fun tpl_anchor
: TplLink do
460 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
462 tpl
.title
= mdoc
.short_comment
463 else if mproperty
.intro
.mdoc
!= null then
464 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
469 redef fun tpl_link
: TplLink do
470 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
472 tpl
.title
= mdoc
.short_comment
473 else if mproperty
.intro
.mdoc
!= null then
474 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
479 redef fun tpl_namespace
do
480 var tpl
= new Template
481 tpl
.add mclassdef
.tpl_namespace
487 redef fun tpl_article
do
488 var tpl
= new TplArticle(nitdoc_id
)
489 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
490 var title
= new Template
492 title
.add mclassdef
.tpl_link
494 tpl
.subtitle
= tpl_declaration
496 tpl
.content
= mdoc
.tpl_comment
501 redef fun tpl_definition
do
502 var tpl
= new TplDefinition
503 tpl
.namespace
= mclassdef
.tpl_namespace
505 tpl
.comment
= mdoc
.tpl_comment
510 redef fun tpl_declaration
do
511 var tpl
= new Template
512 tpl
.add tpl_modifiers
514 tpl
.add tpl_signature
518 redef fun tpl_css_classes
do
519 var set
= new HashSet[String]
520 if is_intro
then set
.add
"intro"
521 set
.add_all mproperty
.intro
.modifiers
522 set
.add_all modifiers
526 fun tpl_modifiers
: Template do
527 var tpl
= new Template
528 for modifier
in modifiers
do
529 if modifier
== "public" then continue
530 tpl
.add
"{modifier} "
535 fun tpl_signature
: Template do return new Template
537 redef fun tpl_list_item
do
538 var lnk
= new Template
539 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
540 var anchor
= tpl_link
541 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
545 lnk
.add mdoc
.tpl_short_comment
546 else if mproperty
.intro
.mdoc
!= null then
548 lnk
.add mproperty
.intro
.mdoc
.tpl_short_comment
550 return new TplListItem.with_content
(lnk
)
553 fun tpl_inheritance_item
: TplListItem do
554 var lnk
= new Template
555 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
556 lnk
.add mclassdef
.mmodule
.tpl_namespace
558 var anchor
= mclassdef
.tpl_link
559 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
563 lnk
.add mdoc
.tpl_short_comment
565 var li
= new TplListItem.with_content
(lnk
)
566 li
.css_classes
.add
"signature"
571 redef class MAttributeDef
572 redef fun tpl_signature
do
573 var tpl
= new Template
574 if static_mtype
!= null then
576 tpl
.add static_mtype
.tpl_signature
583 redef fun tpl_signature
do
584 var tpl
= new Template
585 var params
= new Array[String]
586 for param
in intro
.msignature
.mparameters
do
587 params
.add param
.name
589 if not params
.is_empty
then
591 tpl
.add params
.join
(", ")
598 redef class MMethodDef
599 redef fun tpl_signature
do return msignature
.tpl_signature
602 redef class MVirtualTypeProp
603 redef fun tpl_link
do return mvirtualtype
.tpl_link
604 redef fun tpl_signature
do return tpl_link
607 redef class MVirtualTypeDef
608 redef fun tpl_signature
do
609 var tpl
= new Template
611 tpl
.add bound
.tpl_signature
617 fun tpl_signature
: Template is abstract
620 redef class MClassType
621 redef fun tpl_link
do return mclass
.tpl_link
622 redef fun tpl_signature
do return tpl_link
625 redef class MNullableType
626 redef fun tpl_signature
do
627 var tpl
= new Template
629 tpl
.add mtype
.tpl_signature
634 redef class MGenericType
635 redef fun tpl_signature
do
636 var tpl
= new Template
639 for i
in [0..arguments
.length
[ do
640 tpl
.add arguments
[i
].tpl_signature
641 if i
< arguments
.length
- 1 then tpl
.add
", "
648 redef class MParameterType
649 redef fun tpl_link
do
650 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
652 redef fun tpl_signature
do return tpl_link
655 redef class MVirtualType
656 redef fun tpl_link
do return mproperty
.intro
.tpl_link
657 redef fun tpl_signature
do return tpl_link
660 redef class MSignature
661 redef fun tpl_signature
do
662 var tpl
= new Template
663 if not mparameters
.is_empty
then
665 for i
in [0..mparameters
.length
[ do
666 tpl
.add mparameters
[i
].tpl_signature
667 if i
< mparameters
.length
- 1 then tpl
.add
", "
671 if return_mtype
!= null then
673 tpl
.add return_mtype
.tpl_signature
679 redef class MParameter
680 fun tpl_signature
: Template do
681 var tpl
= new Template
683 tpl
.add mtype
.tpl_signature
684 if is_vararg
then tpl
.add
"..."
689 redef class ConcernsTree
691 private var seen
= new HashSet[MConcern]
693 redef fun add
(p
, e
) do
694 if seen
.has
(e
) then return
699 fun to_tpl
: TplList do
700 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
702 var li
= r
.tpl_concern_item
709 private fun build_list
(e
: MConcern, li
: TplListItem) do
710 if not sub
.has_key
(e
) then return
712 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
714 if e2
isa MGroup and e2
.is_root
then
717 var sli
= e2
.tpl_concern_item
727 ################################################################################
728 # Additions to `model_ext`.
731 redef fun tpl_signature
do
732 var tpl
= new Template
735 if part
.target
!= null then
736 tpl
.add part
.target
.as(not null).tpl_link
738 tpl
.add part
.text
.html_escape
745 redef class MInnerClass
746 redef fun nitdoc_url
do return inner
.nitdoc_url
747 redef fun tpl_signature
do return inner
.tpl_signature
750 redef class MInnerClassDef
751 redef fun nitdoc_url
do return inner
.nitdoc_url
753 redef fun tpl_anchor
do return inner
.tpl_anchor
754 redef fun tpl_link
do return inner
.tpl_link
755 redef fun tpl_signature
do return inner
.tpl_signature
757 redef fun tpl_definition
do
758 var tpl
= new TplClassDefinition
759 tpl
.namespace
= mclassdef
.tpl_namespace
761 tpl
.comment
= mdoc
.tpl_comment