c25c7dcfc174c1bd32b4e8c868525557eefefba8
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 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 if mgroup
.mmodules
.length
== 1 then
221 return "{mgroup.nitdoc_id}-"
223 return "{mgroup.nitdoc_id}__{name.to_cmangle}"
226 return name
.to_cmangle
229 redef fun nitdoc_url
do return "module_{nitdoc_id}.html"
231 redef fun tpl_declaration
do
232 var tpl
= new Template
233 tpl
.add
"<span>module "
234 tpl
.add tpl_namespace
239 redef fun tpl_namespace
do
240 var tpl
= new Template
241 if mgroup
!= null then
242 tpl
.add mgroup
.tpl_namespace
249 redef fun tpl_definition
do
250 var tpl
= new TplClassDefinition
252 tpl
.comment
= mdoc
.tpl_comment
257 redef fun tpl_css_classes
do return ["public"]
261 redef fun nitdoc_name
do return name
.html_escape
262 redef var nitdoc_id
= "{intro_mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
263 redef fun nitdoc_url
do return "class_{nitdoc_id}.html"
264 redef fun mdoc
do return intro
.mdoc
266 redef fun tpl_declaration
do return intro
.tpl_declaration
268 redef fun tpl_namespace
do
269 var tpl
= new Template
270 tpl
.add intro_mmodule
.mgroup
.mproject
.tpl_namespace
277 redef fun tpl_title
do
278 var title
= new Template
281 title
.add tpl_signature
285 redef fun tpl_icon
do return intro
.tpl_icon
287 fun tpl_signature
: Template do
288 var tpl
= new Template
291 var parameter_names
= new Array[String]
292 for p
in mparameters
do
293 parameter_names
.add
(p
.name
)
295 tpl
.add parameter_names
.join
(", ")
301 redef fun tpl_article
do
303 tpl
.summary_title
= "{nitdoc_name}{tpl_signature.write_to_string}"
307 redef fun tpl_css_classes
do return intro
.tpl_css_classes
310 redef class MClassDef
311 redef fun nitdoc_name
do return mclass
.nitdoc_name
312 redef var nitdoc_id
= "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
313 redef fun nitdoc_url
do return "{mclass.nitdoc_url}#{nitdoc_id}"
315 redef fun tpl_namespace
do
316 var tpl
= new Template
317 tpl
.add mmodule
.tpl_namespace
319 tpl
.add mclass
.tpl_link
324 redef fun tpl_article
do
325 var tpl
= new TplArticle(nitdoc_id
)
326 tpl
.summary_title
= "in {mmodule.nitdoc_name}"
327 tpl
.title
= tpl_declaration
328 tpl
.title_classes
.add
"signature"
329 var title
= new Template
331 title
.add mmodule
.tpl_namespace
334 tpl
.content
= mdoc
.tpl_comment
339 redef fun tpl_title
do
340 var title
= new Template
343 title
.add tpl_signature
347 redef fun tpl_declaration
do
348 var tpl
= new Template
349 tpl
.add tpl_modifiers
351 tpl
.add tpl_signature
355 fun tpl_signature
: Template do
356 var tpl
= new Template
357 var mparameters
= mclass
.mparameters
358 if not mparameters
.is_empty
then
360 for i
in [0..mparameters
.length
[ do
361 tpl
.add
"{mparameters[i].name}: "
362 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
363 if i
< mparameters
.length
- 1 then tpl
.add
", "
370 redef fun tpl_definition
do
371 var tpl
= new TplClassDefinition
372 tpl
.namespace
= tpl_namespace
374 tpl
.comment
= mdoc
.tpl_comment
379 redef fun tpl_css_classes
do
380 var set
= new HashSet[String]
381 if is_intro
then set
.add
"intro"
382 set
.add_all mclass
.intro
.modifiers
383 set
.add_all modifiers
387 fun tpl_modifiers
: Template do
388 var tpl
= new Template
389 for modifier
in modifiers
do
390 if modifier
== "public" then continue
391 tpl
.add
"{modifier} "
396 redef fun tpl_list_item
do
397 var lnk
= new Template
398 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
)
402 lnk
.add mdoc
.tpl_short_comment
403 else if mclass
.intro
.mdoc
!= null then
405 lnk
.add mclass
.intro
.mdoc
.tpl_short_comment
407 return new TplListItem.with_content
(lnk
)
410 redef fun tpl_anchor
: TplLink do
411 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
413 tpl
.title
= mdoc
.short_comment
414 else if mclass
.intro
.mdoc
!= null then
415 tpl
.title
= mclass
.intro
.mdoc
.short_comment
420 redef fun tpl_link
: TplLink do
421 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
423 tpl
.title
= mdoc
.short_comment
424 else if mclass
.intro
.mdoc
!= null then
425 tpl
.title
= mclass
.intro
.mdoc
.short_comment
431 redef class MProperty
432 redef var nitdoc_id
= "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}" is lazy
433 redef fun nitdoc_name
do return name
.html_escape
434 redef fun nitdoc_url
do return "property_{nitdoc_id}.html"
436 redef fun mdoc
do return intro
.mdoc
438 redef fun tpl_namespace
do
439 var tpl
= new Template
440 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
442 tpl
.add intro
.tpl_link
447 redef fun tpl_declaration
do return intro
.tpl_declaration
449 fun tpl_signature
: Template do return new Template
451 redef fun tpl_title
do return intro
.tpl_title
453 redef fun tpl_icon
do return intro
.tpl_icon
455 redef fun tpl_css_classes
do return intro
.tpl_css_classes
459 redef fun nitdoc_name
do return mproperty
.nitdoc_name
460 redef var nitdoc_id
= "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
461 redef fun nitdoc_url
do return "{mproperty.nitdoc_url}#{nitdoc_id}"
463 redef fun tpl_anchor
: TplLink do
464 var tpl
= new TplLink("#{nitdoc_id}", nitdoc_name
)
466 tpl
.title
= mdoc
.short_comment
467 else if mproperty
.intro
.mdoc
!= null then
468 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
473 redef fun tpl_link
: TplLink do
474 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
476 tpl
.title
= mdoc
.short_comment
477 else if mproperty
.intro
.mdoc
!= null then
478 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
483 redef fun tpl_namespace
do
484 var tpl
= new Template
485 tpl
.add mclassdef
.tpl_namespace
491 redef fun tpl_article
do
492 var tpl
= new TplArticle(nitdoc_id
)
493 tpl
.summary_title
= "in {mclassdef.nitdoc_name}"
494 var title
= new Template
496 title
.add mclassdef
.tpl_link
498 tpl
.subtitle
= tpl_declaration
500 tpl
.content
= mdoc
.tpl_comment
505 redef fun tpl_definition
do
506 var tpl
= new TplDefinition
507 tpl
.namespace
= mclassdef
.tpl_namespace
509 tpl
.comment
= mdoc
.tpl_comment
514 redef fun tpl_declaration
do
515 var tpl
= new Template
516 tpl
.add tpl_modifiers
518 tpl
.add tpl_signature
522 redef fun tpl_css_classes
do
523 var set
= new HashSet[String]
524 if is_intro
then set
.add
"intro"
525 set
.add_all mproperty
.intro
.modifiers
526 set
.add_all modifiers
530 fun tpl_modifiers
: Template do
531 var tpl
= new Template
532 for modifier
in modifiers
do
533 if modifier
== "public" then continue
534 tpl
.add
"{modifier} "
539 fun tpl_signature
: Template do return new Template
541 redef fun tpl_list_item
do
542 var lnk
= new Template
543 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
544 var anchor
= tpl_link
545 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
549 lnk
.add mdoc
.tpl_short_comment
550 else if mproperty
.intro
.mdoc
!= null then
552 lnk
.add mproperty
.intro
.mdoc
.tpl_short_comment
554 return new TplListItem.with_content
(lnk
)
557 fun tpl_inheritance_item
: TplListItem do
558 var lnk
= new Template
559 lnk
.add
new TplLabel.with_classes
(tpl_css_classes
.to_a
)
560 lnk
.add mclassdef
.mmodule
.tpl_namespace
562 var anchor
= mclassdef
.tpl_link
563 anchor
.href
= "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
567 lnk
.add mdoc
.tpl_short_comment
569 var li
= new TplListItem.with_content
(lnk
)
570 li
.css_classes
.add
"signature"
575 redef class MAttributeDef
576 redef fun tpl_signature
do
577 var tpl
= new Template
578 if static_mtype
!= null then
580 tpl
.add static_mtype
.tpl_signature
587 redef fun tpl_signature
do
588 var tpl
= new Template
589 var params
= new Array[String]
590 for param
in intro
.msignature
.mparameters
do
591 params
.add param
.name
593 if not params
.is_empty
then
595 tpl
.add params
.join
(", ")
602 redef class MMethodDef
603 redef fun tpl_signature
do return msignature
.tpl_signature
606 redef class MVirtualTypeProp
607 redef fun tpl_link
do return mvirtualtype
.tpl_link
608 redef fun tpl_signature
do return tpl_link
611 redef class MVirtualTypeDef
612 redef fun tpl_signature
do
613 var tpl
= new Template
615 tpl
.add bound
.tpl_signature
621 fun tpl_signature
: Template is abstract
624 redef class MClassType
625 redef fun tpl_link
do return mclass
.tpl_link
626 redef fun tpl_signature
do return tpl_link
629 redef class MNullableType
630 redef fun tpl_signature
do
631 var tpl
= new Template
633 tpl
.add mtype
.tpl_signature
638 redef class MGenericType
639 redef fun tpl_signature
do
640 var tpl
= new Template
643 for i
in [0..arguments
.length
[ do
644 tpl
.add arguments
[i
].tpl_signature
645 if i
< arguments
.length
- 1 then tpl
.add
", "
652 redef class MParameterType
653 redef fun tpl_link
do
654 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
656 redef fun tpl_signature
do return tpl_link
659 redef class MVirtualType
660 redef fun tpl_link
do return mproperty
.intro
.tpl_link
661 redef fun tpl_signature
do return tpl_link
664 redef class MSignature
665 redef fun tpl_signature
do
666 var tpl
= new Template
667 if not mparameters
.is_empty
then
669 for i
in [0..mparameters
.length
[ do
670 tpl
.add mparameters
[i
].tpl_signature
671 if i
< mparameters
.length
- 1 then tpl
.add
", "
675 if return_mtype
!= null then
677 tpl
.add return_mtype
.tpl_signature
683 redef class MParameter
684 fun tpl_signature
: Template do
685 var tpl
= new Template
687 tpl
.add mtype
.tpl_signature
688 if is_vararg
then tpl
.add
"..."
693 redef class ConcernsTree
695 private var seen
= new HashSet[MConcern]
697 redef fun add
(p
, e
) do
698 if seen
.has
(e
) then return
703 fun to_tpl
: TplList do
704 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
706 var li
= r
.tpl_concern_item
713 private fun build_list
(e
: MConcern, li
: TplListItem) do
714 if not sub
.has_key
(e
) then return
716 var lst
= new TplList.with_classes
(["list-unstyled", "list-definition"])
718 if e2
isa MGroup and e2
.is_root
then
721 var sli
= e2
.tpl_concern_item
731 ################################################################################
732 # Additions to `model_ext`.
735 redef fun tpl_signature
do
736 var tpl
= new Template
739 if part
.target
!= null then
740 tpl
.add part
.target
.as(not null).tpl_link
742 tpl
.add part
.text
.html_escape
749 redef class MInnerClass
750 redef fun nitdoc_url
do return inner
.nitdoc_url
751 redef fun tpl_signature
do return inner
.tpl_signature
754 redef class MInnerClassDef
755 redef fun nitdoc_url
do return inner
.nitdoc_url
757 redef fun tpl_anchor
do return inner
.tpl_anchor
758 redef fun tpl_link
do return inner
.tpl_link
759 redef fun tpl_signature
do return inner
.tpl_signature
761 redef fun tpl_definition
do
762 var tpl
= new TplClassDefinition
763 tpl
.namespace
= mclassdef
.tpl_namespace
765 tpl
.comment
= mdoc
.tpl_comment