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
19 import modelize_property
24 # Comment synopsys HTML escaped
25 fun short_comment
: String do return content
.first
.html_escape
27 # Full comment HTML escaped
28 fun full_comment
: String do return content
.join
("\n").html_escape
30 # Synopsys in a template
31 fun tpl_short_comment
: Streamable do return short_markdown
33 # Full comment in a template
34 fun tpl_comment
: Streamable do return full_markdown
38 # Github url based on this location
39 fun github
(gitdir
: String): String do
40 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
41 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
42 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
43 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
49 fun nitdoc_name
: String is abstract
51 # HTML anchor to this entity in a nitdoc page
52 fun nitdoc_anchor
: String is abstract
54 # URL of this entity Nitdoc page
55 fun nitdoc_url
: String is abstract
57 # A template link to the mentity `nitdoc_anchor`
58 fun tpl_anchor
: TplLink is abstract
60 # A template link to the mentity `nitdoc_url`
61 fun tpl_link
: TplLink is abstract
63 # A template signature that contains modifiers and parameters
64 fun tpl_declaration
: Template is abstract
66 # A template namespace
67 fun tpl_namespace
: Template is abstract
69 # A template definition of the mentity
70 # include name, sysnopsys, comment and namespace
71 fun tpl_definition
: TplDefinition is abstract
75 fun nitdoc_mdoc
: nullable MDoc do
76 if mdoc
!= null then return mdoc
77 if root
== null then return null
78 if root
.mdoc
!= null then return root
.mdoc
79 if not root
.mmodules
.is_empty
then return root
.mmodules
.first
.mdoc
83 redef fun nitdoc_name
do return name
.html_escape
84 redef fun nitdoc_anchor
do return "PRJ_{nitdoc_name}"
86 redef fun nitdoc_url
do
87 if root
!= null and not root
.mmodules
.is_empty
then return root
.mmodules
.first
.nitdoc_url
88 return "project_{name}.html"
91 redef fun tpl_anchor
do
92 var tpl
= new TplLink("#{nitdoc_anchor}", nitdoc_name
)
93 var mdoc
= nitdoc_mdoc
95 tpl
.title
= mdoc
.short_comment
100 redef fun tpl_link
do
101 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
102 var mdoc
= nitdoc_mdoc
104 tpl
.title
= mdoc
.short_comment
109 redef fun tpl_declaration
do
110 var tpl
= new Template
111 tpl
.add
"<span>project "
117 redef fun tpl_namespace
do return tpl_link
119 redef fun tpl_definition
do
120 var tpl
= new TplDefinition
121 tpl
.namespace
= tpl_namespace
122 var mdoc
= nitdoc_mdoc
124 tpl
.comment
= mdoc
.tpl_comment
129 fun tpl_article
: TplArticle do
130 var article
= new TplArticle.with_title
(nitdoc_anchor
, tpl_link
)
131 article
.title_classes
.add
"signature"
132 article
.subtitle
= tpl_declaration
133 article
.summary_title
= nitdoc_name
134 article
.content
= tpl_definition
140 redef fun tpl_link
do return mmodules
.first
.tpl_link
142 redef fun tpl_namespace
do
143 if mproject
== null then return tpl_link
144 if mproject
.root
!= self then
145 var tpl
= new Template
146 tpl
.add mproject
.tpl_namespace
148 tpl
.add
self.tpl_link
151 return mproject
.tpl_namespace
157 # Is the mmodule created by nitdoc for internal purpose?
158 var is_fictive
: Bool writable = false
160 # Full namespace of this module
161 fun full_namespace
: String do
162 if public_owner
!= null then
163 return "{public_owner.nitdoc_name}::{nitdoc_name}"
168 redef fun nitdoc_name
do return name
.html_escape
170 redef fun nitdoc_url
do
171 var res
= new FlatBuffer
172 res
.append
("module_")
173 var mowner
= public_owner
174 if mowner
!= null then
175 res
.append
("{public_owner.name}_")
177 res
.append
("{self.name}.html")
181 redef fun nitdoc_anchor
: String do
182 var res
= new FlatBuffer
184 var mowner
= public_owner
185 if mowner
!= null then
186 res
.append
("{public_owner.nitdoc_name}_")
188 res
.append
(nitdoc_name
)
192 redef fun tpl_anchor
do
193 var tpl
= new TplLink("#{nitdoc_anchor}", nitdoc_name
)
195 tpl
.title
= mdoc
.short_comment
200 redef fun tpl_link
do
201 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
203 tpl
.title
= mdoc
.short_comment
208 redef fun tpl_declaration
do
209 var tpl
= new Template
210 tpl
.add
"<span>module "
211 tpl
.add tpl_namespace
216 redef fun tpl_namespace
do
217 var tpl
= new Template
218 if mgroup
!= null and mgroup
.mmodules
.first
!= self then
219 tpl
.add mgroup
.tpl_namespace
228 redef fun tpl_definition
do
229 var tpl
= new TplDefinition
230 tpl
.namespace
= tpl_namespace
232 tpl
.comment
= mdoc
.tpl_comment
237 fun tpl_article
: TplArticle do
238 var article
= new TplArticle.with_title
(nitdoc_anchor
, tpl_link
)
239 article
.title_classes
.add
"signature"
240 article
.subtitle
= tpl_declaration
241 article
.summary_title
= nitdoc_name
242 article
.content
= tpl_definition
246 fun tpl_list_item
: TplListItem do
247 var lnk
= new Template
251 lnk
.add mdoc
.short_comment
253 return new TplListItem.with_content
(lnk
)
258 redef fun nitdoc_name
do return name
.html_escape
259 redef fun nitdoc_url
do return "class_{public_owner}_{name}.html"
260 redef fun nitdoc_anchor
do return "CLASS_{public_owner.nitdoc_name}_{nitdoc_name}"
262 redef fun tpl_anchor
do
263 var tpl
= new TplLink("#{nitdoc_anchor}", nitdoc_name
)
264 if intro
.mdoc
!= null then
265 tpl
.title
= intro
.mdoc
.short_comment
270 redef fun tpl_link
do
271 var tpl
= new TplLink(nitdoc_url
, nitdoc_name
)
272 if intro
.mdoc
!= null then
273 tpl
.title
= intro
.mdoc
.short_comment
278 redef fun tpl_declaration
do return intro
.tpl_declaration
280 redef fun tpl_namespace
do
281 var tpl
= new Template
282 tpl
.add intro_mmodule
.tpl_namespace
289 fun tpl_list_item
: TplListItem do
290 var lnk
= new Template
292 if intro
.mdoc
!= null then
294 lnk
.add intro
.mdoc
.short_comment
296 return new TplListItem.with_content
(lnk
)
299 fun tpl_signature
: Template do
300 var tpl
= new Template
303 tpl
.add intro
.parameter_names
.join
(", ")
310 redef class MClassDef
311 redef fun nitdoc_name
do return mclass
.nitdoc_name
313 redef fun tpl_link
do return mclass
.tpl_link
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_declaration
do
325 var tpl
= new Template
326 tpl
.add tpl_modifiers
328 tpl
.add tpl_signature
332 fun tpl_signature
: Template do
333 var tpl
= new Template
334 if not parameter_names
.is_empty
then
336 for i
in [0..parameter_names
.length
[ do
337 tpl
.add
"{parameter_names[i]}: "
338 tpl
.add bound_mtype
.arguments
[i
].tpl_signature
339 if i
< parameter_names
.length
- 1 then tpl
.add
", "
346 redef fun tpl_definition
do
347 var tpl
= new TplClassDefinition
348 tpl
.namespace
= tpl_namespace
350 tpl
.comment
= mdoc
.tpl_comment
355 fun tpl_css_classes
: Set[String] do
356 var set
= new HashSet[String]
357 if is_intro
then set
.add
"intro"
358 set
.add_all mclass
.intro
.modifiers
359 set
.add_all modifiers
363 fun tpl_modifiers
: Template do
364 var tpl
= new Template
365 for modifier
in modifiers
do
366 if modifier
== "public" then continue
367 tpl
.add
"{modifier} "
373 redef class MProperty
374 redef fun nitdoc_name
do return name
.html_escape
376 redef fun tpl_namespace
do
377 var tpl
= new Template
378 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
380 tpl
.add intro
.tpl_link
385 redef fun tpl_declaration
do return intro
.tpl_declaration
387 fun tpl_signature
: Template do return new Template
391 redef fun nitdoc_url
do return "{mclassdef.mclass.nitdoc_url}#{nitdoc_anchor}"
393 redef fun nitdoc_anchor
do
394 return "PROP_{mclassdef.mclass.public_owner.nitdoc_name}_{mproperty.name.to_cmangle}"
397 redef fun tpl_anchor
do
398 var tpl
= new TplLink("#{nitdoc_anchor}", mproperty
.nitdoc_name
)
399 if mproperty
.intro
.mdoc
!= null then
400 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
405 redef fun tpl_link
do
406 var tpl
= new TplLink(nitdoc_url
, mproperty
.nitdoc_name
)
407 if mproperty
.intro
.mdoc
!= null then
408 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
413 redef fun tpl_namespace
do
414 var tpl
= new Template
415 tpl
.add mclassdef
.tpl_namespace
417 tpl
.add mproperty
.name
421 redef fun tpl_definition
do
422 var tpl
= new TplDefinition
423 tpl
.namespace
= mclassdef
.tpl_namespace
425 tpl
.comment
= mdoc
.tpl_comment
430 redef fun tpl_declaration
do
431 var tpl
= new Template
432 tpl
.add tpl_modifiers
434 tpl
.add tpl_signature
438 fun tpl_css_classes
: Set[String] do
439 var set
= new HashSet[String]
440 if is_intro
then set
.add
"intro"
441 set
.add_all mproperty
.intro
.modifiers
442 set
.add_all modifiers
446 fun tpl_modifiers
: Template do
447 var tpl
= new Template
448 for modifier
in modifiers
do
449 if modifier
== "public" then continue
450 tpl
.add
"{modifier} "
455 fun tpl_signature
: Template do return new Template
459 redef fun tpl_signature
do
460 var tpl
= new Template
461 var params
= new Array[String]
462 for param
in intro
.msignature
.mparameters
do
463 params
.add param
.name
465 if not params
.is_empty
then
467 tpl
.add params
.join
(", ")
474 redef class MMethodDef
475 redef fun tpl_signature
do return msignature
.tpl_signature
478 redef class MVirtualTypeProp
479 redef fun tpl_link
do return mvirtualtype
.tpl_link
480 redef fun tpl_signature
do return tpl_link
483 redef class MVirtualTypeDef
484 redef fun tpl_signature
do
485 var tpl
= new Template
487 tpl
.add bound
.tpl_signature
493 fun tpl_signature
: Template is abstract
496 redef class MClassType
497 redef fun tpl_link
do return mclass
.tpl_link
498 redef fun tpl_signature
do return tpl_link
501 redef class MNullableType
502 redef fun tpl_signature
do
503 var tpl
= new Template
505 tpl
.add mtype
.tpl_signature
510 redef class MGenericType
511 redef fun tpl_signature
do
512 var tpl
= new Template
515 for i
in [0..arguments
.length
[ do
516 tpl
.add arguments
[i
].tpl_signature
517 if i
< arguments
.length
- 1 then tpl
.add
", "
524 redef class MParameterType
525 redef fun tpl_link
do
526 var name
= mclass
.intro
.parameter_names
[rank
]
527 return new TplLink.with_title
("{mclass.nitdoc_url}#FT_{name}", name
, "formal type")
529 redef fun tpl_signature
do return tpl_link
532 redef class MVirtualType
533 redef fun tpl_link
do return mproperty
.intro
.tpl_link
534 redef fun tpl_signature
do return tpl_link
537 redef class MSignature
538 redef fun tpl_signature
do
539 var tpl
= new Template
540 if not mparameters
.is_empty
then
542 for i
in [0..mparameters
.length
[ do
543 tpl
.add mparameters
[i
].tpl_signature
544 if i
< mparameters
.length
- 1 then tpl
.add
", "
548 if return_mtype
!= null then
550 tpl
.add return_mtype
.tpl_signature
556 redef class MParameter
557 fun tpl_signature
: Template do
558 var tpl
= new Template
560 tpl
.add mtype
.tpl_signature
561 if is_vararg
then tpl
.add
"..."