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 do return name
.html_escape
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
)
55 var mdoc
= mdoc_or_fallback
57 tpl
.title
= mdoc
.short_comment
62 # A template link to the mentity `nitdoc_url`
63 fun tpl_link
: TplLink do
64 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
65 var mdoc
= mdoc_or_fallback
67 tpl
.title
= mdoc
.short_comment
72 # A template article that briefly describe the entity
73 fun tpl_short_article
: TplArticle do
75 var mdoc
= mdoc_or_fallback
77 tpl
.content
= mdoc
.tpl_short_comment
82 # A template article that describe the entity
83 fun tpl_article
: TplArticle do
84 var tpl
= new TplArticle.with_title
(nitdoc_id
, tpl_title
)
85 tpl
.title_classes
.add
"signature"
86 tpl
.subtitle
= tpl_namespace
87 tpl
.summary_title
= nitdoc_name
91 # A template signature that contains modifiers and parameters
92 fun tpl_declaration
: Template is abstract
94 # A template namespace
95 fun tpl_namespace
: Template is abstract
97 # A template definition of the mentity
98 # include name, sysnopsys, comment and namespace
99 fun tpl_definition
: TplDefinition is abstract
101 # A li element that can go in a list
102 fun tpl_list_item
: TplListItem do
103 var lnk
= new Template
104 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
106 var mdoc
= mdoc_or_fallback
109 lnk
.add mdoc
.tpl_short_comment
111 return new TplListItem.with_content
(lnk
)
114 var tpl_css_classes
= new Array[String]
116 # Box title for this mentity
117 fun tpl_title
: Template do
118 var title
= new Template
120 title
.add tpl_namespace
124 # Icon that will be displayed before the title
125 fun tpl_icon
: TplIcon do
126 var icon
= new TplIcon.with_icon
("tag")
127 icon
.css_classes
.add_all
(tpl_css_classes
)
133 # Return a li element for `self` that can be displayed in a concern list
134 private fun tpl_concern_item
: TplListItem do
135 var lnk
= new Template
137 var mdoc
= mdoc_or_fallback
140 lnk
.add mdoc
.tpl_short_comment
142 return new TplListItem.with_content
(lnk
)
147 redef var nitdoc_id
= name
.to_cmangle
is lazy
148 redef fun nitdoc_url
do return root
.nitdoc_url
150 redef fun tpl_declaration
do
151 var tpl
= new Template
152 tpl
.add
"<span>project "
158 redef fun tpl_namespace
do return tpl_link
160 redef fun tpl_definition
do
161 var tpl
= new TplDefinition
162 var mdoc
= mdoc_or_fallback
164 tpl
.comment
= mdoc
.tpl_comment
169 redef fun tpl_css_classes
do return ["public"]
173 redef var nitdoc_id
is lazy
do
174 if parent
!= null then
175 return "{parent.nitdoc_id}__{name.to_cmangle}"
177 return name
.to_cmangle
180 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
182 redef fun tpl_namespace
do
183 var tpl
= new Template
184 tpl
.add mproject
.tpl_namespace
185 if mproject
.root
!= self then
192 redef fun tpl_declaration
do
193 var tpl
= new Template
194 tpl
.add
"<span>group "
200 redef fun tpl_definition
do
201 var tpl
= new TplDefinition
202 var mdoc
= mdoc_or_fallback
204 tpl
.comment
= mdoc
.tpl_comment
211 redef var nitdoc_id
is lazy
do
212 if mgroup
!= null then
213 if mgroup
.mmodules
.length
== 1 then
214 return "{mgroup.nitdoc_id}-"
216 return "{mgroup.nitdoc_id}__{name.to_cmangle}"
219 return name
.to_cmangle
222 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
224 redef fun tpl_declaration
do
225 var tpl
= new Template
226 tpl
.add
"<span>module "
227 tpl
.add tpl_namespace
232 redef fun tpl_namespace
do
233 var tpl
= new Template
234 if mgroup
!= null then
235 tpl
.add mgroup
.tpl_namespace
242 redef fun tpl_definition
do
243 var tpl
= new TplClassDefinition
244 var mdoc
= mdoc_or_fallback
246 tpl
.comment
= mdoc
.tpl_comment
251 redef fun tpl_css_classes
do return ["public"]
255 redef var nitdoc_id
= "{intro_mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
256 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
257 redef fun mdoc_or_fallback
do return intro
.mdoc
259 redef fun tpl_declaration
do return intro
.tpl_declaration
260 redef fun tpl_definition
do return intro
.tpl_definition
262 redef fun tpl_namespace
do
263 var tpl
= new Template
264 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
271 redef fun tpl_title
do
272 var title
= new Template
275 title
.add tpl_signature
279 redef fun tpl_icon
do return intro
.tpl_icon
281 fun tpl_signature
: Template do
282 var tpl
= new Template
285 var parameter_names
= new Array[String]
286 for p
in mparameters
do
287 parameter_names
.add
(p
.nitdoc_name
)
289 tpl
.add parameter_names
.join
(", ")
295 redef fun tpl_article
do
297 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
301 redef fun tpl_css_classes
do return intro
.tpl_css_classes
304 redef class MClassDef
305 redef fun nitdoc_name
do return mclass
.nitdoc_name
306 redef var nitdoc_id
= "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
307 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
309 redef fun mdoc_or_fallback
do return mdoc
or else mclass
.mdoc_or_fallback
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
329 var mdoc
= mdoc_or_fallback
331 tpl
.content
= mdoc
.tpl_comment
336 redef fun tpl_title
do
337 var title
= new Template
340 title
.add tpl_signature
344 redef fun tpl_declaration
do
345 var tpl
= new Template
346 tpl
.add tpl_modifiers
348 tpl
.add tpl_signature
352 fun tpl_signature
: Template do
353 var tpl
= new Template
354 var mparameters
= mclass
.mparameters
355 if not mparameters
.is_empty
then
357 for i
in [0..mparameters
.length
[ do
358 tpl
.add
"{mparameters[i].nitdoc_name}: "
359 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
360 if i
< mparameters
.length
- 1 then tpl
.add
", "
367 redef fun tpl_definition
do
368 var tpl
= new TplClassDefinition
369 var mdoc
= mdoc_or_fallback
371 tpl
.comment
= mdoc
.tpl_comment
376 redef fun tpl_css_classes
do
377 var set
= new HashSet[String]
378 if is_intro
then set
.add
"intro"
379 for m
in mclass
.intro
.modifiers
do set
.add m
.to_cmangle
380 for m
in modifiers
do set
.add m
.to_cmangle
384 fun tpl_modifiers
: Template do
385 var tpl
= new Template
386 for modifier
in modifiers
do
387 if modifier
== "public" then continue
388 tpl
.add
"{modifier.html_escape} "
394 redef class MProperty
395 redef var nitdoc_id
= "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}" is lazy
396 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
398 redef fun mdoc_or_fallback
do return intro
.mdoc
400 redef fun tpl_namespace
do
401 var tpl
= new Template
402 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
404 tpl
.add intro
.tpl_link
409 redef fun tpl_declaration
do return intro
.tpl_declaration
411 fun tpl_signature
: Template do return new Template
413 redef fun tpl_title
do return intro
.tpl_title
415 redef fun tpl_icon
do return intro
.tpl_icon
417 redef fun tpl_css_classes
do return intro
.tpl_css_classes
421 redef fun nitdoc_name
do return mproperty
.nitdoc_name
422 redef var nitdoc_id
= "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
423 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
425 redef fun mdoc_or_fallback
do return mdoc
or else mproperty
.mdoc_or_fallback
427 redef fun tpl_namespace
do
428 var tpl
= new Template
429 tpl
.add mclassdef
.tpl_namespace
435 redef fun tpl_article
do
436 var tpl
= new TplArticle(nitdoc_id
)
437 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
438 var title
= new Template
440 title
.add mclassdef
.tpl_link
442 tpl
.subtitle
= tpl_declaration
443 var mdoc
= mdoc_or_fallback
445 tpl
.content
= mdoc
.tpl_comment
450 redef fun tpl_definition
do
451 var tpl
= new TplDefinition
452 var mdoc
= mdoc_or_fallback
454 tpl
.comment
= mdoc
.tpl_comment
459 redef fun tpl_declaration
do
460 var tpl
= new Template
461 tpl
.add tpl_modifiers
463 tpl
.add tpl_signature
467 redef fun tpl_css_classes
do
468 var set
= new HashSet[String]
469 if is_intro
then set
.add
"intro"
470 for m
in mproperty
.intro
.modifiers
do set
.add m
.to_cmangle
471 for m
in modifiers
do set
.add m
.to_cmangle
475 fun tpl_modifiers
: Template do
476 var tpl
= new Template
477 for modifier
in modifiers
do
478 if modifier
== "public" then continue
479 tpl
.add
"{modifier.html_escape} "
484 fun tpl_signature
: Template do return new Template
486 redef fun tpl_list_item
do
487 var lnk
= new Template
488 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
489 var anchor
= tpl_link
490 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
492 var mdoc
= mdoc_or_fallback
495 lnk
.add mdoc
.tpl_short_comment
497 return new TplListItem.with_content
(lnk
)
500 fun tpl_inheritance_item
: TplListItem do
501 var lnk
= new Template
502 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
503 lnk
.add mclassdef
.mmodule
.tpl_namespace
505 var anchor
= mclassdef
.tpl_link
506 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
508 var mdoc
= mdoc_or_fallback
511 lnk
.add mdoc
.tpl_short_comment
513 var li
= new TplListItem.with_content
(lnk
)
514 li
.css_classes
.add
"signature"
519 redef class MAttributeDef
520 redef fun tpl_signature
do
521 var tpl
= new Template
522 if static_mtype
!= null then
524 tpl
.add static_mtype
.tpl_signature
531 redef fun tpl_signature
do
532 var tpl
= new Template
533 var params
= new Array[String]
534 for param
in intro
.msignature
.mparameters
do
535 params
.add param
.name
.html_escape
537 if not params
.is_empty
then
539 tpl
.add params
.join
(", ")
546 redef class MMethodDef
547 redef fun tpl_signature
do return msignature
.tpl_signature
550 redef class MVirtualTypeProp
551 redef fun tpl_link
do return mvirtualtype
.tpl_link
552 redef fun tpl_signature
do return tpl_link
555 redef class MVirtualTypeDef
556 redef fun tpl_signature
do
557 var tpl
= new Template
558 if bound
== null then return tpl
560 tpl
.add bound
.tpl_signature
566 fun tpl_signature
: Template is abstract
569 redef class MClassType
570 redef fun tpl_link
do return mclass
.tpl_link
571 redef fun tpl_signature
do return tpl_link
574 redef class MNullableType
575 redef fun tpl_signature
do
576 var tpl
= new Template
578 tpl
.add mtype
.tpl_signature
583 redef class MGenericType
584 redef fun tpl_signature
do
585 var tpl
= new Template
588 for i
in [0..arguments
.length
[ do
589 tpl
.add arguments
[i
].tpl_signature
590 if i
< arguments
.length
- 1 then tpl
.add
", "
597 redef class MParameterType
598 redef fun tpl_link
do
599 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name.to_cmangle}", name
, "formal type")
601 redef fun tpl_signature
do return tpl_link
604 redef class MVirtualType
605 redef fun tpl_link
do return mproperty
.intro
.tpl_link
606 redef fun tpl_signature
do return tpl_link
609 redef class MSignature
610 redef fun tpl_signature
do
611 var tpl
= new Template
612 if not mparameters
.is_empty
then
614 for i
in [0..mparameters
.length
[ do
615 tpl
.add mparameters
[i
].tpl_signature
616 if i
< mparameters
.length
- 1 then tpl
.add
", "
620 if return_mtype
!= null then
622 tpl
.add return_mtype
.tpl_signature
628 redef class MParameter
629 fun tpl_signature
: Template do
630 var tpl
= new Template
632 tpl
.add mtype
.tpl_signature
633 if is_vararg
then tpl
.add
"..."
638 redef class ConcernsTree
640 private var seen
= new HashSet[MConcern]
642 redef fun add
(p
, e
) do
643 if seen
.has
(e
) then return
648 fun to_tpl
: TplList do
649 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
651 var li
= r
.tpl_concern_item
658 private fun build_list
(e
: MConcern, li
: TplListItem) do
659 if not sub
.has_key
(e
) then return
661 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
663 if e2
isa MGroup and e2
.is_root
then
666 var sli
= e2
.tpl_concern_item
676 ################################################################################
677 # Additions to `model_ext`.
680 redef fun tpl_signature
do
681 var tpl
= new Template
684 if part
.target
!= null then
685 tpl
.add part
.target
.as(not null).tpl_link
687 tpl
.add part
.text
.html_escape
694 redef class MInnerClass
695 redef fun nitdoc_url
do return inner
.nitdoc_url
696 redef fun tpl_signature
do return inner
.tpl_signature
699 redef class MInnerClassDef
700 redef fun nitdoc_url
do return inner
.nitdoc_url
702 redef fun tpl_anchor
do return inner
.tpl_anchor
703 redef fun tpl_link
do return inner
.tpl_link
704 redef fun tpl_signature
do return inner
.tpl_signature
706 redef fun tpl_definition
do
707 var tpl
= new TplClassDefinition
708 var mdoc
= mdoc_or_fallback
710 tpl
.comment
= mdoc
.tpl_comment