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 # Documentation generator for the nit language.
16 # Generate API documentation in HTML format from nit source code.
20 import modelize_property
23 # The NitdocContext contains all the knowledge used for doc generation
26 private var toolcontext
= new ToolContext
27 private var model
: Model
28 private var mbuilder
: ModelBuilder
29 private var mainmodule
: MModule
30 private var class_hierarchy
: POSet[MClass]
31 private var arguments
: Array[String]
32 private var output_dir
: nullable String
33 private var dot_dir
: nullable String
34 private var share_dir
: nullable String
35 private var source
: nullable String
36 private var min_visibility
: MVisibility
38 private var github_upstream
: nullable String
39 private var github_basesha1
: nullable String
40 private var github_gitdir
: nullable String
42 private var opt_dir
= new OptionString("Directory where doc is generated", "-d", "--dir")
43 private var opt_source
= new OptionString("What link for source (%f for filename, %l for first line, %L for last line)", "--source")
44 private var opt_sharedir
= new OptionString("Directory containing the nitdoc files", "--sharedir")
45 private var opt_shareurl
= new OptionString("Do not copy shared files, link JS and CSS file to share url instead", "--shareurl")
46 private var opt_nodot
= new OptionBool("Do not generate graphes with graphviz", "--no-dot")
47 private var opt_private
: OptionBool = new OptionBool("Generate the private API", "--private")
49 private var opt_custom_title
: OptionString = new OptionString("Title displayed in the top of the Overview page and as suffix of all page names", "--custom-title")
50 private var opt_custom_menu_items
: OptionString = new OptionString("Items displayed in menu before the 'Overview' item (Each item must be enclosed in 'li' tags)", "--custom-menu-items")
51 private var opt_custom_overview_text
: OptionString = new OptionString("Text displayed as introduction of Overview page before the modules list", "--custom-overview-text")
52 private var opt_custom_footer_text
: OptionString = new OptionString("Text displayed as footer of all pages", "--custom-footer-text")
54 private var opt_github_upstream
: OptionString = new OptionString("The branch where edited commits will be pulled into (ex: user:repo:branch)", "--github-upstream")
55 private var opt_github_base_sha1
: OptionString = new OptionString("The sha1 of the base commit used to create pull request", "--github-base-sha1")
56 private var opt_github_gitdir
: OptionString = new OptionString("The git working directory used to resolve path name (ex: /home/me/myproject/)", "--github-gitdir")
58 private var opt_piwik_tracker
: OptionString = new OptionString("The URL of the Piwik tracker (ex: nitlanguage.org/piwik/)", "--piwik-tracker")
59 private var opt_piwik_site_id
: OptionString = new OptionString("The site ID in Piwik tracker", "--piwik-site-id")
62 toolcontext
.option_context
.add_option
(opt_dir
)
63 toolcontext
.option_context
.add_option
(opt_source
)
64 toolcontext
.option_context
.add_option
(opt_sharedir
, opt_shareurl
)
65 toolcontext
.option_context
.add_option
(opt_nodot
)
66 toolcontext
.option_context
.add_option
(opt_private
)
67 toolcontext
.option_context
.add_option
(opt_custom_title
)
68 toolcontext
.option_context
.add_option
(opt_custom_footer_text
)
69 toolcontext
.option_context
.add_option
(opt_custom_overview_text
)
70 toolcontext
.option_context
.add_option
(opt_custom_menu_items
)
71 toolcontext
.option_context
.add_option
(opt_github_upstream
)
72 toolcontext
.option_context
.add_option
(opt_github_base_sha1
)
73 toolcontext
.option_context
.add_option
(opt_github_gitdir
)
74 toolcontext
.option_context
.add_option
(opt_piwik_tracker
)
75 toolcontext
.option_context
.add_option
(opt_piwik_site_id
)
76 toolcontext
.process_options
77 self.arguments
= toolcontext
.option_context
.rest
79 if arguments
.length
< 1 then
80 print
"usage: nitdoc [options] file..."
81 toolcontext
.option_context
.usage
87 mbuilder
= new ModelBuilder(model
, toolcontext
)
88 # Here we load and process all modules passed on the command line
89 var mmodules
= mbuilder
.parse
(arguments
)
90 if mmodules
.is_empty
then return
93 if mmodules
.length
== 1 then
94 mainmodule
= mmodules
.first
96 # We need a main module, so we build it by importing all modules
97 mainmodule
= new MModule(model
, null, "<main>", new Location(null, 0, 0, 0, 0))
98 mainmodule
.set_imported_mmodules
(mmodules
)
100 self.class_hierarchy
= mainmodule
.flatten_mclass_hierarchy
103 private fun process_options
do
104 if opt_dir
.value
!= null then
105 output_dir
= opt_dir
.value
109 if opt_sharedir
.value
!= null then
110 share_dir
= opt_sharedir
.value
112 var dir
= "NIT_DIR".environ
114 dir
= "{sys.program_name.dirname}/../share/nitdoc"
116 dir
= "{dir}/share/nitdoc"
119 if share_dir
== null then
120 print
"Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
124 if opt_private
.value
then
125 min_visibility
= none_visibility
127 min_visibility
= protected_visibility
129 var gh_upstream
= opt_github_upstream
.value
130 var gh_base_sha
= opt_github_base_sha1
.value
131 var gh_gitdir
= opt_github_gitdir
.value
132 if not gh_upstream
== null or not gh_base_sha
== null or not gh_gitdir
== null then
133 if gh_upstream
== null or gh_base_sha
== null or gh_gitdir
== null then
134 print
"Error: Options {opt_github_upstream.names.first}, {opt_github_base_sha1.names.first} and {opt_github_gitdir.names.first} are required to enable the GitHub plugin"
137 self.github_upstream
= gh_upstream
138 self.github_basesha1
= gh_base_sha
139 self.github_gitdir
= gh_gitdir
142 source
= opt_source
.value
145 fun generate_nitdoc
do
146 # Create destination dir if it's necessary
147 if not output_dir
.file_exists
then output_dir
.mkdir
148 if opt_shareurl
.value
== null then
149 sys
.system
("cp -r {share_dir.to_s}/* {output_dir.to_s}/")
151 sys
.system
("cp -r {share_dir.to_s}/resources/ {output_dir.to_s}/resources/")
154 if not opt_nodot
.value
then self.dot_dir
= output_dir
.to_s
162 private fun overview
do
163 var overviewpage
= new NitdocOverview(self)
164 overviewpage
.save
("{output_dir.to_s}/index.html")
167 private fun search
do
168 var searchpage
= new NitdocSearch(self)
169 searchpage
.save
("{output_dir.to_s}/search.html")
172 private fun modules
do
173 for mmodule
in model
.mmodules
do
174 if mmodule
.name
== "<main>" then continue
175 var modulepage
= new NitdocModule(mmodule
, self)
176 modulepage
.save
("{output_dir.to_s}/{mmodule.url}")
180 private fun classes
do
181 for mclass
in mbuilder
.model
.mclasses
do
182 var classpage
= new NitdocClass(mclass
, self)
183 classpage
.save
("{output_dir.to_s}/{mclass.url}")
187 private fun quicksearch_list
do
188 var file
= new OFStream.open
("{output_dir.to_s}/quicksearch-list.js")
189 file
.write
("var nitdocQuickSearchRawList = \{ ")
190 for mmodule
in model
.mmodules
do
191 if mmodule
.name
== "<main>" then continue
192 file
.write
("\"{mmodule.name}\
": [")
193 file
.write
("\{txt: \"{mmodule.full_name}\", url
:\
"{mmodule.url}\" \
},")
196 for mclass in model.mclasses do
197 if mclass.visibility < min_visibility then continue
198 file.write("\
"{mclass.name}\": [")
199 file.write("\
{txt: \"{mclass.full_name}\
", url:\"{mclass.url}\
" \},")
202 var name2mprops
= new HashMap[String, Set[MPropDef]]
203 for mproperty
in model
.mproperties
do
204 if mproperty
.visibility
< min_visibility
then continue
205 if mproperty
isa MAttribute then continue
206 if not name2mprops
.has_key
(mproperty
.name
) then name2mprops
[mproperty
.name
] = new HashSet[MPropDef]
207 name2mprops
[mproperty
.name
].add_all
(mproperty
.mpropdefs
)
209 for mproperty
, mpropdefs
in name2mprops
do
210 file
.write
("\"{mproperty}\
": [")
211 for mpropdef
in mpropdefs
do
212 file
.write
("\{txt: \"{mpropdef.full_name}\", url
:\
"{mpropdef.url}\" \
},")
223 abstract class NitdocPage
225 var ctx: NitdocContext
228 init(ctx: NitdocContext) do
230 if ctx.opt_shareurl.value != null then shareurl = ctx.opt_shareurl.value.as(not null)
233 protected fun head do
234 append("<meta charset
='utf-8'/>")
235 append("<link rel
='stylesheet' href
='{shareurl}/css/main.css' type='text/css'/>")
236 append("<link rel
='stylesheet' href
='{shareurl}/css/Nitdoc.UI.css' type='text/css''/>")
237 append("<link rel='stylesheet
' href='{shareurl}/css
/Nitdoc.QuickSearch.css
' type='text
/css
'/>")
238 append("<link rel='stylesheet
' href='{shareurl}/css
/Nitdoc.GitHub.css
' type='text
/css
'/>")
239 append("<link rel='stylesheet
' href='{shareurl}/css
/Nitdoc.ModalBox.css
' type='text
/css
'/>")
241 if ctx.opt_custom_title.value != null then
242 title = " | {ctx.opt_custom_title.value.to_s}"
244 append("<title>{self.title}{title}</title>")
247 protected fun menu do
248 if ctx.opt_custom_menu_items.value != null then
249 append(ctx.opt_custom_menu_items.value.to_s)
253 protected fun title: String is abstract
255 protected fun header do
257 append("<nav class='main
'>")
265 protected fun content is abstract
267 protected fun footer do
268 if ctx.opt_custom_footer_text.value != null then
269 append("<footer>{ctx.opt_custom_footer_text.value.to_s}</footer>")
273 # Generate a clickable graphviz image using a dot content
274 protected fun generate_dot(dot: String, name: String, alt: String) do
275 var output_dir = ctx.dot_dir
276 if output_dir == null then return
277 var file = new OFStream.open("{output_dir}/{name}.dot")
280 sys.system("\{ test -f {output_dir}/{name}.png && test -f {output_dir}/{name}.s.dot && diff {output_dir}/{name}.dot {output_dir}/{name}.s.dot >/dev/null 2>&1 ; \} || \{ cp {output_dir}/{name}.dot {output_dir}/{name}.s.dot && dot -Tpng -o{output_dir}/{name}.png -Tcmapx -o{output_dir}/{name}.map {output_dir}/{name}.s.dot ; \}")
281 append("<article class='graph
'>")
282 append("<img src='{name}.png
' usemap='#{name}' style='margin:auto' alt='{alt}'/>")
284 var fmap
= new IFStream.open
("{output_dir}/{name}.map")
285 append
(fmap
.read_all
)
289 # Add a (source) link for a given location
290 protected fun show_source
(l
: Location): String
292 var source
= ctx
.source
293 if source
== null then
294 return "({l.file.filename.simplify_path})"
296 # THIS IS JUST UGLY ! (but there is no replace yet)
297 var x
= source
.split_with
("%f")
298 source
= x
.join
(l
.file
.filename
.simplify_path
)
299 x
= source
.split_with
("%l")
300 source
= x
.join
(l
.line_start
.to_s
)
301 x
= source
.split_with
("%L")
302 source
= x
.join
(l
.line_end
.to_s
)
303 source
= source
.simplify_path
304 return " (<a target='_blank' title='Show source' href=\"{source.to_s}\
">source</a>)"
308 # Render the page as a html string
309 protected fun render
do
310 append
("<!DOCTYPE html>")
315 append
(" data-bootstrap-share='{shareurl}'")
316 if ctx
.opt_github_upstream
.value
!= null and ctx
.opt_github_base_sha1
.value
!= null then
317 append
(" data-github-upstream='{ctx.opt_github_upstream.value.as(not null)}'")
318 append
(" data-github-base-sha1='{ctx.opt_github_base_sha1.value.as(not null)}'")
323 if ctx
.opt_custom_footer_text
.value
!= null then footed
= "footed"
324 append
("<div class='page {footed}'>")
328 append
("<script data-main=\"{shareurl}/js
/nitdoc\
" src=\"{shareurl}/js
/lib
/require
.js\
"></script>")
331 var tracker_url
= ctx
.opt_piwik_tracker
.value
332 var site_id
= ctx
.opt_piwik_site_id
.value
333 if tracker_url
!= null and site_id
!= null then
334 append
("<!-- Piwik -->")
335 append
("<script type=\"text
/javascript\
">")
336 append
(" var _paq = _paq || [];")
337 append
(" _paq.push([\"trackPageView\
"]);")
338 append
(" _paq.push([\"enableLinkTracking\
"]);")
339 append
(" (function() \{")
340 append
(" var u=((\"https
:\
" == document.location.protocol) ? \"https\
" : \"http\
") + \"://{tracker_url}\
";")
341 append
(" _paq.push([\"setTrackerUrl\
", u+\"piwik
.php\
"]);")
342 append
(" _paq.push([\"setSiteId\
", \"{site_id}\
"]);")
343 append
(" var d=document, g=d.createElement(\"script\
"), s=d.getElementsByTagName(\"script\
")[0]; g.type=\"text
/javascript\
";")
344 append
(" g.defer=true; g.async=true; g.src=u+\"piwik
.js\
"; s.parentNode.insertBefore(g,s);")
347 append
("<!-- End Piwik Code -->")
352 # Append a string to the page
353 fun append
(s
: String) do out
.write
(s
)
355 # Save html page in the specified file
356 fun save
(file
: String) do
357 self.out
= new OFStream.open
(file
)
361 private var out
: nullable OFStream
367 private var mbuilder
: ModelBuilder
368 private var mmodules
= new Array[MModule]
370 init(ctx
: NitdocContext) do
372 self.mbuilder
= ctx
.mbuilder
374 var mmodules
= new HashSet[MModule]
375 for mmodule
in mbuilder
.model
.mmodule_importation_hierarchy
do
376 if mmodule
.name
== "<main>" then continue
377 var owner
= mmodule
.public_owner
378 if owner
!= null then
381 mmodules
.add
(mmodule
)
385 var sorter
= new MModuleNameSorter
386 self.mmodules
.add_all
(mmodules
)
387 sorter
.sort
(self.mmodules
)
390 redef fun title
do return "Overview"
394 append
("<li class='current'>Overview</li>")
395 append
("<li><a href='search.html'>Search</a></li>")
399 append
("<div class='content fullpage'>")
400 var title
= "Overview"
401 if ctx
.opt_custom_title
.value
!= null then
402 title
= ctx
.opt_custom_title
.value
.to_s
404 append
("<h1>{title}</h1>")
406 if ctx
.opt_custom_overview_text
.value
!= null then
407 text
= ctx
.opt_custom_overview_text
.value
.to_s
409 append
("<article class='overview'>{text}</article>")
410 append
("<article class='overview'>")
412 append
("<h2>Modules</h2>")
414 for mmodule
in mmodules
do
415 if mbuilder
.mmodule2nmodule
.has_key
(mmodule
) then
416 var amodule
= mbuilder
.mmodule2nmodule
[mmodule
]
418 mmodule
.html_link
(self)
419 append
(" {amodule.short_comment}</li>")
429 private fun process_generate_dot
do
430 # build poset with public owners
431 var poset
= new POSet[MModule]
432 for mmodule
in mmodules
do
433 poset
.add_node
(mmodule
)
434 for omodule
in mmodules
do
435 if mmodule
== omodule
then continue
436 if mmodule
.in_importation
< omodule
then
437 poset
.add_node
(omodule
)
438 poset
.add_edge
(mmodule
, omodule
)
444 op
.append
("digraph dep \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
445 for mmodule
in poset
do
446 op
.append
("\"{mmodule.name}\
"[URL=\"{mmodule.url}\
"];\n")
447 for omodule
in poset
[mmodule
].direct_greaters
do
448 op
.append
("\"{mmodule.name}\
"->\"{omodule.name}\
";\n")
452 generate_dot
(op
.to_s
, "dep", "Modules hierarchy")
460 init(ctx
: NitdocContext) do
464 redef fun title
do return "Search"
468 append
("<li><a href='index.html'>Overview</a></li>")
469 append
("<li class='current'>Search</li>")
473 append
("<div class='content fullpage'>")
474 append
("<h1>{title}</h1>")
481 # Add to content modules column
482 private fun module_column
do
483 var sorted
= ctx
.mbuilder
.model
.mmodule_importation_hierarchy
.to_a
484 var sorter
= new MModuleNameSorter
486 append
("<article class='modules filterable'>")
487 append
("<h2>Modules</h2>")
489 for mmodule
in sorted
do
490 if mmodule
.name
== "<main>" then continue
492 mmodule
.html_link
(self)
499 # Add to content classes modules
500 private fun classes_column
do
501 var sorted
= ctx
.mbuilder
.model
.mclasses
502 var sorter
= new MClassNameSorter
504 append
("<article class='modules filterable'>")
505 append
("<h2>Classes</h2>")
507 for mclass
in sorted
do
508 if mclass
.visibility
< ctx
.min_visibility
then continue
510 mclass
.html_link
(self)
517 # Insert the properties column of fullindex page
518 private fun properties_column
do
519 var sorted
= ctx
.mbuilder
.model
.mproperties
520 var sorter
= new MPropertyNameSorter
522 append
("<article class='modules filterable'>")
523 append
("<h2>Properties</h2>")
525 for mproperty
in sorted
do
526 if mproperty
.visibility
< ctx
.min_visibility
then continue
527 if mproperty
isa MAttribute then continue
529 mproperty
.intro
.html_link
(self)
531 mproperty
.intro
.mclassdef
.mclass
.html_link
(self)
544 private var mmodule
: MModule
545 private var mbuilder
: ModelBuilder
546 private var local_mclasses
= new HashSet[MClass]
547 private var intro_mclasses
= new HashSet[MClass]
548 private var redef_mclasses
= new HashSet[MClass]
550 init(mmodule
: MModule, ctx
: NitdocContext) do
552 self.mmodule
= mmodule
553 self.mbuilder
= ctx
.mbuilder
555 for m
in mmodule
.in_nesting
.greaters
do
556 for mclassdef
in m
.mclassdefs
do
557 if mclassdef
.mclass
.visibility
< ctx
.min_visibility
then continue
558 if mclassdef
.is_intro
then
559 intro_mclasses
.add
(mclassdef
.mclass
)
561 if mclassdef
.mclass
.mpropdefs_in_module
(self).is_empty
then continue
562 redef_mclasses
.add
(mclassdef
.mclass
)
564 local_mclasses
.add
(mclassdef
.mclass
)
570 if mbuilder
.mmodule2nmodule
.has_key
(mmodule
) and not mbuilder
.mmodule2nmodule
[mmodule
].short_comment
.is_empty
then
571 var nmodule
= mbuilder
.mmodule2nmodule
[mmodule
]
572 return "{mmodule.html_name} module | {nmodule.short_comment}"
574 return "{mmodule.html_name} module"
580 append
("<li><a href='index.html'>Overview</a></li>")
581 append
("<li class='current'>{mmodule.html_name}</li>")
582 append
("<li><a href='search.html'>Search</a></li>")
586 append
("<div class='sidebar'>")
590 append
("<div class='content'>")
595 private fun classes_column
do
596 var sorter
= new MClassNameSorter
597 var sorted
= new Array[MClass]
598 sorted
.add_all
(intro_mclasses
)
599 sorted
.add_all
(redef_mclasses
)
601 if not sorted
.is_empty
then
602 append
("<nav class='properties filterable'>")
603 append
("<h3>Classes</h3>")
604 append
("<h4>Classes</h4>")
606 for mclass
in sorted
do mclass
.html_sidebar_item
(self)
612 private fun importation_column
do
614 append
("<h3>Module Hierarchy</h3>")
615 var dependencies
= new Array[MModule]
616 for dep
in mmodule
.in_importation
.greaters
do
617 if dep
== mmodule
or dep
.direct_owner
== mmodule
or dep
.public_owner
== mmodule
then continue
618 dependencies
.add
(dep
)
620 if mmodule
.in_nesting
.direct_greaters
.length
> 0 then
621 append
("<h4>Nested Modules</h4>")
622 display_module_list
(mmodule
.in_nesting
.direct_greaters
.to_a
)
624 if dependencies
.length
> 0 then
625 append
("<h4>All dependencies</h4>")
626 display_module_list
(dependencies
)
628 var clients
= new Array[MModule]
629 for dep
in mmodule
.in_importation
.smallers
do
630 if dep
.name
== "<main>" then continue
631 if dep
== mmodule
then continue
634 if clients
.length
> 0 then
635 append
("<h4>All clients</h4>")
636 display_module_list
(clients
)
641 private fun display_module_list
(list
: Array[MModule]) do
643 var sorter
= new MModuleNameSorter
653 private fun module_doc
do
655 append
("<h1>{mmodule.html_name}</h1>")
656 append
("<div class='subtitle info'>")
657 mmodule
.html_signature
(self)
660 mmodule
.html_comment
(self)
663 var class_sorter
= new MClassNameSorter
665 if not intro_mclasses
.is_empty
then
666 var sorted
= new Array[MClass]
667 sorted
.add_all
(intro_mclasses
)
668 class_sorter
.sort
(sorted
)
669 append
("<section class='classes'>")
670 append
("<h2 class='section-header'>Introduced classes</h2>")
671 for mclass
in sorted
do mclass
.html_full_desc
(self)
675 var redefs
= new Array[MClass]
676 for mclass
in redef_mclasses
do if not intro_mclasses
.has
(mclass
) then redefs
.add
(mclass
)
677 class_sorter
.sort
(redefs
)
678 if not redefs
.is_empty
then
679 append
("<section class='classes'>")
680 append
("<h2 class='section-header'>Refined classes</h2>")
681 for mclass
in redefs
do mclass
.html_full_desc
(self)
686 private fun process_generate_dot
do
687 # build poset with public owners
688 var poset
= new POSet[MModule]
689 for mmodule
in self.mmodule
.in_importation
.poset
do
690 if mmodule
.name
== "<main>" then continue
691 #if mmodule.public_owner != null then continue
692 if not mmodule
.in_importation
< self.mmodule
and not self.mmodule
.in_importation
< mmodule
and mmodule
!= self.mmodule
then continue
693 poset
.add_node
(mmodule
)
694 for omodule
in mmodule
.in_importation
.poset
do
695 if mmodule
== omodule
then continue
696 if omodule
.name
== "<main>" then continue
697 if not omodule
.in_importation
< self.mmodule
and not self.mmodule
.in_importation
< omodule
then continue
698 if omodule
.in_importation
< mmodule
then
699 poset
.add_node
(omodule
)
700 poset
.add_edge
(omodule
, mmodule
)
702 if mmodule
.in_importation
< omodule
then
703 poset
.add_node
(omodule
)
704 poset
.add_edge
(mmodule
, omodule
)
706 #if omodule.public_owner != null then continue
707 #if mmodule.in_importation < omodule then
708 #poset.add_node(omodule)
709 #poset.add_edge(mmodule, omodule)
715 var name
= "dep_{mmodule.name}"
716 op
.append
("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
717 for mmodule
in poset
do
718 if mmodule
== self.mmodule
then
719 op
.append
("\"{mmodule.name}\
"[shape=box,margin=0.03];\n")
721 op
.append
("\"{mmodule.name}\
"[URL=\"{mmodule.url}\
"];\n")
723 for omodule
in poset
[mmodule
].direct_greaters
do
724 op
.append
("\"{mmodule.name}\
"->\"{omodule.name}\
";\n")
728 generate_dot
(op
.to_s
, name
, "Dependency graph for module {mmodule.name}")
736 private var mclass
: MClass
737 private var vtypes
= new HashSet[MVirtualTypeDef]
738 private var consts
= new HashSet[MMethodDef]
739 private var meths
= new HashSet[MMethodDef]
740 private var inherited
= new HashSet[MPropDef]
742 init(mclass
: MClass, ctx
: NitdocContext) do
746 var locals
= new HashSet[MProperty]
747 for mclassdef
in mclass
.mclassdefs
do
748 for mpropdef
in mclassdef
.mpropdefs
do
749 if mpropdef
.mproperty
.visibility
< ctx
.min_visibility
then continue
750 if mpropdef
isa MVirtualTypeDef then vtypes
.add
(mpropdef
)
751 if mpropdef
isa MMethodDef then
752 if mpropdef
.mproperty
.is_init
then
758 locals
.add
(mpropdef
.mproperty
)
761 # get inherited properties
762 for pclass
in mclass
.in_hierarchy
(ctx
.mainmodule
).greaters
do
763 if pclass
== mclass
then continue
764 for pclassdef
in pclass
.mclassdefs
do
765 for mprop
in pclassdef
.intro_mproperties
do
766 var mpropdef
= mprop
.intro
767 if mprop
.visibility
< ctx
.min_visibility
then continue # skip if not correct visibiility
768 if locals
.has
(mprop
) then continue # skip if local
769 if mclass
.name
!= "Object" and mprop
.intro_mclassdef
.mclass
.name
== "Object" and (mprop
.visibility
<= protected_visibility
or mprop
.intro_mclassdef
.mmodule
.public_owner
== null or mprop
.intro_mclassdef
.mmodule
.public_owner
.name
!= "standard") then continue # skip toplevels
770 if mpropdef
isa MVirtualTypeDef then vtypes
.add
(mpropdef
)
771 if mpropdef
isa MMethodDef then
772 if mpropdef
.mproperty
.is_init
then
778 inherited
.add
(mpropdef
)
785 var nclass
= ctx
.mbuilder
.mclassdef2nclassdef
[mclass
.intro
]
786 if nclass
isa AStdClassdef then
787 return "{mclass.html_name} class | {nclass.short_comment}"
789 return "{mclass.html_name} class"
795 append
("<li><a href='index.html'>Overview</a></li>")
796 var public_owner
= mclass
.public_owner
797 if public_owner
== null then
799 mclass
.intro_mmodule
.html_link
(self)
803 public_owner
.html_link
(self)
806 append
("<li class='current'>{mclass.html_name}</li>")
807 append
("<li><a href='search.html'>Search</a></li>")
811 append
("<div class='sidebar'>")
815 append
("<div class='content'>")
820 private fun properties_column
do
821 var sorter
= new MPropDefNameSorter
822 append
("<nav class='properties filterable'>")
823 append
("<h3>Properties</h3>")
825 if vtypes
.length
> 0 then
826 var vts
= new Array[MVirtualTypeDef]
829 append
("<h4>Virtual Types</h4>")
832 mprop
.html_sidebar_item
(self)
837 if consts
.length
> 0 then
838 var cts
= new Array[MMethodDef]
841 append
("<h4>Constructors</h4>")
844 if mprop
.mproperty
.name
== "init" and mprop
.mclassdef
.mclass
!= mclass
then continue
845 mprop
.html_sidebar_item
(self)
850 if meths
.length
> 0 then
851 var mts
= new Array[MMethodDef]
854 append
("<h4>Methods</h4>")
857 mprop
.html_sidebar_item
(self)
864 private fun inheritance_column
do
865 var sorted
= new Array[MClass]
866 var sorterp
= new MClassNameSorter
868 append
("<h3>Inheritance</h3>")
869 var greaters
= mclass
.in_hierarchy
(ctx
.mainmodule
).greaters
.to_a
870 if greaters
.length
> 1 then
871 ctx
.mainmodule
.linearize_mclasses
(greaters
)
872 append
("<h4>Superclasses</h4>")
874 for sup
in greaters
do
875 if sup
== mclass
then continue
882 var smallers
= mclass
.in_hierarchy
(ctx
.mainmodule
).smallers
.to_a
883 var direct_smallers
= mclass
.in_hierarchy
(ctx
.mainmodule
).direct_smallers
.to_a
884 if smallers
.length
<= 1 then
885 append
("<h4>No Known Subclasses</h4>")
886 else if smallers
.length
<= 100 then
887 ctx
.mainmodule
.linearize_mclasses
(smallers
)
888 append
("<h4>Subclasses</h4>")
890 for sub
in smallers
do
891 if sub
== mclass
then continue
897 else if direct_smallers
.length
<= 100 then
898 ctx
.mainmodule
.linearize_mclasses
(direct_smallers
)
899 append
("<h4>Direct Subclasses Only</h4>")
901 for sub
in direct_smallers
do
902 if sub
== mclass
then continue
909 append
("<h4>Too much Subclasses to list</h4>")
914 private fun class_doc
do
916 append
("<h1>{mclass.html_name}{mclass.html_short_signature}</h1>")
917 append
("<div class='subtitle info'>")
918 if mclass
.visibility
< public_visibility
then append
("{mclass.visibility.to_s} ")
919 append
("{mclass.kind.to_s} ")
920 mclass
.html_namespace
(self)
921 append
("{mclass.html_short_signature}</div>")
923 mclass
.html_comment
(self)
926 var concern2meths
= new ArrayMap[MModule, Array[MMethodDef]]
927 var sorted_meths
= new Array[MMethodDef]
928 var sorted
= new Array[MModule]
929 sorted_meths
.add_all
(meths
)
930 ctx
.mainmodule
.linearize_mpropdefs
(sorted_meths
)
932 if inherited
.has
(meth
) then continue
933 var mmodule
= meth
.mclassdef
.mmodule
934 if not concern2meths
.has_key
(mmodule
) then
936 concern2meths
[mmodule
] = new Array[MMethodDef]
938 concern2meths
[mmodule
].add
(meth
)
940 var sections
= new ArrayMap[MModule, Array[MModule]]
941 for mmodule
in concern2meths
.keys
do
942 var owner
= mmodule
.public_owner
943 if owner
== null then owner
= mmodule
944 if not sections
.has_key
(owner
) then sections
[owner
] = new Array[MModule]
945 if owner
!= mmodule
then sections
[owner
].add
(mmodule
)
947 append
("<section class='concerns'>")
948 append
("<h2 class='section-header'>Concerns</h2>")
950 for owner
, mmodules
in sections
do
951 var nowner
= ctx
.mbuilder
.mmodule2nmodule
[owner
]
953 if nowner
.short_comment
.is_empty
then
954 append
("<a href=\"#{owner.anchor}\">{owner.html_name}</a>")
956 append
("<a href=\"#{owner.anchor}\">{owner.html_name}</a>: {nowner.short_comment}")
958 if not mmodules
.is_empty
then
960 for mmodule
in mmodules
do
961 var nmodule
= ctx
.mbuilder
.mmodule2nmodule
[mmodule
]
962 if nmodule
.short_comment
.is_empty
then
963 append
("<li><a href=\"#{mmodule.anchor}\">{mmodule.html_name}</a></li>")
965 append
("<li><a href=\"#{mmodule.anchor}\">{mmodule.html_name}</a>: {nmodule.short_comment}</li>")
975 var prop_sorter
= new MPropDefNameSorter
976 var lmmodule
= new List[MModule]
977 var nclass
= ctx
.mbuilder
.mclassdef2nclassdef
[mclass
.intro
]
978 # virtual and formal types
979 var local_vtypes
= new Array[MVirtualTypeDef]
980 for vt
in vtypes
do if not inherited
.has
(vt
) then local_vtypes
.add
(vt
)
981 if local_vtypes
.length
> 0 or mclass
.arity
> 0 then
982 append
("<section class='types'>")
983 append
("<h2>Formal and Virtual Types</h2>")
985 if mclass
.arity
> 0 and nclass
isa AStdClassdef then
986 for ft
, bound
in mclass
.parameter_types
do
987 append
("<article id='FT_{ft}'>")
988 append
("<h3 class='signature' data-untyped-signature='{ft.to_s}'><span>{ft}: ")
989 bound
.html_link
(self)
990 append
("</span></h3>")
991 append
("<div class=\"info\
">formal generic type</div>")
996 prop_sorter
.sort
(local_vtypes
)
997 for prop
in local_vtypes
do prop
.html_full_desc
(self, self.mclass
)
1001 var local_consts
= new Array[MMethodDef]
1002 for const
in consts
do if not inherited
.has
(const
) then local_consts
.add
(const
)
1003 prop_sorter
.sort
(local_consts
)
1004 if local_consts
.length
> 0 then
1005 append
("<section class='constructors'>")
1006 append
("<h2 class='section-header'>Constructors</h2>")
1007 for prop
in local_consts
do prop
.html_full_desc
(self, self.mclass
)
1008 append
("</section>")
1011 if not concern2meths
.is_empty
then
1012 append
("<section class='methods'>")
1013 append
("<h2 class='section-header'>Methods</h2>")
1014 for owner
, mmodules
in sections
do
1015 append
("<a id=\"{owner.anchor}\
"></a>")
1016 if owner
!= mclass
.intro_mmodule
and owner
!= mclass
.public_owner
then
1017 var nowner
= ctx
.mbuilder
.mmodule2nmodule
[owner
]
1018 append
("<h3 class=\"concern-toplevel\
">Methods refined in ")
1019 owner
.html_link
(self)
1021 append
("<p class=\"concern-doc\
">")
1022 owner
.html_link
(self)
1023 if not nowner
.short_comment
.is_empty
then
1024 append
(": {nowner.short_comment}")
1028 if concern2meths
.has_key
(owner
) then
1029 var mmethods
= concern2meths
[owner
]
1030 prop_sorter
.sort
(mmethods
)
1031 for prop
in mmethods
do prop
.html_full_desc
(self, self.mclass
)
1033 for mmodule
in mmodules
do
1034 append
("<a id=\"{mmodule.anchor}\
"></a>")
1035 var nmodule
= ctx
.mbuilder
.mmodule2nmodule
[mmodule
]
1036 if mmodule
!= mclass
.intro_mmodule
and mmodule
!= mclass
.public_owner
then
1037 append
("<p class=\"concern-doc\
">")
1038 mmodule
.html_link
(self)
1039 if not nmodule
.short_comment
.is_empty
then
1040 append
(": {nmodule.short_comment}")
1044 var mmethods
= concern2meths
[mmodule
]
1045 prop_sorter
.sort
(mmethods
)
1046 for prop
in mmethods
do prop
.html_full_desc
(self, self.mclass
)
1049 append
("</section>")
1051 # inherited properties
1052 if inherited
.length
> 0 then
1053 var sorted_inherited
= new Array[MPropDef]
1054 sorted_inherited
.add_all
(inherited
)
1055 ctx
.mainmodule
.linearize_mpropdefs
(sorted_inherited
)
1056 var classes
= new ArrayMap[MClass, Array[MPropDef]]
1057 for mmethod
in sorted_inherited
.reversed
do
1058 var mclass
= mmethod
.mclassdef
.mclass
1059 if not classes
.has_key
(mclass
) then classes
[mclass
] = new Array[MPropDef]
1060 classes
[mclass
].add
(mmethod
)
1062 append
("<section class='inherited'>")
1063 append
("<h2 class='section-header'>Inherited Properties</h2>")
1064 for c
, mmethods
in classes
do
1065 prop_sorter
.sort
(mmethods
)
1066 append
("<p>Defined in ")
1069 for i
in [0..mmethods
.length
[ do
1070 var mmethod
= mmethods
[i
]
1071 mmethod
.html_link
(self)
1072 if i
<= mmethods
.length
- 1 then append
(", ")
1076 append
("</section>")
1080 private fun process_generate_dot
do
1081 var pe
= ctx
.class_hierarchy
[mclass
]
1082 var cla
= new HashSet[MClass]
1083 var sm
= new HashSet[MClass]
1084 var sm2
= new HashSet[MClass]
1086 while cla
.length
+ sm
.length
< 10 and sm
.length
> 0 do
1090 sm2
.add_all
(pe
.poset
[x
].direct_smallers
)
1096 cla
.add_all
(pe
.greaters
)
1099 var name
= "dep_{mclass.name}"
1100 op
.append
("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
1103 op
.append
("\"{c.name}\
"[shape=box,margin=0.03];\n")
1105 op
.append
("\"{c.name}\
"[URL=\"{c.url}\
"];\n")
1107 for c2
in pe
.poset
[c
].direct_greaters
do
1108 if not cla
.has
(c2
) then continue
1109 op
.append
("\"{c.name}\
"->\"{c2.name}\
";\n")
1111 if not pe
.poset
[c
].direct_smallers
.is_empty
then
1113 for c2
in pe
.poset
[c
].direct_smallers
do
1114 if cla
.has
(c2
) then others
= false
1117 op
.append
("\"{c.name}...\
"[label=\"\
"];\n")
1118 op
.append
("\"{c.name}...\
"->\"{c.name}\
"[style=dotted];\n")
1123 generate_dot
(op
.to_s
, name
, "Dependency graph for class {mclass.name}")
1132 # Return the HTML escaped name of the module
1133 private fun html_name
: String do return name
.html_escape
1135 # URL to nitdoc page
1136 # module_owner_name.html
1137 private fun url
: String do
1138 if url_cache
== null then
1139 var res
= new Buffer
1140 res
.append
("module_")
1141 var mowner
= public_owner
1142 if mowner
!= null then
1143 res
.append
("{public_owner.name}_")
1145 res
.append
("{self.name}.html")
1146 url_cache
= res
.to_s
1148 return url_cache
.as(not null)
1150 private var url_cache
: nullable String
1152 # html anchor id for the module in a nitdoc page
1154 private fun anchor
: String do
1155 if anchor_cache
== null then
1156 var res
= new Buffer
1158 var mowner
= public_owner
1159 if mowner
!= null then
1160 res
.append
("{public_owner.name}_")
1162 res
.append
(self.name
)
1163 anchor_cache
= res
.to_s
1165 return anchor_cache
.as(not null)
1167 private var anchor_cache
: nullable String
1169 # Return a link (html a tag) to the nitdoc module page
1170 # <a href="url" title="short_comment">html_name</a>
1171 private fun html_link
(page
: NitdocPage) do
1172 if html_link_cache
== null then
1173 var res
= new Buffer
1174 if page
.ctx
.mbuilder
.mmodule2nmodule
.has_key
(self) then
1175 res
.append
("<a href='{url}' title='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{html_name}</a>")
1177 res
.append
("<a href='{url}'>{html_name}</a>")
1179 html_link_cache
= res
.to_s
1181 page
.append
(html_link_cache
.as(not null))
1183 private var html_link_cache
: nullable String
1185 # Return the module signature decorated with html
1186 # <span>module html_full_namespace</span>
1187 private fun html_signature
(page
: NitdocPage) do
1188 page
.append
("<span>module ")
1189 html_full_namespace
(page
)
1190 page
.append
("</span>")
1193 # Return the module full namespace decorated with html
1194 # <span>public_owner.html_namespace::html_link</span>
1195 private fun html_full_namespace
(page
: NitdocPage) do
1196 page
.append
("<span>")
1197 var mowner
= public_owner
1198 if mowner
!= null then
1199 public_owner
.html_namespace
(page
)
1203 page
.append
("</span>")
1206 # Return the module full namespace decorated with html
1207 # <span>public_owner.html_namespace</span>
1208 private fun html_namespace
(page
: NitdocPage) do
1209 page
.append
("<span>")
1210 var mowner
= public_owner
1211 if mowner
!= null then
1212 public_owner
.html_namespace
(page
)
1216 page
.append
("</span>")
1219 # Return the full comment of the module decorated with html
1220 private fun html_comment
(page
: NitdocPage) do
1221 page
.append
("<div class='description'>")
1222 if page
.ctx
.mbuilder
.mmodule2nmodule
.has_key
(self) then
1223 var nmodule
= page
.ctx
.mbuilder
.mmodule2nmodule
[self]
1224 if page
.ctx
.github_gitdir
!= null then
1225 var loc
= nmodule
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1226 page
.append
("<textarea class='baseComment' data-comment-namespace='{full_name}' data-comment-location='{loc}'>{nmodule.full_comment}</textarea>")
1228 if nmodule
.full_comment
== "" then
1229 page
.append
("<p class='info inheritance'>")
1230 page
.append
("<span class=\"noComment\
">no comment for </span>")
1232 page
.append
("<div class='comment'>{nmodule.full_markdown}</div>")
1233 page
.append
("<p class='info inheritance'>")
1235 page
.append
("definition in ")
1236 self.html_full_namespace
(page
)
1237 page
.append
(" {page.show_source(nmodule.location)}</p>")
1239 page
.append
("</div>")
1242 private fun has_mclassdef_for
(mclass
: MClass): Bool do
1243 for mmodule
in self.in_nesting
.greaters
do
1244 for mclassdef
in mmodule
.mclassdefs
do
1245 if mclassdef
.mclass
== mclass
then return true
1251 private fun has_mclassdef
(mclassdef
: MClassDef): Bool do
1252 for mmodule
in self.in_nesting
.greaters
do
1253 for oclassdef
in mmodule
.mclassdefs
do
1254 if mclassdef
== oclassdef
then return true
1262 # Return the HTML escaped name of the module
1263 private fun html_name
: String do return name
.html_escape
1265 # URL to nitdoc page
1266 # class_owner_name.html
1267 private fun url
: String do
1268 return "class_{public_owner}_{name}.html"
1271 # html anchor id for the class in a nitdoc page
1273 private fun anchor
: String do
1274 if anchor_cache
== null then
1275 anchor_cache
= "CLASS_{public_owner.name}_{name}"
1277 return anchor_cache
.as(not null)
1279 private var anchor_cache
: nullable String
1281 # Return a link (with signature) to the nitdoc class page
1282 # <a href="url" title="short_comment">html_name(signature)</a>
1283 private fun html_link
(page
: NitdocPage) do
1284 if html_link_cache
== null then
1285 var res
= new Buffer
1286 res
.append
("<a href='{url}'")
1287 if page
.ctx
.mbuilder
.mclassdef2nclassdef
.has_key
(intro
) then
1288 var nclass
= page
.ctx
.mbuilder
.mclassdef2nclassdef
[intro
]
1289 if nclass
isa AStdClassdef then
1290 res
.append
(" title=\"{nclass.short_comment}\
"")
1293 res
.append
(">{html_name}{html_short_signature}</a>")
1294 html_link_cache
= res
.to_s
1296 page
.append
(html_link_cache
.as(not null))
1298 private var html_link_cache
: nullable String
1300 # Return a short link (without signature) to the nitdoc class page
1301 # <a href="url" title="short_comment">html_name</a>
1302 private fun html_short_link
(page
: NitdocPage) do
1303 if html_short_link_cache
== null then
1304 var res
= new Buffer
1305 res
.append
("<a href='{url}'")
1306 if page
.ctx
.mbuilder
.mclassdef2nclassdef
.has_key
(intro
) then
1307 var nclass
= page
.ctx
.mbuilder
.mclassdef2nclassdef
[intro
]
1308 if nclass
isa AStdClassdef then
1309 res
.append
(" title=\"{nclass.short_comment}\
"")
1312 res
.append
(">{html_name}</a>")
1313 html_short_link_cache
= res
.to_s
1315 page
.append
(html_short_link_cache
.as(not null))
1317 private var html_short_link_cache
: nullable String
1319 # Return a link (with signature) to the class anchor
1320 # <a href="url" title="short_comment">html_name</a>
1321 private fun html_link_anchor
(page
: NitdocPage) do
1322 if html_link_anchor_cache
== null then
1323 var res
= new Buffer
1324 res
.append
("<a href='#{anchor}'")
1325 if page
.ctx
.mbuilder
.mclassdef2nclassdef
.has_key
(intro
) then
1326 var nclass
= page
.ctx
.mbuilder
.mclassdef2nclassdef
[intro
]
1327 if nclass
isa AStdClassdef then
1328 res
.append
(" title=\"{nclass.short_comment}\
"")
1331 res
.append
(">{html_name}{html_short_signature}</a>")
1332 html_link_anchor_cache
= res
.to_s
1334 page
.append
(html_link_anchor_cache
.as(not null))
1336 private var html_link_anchor_cache
: nullable String
1338 # Return the generic signature of the class with bounds
1339 # [E: <a>MType</a>, F: <a>MType</a>]
1340 private fun html_signature
(page
: NitdocPage) do
1343 for i
in [0..intro
.parameter_names
.length
[ do
1344 page
.append
("{intro.parameter_names[i]}: ")
1345 intro
.bound_mtype
.arguments
[i
].html_link
(page
)
1346 if i
< intro
.parameter_names
.length
- 1 then page
.append
(", ")
1352 # Return the generic signature of the class without bounds
1354 private fun html_short_signature
: String do
1356 return "[{intro.parameter_names.join(", ")}]"
1362 # Return the class namespace decorated with html
1363 # <span>intro_module::html_short_link</span>
1364 private fun html_namespace
(page
: NitdocPage) do
1365 intro_mmodule
.html_namespace
(page
)
1366 page
.append
("::<span>")
1367 html_short_link
(page
)
1368 page
.append
("</span>")
1371 # Return a list item for the mclass
1372 # <li>html_link</li>
1373 private fun html_sidebar_item
(page
: NitdocModule) do
1374 if page
.mmodule
.in_nesting
.greaters
.has
(intro
.mmodule
) then
1375 page
.append
("<li class='intro'>")
1376 page
.append
("<span title='Introduced'>I</span>")
1377 html_link_anchor
(page
)
1378 else if page
.mmodule
.has_mclassdef_for
(self) then
1379 page
.append
("<li class='redef'>")
1380 page
.append
("<span title='Redefined'>R</span>")
1381 html_link_anchor
(page
)
1383 page
.append
("<li class='inherit'>")
1384 page
.append
("<span title='Inherited'>H</span>")
1387 page
.append
("</li>")
1390 private fun html_full_desc
(page
: NitdocModule) do
1391 var is_redef
= not page
.mmodule
.in_nesting
.greaters
.has
(intro
.mmodule
)
1392 var redefs
= mpropdefs_in_module
(page
)
1393 if not is_redef
or not redefs
.is_empty
then
1394 var classes
= new Array[String]
1395 classes
.add
(kind
.to_s
)
1396 if is_redef
then classes
.add
("redef")
1397 classes
.add
(visibility
.to_s
)
1398 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1399 page
.append
("<h3 class='signature' data-untyped-signature='{html_name}{html_short_signature}'>")
1400 page
.append
("<span>")
1401 html_short_link
(page
)
1402 html_signature
(page
)
1403 page
.append
("</span></h3>")
1406 page
.append
("</article>")
1410 private fun html_info
(page
: NitdocModule) do
1411 page
.append
("<div class='info'>")
1412 if visibility
< public_visibility
then page
.append
("{visibility.to_s} ")
1413 if not page
.mmodule
.in_nesting
.greaters
.has
(intro
.mmodule
) then page
.append
("redef ")
1414 page
.append
("{kind} ")
1415 html_namespace
(page
)
1416 page
.append
("{html_short_signature}</div>")
1419 private fun html_comment
(page
: NitdocPage) do
1420 page
.append
("<div class='description'>")
1421 if page
isa NitdocModule then
1422 page
.mmodule
.linearize_mclassdefs
(mclassdefs
)
1423 # comments for each mclassdef contained in current mmodule
1424 for mclassdef
in mclassdefs
do
1425 if not mclassdef
.is_intro
and not page
.mmodule
.mclassdefs
.has
(mclassdef
) then continue
1426 if page
.ctx
.mbuilder
.mclassdef2nclassdef
.has_key
(mclassdef
) then
1427 var nclass
= page
.ctx
.mbuilder
.mclassdef2nclassdef
[mclassdef
]
1428 if nclass
isa AStdClassdef then
1429 if page
.ctx
.github_gitdir
!= null then
1430 var loc
= nclass
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1431 page
.append
("<textarea class='baseComment' data-comment-namespace='{mclassdef.mmodule.full_name}::{name}' data-comment-location='{loc}'>{nclass.full_comment}</textarea>")
1433 if nclass
.full_comment
== "" then
1434 page
.append
("<p class='info inheritance'>")
1435 page
.append
("<span class=\"noComment\
">no comment for </span>")
1437 page
.append
("<div class='comment'>{nclass.full_markdown}</div>")
1438 page
.append
("<p class='info inheritance'>")
1440 if mclassdef
.is_intro
then
1441 page
.append
("introduction in ")
1443 page
.append
("refinement in ")
1445 mclassdef
.mmodule
.html_full_namespace
(page
)
1446 page
.append
(" {page.show_source(nclass.location)}</p>")
1451 # comments for intro
1452 if page
.ctx
.mbuilder
.mclassdef2nclassdef
.has_key
(intro
) then
1453 var nclass
= page
.ctx
.mbuilder
.mclassdef2nclassdef
[intro
]
1454 if nclass
isa AStdClassdef then
1455 if page
.ctx
.github_gitdir
!= null then
1456 var loc
= nclass
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1457 page
.append
("<textarea class='baseComment' data-comment-namespace='{intro.mmodule.full_name}::{name}' data-comment-location='{loc}'>{nclass.full_comment}</textarea>")
1459 if nclass
.full_comment
== "" then
1460 page
.append
("<p class='info inheritance'>")
1461 page
.append
("<span class=\"noComment\
">no comment for </span>")
1463 page
.append
("<div class='comment'>{nclass.full_markdown}</div>")
1464 page
.append
("<p class='info inheritance'>")
1466 page
.append
("introduction in ")
1467 intro
.mmodule
.html_full_namespace
(page
)
1468 page
.append
(" {page.show_source(nclass.location)}</p>")
1472 page
.append
("</div>")
1475 private fun mpropdefs_in_module
(page
: NitdocModule): Array[MPropDef] do
1476 var res
= new Array[MPropDef]
1477 page
.mmodule
.linearize_mclassdefs
(mclassdefs
)
1478 for mclassdef
in mclassdefs
do
1479 if not page
.mmodule
.mclassdefs
.has
(mclassdef
) then continue
1480 if mclassdef
.is_intro
then continue
1481 for mpropdef
in mclassdef
.mpropdefs
do
1482 if mpropdef
.mproperty
.visibility
< page
.ctx
.min_visibility
then continue
1483 if mpropdef
isa MAttributeDef then continue
1491 redef class MProperty
1492 # Escape name for html output
1493 private fun html_name
: String do return name
.html_escape
1495 # Return the property namespace decorated with html
1496 # <span>intro_module::intro_class::html_link</span>
1497 private fun html_namespace
(page
: NitdocPage) do
1498 intro_mclassdef
.mclass
.html_namespace
(page
)
1499 page
.append
(intro_mclassdef
.mclass
.html_short_signature
)
1500 page
.append
("::<span>")
1501 intro
.html_link
(page
)
1502 page
.append
("</span>")
1507 # Link to the type definition in the nitdoc page
1508 private fun html_link
(page
: NitdocPage) is abstract
1511 redef class MClassType
1512 redef fun html_link
(page
) do mclass
.html_link
(page
)
1515 redef class MNullableType
1516 redef fun html_link
(page
) do
1517 page
.append
("nullable ")
1518 mtype
.html_link
(page
)
1522 redef class MGenericType
1523 redef fun html_link
(page
) do
1524 page
.append
("<a href='{mclass.url}'>{mclass.html_name}</a>[")
1525 for i
in [0..arguments
.length
[ do
1526 arguments
[i
].html_link
(page
)
1527 if i
< arguments
.length
- 1 then page
.append
(", ")
1533 redef class MParameterType
1534 redef fun html_link
(page
) do
1535 var name
= mclass
.intro
.parameter_names
[rank
]
1536 page
.append
("<a href='{mclass.url}#FT_{name}' title='formal type'>{name}</a>")
1540 redef class MVirtualType
1541 redef fun html_link
(page
) do mproperty
.intro
.html_link
(page
)
1544 redef class MClassDef
1545 # Return the classdef namespace decorated with html
1546 private fun html_namespace
(page
: NitdocPage) do
1547 mmodule
.html_full_namespace
(page
)
1548 page
.append
("::<span>")
1549 mclass
.html_link
(page
)
1550 page
.append
("</span>")
1554 redef class MPropDef
1555 # Return the full qualified name of the mpropdef
1556 # module::classdef::name
1557 private fun full_name
: String do
1558 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1561 # URL into the nitdoc page
1562 # class_owner_name.html#anchor
1563 private fun url
: String do
1564 if url_cache
== null then
1565 url_cache
= "{mclassdef.mclass.url}#{anchor}"
1567 return url_cache
.as(not null)
1569 private var url_cache
: nullable String
1571 # html anchor id for the property in a nitdoc class page
1572 # PROP_mclass_propertyname
1573 private fun anchor
: String do
1574 if anchor_cache
== null then
1575 anchor_cache
= "PROP_{mclassdef.mclass.public_owner.name}_{mproperty.name.replace(" ", "_")}"
1577 return anchor_cache
.as(not null)
1579 private var anchor_cache
: nullable String
1581 # Return a link to property into the nitdoc class page
1582 # <a href="url" title="short_comment">html_name</a>
1583 private fun html_link
(page
: NitdocPage) do
1584 if html_link_cache
== null then
1585 var res
= new Buffer
1586 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1587 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1588 res
.append
("<a href=\"{url}\
" title=\"{nprop.short_comment}\
">{mproperty.html_name}</a>")
1590 res
.append
("<a href=\"{url}\
">{mproperty.html_name}</a>")
1592 html_link_cache
= res
.to_s
1594 page
.append
(html_link_cache
.as(not null))
1596 private var html_link_cache
: nullable String
1598 # Return a list item for the mpropdef
1599 # <li>html_link</li>
1600 private fun html_sidebar_item
(page
: NitdocClass) do
1601 if is_intro
and mclassdef
.mclass
== page
.mclass
then
1602 page
.append
("<li class='intro'>")
1603 page
.append
("<span title='Introduced'>I</span>")
1604 else if is_intro
and mclassdef
.mclass
!= page
.mclass
then
1605 page
.append
("<li class='inherit'>")
1606 page
.append
("<span title='Inherited'>H</span>")
1608 page
.append
("<li class='redef'>")
1609 page
.append
("<span title='Redefined'>R</span>")
1612 page
.append
("</li>")
1615 private fun html_full_desc
(page
: NitdocPage, ctx
: MClass) is abstract
1616 private fun html_info
(page
: NitdocPage, ctx
: MClass) is abstract
1618 private fun html_comment
(page
: NitdocPage) do
1619 page
.append
("<div class='description'>")
1620 if not is_intro
then
1621 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(mproperty
.intro
) then
1622 var intro_nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[mproperty
.intro
]
1623 if page
.ctx
.github_gitdir
!= null then
1624 var loc
= intro_nprop
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1625 page
.append
("<textarea class='baseComment' data-comment-namespace='{mproperty.intro.mclassdef.mmodule.full_name}::{mproperty.intro.mclassdef.mclass.name}::{mproperty.name}' data-comment-location='{loc}'>{intro_nprop.full_comment}</textarea>")
1627 if intro_nprop
.full_comment
.is_empty
then
1628 page
.append
("<p class='info inheritance'>")
1629 page
.append
("<span class=\"noComment\
">no comment for </span>")
1631 page
.append
("<div class='comment'>{intro_nprop.full_markdown}</div>")
1632 page
.append
("<p class='info inheritance'>")
1634 page
.append
("introduction in ")
1635 mproperty
.intro
.mclassdef
.html_namespace
(page
)
1636 page
.append
(" {page.show_source(intro_nprop.location)}</p>")
1639 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1640 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1641 if page
.ctx
.github_gitdir
!= null then
1642 var loc
= nprop
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1643 page
.append
("<textarea class='baseComment' data-comment-namespace='{mclassdef.mmodule.full_name}::{mclassdef.mclass.name}::{mproperty.name}' data-comment-location='{loc}'>{nprop.full_comment}</textarea>")
1645 if nprop
.full_comment
== "" then
1646 page
.append
("<p class='info inheritance'>")
1647 page
.append
("<span class=\"noComment\
">no comment for </span>")
1649 page
.append
("<div class='comment'>{nprop.full_markdown}</div>")
1650 page
.append
("<p class='info inheritance'>")
1653 page
.append
("introduction in ")
1655 page
.append
("redefinition in ")
1657 mclassdef
.html_namespace
(page
)
1658 page
.append
(" {page.show_source(nprop.location)}</p>")
1660 page
.append
("</div>")
1664 redef class MMethodDef
1665 redef fun html_full_desc
(page
, ctx
) do
1666 var classes
= new Array[String]
1667 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= ctx
1668 if mproperty
.is_init
then
1673 if is_redef
then classes
.add
("redef")
1674 classes
.add
(mproperty
.visibility
.to_s
)
1675 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1676 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1677 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}{msignature.untyped_signature(page)}'>")
1678 page
.append
("<span>{mproperty.html_name}")
1679 msignature
.html_signature
(page
)
1680 page
.append
("</span></h3>")
1682 page
.append
("<h3 class='signature' data-untyped-signature='init{msignature.untyped_signature(page)}'>")
1683 page
.append
("<span>init")
1684 msignature
.html_signature
(page
)
1685 page
.append
("</span></h3>")
1687 html_info
(page
, ctx
)
1689 page
.append
("</article>")
1692 redef fun html_info
(page
, ctx
) do
1693 page
.append
("<div class='info'>")
1694 if mproperty
.visibility
< public_visibility
then page
.append
("{mproperty.visibility.to_s} ")
1695 if mproperty
.intro_mclassdef
.mclass
!= ctx
then page
.append
("redef ")
1696 if mproperty
.is_init
then
1697 page
.append
("init ")
1701 mproperty
.html_namespace
(page
)
1702 page
.append
("</div>")
1706 redef class MVirtualTypeDef
1707 redef fun html_full_desc
(page
, ctx
) do
1708 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= ctx
1709 var classes
= new Array[String]
1711 if is_redef
then classes
.add
("redef")
1712 classes
.add
(mproperty
.visibility
.to_s
)
1713 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1714 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}'><span>{mproperty.html_name}: ")
1715 bound
.html_link
(page
)
1716 page
.append
("</span></h3>")
1717 html_info
(page
, ctx
)
1719 page
.append
("</article>")
1722 redef fun html_info
(page
, ctx
) do
1723 page
.append
("<div class='info'>")
1724 if mproperty
.intro_mclassdef
.mclass
!= ctx
then page
.append
("redef ")
1725 page
.append
("type ")
1726 mproperty
.html_namespace
(page
)
1727 page
.append
("</div>")
1731 redef class MSignature
1732 private fun html_signature
(page
: NitdocPage) do
1733 if not mparameters
.is_empty
then
1735 for i
in [0..mparameters
.length
[ do
1736 mparameters
[i
].html_link
(page
)
1737 if i
< mparameters
.length
- 1 then page
.append
(", ")
1741 if return_mtype
!= null then
1743 return_mtype
.html_link
(page
)
1747 private fun untyped_signature
(page
: NitdocPage): String do
1748 var res
= new Buffer
1749 if not mparameters
.is_empty
then
1751 for i
in [0..mparameters
.length
[ do
1752 res
.append
(mparameters
[i
].name
)
1753 if i
< mparameters
.length
- 1 then res
.append
(", ")
1761 redef class MParameter
1762 private fun html_link
(page
: NitdocPage) do
1763 page
.append
("{name}: ")
1764 mtype
.html_link
(page
)
1765 if is_vararg
then page
.append
("...")
1773 redef class Location
1774 fun github
(gitdir
: String): String do
1775 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
1776 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
1777 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
1778 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
1783 private fun short_comment
: String do
1784 return n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1787 private fun full_comment
: String do
1788 var res
= new Buffer
1789 for t
in n_comment
do
1791 text
= text
.substring_from
(1)
1792 if text
.first
== ' ' then text
= text
.substring_from
(1)
1793 res
.append
(text
.html_escape
)
1796 return str
.substring
(0, str
.length
- 1)
1801 private fun short_comment
: String do
1802 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1803 return n_moduledecl
.n_doc
.short_comment
1808 private fun full_comment
: String do
1809 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1810 return n_moduledecl
.n_doc
.full_comment
1815 private fun full_markdown
: String do
1816 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1817 return n_moduledecl
.n_doc
.full_markdown
.write_to_string
1822 # The doc location or the first line of the block if doc node is null
1823 private fun doc_location
: Location do
1824 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1825 return n_moduledecl
.n_doc
.location
1828 return new Location(l
.file
, l
.line_start
, l
.line_start
, l
.column_start
, l
.column_start
)
1832 redef class AStdClassdef
1833 private fun short_comment
: String do
1834 if n_doc
!= null then return n_doc
.short_comment
1838 private fun full_comment
: String do
1839 if n_doc
!= null then return n_doc
.full_comment
1843 private fun full_markdown
: String do
1844 if n_doc
!= null then return n_doc
.full_markdown
.write_to_string
1848 # The doc location or the first line of the block if doc node is null
1849 private fun doc_location
: Location do
1850 if n_doc
!= null then return n_doc
.location
1852 return new Location(l
.file
, l
.line_start
, l
.line_start
, l
.column_start
, l
.column_start
)
1856 redef class APropdef
1857 private fun short_comment
: String do
1858 if n_doc
!= null then return n_doc
.short_comment
1862 private fun full_comment
: String do
1863 if n_doc
!= null then return n_doc
.full_comment
1867 private fun full_markdown
: String do
1868 if n_doc
!= null then return n_doc
.full_markdown
.write_to_string
1872 private fun doc_location
: Location do
1873 if n_doc
!= null then return n_doc
.location
1875 return new Location(l
.file
, l
.line_start
, l
.line_start
, l
.column_start
, l
.column_start
)
1881 var nitdoc
= new NitdocContext
1882 nitdoc
.generate_nitdoc