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
)
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 fun tpl_css_classes
: Array[String] is abstract
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_name
do return name
.html_escape
149 redef fun nitdoc_url
do return root
.nitdoc_url
151 redef fun tpl_declaration
do
152 var tpl
= new Template
153 tpl
.add
"<span>project "
159 redef fun tpl_namespace
do return tpl_link
161 redef fun tpl_definition
do
162 var tpl
= new TplDefinition
163 var mdoc
= mdoc_or_fallback
165 tpl
.comment
= mdoc
.tpl_comment
170 redef fun tpl_css_classes
do return ["public"]
174 redef fun nitdoc_name
do return name
.html_escape
176 redef var nitdoc_id
is lazy
do
177 if parent
!= null then
178 return "{parent.nitdoc_id}__{name.to_cmangle}"
180 return name
.to_cmangle
183 redef fun nitdoc_url
do return "group_{nitdoc_id}.html"
185 redef fun tpl_namespace
do
186 var tpl
= new Template
187 tpl
.add mproject
.tpl_namespace
188 if mproject
.root
!= self then
195 redef fun tpl_declaration
do
196 var tpl
= new Template
197 tpl
.add
"<span>group "
203 redef fun tpl_definition
do
204 var tpl
= new TplDefinition
205 var mdoc
= mdoc_or_fallback
207 tpl
.comment
= mdoc
.tpl_comment
214 redef fun nitdoc_name
do return name
.html_escape
216 redef var nitdoc_id
is lazy
do
217 if mgroup
!= null then
218 if mgroup
.mmodules
.length
== 1 then
219 return "{mgroup.nitdoc_id}-"
221 return "{mgroup.nitdoc_id}__{name.to_cmangle}"
224 return name
.to_cmangle
227 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
229 redef fun tpl_declaration
do
230 var tpl
= new Template
231 tpl
.add
"<span>module "
232 tpl
.add tpl_namespace
237 redef fun tpl_namespace
do
238 var tpl
= new Template
239 if mgroup
!= null then
240 tpl
.add mgroup
.tpl_namespace
247 redef fun tpl_definition
do
248 var tpl
= new TplClassDefinition
249 var mdoc
= mdoc_or_fallback
251 tpl
.comment
= mdoc
.tpl_comment
256 redef fun tpl_css_classes
do return ["public"]
260 redef fun nitdoc_name
do return name
.html_escape
261 redef var nitdoc_id
= "{intro_mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
262 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
263 redef fun mdoc_or_fallback
do return intro
.mdoc
265 redef fun tpl_declaration
do return intro
.tpl_declaration
267 redef fun tpl_namespace
do
268 var tpl
= new Template
269 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
276 redef fun tpl_title
do
277 var title
= new Template
280 title
.add tpl_signature
284 redef fun tpl_icon
do return intro
.tpl_icon
286 fun tpl_signature
: Template do
287 var tpl
= new Template
290 var parameter_names
= new Array[String]
291 for p
in mparameters
do
292 parameter_names
.add
(p
.name
)
294 tpl
.add parameter_names
.join
(", ")
300 redef fun tpl_article
do
302 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
306 redef fun tpl_css_classes
do return intro
.tpl_css_classes
309 redef class MClassDef
310 redef fun nitdoc_name
do return mclass
.nitdoc_name
311 redef var nitdoc_id
= "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
312 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
314 redef fun mdoc_or_fallback
do return mdoc
or else mclass
.mdoc_or_fallback
316 redef fun tpl_namespace
do
317 var tpl
= new Template
318 tpl
.add mmodule
.tpl_namespace
320 tpl
.add mclass
.tpl_link
325 redef fun tpl_article
do
326 var tpl
= new TplArticle(nitdoc_id
)
327 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
328 tpl
.title
= tpl_declaration
329 tpl
.title_classes
.add
"signature"
330 var title
= new Template
332 title
.add mmodule
.tpl_namespace
334 var mdoc
= mdoc_or_fallback
336 tpl
.content
= mdoc
.tpl_comment
341 redef fun tpl_title
do
342 var title
= new Template
345 title
.add tpl_signature
349 redef fun tpl_declaration
do
350 var tpl
= new Template
351 tpl
.add tpl_modifiers
353 tpl
.add tpl_signature
357 fun tpl_signature
: Template do
358 var tpl
= new Template
359 var mparameters
= mclass
.mparameters
360 if not mparameters
.is_empty
then
362 for i
in [0..mparameters
.length
[ do
363 tpl
.add
"{mparameters[i].name}: "
364 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
365 if i
< mparameters
.length
- 1 then tpl
.add
", "
372 redef fun tpl_definition
do
373 var tpl
= new TplClassDefinition
374 tpl
.namespace
= tpl_namespace
375 var mdoc
= mdoc_or_fallback
377 tpl
.comment
= mdoc
.tpl_comment
382 redef fun tpl_css_classes
do
383 var set
= new HashSet[String]
384 if is_intro
then set
.add
"intro"
385 set
.add_all mclass
.intro
.modifiers
386 set
.add_all modifiers
390 fun tpl_modifiers
: Template do
391 var tpl
= new Template
392 for modifier
in modifiers
do
393 if modifier
== "public" then continue
394 tpl
.add
"{modifier} "
400 redef class MProperty
401 redef var nitdoc_id
= "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}" is lazy
402 redef fun nitdoc_name
do return name
.html_escape
403 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
405 redef fun mdoc_or_fallback
do return intro
.mdoc
407 redef fun tpl_namespace
do
408 var tpl
= new Template
409 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
411 tpl
.add intro
.tpl_link
416 redef fun tpl_declaration
do return intro
.tpl_declaration
418 fun tpl_signature
: Template do return new Template
420 redef fun tpl_title
do return intro
.tpl_title
422 redef fun tpl_icon
do return intro
.tpl_icon
424 redef fun tpl_css_classes
do return intro
.tpl_css_classes
428 redef fun nitdoc_name
do return mproperty
.nitdoc_name
429 redef var nitdoc_id
= "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
430 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
432 redef fun mdoc_or_fallback
do return mdoc
or else mproperty
.mdoc_or_fallback
434 redef fun tpl_namespace
do
435 var tpl
= new Template
436 tpl
.add mclassdef
.tpl_namespace
442 redef fun tpl_article
do
443 var tpl
= new TplArticle(nitdoc_id
)
444 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
445 var title
= new Template
447 title
.add mclassdef
.tpl_link
449 tpl
.subtitle
= tpl_declaration
450 var mdoc
= mdoc_or_fallback
452 tpl
.content
= mdoc
.tpl_comment
457 redef fun tpl_definition
do
458 var tpl
= new TplDefinition
459 tpl
.namespace
= mclassdef
.tpl_namespace
460 var mdoc
= mdoc_or_fallback
462 tpl
.comment
= mdoc
.tpl_comment
467 redef fun tpl_declaration
do
468 var tpl
= new Template
469 tpl
.add tpl_modifiers
471 tpl
.add tpl_signature
475 redef fun tpl_css_classes
do
476 var set
= new HashSet[String]
477 if is_intro
then set
.add
"intro"
478 set
.add_all mproperty
.intro
.modifiers
479 set
.add_all modifiers
483 fun tpl_modifiers
: Template do
484 var tpl
= new Template
485 for modifier
in modifiers
do
486 if modifier
== "public" then continue
487 tpl
.add
"{modifier} "
492 fun tpl_signature
: Template do return new Template
494 redef fun tpl_list_item
do
495 var lnk
= new Template
496 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
497 var anchor
= tpl_link
498 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
500 var mdoc
= mdoc_or_fallback
503 lnk
.add mdoc
.tpl_short_comment
505 return new TplListItem.with_content
(lnk
)
508 fun tpl_inheritance_item
: TplListItem do
509 var lnk
= new Template
510 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
511 lnk
.add mclassdef
.mmodule
.tpl_namespace
513 var anchor
= mclassdef
.tpl_link
514 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
516 var mdoc
= mdoc_or_fallback
519 lnk
.add mdoc
.tpl_short_comment
521 var li
= new TplListItem.with_content
(lnk
)
522 li
.css_classes
.add
"signature"
527 redef class MAttributeDef
528 redef fun tpl_signature
do
529 var tpl
= new Template
530 if static_mtype
!= null then
532 tpl
.add static_mtype
.tpl_signature
539 redef fun tpl_signature
do
540 var tpl
= new Template
541 var params
= new Array[String]
542 for param
in intro
.msignature
.mparameters
do
543 params
.add param
.name
545 if not params
.is_empty
then
547 tpl
.add params
.join
(", ")
554 redef class MMethodDef
555 redef fun tpl_signature
do return msignature
.tpl_signature
558 redef class MVirtualTypeProp
559 redef fun tpl_link
do return mvirtualtype
.tpl_link
560 redef fun tpl_signature
do return tpl_link
563 redef class MVirtualTypeDef
564 redef fun tpl_signature
do
565 var tpl
= new Template
567 tpl
.add bound
.tpl_signature
573 fun tpl_signature
: Template is abstract
576 redef class MClassType
577 redef fun tpl_link
do return mclass
.tpl_link
578 redef fun tpl_signature
do return tpl_link
581 redef class MNullableType
582 redef fun tpl_signature
do
583 var tpl
= new Template
585 tpl
.add mtype
.tpl_signature
590 redef class MGenericType
591 redef fun tpl_signature
do
592 var tpl
= new Template
595 for i
in [0..arguments
.length
[ do
596 tpl
.add arguments
[i
].tpl_signature
597 if i
< arguments
.length
- 1 then tpl
.add
", "
604 redef class MParameterType
605 redef fun tpl_link
do
606 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
608 redef fun tpl_signature
do return tpl_link
611 redef class MVirtualType
612 redef fun tpl_link
do return mproperty
.intro
.tpl_link
613 redef fun tpl_signature
do return tpl_link
616 redef class MSignature
617 redef fun tpl_signature
do
618 var tpl
= new Template
619 if not mparameters
.is_empty
then
621 for i
in [0..mparameters
.length
[ do
622 tpl
.add mparameters
[i
].tpl_signature
623 if i
< mparameters
.length
- 1 then tpl
.add
", "
627 if return_mtype
!= null then
629 tpl
.add return_mtype
.tpl_signature
635 redef class MParameter
636 fun tpl_signature
: Template do
637 var tpl
= new Template
639 tpl
.add mtype
.tpl_signature
640 if is_vararg
then tpl
.add
"..."
645 redef class ConcernsTree
647 private var seen
= new HashSet[MConcern]
649 redef fun add
(p
, e
) do
650 if seen
.has
(e
) then return
655 fun to_tpl
: TplList do
656 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
658 var li
= r
.tpl_concern_item
665 private fun build_list
(e
: MConcern, li
: TplListItem) do
666 if not sub
.has_key
(e
) then return
668 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
670 if e2
isa MGroup and e2
.is_root
then
673 var sli
= e2
.tpl_concern_item
683 ################################################################################
684 # Additions to `model_ext`.
687 redef fun tpl_signature
do
688 var tpl
= new Template
691 if part
.target
!= null then
692 tpl
.add part
.target
.as(not null).tpl_link
694 tpl
.add part
.text
.html_escape
701 redef class MInnerClass
702 redef fun nitdoc_url
do return inner
.nitdoc_url
703 redef fun tpl_signature
do return inner
.tpl_signature
706 redef class MInnerClassDef
707 redef fun nitdoc_url
do return inner
.nitdoc_url
709 redef fun tpl_anchor
do return inner
.tpl_anchor
710 redef fun tpl_link
do return inner
.tpl_link
711 redef fun tpl_signature
do return inner
.tpl_signature
713 redef fun tpl_definition
do
714 var tpl
= new TplClassDefinition
715 tpl
.namespace
= mclassdef
.tpl_namespace
716 var mdoc
= mdoc_or_fallback
718 tpl
.comment
= mdoc
.tpl_comment