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 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_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
261 redef fun tpl_namespace
do
262 var tpl
= new Template
263 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
270 redef fun tpl_title
do
271 var title
= new Template
274 title
.add tpl_signature
278 redef fun tpl_icon
do return intro
.tpl_icon
280 fun tpl_signature
: Template do
281 var tpl
= new Template
284 var parameter_names
= new Array[String]
285 for p
in mparameters
do
286 parameter_names
.add
(p
.name
)
288 tpl
.add parameter_names
.join
(", ")
294 redef fun tpl_article
do
296 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
300 redef fun tpl_css_classes
do return intro
.tpl_css_classes
303 redef class MClassDef
304 redef fun nitdoc_name
do return mclass
.nitdoc_name
305 redef var nitdoc_id
= "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
306 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
308 redef fun mdoc_or_fallback
do return mdoc
or else mclass
.mdoc_or_fallback
310 redef fun tpl_namespace
do
311 var tpl
= new Template
312 tpl
.add mmodule
.tpl_namespace
314 tpl
.add mclass
.tpl_link
319 redef fun tpl_article
do
320 var tpl
= new TplArticle(nitdoc_id
)
321 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
322 tpl
.title
= tpl_declaration
323 tpl
.title_classes
.add
"signature"
324 var title
= new Template
326 title
.add mmodule
.tpl_namespace
328 var mdoc
= mdoc_or_fallback
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
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 set
.add_all mclass
.intro
.modifiers
380 set
.add_all modifiers
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} "
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 tpl
.namespace
= mclassdef
.tpl_namespace
453 var mdoc
= mdoc_or_fallback
455 tpl
.comment
= mdoc
.tpl_comment
460 redef fun tpl_declaration
do
461 var tpl
= new Template
462 tpl
.add tpl_modifiers
464 tpl
.add tpl_signature
468 redef fun tpl_css_classes
do
469 var set
= new HashSet[String]
470 if is_intro
then set
.add
"intro"
471 set
.add_all mproperty
.intro
.modifiers
472 set
.add_all modifiers
476 fun tpl_modifiers
: Template do
477 var tpl
= new Template
478 for modifier
in modifiers
do
479 if modifier
== "public" then continue
480 tpl
.add
"{modifier} "
485 fun tpl_signature
: Template do return new Template
487 redef fun tpl_list_item
do
488 var lnk
= new Template
489 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
490 var anchor
= tpl_link
491 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
493 var mdoc
= mdoc_or_fallback
496 lnk
.add mdoc
.tpl_short_comment
498 return new TplListItem.with_content
(lnk
)
501 fun tpl_inheritance_item
: TplListItem do
502 var lnk
= new Template
503 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
504 lnk
.add mclassdef
.mmodule
.tpl_namespace
506 var anchor
= mclassdef
.tpl_link
507 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
509 var mdoc
= mdoc_or_fallback
512 lnk
.add mdoc
.tpl_short_comment
514 var li
= new TplListItem.with_content
(lnk
)
515 li
.css_classes
.add
"signature"
520 redef class MAttributeDef
521 redef fun tpl_signature
do
522 var tpl
= new Template
523 if static_mtype
!= null then
525 tpl
.add static_mtype
.tpl_signature
532 redef fun tpl_signature
do
533 var tpl
= new Template
534 var params
= new Array[String]
535 for param
in intro
.msignature
.mparameters
do
536 params
.add param
.name
538 if not params
.is_empty
then
540 tpl
.add params
.join
(", ")
547 redef class MMethodDef
548 redef fun tpl_signature
do return msignature
.tpl_signature
551 redef class MVirtualTypeProp
552 redef fun tpl_link
do return mvirtualtype
.tpl_link
553 redef fun tpl_signature
do return tpl_link
556 redef class MVirtualTypeDef
557 redef fun tpl_signature
do
558 var tpl
= new Template
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}", 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 tpl
.namespace
= mclassdef
.tpl_namespace
709 var mdoc
= mdoc_or_fallback
711 tpl
.comment
= mdoc
.tpl_comment