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}/ZeroClipboard.swf {output_dir.to_s}/")
152 sys
.system
("cp -r {share_dir.to_s}/resources/ {output_dir.to_s}/resources/")
155 if not opt_nodot
.value
then self.dot_dir
= output_dir
.to_s
163 private fun overview
do
164 var overviewpage
= new NitdocOverview(self, dot_dir
)
165 overviewpage
.save
("{output_dir.to_s}/index.html")
168 private fun search
do
169 var searchpage
= new NitdocSearch(self)
170 searchpage
.save
("{output_dir.to_s}/search.html")
173 private fun modules
do
174 for mmodule
in model
.mmodules
do
175 if mmodule
.name
== "<main>" then continue
176 var modulepage
= new NitdocModule(mmodule
, self, dot_dir
)
177 modulepage
.save
("{output_dir.to_s}/{mmodule.url}")
181 private fun classes
do
182 for mclass
in mbuilder
.model
.mclasses
do
183 var classpage
= new NitdocClass(mclass
, self, dot_dir
, source
)
184 classpage
.save
("{output_dir.to_s}/{mclass.url}")
188 private fun quicksearch_list
do
189 var file
= new OFStream.open
("{output_dir.to_s}/quicksearch-list.js")
190 file
.write
("var nitdocQuickSearchRawList = \{ ")
191 for mmodule
in model
.mmodules
do
192 if mmodule
.name
== "<main>" then continue
193 file
.write
("\"{mmodule.name}\
": [")
194 file
.write
("\{txt: \"{mmodule.full_name}\", url
:\
"{mmodule.url}\" \
},")
197 for mclass in model.mclasses do
198 if mclass.visibility < min_visibility then continue
199 file.write("\
"{mclass.name}\": [")
200 file.write("\
{txt: \"{mclass.full_name}\
", url:\"{mclass.url}\
" \},")
203 var name2mprops
= new HashMap[String, Set[MPropDef]]
204 for mproperty
in model
.mproperties
do
205 if mproperty
.visibility
< min_visibility
then continue
206 if mproperty
isa MAttribute then continue
207 if not name2mprops
.has_key
(mproperty
.name
) then name2mprops
[mproperty
.name
] = new HashSet[MPropDef]
208 name2mprops
[mproperty
.name
].add_all
(mproperty
.mpropdefs
)
210 for mproperty
, mpropdefs
in name2mprops
do
211 file
.write
("\"{mproperty}\
": [")
212 for mpropdef
in mpropdefs
do
213 file
.write
("\{txt: \"{mpropdef.full_name}\", url
:\
"{mpropdef.url}\" \
},")
224 abstract class NitdocPage
226 var dot_dir: nullable String
227 var source: nullable String
228 var ctx: NitdocContext
231 init(ctx: NitdocContext) do
233 if ctx.opt_shareurl.value != null then shareurl = ctx.opt_shareurl.value.as(not null)
236 protected fun head do
237 append("<meta charset
='utf-8'/>")
238 append("<link rel
='stylesheet' href
='{shareurl}/css/main.css' type='text/css'/>")
239 append("<link rel
='stylesheet' href
='{shareurl}/css/Nitdoc.UI.css' type='text/css''/>")
240 append("<link rel='stylesheet
' href='{shareurl}/css
/Nitdoc.QuickSearch.css
' type='text
/css
'/>")
241 append("<link rel='stylesheet
' href='{shareurl}/css
/Nitdoc.GitHub.css
' type='text
/css
'/>")
242 append("<link rel='stylesheet
' href='{shareurl}/css
/Nitdoc.ModalBox.css
' type='text
/css
'/>")
244 if ctx.opt_custom_title.value != null then
245 title = " | {ctx.opt_custom_title.value.to_s}"
247 append("<title>{self.title}{title}</title>")
250 protected fun menu do
251 if ctx.opt_custom_menu_items.value != null then
252 append(ctx.opt_custom_menu_items.value.to_s)
256 protected fun title: String is abstract
258 protected fun header do
260 append("<nav class='main
'>")
268 protected fun content is abstract
270 protected fun footer do
271 if ctx.opt_custom_footer_text.value != null then
272 append("<footer>{ctx.opt_custom_footer_text.value.to_s}</footer>")
276 # Generate a clickable graphviz image using a dot content
277 protected fun generate_dot(dot: String, name: String, alt: String) do
278 var output_dir = dot_dir
279 if output_dir == null then return
280 var file = new OFStream.open("{output_dir}/{name}.dot")
283 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 ; \}")
284 append("<article class='graph
'>")
285 append("<img src='{name}.png
' usemap='#{name}' style='margin:auto' alt='{alt}'/>")
287 var fmap
= new IFStream.open
("{output_dir}/{name}.map")
288 append
(fmap
.read_all
)
292 # Add a (source) link for a given location
293 protected fun show_source
(l
: Location): String
295 if source
== null then
296 return "({l.file.filename.simplify_path})"
298 # THIS IS JUST UGLY ! (but there is no replace yet)
299 var x
= source
.split_with
("%f")
300 source
= x
.join
(l
.file
.filename
.simplify_path
)
301 x
= source
.split_with
("%l")
302 source
= x
.join
(l
.line_start
.to_s
)
303 x
= source
.split_with
("%L")
304 source
= x
.join
(l
.line_end
.to_s
)
305 return " (<a target='_blank' title='Show source' href=\"{source.to_s}\
">source</a>)"
309 # Render the page as a html string
310 protected fun render
do
311 append
("<!DOCTYPE html>")
316 append
(" data-bootstrap-share='{shareurl}'")
317 if ctx
.opt_github_upstream
.value
!= null and ctx
.opt_github_base_sha1
.value
!= null then
318 append
(" data-github-upstream='{ctx.opt_github_upstream.value.as(not null)}'")
319 append
(" data-github-base-sha1='{ctx.opt_github_base_sha1.value.as(not null)}'")
324 if ctx
.opt_custom_footer_text
.value
!= null then footed
= "footed"
325 append
("<div class='page {footed}'>")
329 append
("<script data-main=\"{shareurl}/js
/nitdoc\
" src=\"{shareurl}/js
/lib
/require
.js\
"></script>")
332 var tracker_url
= ctx
.opt_piwik_tracker
.value
333 var site_id
= ctx
.opt_piwik_site_id
.value
334 if tracker_url
!= null and site_id
!= null then
335 append
("<!-- Piwik -->")
336 append
("<script type=\"text
/javascript\
">")
337 append
(" var _paq = _paq || [];")
338 append
(" _paq.push([\"trackPageView\
"]);")
339 append
(" _paq.push([\"enableLinkTracking\
"]);")
340 append
(" (function() \{")
341 append
(" var u=((\"https
:\
" == document.location.protocol) ? \"https\
" : \"http\
") + \"://{tracker_url}\
";")
342 append
(" _paq.push([\"setTrackerUrl\
", u+\"piwik
.php\
"]);")
343 append
(" _paq.push([\"setSiteId\
", \"{site_id}\
"]);")
344 append
(" var d=document, g=d.createElement(\"script\
"), s=d.getElementsByTagName(\"script\
")[0]; g.type=\"text
/javascript\
";")
345 append
(" g.defer=true; g.async=true; g.src=u+\"piwik
.js\
"; s.parentNode.insertBefore(g,s);")
348 append
("<!-- End Piwik Code -->")
353 # Append a string to the page
354 fun append
(s
: String) do out
.write
(s
)
356 # Save html page in the specified file
357 fun save
(file
: String) do
358 self.out
= new OFStream.open
(file
)
362 private var out
: nullable OFStream
368 private var mbuilder
: ModelBuilder
369 private var mmodules
= new Array[MModule]
371 init(ctx
: NitdocContext, dot_dir
: nullable String) do
373 self.mbuilder
= ctx
.mbuilder
374 self.dot_dir
= dot_dir
376 var mmodules
= new HashSet[MModule]
377 for mmodule
in mbuilder
.model
.mmodule_importation_hierarchy
do
378 if mmodule
.name
== "<main>" then continue
379 var owner
= mmodule
.public_owner
380 if owner
!= null then
383 mmodules
.add
(mmodule
)
387 var sorter
= new MModuleNameSorter
388 self.mmodules
.add_all
(mmodules
)
389 sorter
.sort
(self.mmodules
)
392 redef fun title
do return "Overview"
396 append
("<li class='current'>Overview</li>")
397 append
("<li><a href='search.html'>Search</a></li>")
401 append
("<div class='content fullpage'>")
402 var title
= "Overview"
403 if ctx
.opt_custom_title
.value
!= null then
404 title
= ctx
.opt_custom_title
.value
.to_s
406 append
("<h1>{title}</h1>")
408 if ctx
.opt_custom_overview_text
.value
!= null then
409 text
= ctx
.opt_custom_overview_text
.value
.to_s
411 append
("<article class='overview'>{text}</article>")
412 append
("<article class='overview'>")
414 append
("<h2>Modules</h2>")
416 for mmodule
in mmodules
do
417 if mbuilder
.mmodule2nmodule
.has_key
(mmodule
) then
418 var amodule
= mbuilder
.mmodule2nmodule
[mmodule
]
420 mmodule
.html_link
(self)
421 append
(" {amodule.short_comment}</li>")
431 private fun process_generate_dot
do
432 # build poset with public owners
433 var poset
= new POSet[MModule]
434 for mmodule
in mmodules
do
435 poset
.add_node
(mmodule
)
436 for omodule
in mmodules
do
437 if mmodule
== omodule
then continue
438 if mmodule
.in_importation
< omodule
then
439 poset
.add_node
(omodule
)
440 poset
.add_edge
(mmodule
, omodule
)
446 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")
447 for mmodule
in poset
do
448 op
.append
("\"{mmodule.name}\
"[URL=\"{mmodule.url}\
"];\n")
449 for omodule
in poset
[mmodule
].direct_greaters
do
450 op
.append
("\"{mmodule.name}\
"->\"{omodule.name}\
";\n")
454 generate_dot
(op
.to_s
, "dep", "Modules hierarchy")
462 init(ctx
: NitdocContext) do
467 redef fun title
do return "Search"
471 append
("<li><a href='index.html'>Overview</a></li>")
472 append
("<li class='current'>Search</li>")
476 append
("<div class='content fullpage'>")
477 append
("<h1>{title}</h1>")
484 # Add to content modules column
485 private fun module_column
do
486 var sorted
= ctx
.mbuilder
.model
.mmodule_importation_hierarchy
.to_a
487 var sorter
= new MModuleNameSorter
489 append
("<article class='modules filterable'>")
490 append
("<h2>Modules</h2>")
492 for mmodule
in sorted
do
493 if mmodule
.name
== "<main>" then continue
495 mmodule
.html_link
(self)
502 # Add to content classes modules
503 private fun classes_column
do
504 var sorted
= ctx
.mbuilder
.model
.mclasses
505 var sorter
= new MClassNameSorter
507 append
("<article class='modules filterable'>")
508 append
("<h2>Classes</h2>")
510 for mclass
in sorted
do
511 if mclass
.visibility
< ctx
.min_visibility
then continue
513 mclass
.html_link
(self)
520 # Insert the properties column of fullindex page
521 private fun properties_column
do
522 var sorted
= ctx
.mbuilder
.model
.mproperties
523 var sorter
= new MPropertyNameSorter
525 append
("<article class='modules filterable'>")
526 append
("<h2>Properties</h2>")
528 for mproperty
in sorted
do
529 if mproperty
.visibility
< ctx
.min_visibility
then continue
530 if mproperty
isa MAttribute then continue
532 mproperty
.intro
.html_link
(self)
534 mproperty
.intro
.mclassdef
.mclass
.html_link
(self)
547 private var mmodule
: MModule
548 private var mbuilder
: ModelBuilder
549 private var local_mclasses
= new HashSet[MClass]
550 private var intro_mclasses
= new HashSet[MClass]
551 private var redef_mclasses
= new HashSet[MClass]
553 init(mmodule
: MModule, ctx
: NitdocContext, dot_dir
: nullable String) do
555 self.mmodule
= mmodule
556 self.mbuilder
= ctx
.mbuilder
557 self.dot_dir
= dot_dir
559 for m
in mmodule
.in_nesting
.greaters
do
560 for mclassdef
in m
.mclassdefs
do
561 if mclassdef
.mclass
.visibility
< ctx
.min_visibility
then continue
562 if mclassdef
.is_intro
then
563 intro_mclasses
.add
(mclassdef
.mclass
)
565 if mclassdef
.mclass
.mpropdefs_in_module
(self).is_empty
then continue
566 redef_mclasses
.add
(mclassdef
.mclass
)
568 local_mclasses
.add
(mclassdef
.mclass
)
574 if mbuilder
.mmodule2nmodule
.has_key
(mmodule
) and not mbuilder
.mmodule2nmodule
[mmodule
].short_comment
.is_empty
then
575 var nmodule
= mbuilder
.mmodule2nmodule
[mmodule
]
576 return "{mmodule.html_name} module | {nmodule.short_comment}"
578 return "{mmodule.html_name} module"
584 append
("<li><a href='index.html'>Overview</a></li>")
585 append
("<li class='current'>{mmodule.html_name}</li>")
586 append
("<li><a href='search.html'>Search</a></li>")
590 append
("<div class='sidebar'>")
594 append
("<div class='content'>")
599 private fun classes_column
do
600 var sorter
= new MClassNameSorter
601 var sorted
= new Array[MClass]
602 sorted
.add_all
(intro_mclasses
)
603 sorted
.add_all
(redef_mclasses
)
605 if not sorted
.is_empty
then
606 append
("<nav class='properties filterable'>")
607 append
("<h3>Classes</h3>")
608 append
("<h4>Classes</h4>")
610 for mclass
in sorted
do mclass
.html_sidebar_item
(self)
616 private fun importation_column
do
618 append
("<h3>Module Hierarchy</h3>")
619 var dependencies
= new Array[MModule]
620 for dep
in mmodule
.in_importation
.greaters
do
621 if dep
== mmodule
or dep
.direct_owner
== mmodule
or dep
.public_owner
== mmodule
then continue
622 dependencies
.add
(dep
)
624 if mmodule
.in_nesting
.direct_greaters
.length
> 0 then
625 append
("<h4>Nested Modules</h4>")
626 display_module_list
(mmodule
.in_nesting
.direct_greaters
.to_a
)
628 if dependencies
.length
> 0 then
629 append
("<h4>All dependencies</h4>")
630 display_module_list
(dependencies
)
632 var clients
= new Array[MModule]
633 for dep
in mmodule
.in_importation
.smallers
do
634 if dep
.name
== "<main>" then continue
635 if dep
== mmodule
then continue
638 if clients
.length
> 0 then
639 append
("<h4>All clients</h4>")
640 display_module_list
(clients
)
645 private fun display_module_list
(list
: Array[MModule]) do
647 var sorter
= new MModuleNameSorter
657 private fun module_doc
do
659 append
("<h1>{mmodule.html_name}</h1>")
660 append
("<div class='subtitle info'>")
661 mmodule
.html_signature
(self)
664 mmodule
.html_comment
(self)
667 var class_sorter
= new MClassNameSorter
669 if not intro_mclasses
.is_empty
then
670 var sorted
= new Array[MClass]
671 sorted
.add_all
(intro_mclasses
)
672 class_sorter
.sort
(sorted
)
673 append
("<section class='classes'>")
674 append
("<h2 class='section-header'>Introduced classes</h2>")
675 for mclass
in sorted
do mclass
.html_full_desc
(self)
679 var redefs
= new Array[MClass]
680 for mclass
in redef_mclasses
do if not intro_mclasses
.has
(mclass
) then redefs
.add
(mclass
)
681 class_sorter
.sort
(redefs
)
682 if not redefs
.is_empty
then
683 append
("<section class='classes'>")
684 append
("<h2 class='section-header'>Refined classes</h2>")
685 for mclass
in redefs
do mclass
.html_full_desc
(self)
690 private fun process_generate_dot
do
691 # build poset with public owners
692 var poset
= new POSet[MModule]
693 for mmodule
in self.mmodule
.in_importation
.poset
do
694 if mmodule
.name
== "<main>" then continue
695 #if mmodule.public_owner != null then continue
696 if not mmodule
.in_importation
< self.mmodule
and not self.mmodule
.in_importation
< mmodule
and mmodule
!= self.mmodule
then continue
697 poset
.add_node
(mmodule
)
698 for omodule
in mmodule
.in_importation
.poset
do
699 if mmodule
== omodule
then continue
700 if omodule
.name
== "<main>" then continue
701 if not omodule
.in_importation
< self.mmodule
and not self.mmodule
.in_importation
< omodule
then continue
702 if omodule
.in_importation
< mmodule
then
703 poset
.add_node
(omodule
)
704 poset
.add_edge
(omodule
, mmodule
)
706 if mmodule
.in_importation
< omodule
then
707 poset
.add_node
(omodule
)
708 poset
.add_edge
(mmodule
, omodule
)
710 #if omodule.public_owner != null then continue
711 #if mmodule.in_importation < omodule then
712 #poset.add_node(omodule)
713 #poset.add_edge(mmodule, omodule)
719 var name
= "dep_{mmodule.name}"
720 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")
721 for mmodule
in poset
do
722 if mmodule
== self.mmodule
then
723 op
.append
("\"{mmodule.name}\
"[shape=box,margin=0.03];\n")
725 op
.append
("\"{mmodule.name}\
"[URL=\"{mmodule.url}\
"];\n")
727 for omodule
in poset
[mmodule
].direct_greaters
do
728 op
.append
("\"{mmodule.name}\
"->\"{omodule.name}\
";\n")
732 generate_dot
(op
.to_s
, name
, "Dependency graph for module {mmodule.name}")
740 private var mclass
: MClass
741 private var vtypes
= new HashSet[MVirtualTypeDef]
742 private var consts
= new HashSet[MMethodDef]
743 private var meths
= new HashSet[MMethodDef]
744 private var inherited
= new HashSet[MPropDef]
746 init(mclass
: MClass, ctx
: NitdocContext, dot_dir
: nullable String, source
: nullable String) do
749 self.dot_dir
= dot_dir
752 var locals
= new HashSet[MProperty]
753 for mclassdef
in mclass
.mclassdefs
do
754 for mpropdef
in mclassdef
.mpropdefs
do
755 if mpropdef
.mproperty
.visibility
< ctx
.min_visibility
then continue
756 if mpropdef
isa MVirtualTypeDef then vtypes
.add
(mpropdef
)
757 if mpropdef
isa MMethodDef then
758 if mpropdef
.mproperty
.is_init
then
764 locals
.add
(mpropdef
.mproperty
)
767 # get inherited properties
768 for pclass
in mclass
.in_hierarchy
(ctx
.mainmodule
).greaters
do
769 if pclass
== mclass
then continue
770 for pclassdef
in pclass
.mclassdefs
do
771 for mprop
in pclassdef
.intro_mproperties
do
772 var mpropdef
= mprop
.intro
773 if mprop
.visibility
< ctx
.min_visibility
then continue # skip if not correct visibiility
774 if locals
.has
(mprop
) then continue # skip if local
775 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
776 if mpropdef
isa MVirtualTypeDef then vtypes
.add
(mpropdef
)
777 if mpropdef
isa MMethodDef then
778 if mpropdef
.mproperty
.is_init
then
784 inherited
.add
(mpropdef
)
791 var nclass
= ctx
.mbuilder
.mclassdef2nclassdef
[mclass
.intro
]
792 if nclass
isa AStdClassdef then
793 return "{mclass.html_name} class | {nclass.short_comment}"
795 return "{mclass.html_name} class"
801 append
("<li><a href='index.html'>Overview</a></li>")
802 var public_owner
= mclass
.public_owner
803 if public_owner
== null then
805 mclass
.intro_mmodule
.html_link
(self)
809 public_owner
.html_link
(self)
812 append
("<li class='current'>{mclass.html_name}</li>")
813 append
("<li><a href='search.html'>Search</a></li>")
817 append
("<div class='sidebar'>")
821 append
("<div class='content'>")
826 private fun properties_column
do
827 var sorter
= new MPropDefNameSorter
828 append
("<nav class='properties filterable'>")
829 append
("<h3>Properties</h3>")
831 if vtypes
.length
> 0 then
832 var vts
= new Array[MVirtualTypeDef]
835 append
("<h4>Virtual Types</h4>")
838 mprop
.html_sidebar_item
(self)
843 if consts
.length
> 0 then
844 var cts
= new Array[MMethodDef]
847 append
("<h4>Constructors</h4>")
850 if mprop
.mproperty
.name
== "init" and mprop
.mclassdef
.mclass
!= mclass
then continue
851 mprop
.html_sidebar_item
(self)
856 if meths
.length
> 0 then
857 var mts
= new Array[MMethodDef]
860 append
("<h4>Methods</h4>")
863 mprop
.html_sidebar_item
(self)
870 private fun inheritance_column
do
871 var sorted
= new Array[MClass]
872 var sorterp
= new MClassNameSorter
874 append
("<h3>Inheritance</h3>")
875 var greaters
= mclass
.in_hierarchy
(ctx
.mainmodule
).greaters
.to_a
876 if greaters
.length
> 1 then
877 ctx
.mainmodule
.linearize_mclasses
(greaters
)
878 append
("<h4>Superclasses</h4>")
880 for sup
in greaters
do
881 if sup
== mclass
then continue
888 var smallers
= mclass
.in_hierarchy
(ctx
.mainmodule
).smallers
.to_a
889 var direct_smallers
= mclass
.in_hierarchy
(ctx
.mainmodule
).direct_smallers
.to_a
890 if smallers
.length
<= 1 then
891 append
("<h4>No Known Subclasses</h4>")
892 else if smallers
.length
<= 100 then
893 ctx
.mainmodule
.linearize_mclasses
(smallers
)
894 append
("<h4>Subclasses</h4>")
896 for sub
in smallers
do
897 if sub
== mclass
then continue
903 else if direct_smallers
.length
<= 100 then
904 ctx
.mainmodule
.linearize_mclasses
(direct_smallers
)
905 append
("<h4>Direct Subclasses Only</h4>")
907 for sub
in direct_smallers
do
908 if sub
== mclass
then continue
915 append
("<h4>Too much Subclasses to list</h4>")
920 private fun class_doc
do
922 append
("<h1>{mclass.html_name}{mclass.html_short_signature}</h1>")
923 append
("<div class='subtitle info'>")
924 if mclass
.visibility
< public_visibility
then append
("{mclass.visibility.to_s} ")
925 append
("{mclass.kind.to_s} ")
926 mclass
.html_namespace
(self)
927 append
("{mclass.html_short_signature}</div>")
929 mclass
.html_comment
(self)
932 var concern2meths
= new ArrayMap[MModule, Array[MMethodDef]]
933 var sorted_meths
= new Array[MMethodDef]
934 var sorted
= new Array[MModule]
935 sorted_meths
.add_all
(meths
)
936 ctx
.mainmodule
.linearize_mpropdefs
(sorted_meths
)
938 if inherited
.has
(meth
) then continue
939 var mmodule
= meth
.mclassdef
.mmodule
940 if not concern2meths
.has_key
(mmodule
) then
942 concern2meths
[mmodule
] = new Array[MMethodDef]
944 concern2meths
[mmodule
].add
(meth
)
946 var sections
= new ArrayMap[MModule, Array[MModule]]
947 for mmodule
in concern2meths
.keys
do
948 var owner
= mmodule
.public_owner
949 if owner
== null then owner
= mmodule
950 if not sections
.has_key
(owner
) then sections
[owner
] = new Array[MModule]
951 if owner
!= mmodule
then sections
[owner
].add
(mmodule
)
953 append
("<section class='concerns'>")
954 append
("<h2 class='section-header'>Concerns</h2>")
956 for owner
, mmodules
in sections
do
957 var nowner
= ctx
.mbuilder
.mmodule2nmodule
[owner
]
959 if nowner
.short_comment
.is_empty
then
960 append
("<a href=\"#{owner.anchor}\">{owner.html_name}</a>")
962 append
("<a href=\"#{owner.anchor}\">{owner.html_name}</a>: {nowner.short_comment}")
964 if not mmodules
.is_empty
then
966 for mmodule
in mmodules
do
967 var nmodule
= ctx
.mbuilder
.mmodule2nmodule
[mmodule
]
968 if nmodule
.short_comment
.is_empty
then
969 append
("<li><a href=\"#{mmodule.anchor}\">{mmodule.html_name}</a></li>")
971 append
("<li><a href=\"#{mmodule.anchor}\">{mmodule.html_name}</a>: {nmodule.short_comment}</li>")
981 var prop_sorter
= new MPropDefNameSorter
982 var lmmodule
= new List[MModule]
983 var nclass
= ctx
.mbuilder
.mclassdef2nclassdef
[mclass
.intro
]
984 # virtual and formal types
985 var local_vtypes
= new Array[MVirtualTypeDef]
986 for vt
in vtypes
do if not inherited
.has
(vt
) then local_vtypes
.add
(vt
)
987 if local_vtypes
.length
> 0 or mclass
.arity
> 0 then
988 append
("<section class='types'>")
989 append
("<h2>Formal and Virtual Types</h2>")
991 if mclass
.arity
> 0 and nclass
isa AStdClassdef then
992 for ft
, bound
in mclass
.parameter_types
do
993 append
("<article id='FT_{ft}'>")
994 append
("<h3 class='signature' data-untyped-signature='{ft.to_s}'><span>{ft}: ")
995 bound
.html_link
(self)
996 append
("</span></h3>")
997 append
("<div class=\"info\
">formal generic type</div>")
1002 prop_sorter
.sort
(local_vtypes
)
1003 for prop
in local_vtypes
do prop
.html_full_desc
(self, self.mclass
)
1004 append
("</section>")
1007 var local_consts
= new Array[MMethodDef]
1008 for const
in consts
do if not inherited
.has
(const
) then local_consts
.add
(const
)
1009 prop_sorter
.sort
(local_consts
)
1010 if local_consts
.length
> 0 then
1011 append
("<section class='constructors'>")
1012 append
("<h2 class='section-header'>Constructors</h2>")
1013 for prop
in local_consts
do prop
.html_full_desc
(self, self.mclass
)
1014 append
("</section>")
1017 if not concern2meths
.is_empty
then
1018 append
("<section class='methods'>")
1019 append
("<h2 class='section-header'>Methods</h2>")
1020 for owner
, mmodules
in sections
do
1021 append
("<a id=\"{owner.anchor}\
"></a>")
1022 if owner
!= mclass
.intro_mmodule
and owner
!= mclass
.public_owner
then
1023 var nowner
= ctx
.mbuilder
.mmodule2nmodule
[owner
]
1024 append
("<h3 class=\"concern-toplevel\
">Methods refined in ")
1025 owner
.html_link
(self)
1027 append
("<p class=\"concern-doc\
">")
1028 owner
.html_link
(self)
1029 if not nowner
.short_comment
.is_empty
then
1030 append
(": {nowner.short_comment}")
1034 if concern2meths
.has_key
(owner
) then
1035 var mmethods
= concern2meths
[owner
]
1036 prop_sorter
.sort
(mmethods
)
1037 for prop
in mmethods
do prop
.html_full_desc
(self, self.mclass
)
1039 for mmodule
in mmodules
do
1040 append
("<a id=\"{mmodule.anchor}\
"></a>")
1041 var nmodule
= ctx
.mbuilder
.mmodule2nmodule
[mmodule
]
1042 if mmodule
!= mclass
.intro_mmodule
and mmodule
!= mclass
.public_owner
then
1043 append
("<p class=\"concern-doc\
">")
1044 mmodule
.html_link
(self)
1045 if not nmodule
.short_comment
.is_empty
then
1046 append
(": {nmodule.short_comment}")
1050 var mmethods
= concern2meths
[mmodule
]
1051 prop_sorter
.sort
(mmethods
)
1052 for prop
in mmethods
do prop
.html_full_desc
(self, self.mclass
)
1055 append
("</section>")
1057 # inherited properties
1058 if inherited
.length
> 0 then
1059 var sorted_inherited
= new Array[MPropDef]
1060 sorted_inherited
.add_all
(inherited
)
1061 ctx
.mainmodule
.linearize_mpropdefs
(sorted_inherited
)
1062 var classes
= new ArrayMap[MClass, Array[MPropDef]]
1063 for mmethod
in sorted_inherited
.reversed
do
1064 var mclass
= mmethod
.mclassdef
.mclass
1065 if not classes
.has_key
(mclass
) then classes
[mclass
] = new Array[MPropDef]
1066 classes
[mclass
].add
(mmethod
)
1068 append
("<section class='inherited'>")
1069 append
("<h2 class='section-header'>Inherited Properties</h2>")
1070 for c
, mmethods
in classes
do
1071 prop_sorter
.sort
(mmethods
)
1072 append
("<p>Defined in ")
1075 for i
in [0..mmethods
.length
[ do
1076 var mmethod
= mmethods
[i
]
1077 mmethod
.html_link
(self)
1078 if i
<= mmethods
.length
- 1 then append
(", ")
1082 append
("</section>")
1086 private fun process_generate_dot
do
1087 var pe
= ctx
.class_hierarchy
[mclass
]
1088 var cla
= new HashSet[MClass]
1089 var sm
= new HashSet[MClass]
1090 var sm2
= new HashSet[MClass]
1092 while cla
.length
+ sm
.length
< 10 and sm
.length
> 0 do
1096 sm2
.add_all
(pe
.poset
[x
].direct_smallers
)
1102 cla
.add_all
(pe
.greaters
)
1105 var name
= "dep_{mclass.name}"
1106 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")
1109 op
.append
("\"{c.name}\
"[shape=box,margin=0.03];\n")
1111 op
.append
("\"{c.name}\
"[URL=\"{c.url}\
"];\n")
1113 for c2
in pe
.poset
[c
].direct_greaters
do
1114 if not cla
.has
(c2
) then continue
1115 op
.append
("\"{c.name}\
"->\"{c2.name}\
";\n")
1117 if not pe
.poset
[c
].direct_smallers
.is_empty
then
1119 for c2
in pe
.poset
[c
].direct_smallers
do
1120 if cla
.has
(c2
) then others
= false
1123 op
.append
("\"{c.name}...\
"[label=\"\
"];\n")
1124 op
.append
("\"{c.name}...\
"->\"{c.name}\
"[style=dotted];\n")
1129 generate_dot
(op
.to_s
, name
, "Dependency graph for class {mclass.name}")
1138 # Return the HTML escaped name of the module
1139 private fun html_name
: String do return name
.html_escape
1141 # URL to nitdoc page
1142 # module_owner_name.html
1143 private fun url
: String do
1144 if url_cache
== null then
1145 var res
= new Buffer
1146 res
.append
("module_")
1147 var mowner
= public_owner
1148 if mowner
!= null then
1149 res
.append
("{public_owner.name}_")
1151 res
.append
("{self.name}.html")
1152 url_cache
= res
.to_s
1154 return url_cache
.as(not null)
1156 private var url_cache
: nullable String
1158 # html anchor id for the module in a nitdoc page
1160 private fun anchor
: String do
1161 if anchor_cache
== null then
1162 var res
= new Buffer
1164 var mowner
= public_owner
1165 if mowner
!= null then
1166 res
.append
("{public_owner.name}_")
1168 res
.append
(self.name
)
1169 anchor_cache
= res
.to_s
1171 return anchor_cache
.as(not null)
1173 private var anchor_cache
: nullable String
1175 # Return a link (html a tag) to the nitdoc module page
1176 # <a href="url" title="short_comment">html_name</a>
1177 private fun html_link
(page
: NitdocPage) do
1178 if html_link_cache
== null then
1179 var res
= new Buffer
1180 if page
.ctx
.mbuilder
.mmodule2nmodule
.has_key
(self) then
1181 res
.append
("<a href='{url}' title='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{html_name}</a>")
1183 res
.append
("<a href='{url}'>{html_name}</a>")
1185 html_link_cache
= res
.to_s
1187 page
.append
(html_link_cache
.as(not null))
1189 private var html_link_cache
: nullable String
1191 # Return the module signature decorated with html
1192 # <span>module html_full_namespace</span>
1193 private fun html_signature
(page
: NitdocPage) do
1194 page
.append
("<span>module ")
1195 html_full_namespace
(page
)
1196 page
.append
("</span>")
1199 # Return the module full namespace decorated with html
1200 # <span>public_owner.html_namespace::html_link</span>
1201 private fun html_full_namespace
(page
: NitdocPage) do
1202 page
.append
("<span>")
1203 var mowner
= public_owner
1204 if mowner
!= null then
1205 public_owner
.html_namespace
(page
)
1209 page
.append
("</span>")
1212 # Return the module full namespace decorated with html
1213 # <span>public_owner.html_namespace</span>
1214 private fun html_namespace
(page
: NitdocPage) do
1215 page
.append
("<span>")
1216 var mowner
= public_owner
1217 if mowner
!= null then
1218 public_owner
.html_namespace
(page
)
1222 page
.append
("</span>")
1225 # Return the full comment of the module decorated with html
1226 private fun html_comment
(page
: NitdocPage) do
1227 page
.append
("<div class='description'>")
1228 if page
.ctx
.mbuilder
.mmodule2nmodule
.has_key
(self) then
1229 var nmodule
= page
.ctx
.mbuilder
.mmodule2nmodule
[self]
1230 if page
.ctx
.github_gitdir
!= null then
1231 var loc
= nmodule
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1232 page
.append
("<textarea class='baseComment' data-comment-namespace='{full_name}' data-comment-location='{loc}'>{nmodule.full_comment}</textarea>")
1234 if nmodule
.full_comment
== "" then
1235 page
.append
("<p class='info inheritance'>")
1236 page
.append
("<span class=\"noComment\
">no comment for </span>")
1238 page
.append
("<div class='comment'>{nmodule.full_markdown}</div>")
1239 page
.append
("<p class='info inheritance'>")
1241 page
.append
("definition in ")
1242 self.html_full_namespace
(page
)
1243 page
.append
(" {page.show_source(nmodule.location)}</p>")
1245 page
.append
("</div>")
1248 private fun has_mclassdef_for
(mclass
: MClass): Bool do
1249 for mmodule
in self.in_nesting
.greaters
do
1250 for mclassdef
in mmodule
.mclassdefs
do
1251 if mclassdef
.mclass
== mclass
then return true
1257 private fun has_mclassdef
(mclassdef
: MClassDef): Bool do
1258 for mmodule
in self.in_nesting
.greaters
do
1259 for oclassdef
in mmodule
.mclassdefs
do
1260 if mclassdef
== oclassdef
then return true
1268 # Return the HTML escaped name of the module
1269 private fun html_name
: String do return name
.html_escape
1271 # URL to nitdoc page
1272 # class_owner_name.html
1273 private fun url
: String do
1274 return "class_{public_owner}_{name}.html"
1277 # html anchor id for the class in a nitdoc page
1279 private fun anchor
: String do
1280 if anchor_cache
== null then
1281 anchor_cache
= "CLASS_{public_owner.name}_{name}"
1283 return anchor_cache
.as(not null)
1285 private var anchor_cache
: nullable String
1287 # Return a link (with signature) to the nitdoc class page
1288 # <a href="url" title="short_comment">html_name(signature)</a>
1289 private fun html_link
(page
: NitdocPage) do
1290 if html_link_cache
== null then
1291 var res
= new Buffer
1292 res
.append
("<a href='{url}'")
1293 if page
.ctx
.mbuilder
.mclassdef2nclassdef
.has_key
(intro
) then
1294 var nclass
= page
.ctx
.mbuilder
.mclassdef2nclassdef
[intro
]
1295 if nclass
isa AStdClassdef then
1296 res
.append
(" title=\"{nclass.short_comment}\
"")
1299 res
.append
(">{html_name}{html_short_signature}</a>")
1300 html_link_cache
= res
.to_s
1302 page
.append
(html_link_cache
.as(not null))
1304 private var html_link_cache
: nullable String
1306 # Return a short link (without signature) to the nitdoc class page
1307 # <a href="url" title="short_comment">html_name</a>
1308 private fun html_short_link
(page
: NitdocPage) do
1309 if html_short_link_cache
== null then
1310 var res
= new Buffer
1311 res
.append
("<a href='{url}'")
1312 if page
.ctx
.mbuilder
.mclassdef2nclassdef
.has_key
(intro
) then
1313 var nclass
= page
.ctx
.mbuilder
.mclassdef2nclassdef
[intro
]
1314 if nclass
isa AStdClassdef then
1315 res
.append
(" title=\"{nclass.short_comment}\
"")
1318 res
.append
(">{html_name}</a>")
1319 html_short_link_cache
= res
.to_s
1321 page
.append
(html_short_link_cache
.as(not null))
1323 private var html_short_link_cache
: nullable String
1325 # Return a link (with signature) to the class anchor
1326 # <a href="url" title="short_comment">html_name</a>
1327 private fun html_link_anchor
(page
: NitdocPage) do
1328 if html_link_anchor_cache
== null then
1329 var res
= new Buffer
1330 res
.append
("<a href='#{anchor}'")
1331 if page
.ctx
.mbuilder
.mclassdef2nclassdef
.has_key
(intro
) then
1332 var nclass
= page
.ctx
.mbuilder
.mclassdef2nclassdef
[intro
]
1333 if nclass
isa AStdClassdef then
1334 res
.append
(" title=\"{nclass.short_comment}\
"")
1337 res
.append
(">{html_name}{html_short_signature}</a>")
1338 html_link_anchor_cache
= res
.to_s
1340 page
.append
(html_link_anchor_cache
.as(not null))
1342 private var html_link_anchor_cache
: nullable String
1344 # Return the generic signature of the class with bounds
1345 # [E: <a>MType</a>, F: <a>MType</a>]
1346 private fun html_signature
(page
: NitdocPage) do
1349 for i
in [0..intro
.parameter_names
.length
[ do
1350 page
.append
("{intro.parameter_names[i]}: ")
1351 intro
.bound_mtype
.arguments
[i
].html_link
(page
)
1352 if i
< intro
.parameter_names
.length
- 1 then page
.append
(", ")
1358 # Return the generic signature of the class without bounds
1360 private fun html_short_signature
: String do
1362 return "[{intro.parameter_names.join(", ")}]"
1368 # Return the class namespace decorated with html
1369 # <span>intro_module::html_short_link</span>
1370 private fun html_namespace
(page
: NitdocPage) do
1371 intro_mmodule
.html_namespace
(page
)
1372 page
.append
("::<span>")
1373 html_short_link
(page
)
1374 page
.append
("</span>")
1377 # Return a list item for the mclass
1378 # <li>html_link</li>
1379 private fun html_sidebar_item
(page
: NitdocModule) do
1380 if page
.mmodule
.in_nesting
.greaters
.has
(intro
.mmodule
) then
1381 page
.append
("<li class='intro'>")
1382 page
.append
("<span title='Introduced'>I</span>")
1383 html_link_anchor
(page
)
1384 else if page
.mmodule
.has_mclassdef_for
(self) then
1385 page
.append
("<li class='redef'>")
1386 page
.append
("<span title='Redefined'>R</span>")
1387 html_link_anchor
(page
)
1389 page
.append
("<li class='inherit'>")
1390 page
.append
("<span title='Inherited'>H</span>")
1393 page
.append
("</li>")
1396 private fun html_full_desc
(page
: NitdocModule) do
1397 var is_redef
= not page
.mmodule
.in_nesting
.greaters
.has
(intro
.mmodule
)
1398 var redefs
= mpropdefs_in_module
(page
)
1399 if not is_redef
or not redefs
.is_empty
then
1400 var classes
= new Array[String]
1401 classes
.add
(kind
.to_s
)
1402 if is_redef
then classes
.add
("redef")
1403 classes
.add
(visibility
.to_s
)
1404 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1405 page
.append
("<h3 class='signature' data-untyped-signature='{html_name}{html_short_signature}'>")
1406 page
.append
("<span>")
1407 html_short_link
(page
)
1408 html_signature
(page
)
1409 page
.append
("</span></h3>")
1412 page
.append
("</article>")
1416 private fun html_info
(page
: NitdocModule) do
1417 page
.append
("<div class='info'>")
1418 if visibility
< public_visibility
then page
.append
("{visibility.to_s} ")
1419 if not page
.mmodule
.in_nesting
.greaters
.has
(intro
.mmodule
) then page
.append
("redef ")
1420 page
.append
("{kind} ")
1421 html_namespace
(page
)
1422 page
.append
("{html_short_signature}</div>")
1425 private fun html_comment
(page
: NitdocPage) do
1426 page
.append
("<div class='description'>")
1427 if page
isa NitdocModule then
1428 page
.mmodule
.linearize_mclassdefs
(mclassdefs
)
1429 # comments for each mclassdef contained in current mmodule
1430 for mclassdef
in mclassdefs
do
1431 if not mclassdef
.is_intro
and not page
.mmodule
.mclassdefs
.has
(mclassdef
) then continue
1432 if page
.ctx
.mbuilder
.mclassdef2nclassdef
.has_key
(mclassdef
) then
1433 var nclass
= page
.ctx
.mbuilder
.mclassdef2nclassdef
[mclassdef
]
1434 if nclass
isa AStdClassdef then
1435 if page
.ctx
.github_gitdir
!= null then
1436 var loc
= nclass
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1437 page
.append
("<textarea class='baseComment' data-comment-namespace='{mclassdef.mmodule.full_name}::{name}' data-comment-location='{loc}'>{nclass.full_comment}</textarea>")
1439 if nclass
.full_comment
== "" then
1440 page
.append
("<p class='info inheritance'>")
1441 page
.append
("<span class=\"noComment\
">no comment for </span>")
1443 page
.append
("<div class='comment'>{nclass.full_markdown}</div>")
1444 page
.append
("<p class='info inheritance'>")
1446 if mclassdef
.is_intro
then
1447 page
.append
("introduction in ")
1449 page
.append
("refinement in ")
1451 mclassdef
.mmodule
.html_full_namespace
(page
)
1452 page
.append
(" {page.show_source(nclass.location)}</p>")
1457 # comments for intro
1458 if page
.ctx
.mbuilder
.mclassdef2nclassdef
.has_key
(intro
) then
1459 var nclass
= page
.ctx
.mbuilder
.mclassdef2nclassdef
[intro
]
1460 if nclass
isa AStdClassdef then
1461 if page
.ctx
.github_gitdir
!= null then
1462 var loc
= nclass
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1463 page
.append
("<textarea class='baseComment' data-comment-namespace='{intro.mmodule.full_name}::{name}' data-comment-location='{loc}'>{nclass.full_comment}</textarea>")
1465 if nclass
.full_comment
== "" then
1466 page
.append
("<p class='info inheritance'>")
1467 page
.append
("<span class=\"noComment\
">no comment for </span>")
1469 page
.append
("<div class='comment'>{nclass.full_markdown}</div>")
1470 page
.append
("<p class='info inheritance'>")
1472 page
.append
("introduction in ")
1473 intro
.mmodule
.html_full_namespace
(page
)
1474 page
.append
(" {page.show_source(nclass.location)}</p>")
1478 page
.append
("</div>")
1481 private fun mpropdefs_in_module
(page
: NitdocModule): Array[MPropDef] do
1482 var res
= new Array[MPropDef]
1483 page
.mmodule
.linearize_mclassdefs
(mclassdefs
)
1484 for mclassdef
in mclassdefs
do
1485 if not page
.mmodule
.mclassdefs
.has
(mclassdef
) then continue
1486 if mclassdef
.is_intro
then continue
1487 for mpropdef
in mclassdef
.mpropdefs
do
1488 if mpropdef
.mproperty
.visibility
< page
.ctx
.min_visibility
then continue
1489 if mpropdef
isa MAttributeDef then continue
1497 redef class MProperty
1498 # Escape name for html output
1499 private fun html_name
: String do return name
.html_escape
1501 # Return the property namespace decorated with html
1502 # <span>intro_module::intro_class::html_link</span>
1503 private fun html_namespace
(page
: NitdocPage) do
1504 intro_mclassdef
.mclass
.html_namespace
(page
)
1505 page
.append
(intro_mclassdef
.mclass
.html_short_signature
)
1506 page
.append
("::<span>")
1507 intro
.html_link
(page
)
1508 page
.append
("</span>")
1513 # Link to the type definition in the nitdoc page
1514 private fun html_link
(page
: NitdocPage) is abstract
1517 redef class MClassType
1518 redef fun html_link
(page
) do mclass
.html_link
(page
)
1521 redef class MNullableType
1522 redef fun html_link
(page
) do
1523 page
.append
("nullable ")
1524 mtype
.html_link
(page
)
1528 redef class MGenericType
1529 redef fun html_link
(page
) do
1530 page
.append
("<a href='{mclass.url}'>{mclass.html_name}</a>[")
1531 for i
in [0..arguments
.length
[ do
1532 arguments
[i
].html_link
(page
)
1533 if i
< arguments
.length
- 1 then page
.append
(", ")
1539 redef class MParameterType
1540 redef fun html_link
(page
) do
1541 var name
= mclass
.intro
.parameter_names
[rank
]
1542 page
.append
("<a href='{mclass.url}#FT_{name}' title='formal type'>{name}</a>")
1546 redef class MVirtualType
1547 redef fun html_link
(page
) do mproperty
.intro
.html_link
(page
)
1550 redef class MClassDef
1551 # Return the classdef namespace decorated with html
1552 private fun html_namespace
(page
: NitdocPage) do
1553 mmodule
.html_full_namespace
(page
)
1554 page
.append
("::<span>")
1555 mclass
.html_link
(page
)
1556 page
.append
("</span>")
1560 redef class MPropDef
1561 # Return the full qualified name of the mpropdef
1562 # module::classdef::name
1563 private fun full_name
: String do
1564 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1567 # URL into the nitdoc page
1568 # class_owner_name.html#anchor
1569 private fun url
: String do
1570 if url_cache
== null then
1571 url_cache
= "{mclassdef.mclass.url}#{anchor}"
1573 return url_cache
.as(not null)
1575 private var url_cache
: nullable String
1577 # html anchor id for the property in a nitdoc class page
1578 # PROP_mclass_propertyname
1579 private fun anchor
: String do
1580 if anchor_cache
== null then
1581 anchor_cache
= "PROP_{mclassdef.mclass.public_owner.name}_{mproperty.name.replace(" ", "_")}"
1583 return anchor_cache
.as(not null)
1585 private var anchor_cache
: nullable String
1587 # Return a link to property into the nitdoc class page
1588 # <a href="url" title="short_comment">html_name</a>
1589 private fun html_link
(page
: NitdocPage) do
1590 if html_link_cache
== null then
1591 var res
= new Buffer
1592 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1593 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1594 res
.append
("<a href=\"{url}\
" title=\"{nprop.short_comment}\
">{mproperty.html_name}</a>")
1596 res
.append
("<a href=\"{url}\
">{mproperty.html_name}</a>")
1598 html_link_cache
= res
.to_s
1600 page
.append
(html_link_cache
.as(not null))
1602 private var html_link_cache
: nullable String
1604 # Return a list item for the mpropdef
1605 # <li>html_link</li>
1606 private fun html_sidebar_item
(page
: NitdocClass) do
1607 if is_intro
and mclassdef
.mclass
== page
.mclass
then
1608 page
.append
("<li class='intro'>")
1609 page
.append
("<span title='Introduced'>I</span>")
1610 else if is_intro
and mclassdef
.mclass
!= page
.mclass
then
1611 page
.append
("<li class='inherit'>")
1612 page
.append
("<span title='Inherited'>H</span>")
1614 page
.append
("<li class='redef'>")
1615 page
.append
("<span title='Redefined'>R</span>")
1618 page
.append
("</li>")
1621 private fun html_full_desc
(page
: NitdocPage, ctx
: MClass) is abstract
1622 private fun html_info
(page
: NitdocPage, ctx
: MClass) is abstract
1624 private fun html_comment
(page
: NitdocPage) do
1625 page
.append
("<div class='description'>")
1626 if not is_intro
then
1627 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(mproperty
.intro
) then
1628 var intro_nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[mproperty
.intro
]
1629 if page
.ctx
.github_gitdir
!= null then
1630 var loc
= intro_nprop
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1631 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>")
1633 if intro_nprop
.full_comment
.is_empty
then
1634 page
.append
("<p class='info inheritance'>")
1635 page
.append
("<span class=\"noComment\
">no comment for </span>")
1637 page
.append
("<div class='comment'>{intro_nprop.full_markdown}</div>")
1638 page
.append
("<p class='info inheritance'>")
1640 page
.append
("introduction in ")
1641 mproperty
.intro
.mclassdef
.html_namespace
(page
)
1642 page
.append
(" {page.show_source(intro_nprop.location)}</p>")
1645 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1646 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1647 if page
.ctx
.github_gitdir
!= null then
1648 var loc
= nprop
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1649 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>")
1651 if nprop
.full_comment
== "" then
1652 page
.append
("<p class='info inheritance'>")
1653 page
.append
("<span class=\"noComment\
">no comment for </span>")
1655 page
.append
("<div class='comment'>{nprop.full_markdown}</div>")
1656 page
.append
("<p class='info inheritance'>")
1659 page
.append
("introduction in ")
1661 page
.append
("redefinition in ")
1663 mclassdef
.html_namespace
(page
)
1664 page
.append
(" {page.show_source(nprop.location)}</p>")
1666 page
.append
("</div>")
1670 redef class MMethodDef
1671 redef fun html_full_desc
(page
, ctx
) do
1672 var classes
= new Array[String]
1673 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= ctx
1674 if mproperty
.is_init
then
1679 if is_redef
then classes
.add
("redef")
1680 classes
.add
(mproperty
.visibility
.to_s
)
1681 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1682 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1683 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}{msignature.untyped_signature(page)}'>")
1684 page
.append
("<span>{mproperty.html_name}")
1685 msignature
.html_signature
(page
)
1686 page
.append
("</span></h3>")
1688 page
.append
("<h3 class='signature' data-untyped-signature='init{msignature.untyped_signature(page)}'>")
1689 page
.append
("<span>init")
1690 msignature
.html_signature
(page
)
1691 page
.append
("</span></h3>")
1693 html_info
(page
, ctx
)
1695 page
.append
("</article>")
1698 redef fun html_info
(page
, ctx
) do
1699 page
.append
("<div class='info'>")
1700 if mproperty
.visibility
< public_visibility
then page
.append
("{mproperty.visibility.to_s} ")
1701 if mproperty
.intro_mclassdef
.mclass
!= ctx
then page
.append
("redef ")
1702 if mproperty
.is_init
then
1703 page
.append
("init ")
1707 mproperty
.html_namespace
(page
)
1708 page
.append
("</div>")
1712 redef class MVirtualTypeDef
1713 redef fun html_full_desc
(page
, ctx
) do
1714 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= ctx
1715 var classes
= new Array[String]
1717 if is_redef
then classes
.add
("redef")
1718 classes
.add
(mproperty
.visibility
.to_s
)
1719 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1720 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}'><span>{mproperty.html_name}: ")
1721 bound
.html_link
(page
)
1722 page
.append
("</span></h3>")
1723 html_info
(page
, ctx
)
1725 page
.append
("</article>")
1728 redef fun html_info
(page
, ctx
) do
1729 page
.append
("<div class='info'>")
1730 if mproperty
.intro_mclassdef
.mclass
!= ctx
then page
.append
("redef ")
1731 page
.append
("type ")
1732 mproperty
.html_namespace
(page
)
1733 page
.append
("</div>")
1737 redef class MSignature
1738 private fun html_signature
(page
: NitdocPage) do
1739 if not mparameters
.is_empty
then
1741 for i
in [0..mparameters
.length
[ do
1742 mparameters
[i
].html_link
(page
)
1743 if i
< mparameters
.length
- 1 then page
.append
(", ")
1747 if return_mtype
!= null then
1749 return_mtype
.html_link
(page
)
1753 private fun untyped_signature
(page
: NitdocPage): String do
1754 var res
= new Buffer
1755 if not mparameters
.is_empty
then
1757 for i
in [0..mparameters
.length
[ do
1758 res
.append
(mparameters
[i
].name
)
1759 if i
< mparameters
.length
- 1 then res
.append
(", ")
1767 redef class MParameter
1768 private fun html_link
(page
: NitdocPage) do
1769 page
.append
("{name}: ")
1770 mtype
.html_link
(page
)
1771 if is_vararg
then page
.append
("...")
1779 redef class Location
1780 fun github
(gitdir
: String): String do
1781 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
1782 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
1783 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
1784 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
1789 private fun short_comment
: String do
1790 return n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1793 private fun full_comment
: String do
1794 var res
= new Buffer
1795 for t
in n_comment
do
1797 text
= text
.substring_from
(1)
1798 if text
.first
== ' ' then text
= text
.substring_from
(1)
1799 res
.append
(text
.html_escape
)
1802 return str
.substring
(0, str
.length
- 1)
1807 private fun short_comment
: String do
1808 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1809 return n_moduledecl
.n_doc
.short_comment
1814 private fun full_comment
: String do
1815 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1816 return n_moduledecl
.n_doc
.full_comment
1821 private fun full_markdown
: String do
1822 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1823 return n_moduledecl
.n_doc
.full_markdown
.html
1828 # The doc location or the first line of the block if doc node is null
1829 private fun doc_location
: Location do
1830 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1831 return n_moduledecl
.n_doc
.location
1834 return new Location(l
.file
, l
.line_start
, l
.line_start
, l
.column_start
, l
.column_start
)
1838 redef class AStdClassdef
1839 private fun short_comment
: String do
1840 if n_doc
!= null then return n_doc
.short_comment
1844 private fun full_comment
: String do
1845 if n_doc
!= null then return n_doc
.full_comment
1849 private fun full_markdown
: String do
1850 if n_doc
!= null then return n_doc
.full_markdown
.html
1854 # The doc location or the first line of the block if doc node is null
1855 private fun doc_location
: Location do
1856 if n_doc
!= null then return n_doc
.location
1858 return new Location(l
.file
, l
.line_start
, l
.line_start
, l
.column_start
, l
.column_start
)
1862 redef class APropdef
1863 private fun short_comment
: String do
1864 if n_doc
!= null then return n_doc
.short_comment
1868 private fun full_comment
: String do
1869 if n_doc
!= null then return n_doc
.full_comment
1873 private fun full_markdown
: String do
1874 if n_doc
!= null then return n_doc
.full_markdown
.html
1878 private fun doc_location
: Location do
1879 if n_doc
!= null then return n_doc
.location
1881 return new Location(l
.file
, l
.line_start
, l
.line_start
, l
.column_start
, l
.column_start
)
1887 var nitdoc
= new NitdocContext
1888 nitdoc
.generate_nitdoc