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_nodot
= new OptionBool("Do not generate graphes with graphviz", "--no-dot")
46 private var opt_private
: OptionBool = new OptionBool("Generate the private API", "--private")
48 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")
49 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")
50 private var opt_custom_overview_text
: OptionString = new OptionString("Text displayed as introduction of Overview page before the modules list", "--custom-overview-text")
51 private var opt_custom_footer_text
: OptionString = new OptionString("Text displayed as footer of all pages", "--custom-footer-text")
53 private var opt_github_upstream
: OptionString = new OptionString("The branch where edited commits will be pulled into (ex: user:repo:branch)", "--github-upstream")
54 private var opt_github_base_sha1
: OptionString = new OptionString("The sha1 of the base commit used to create pull request", "--github-base-sha1")
55 private var opt_github_gitdir
: OptionString = new OptionString("The git working directory used to resolve path name (ex: /home/me/myproject/)", "--github-gitdir")
57 private var opt_piwik_tracker
: OptionString = new OptionString("The URL of the Piwik tracker (ex: nitlanguage.org/piwik/)", "--piwik-tracker")
58 private var opt_piwik_site_id
: OptionString = new OptionString("The site ID in Piwik tracker", "--piwik-site-id")
61 toolcontext
.option_context
.add_option
(opt_dir
)
62 toolcontext
.option_context
.add_option
(opt_source
)
63 toolcontext
.option_context
.add_option
(opt_sharedir
)
64 toolcontext
.option_context
.add_option
(opt_nodot
)
65 toolcontext
.option_context
.add_option
(opt_private
)
66 toolcontext
.option_context
.add_option
(opt_custom_title
)
67 toolcontext
.option_context
.add_option
(opt_custom_footer_text
)
68 toolcontext
.option_context
.add_option
(opt_custom_overview_text
)
69 toolcontext
.option_context
.add_option
(opt_custom_menu_items
)
70 toolcontext
.option_context
.add_option
(opt_github_upstream
)
71 toolcontext
.option_context
.add_option
(opt_github_base_sha1
)
72 toolcontext
.option_context
.add_option
(opt_github_gitdir
)
73 toolcontext
.option_context
.add_option
(opt_piwik_tracker
)
74 toolcontext
.option_context
.add_option
(opt_piwik_site_id
)
75 toolcontext
.process_options
76 self.arguments
= toolcontext
.option_context
.rest
78 if arguments
.length
< 1 then
79 print
"usage: nitdoc [options] file..."
80 toolcontext
.option_context
.usage
86 mbuilder
= new ModelBuilder(model
, toolcontext
)
87 # Here we load and process all modules passed on the command line
88 var mmodules
= mbuilder
.parse
(arguments
)
89 if mmodules
.is_empty
then return
92 if mmodules
.length
== 1 then
93 mainmodule
= mmodules
.first
95 # We need a main module, so we build it by importing all modules
96 mainmodule
= new MModule(model
, null, "<main>", new Location(null, 0, 0, 0, 0))
97 mainmodule
.set_imported_mmodules
(mmodules
)
99 self.class_hierarchy
= mainmodule
.flatten_mclass_hierarchy
102 private fun process_options
do
103 if opt_dir
.value
!= null then
104 output_dir
= opt_dir
.value
108 if opt_sharedir
.value
!= null then
109 share_dir
= opt_sharedir
.value
111 var dir
= "NIT_DIR".environ
113 dir
= "{sys.program_name.dirname}/../share/nitdoc"
115 dir
= "{dir}/share/nitdoc"
118 if share_dir
== null then
119 print
"Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
122 dir
= "{share_dir.to_s}/scripts/js-facilities.js"
123 if share_dir
== null then
124 print
"Error: Invalid nitdoc share files. Check --sharedir or envvar NIT_DIR"
128 if opt_private
.value
then
129 min_visibility
= none_visibility
131 min_visibility
= protected_visibility
134 var gh_upstream
= opt_github_upstream
.value
135 var gh_base_sha
= opt_github_base_sha1
.value
136 var gh_gitdir
= opt_github_gitdir
.value
137 if not gh_upstream
== null or not gh_base_sha
== null or not gh_gitdir
== null then
138 if gh_upstream
== null or gh_base_sha
== null or gh_gitdir
== null then
139 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"
142 self.github_upstream
= gh_upstream
143 self.github_basesha1
= gh_base_sha
144 self.github_gitdir
= gh_gitdir
147 source
= opt_source
.value
150 fun generate_nitdoc
do
151 # Create destination dir if it's necessary
152 if not output_dir
.file_exists
then output_dir
.mkdir
153 sys
.system
("cp -r {share_dir.to_s}/* {output_dir.to_s}/")
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)
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)
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)
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 ctx: NitdocContext
228 init(ctx: NitdocContext) do
232 protected fun head do
233 append("<meta charset
='utf-8'/>")
234 append("<script
type='text/javascript' src
='scripts/jquery-1.7.1.min.js'></script
>")
235 append("<script
type='text/javascript' src
='scripts/ZeroClipboard.min.js'></script
>")
236 append("<script
type='text/javascript' src
='scripts/Nitdoc.UI.js'></script
>")
237 append("<script
type='text/javascript' src
='scripts/Markdown.Converter.js'></script
>")
238 append("<script
type='text/javascript' src
='scripts/base64.js'></script
>")
239 append("<script
type='text/javascript' src
='scripts/Nitdoc.GitHub.js'></script
>")
240 append("<script
type='text/javascript' src
='quicksearch-list.js'></script
>")
241 append("<script
type='text/javascript' src
='scripts/Nitdoc.QuickSearch.js'></script
>")
242 append("<link rel
='stylesheet' href
='styles/main.css' type='text/css' media
='screen'/>")
243 append("<link rel
='stylesheet' href
='styles/Nitdoc.UI.css' type='text/css' media
='screen'/>")
244 append("<link rel
='stylesheet' href
='styles/Nitdoc.QuickSearch.css' type='text/css' media
='screen'/>")
245 append("<link rel
='stylesheet' href
='styles/Nitdoc.GitHub.css' type='text/css' media
='screen'/>")
247 if ctx.opt_custom_title.value != null then
248 title = " | {ctx.opt_custom_title.value.to_s}"
250 append("<title
>{self.title}{title}</title
>")
253 protected fun menu do
254 if ctx.opt_custom_menu_items.value != null then
255 append(ctx.opt_custom_menu_items.value.to_s)
259 protected fun title: String is abstract
261 protected fun header do
263 append("<nav
class='main'>")
271 protected fun content is abstract
273 protected fun footer do
274 if ctx.opt_custom_footer_text.value != null then
275 append("<footer
>{ctx.opt_custom_footer_text.value.to_s}</footer
>")
279 # Generate a clickable graphviz image using a dot content
280 protected fun generate_dot(dot: String, name: String, alt: String) do
281 var output_dir = ctx.dot_dir
282 if output_dir == null then return
283 var file = new OFStream.open("{output_dir}/{name}.dot
")
286 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
; \
}")
287 append("<article
class='graph'>")
288 append("<img src
='{name}.png' usemap
='#{name}' style
='margin:auto' alt
='{alt}'/>")
290 var fmap = new IFStream.open("{output_dir}/{name}.map
")
291 append(fmap.read_all)
295 # Add a (source) link for a given location
296 protected fun show_source(l: Location): String
298 var source = ctx.source
299 if source == null then
300 return "({l.file.filename.simplify_path})"
302 # THIS IS JUST UGLY ! (but there is no replace yet)
303 var x = source.split_with("%f
")
304 source = x.join(l.file.filename.simplify_path)
305 x = source.split_with("%l
")
306 source = x.join(l.line_start.to_s)
307 x = source.split_with("%L
")
308 source = x.join(l.line_end.to_s)
309 source = source.simplify_path
310 return " (<a target
='_blank' title
='Show source' href
=\
"{source.to_s}\">source
</a
>)"
314 # Render the page as a html string
315 protected fun render do
316 append("<!DOCTYPE html
>")
321 if ctx.opt_github_upstream.value != null and ctx.opt_github_base_sha1.value != null then
322 append(" data-github-upstream
='{ctx.opt_github_upstream.value.as(not null)}'")
323 append(" data-github-base-sha1
='{ctx.opt_github_base_sha1.value.as(not null)}'")
328 if ctx.opt_custom_footer_text.value != null then footed = "footed
"
329 append("<div
class='page {footed}'>")
333 var tracker_url = ctx.opt_piwik_tracker.value
334 var site_id = ctx.opt_piwik_site_id.value
335 if tracker_url != null and site_id != null then
336 append("<!-- Piwik -->")
337 append("<script
type=\
"text/javascript\">")
338 append(" var _paq
= _paq
|| [];")
339 append(" _paq
.push
([\
"trackPageView\"]);")
340 append(" _paq
.push
([\
"enableLinkTracking\"]);")
341 append(" (function
() \
{")
342 append(" var u
=((\
"https:\" == document
.location
.protocol
) ? \
"https\" : \
"http\") + \
"://{tracker_url}\";")
343 append(" _paq
.push
([\
"setTrackerUrl\", u
+\
"piwik.php\"]);")
344 append(" _paq
.push
([\
"setSiteId\", \
"{site_id}\"]);")
345 append(" var d
=document
, g
=d
.createElement
(\
"script\"), s
=d
.getElementsByTagName
(\
"script\")[0]; g
.type=\
"text/javascript\";")
346 append(" g
.defer
=true; g
.async
=true; g
.src
=u
+\
"piwik.js\"; s
.parentNode
.insertBefore
(g
,s
);")
349 append("<!-- End Piwik Code -->")
356 # Append a string to the page
357 fun append(s: String) do out.write(s)
359 # Save html page in the specified file
360 fun save(file: String) do
361 self.out = new OFStream.open(file)
365 private var out: nullable OFStream
371 private var mbuilder: ModelBuilder
372 private var mmodules = new Array[MModule]
374 init(ctx: NitdocContext) do
376 self.mbuilder = ctx.mbuilder
378 var mmodules = new HashSet[MModule]
379 for mmodule in mbuilder.model.mmodule_importation_hierarchy do
380 if mmodule.name == "<main
>" then continue
381 var owner = mmodule.public_owner
382 if owner != null then
385 mmodules.add(mmodule)
389 var sorter = new MModuleNameSorter
390 self.mmodules.add_all(mmodules)
391 sorter.sort(self.mmodules)
394 redef fun title do return "Overview"
398 append("<li
class='current'>Overview</li
>")
399 append("<li
><a href
='search.html'>Search</a
></li
>")
403 append("<div
class='content fullpage'>")
404 var title = "Overview"
405 if ctx.opt_custom_title.value != null then
406 title = ctx.opt_custom_title.value.to_s
408 append("<h1
>{title}</h1
>")
410 if ctx.opt_custom_overview_text.value != null then
411 text = ctx.opt_custom_overview_text.value.to_s
413 append("<article
class='overview'>{text}</article
>")
414 append("<article
class='overview'>")
416 append("<h2
>Modules</h2
>")
418 for mmodule in mmodules do
419 if mbuilder.mmodule2nmodule.has_key(mmodule) then
420 var amodule = mbuilder.mmodule2nmodule[mmodule]
422 mmodule.html_link(self)
423 append(" 
;{amodule.short_comment}</li
>")
433 private fun process_generate_dot do
434 # build poset with public owners
435 var poset = new POSet[MModule]
436 for mmodule in mmodules do
437 poset.add_node(mmodule)
438 for omodule in mmodules do
439 if mmodule == omodule then continue
440 if mmodule.in_importation < omodule then
441 poset.add_node(omodule)
442 poset.add_edge(mmodule, omodule)
448 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
")
449 for mmodule in poset do
450 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
451 for omodule in poset[mmodule].direct_greaters do
452 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
456 generate_dot(op.to_s, "dep
", "Modules hierarchy
")
464 init(ctx: NitdocContext) do
468 redef fun title do return "Search"
472 append("<li
><a href
='index.html'>Overview</a
></li
>")
473 append("<li
class='current'>Search</li
>")
477 append("<div
class='content fullpage'>")
478 append("<h1
>{title}</h1
>")
485 # Add to content modules column
486 private fun module_column do
487 var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
488 var sorter = new MModuleNameSorter
490 append("<article
class='modules filterable'>")
491 append("<h2
>Modules</h2
>")
493 for mmodule in sorted do
494 if mmodule.name == "<main
>" then continue
496 mmodule.html_link(self)
503 # Add to content classes modules
504 private fun classes_column do
505 var sorted = ctx.mbuilder.model.mclasses
506 var sorter = new MClassNameSorter
508 append("<article
class='modules filterable'>")
509 append("<h2
>Classes</h2
>")
511 for mclass in sorted do
512 if mclass.visibility < ctx.min_visibility then continue
514 mclass.html_link(self)
521 # Insert the properties column of fullindex page
522 private fun properties_column do
523 var sorted = ctx.mbuilder.model.mproperties
524 var sorter = new MPropertyNameSorter
526 append("<article
class='modules filterable'>")
527 append("<h2
>Properties</h2
>")
529 for mproperty in sorted do
530 if mproperty.visibility < ctx.min_visibility then continue
531 if mproperty isa MAttribute then continue
533 mproperty.intro.html_link(self)
535 mproperty.intro.mclassdef.mclass.html_link(self)
548 private var mmodule: MModule
549 private var mbuilder: ModelBuilder
550 private var local_mclasses = new HashSet[MClass]
551 private var intro_mclasses = new HashSet[MClass]
552 private var redef_mclasses = new HashSet[MClass]
554 init(mmodule: MModule, ctx: NitdocContext) do
556 self.mmodule = mmodule
557 self.mbuilder = ctx.mbuilder
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) do
750 var locals = new HashSet[MProperty]
751 for mclassdef in mclass.mclassdefs do
752 for mpropdef in mclassdef.mpropdefs do
753 if mpropdef.mproperty.visibility < ctx.min_visibility then continue
754 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
755 if mpropdef isa MMethodDef then
756 if mpropdef.mproperty.is_init then
762 locals.add(mpropdef.mproperty)
765 # get inherited properties
766 for pclass in mclass.in_hierarchy(ctx.mainmodule).greaters do
767 if pclass == mclass then continue
768 for pclassdef in pclass.mclassdefs do
769 for mprop in pclassdef.intro_mproperties do
770 var mpropdef = mprop.intro
771 if mprop.visibility < ctx.min_visibility then continue # skip if not correct visibiility
772 if locals.has(mprop) then continue # skip if local
773 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
774 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
775 if mpropdef isa MMethodDef then
776 if mpropdef.mproperty.is_init then
782 inherited.add(mpropdef)
789 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
790 if nclass isa AStdClassdef then
791 return "{mclass.html_name} class | {nclass.short_comment}"
793 return "{mclass.html_name} class"
799 append("<li
><a href
='index.html'>Overview</a
></li
>")
800 var public_owner = mclass.public_owner
801 if public_owner == null then
803 mclass.intro_mmodule.html_link(self)
807 public_owner.html_link(self)
810 append("<li
class='current'>{mclass.html_name}</li
>")
811 append("<li
><a href
='search.html'>Search</a
></li
>")
815 append("<div
class='sidebar'>")
819 append("<div
class='content'>")
824 private fun properties_column do
825 var sorter = new MPropDefNameSorter
826 append("<nav
class='properties filterable'>")
827 append("<h3
>Properties</h3
>")
829 if vtypes.length > 0 then
830 var vts = new Array[MVirtualTypeDef]
833 append("<h4
>Virtual Types</h4
>")
836 mprop.html_sidebar_item(self)
841 if consts.length > 0 then
842 var cts = new Array[MMethodDef]
845 append("<h4
>Constructors</h4
>")
848 if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
849 mprop.html_sidebar_item(self)
854 if meths.length > 0 then
855 var mts = new Array[MMethodDef]
858 append("<h4
>Methods</h4
>")
861 mprop.html_sidebar_item(self)
868 private fun inheritance_column do
869 var sorted = new Array[MClass]
870 var sorterp = new MClassNameSorter
872 append("<h3
>Inheritance</h3
>")
873 var greaters = mclass.in_hierarchy(ctx.mainmodule).greaters.to_a
874 if greaters.length > 1 then
875 ctx.mainmodule.linearize_mclasses(greaters)
876 append("<h4
>Superclasses</h4
>")
878 for sup in greaters do
879 if sup == mclass then continue
886 var smallers = mclass.in_hierarchy(ctx.mainmodule).smallers.to_a
887 var direct_smallers = mclass.in_hierarchy(ctx.mainmodule).direct_smallers.to_a
888 if smallers.length <= 1 then
889 append("<h4
>No Known Subclasses</h4
>")
890 else if smallers.length <= 100 then
891 ctx.mainmodule.linearize_mclasses(smallers)
892 append("<h4
>Subclasses</h4
>")
894 for sub in smallers do
895 if sub == mclass then continue
901 else if direct_smallers.length <= 100 then
902 ctx.mainmodule.linearize_mclasses(direct_smallers)
903 append("<h4
>Direct Subclasses Only</h4
>")
905 for sub in direct_smallers do
906 if sub == mclass then continue
913 append("<h4
>Too much
Subclasses to list
</h4
>")
918 private fun class_doc do
920 append("<h1
>{mclass.html_name}{mclass.html_short_signature}</h1
>")
921 append("<div
class='subtitle info'>")
922 if mclass.visibility < public_visibility then append("{mclass.visibility.to_s} ")
923 append("{mclass.kind.to_s} ")
924 mclass.html_namespace(self)
925 append("{mclass.html_short_signature}</div
>")
927 mclass.html_comment(self)
930 var concern2meths = new ArrayMap[MModule, Array[MMethodDef]]
931 var sorted_meths = new Array[MMethodDef]
932 var sorted = new Array[MModule]
933 sorted_meths.add_all(meths)
934 ctx.mainmodule.linearize_mpropdefs(sorted_meths)
936 if inherited.has(meth) then continue
937 var mmodule = meth.mclassdef.mmodule
938 if not concern2meths.has_key(mmodule) then
940 concern2meths[mmodule] = new Array[MMethodDef]
942 concern2meths[mmodule].add(meth)
944 var sections = new ArrayMap[MModule, Array[MModule]]
945 for mmodule in concern2meths.keys do
946 var owner = mmodule.public_owner
947 if owner == null then owner = mmodule
948 if not sections.has_key(owner) then sections[owner] = new Array[MModule]
949 if owner != mmodule then sections[owner].add(mmodule)
951 append("<section
class='concerns'>")
952 append("<h2
class='section-header'>Concerns</h2
>")
954 for owner, mmodules in sections do
955 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
957 if nowner.short_comment.is_empty then
958 append("<a href
=\
"#{owner.anchor}\">{owner.html_name}</a
>")
960 append("<a href
=\
"#{owner.anchor}\">{owner.html_name}</a
>: {nowner.short_comment}")
962 if not mmodules.is_empty then
964 for mmodule in mmodules do
965 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
966 if nmodule.short_comment.is_empty then
967 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.html_name}</a
></li
>")
969 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.html_name}</a
>: {nmodule.short_comment}</li
>")
979 var prop_sorter = new MPropDefNameSorter
980 var lmmodule = new List[MModule]
981 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
982 # virtual and formal types
983 var local_vtypes = new Array[MVirtualTypeDef]
984 for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
985 if local_vtypes.length > 0 or mclass.arity > 0 then
986 append("<section
class='types'>")
987 append("<h2
>Formal and Virtual Types</h2
>")
989 if mclass.arity > 0 and nclass isa AStdClassdef then
990 for ft, bound in mclass.parameter_types do
991 append("<article id
='FT_{ft}'>")
992 append("<h3
class='signature' data-untyped-signature
='{ft.to_s}'><span
>{ft}: ")
993 bound.html_link(self)
994 append("</span
></h3
>")
995 append("<div
class=\
"info\">formal generic
type</div
>")
1000 prop_sorter.sort(local_vtypes)
1001 for prop in local_vtypes do prop.html_full_desc(self, self.mclass)
1002 append("</section
>")
1005 var local_consts = new Array[MMethodDef]
1006 for const in consts do if not inherited.has(const) then local_consts.add(const)
1007 prop_sorter.sort(local_consts)
1008 if local_consts.length > 0 then
1009 append("<section
class='constructors'>")
1010 append("<h2
class='section-header'>Constructors</h2
>")
1011 for prop in local_consts do prop.html_full_desc(self, self.mclass)
1012 append("</section
>")
1015 if not concern2meths.is_empty then
1016 append("<section
class='methods'>")
1017 append("<h2
class='section-header'>Methods</h2
>")
1018 for owner, mmodules in sections do
1019 append("<a id
=\
"{owner.anchor}\"></a
>")
1020 if owner != mclass.intro_mmodule and owner != mclass.public_owner then
1021 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
1022 append("<h3
class=\
"concern-toplevel\">Methods refined
in ")
1023 owner.html_link(self)
1025 append("<p
class=\
"concern-doc\">")
1026 owner.html_link(self)
1027 if not nowner.short_comment.is_empty then
1028 append(": {nowner.short_comment}")
1032 if concern2meths.has_key(owner) then
1033 var mmethods = concern2meths[owner]
1034 prop_sorter.sort(mmethods)
1035 for prop in mmethods do prop.html_full_desc(self, self.mclass)
1037 for mmodule in mmodules do
1038 append("<a id
=\
"{mmodule.anchor}\"></a
>")
1039 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
1040 if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
1041 append("<p
class=\
"concern-doc\">")
1042 mmodule.html_link(self)
1043 if not nmodule.short_comment.is_empty then
1044 append(": {nmodule.short_comment}")
1048 var mmethods = concern2meths[mmodule]
1049 prop_sorter.sort(mmethods)
1050 for prop in mmethods do prop.html_full_desc(self, self.mclass)
1053 append("</section
>")
1055 # inherited properties
1056 if inherited.length > 0 then
1057 var sorted_inherited = new Array[MPropDef]
1058 sorted_inherited.add_all(inherited)
1059 ctx.mainmodule.linearize_mpropdefs(sorted_inherited)
1060 var classes = new ArrayMap[MClass, Array[MPropDef]]
1061 for mmethod in sorted_inherited.reversed do
1062 var mclass = mmethod.mclassdef.mclass
1063 if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
1064 classes[mclass].add(mmethod)
1066 append("<section
class='inherited'>")
1067 append("<h2
class='section-header'>Inherited Properties</h2
>")
1068 for c, mmethods in classes do
1069 prop_sorter.sort(mmethods)
1070 append("<p
>Defined in ")
1073 for i in [0..mmethods.length[ do
1074 var mmethod = mmethods[i]
1075 mmethod.html_link(self)
1076 if i <= mmethods.length - 1 then append(", ")
1080 append("</section
>")
1084 private fun process_generate_dot do
1085 var pe = ctx.class_hierarchy[mclass]
1086 var cla = new HashSet[MClass]
1087 var sm = new HashSet[MClass]
1088 var sm2 = new HashSet[MClass]
1090 while cla.length + sm.length < 10 and sm.length > 0 do
1094 sm2.add_all(pe.poset[x].direct_smallers)
1100 cla.add_all(pe.greaters)
1103 var name = "dep_
{mclass.name}"
1104 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
")
1107 op.append("\
"{c.name}\"[shape
=box
,margin
=0.03];\n
")
1109 op.append("\
"{c.name}\"[URL=\
"{c.url}\"];\n
")
1111 for c2 in pe.poset[c].direct_greaters do
1112 if not cla.has(c2) then continue
1113 op.append("\
"{c.name}\"->\
"{c2.name}\";\n
")
1115 if not pe.poset[c].direct_smallers.is_empty then
1117 for c2 in pe.poset[c].direct_smallers do
1118 if cla.has(c2) then others = false
1121 op.append("\
"{c.name}...\"[label=\
"\"];\n
")
1122 op.append("\
"{c.name}...\"->\
"{c.name}\"[style
=dotted
];\n
")
1127 generate_dot(op.to_s, name, "Dependency graph
for class {mclass.name}")
1136 # Return the HTML escaped name of the module
1137 private fun html_name: String do return name.html_escape
1139 # URL to nitdoc page
1140 # module_owner_name.html
1141 private fun url: String do
1142 if url_cache == null then
1143 var res = new Buffer
1144 res.append("module_
")
1145 var mowner = public_owner
1146 if mowner != null then
1147 res.append("{public_owner.name}_
")
1149 res.append("{self.name}.html
")
1150 url_cache = res.to_s
1152 return url_cache.as(not null)
1154 private var url_cache: nullable String
1156 # html anchor id for the module in a nitdoc page
1158 private fun anchor: String do
1159 if anchor_cache == null then
1160 var res = new Buffer
1162 var mowner = public_owner
1163 if mowner != null then
1164 res.append("{public_owner.name}_
")
1166 res.append(self.name)
1167 anchor_cache = res.to_s
1169 return anchor_cache.as(not null)
1171 private var anchor_cache: nullable String
1173 # Return a link (html a tag) to the nitdoc module page
1174 # <a href="url
" title="short_comment
">html_name</a>
1175 private fun html_link(page: NitdocPage) do
1176 if html_link_cache == null then
1177 var res = new Buffer
1178 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1179 res.append("<a href
='{url}' title
='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{html_name}</a
>")
1181 res.append("<a href
='{url}'>{html_name}</a
>")
1183 html_link_cache = res.to_s
1185 page.append(html_link_cache.as(not null))
1187 private var html_link_cache: nullable String
1189 # Return the module signature decorated with html
1190 # <span>module html_full_namespace</span>
1191 private fun html_signature(page: NitdocPage) do
1192 page.append("<span
>module ")
1193 html_full_namespace(page)
1194 page.append("</span
>")
1197 # Return the module full namespace decorated with html
1198 # <span>public_owner.html_namespace::html_link</span>
1199 private fun html_full_namespace(page: NitdocPage) do
1200 page.append("<span
>")
1201 var mowner = public_owner
1202 if mowner != null then
1203 public_owner.html_namespace(page)
1207 page.append("</span
>")
1210 # Return the module full namespace decorated with html
1211 # <span>public_owner.html_namespace</span>
1212 private fun html_namespace(page: NitdocPage) do
1213 page.append("<span
>")
1214 var mowner = public_owner
1215 if mowner != null then
1216 public_owner.html_namespace(page)
1220 page.append("</span
>")
1223 # Return the full comment of the module decorated with html
1224 private fun html_comment(page: NitdocPage) do
1225 page.append("<div
class='description'>")
1226 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1227 var nmodule = page.ctx.mbuilder.mmodule2nmodule[self]
1228 if page.ctx.github_gitdir != null then
1229 var loc = nmodule.doc_location.github(page.ctx.github_gitdir.as(not null))
1230 page.append("<textarea
class='baseComment' data-comment-namespace
='{full_name}' data-comment-location
='{loc}'>{nmodule.full_comment}</textarea
>")
1232 if nmodule.full_comment == "" then
1233 page.append("<p
class='info inheritance'>")
1234 page.append("<span
class=\
"noComment\">no comment
for </span
>")
1236 page.append("<div
class='comment'>{nmodule.full_markdown}</div
>")
1237 page.append("<p
class='info inheritance'>")
1239 page.append("definition
in ")
1240 self.html_full_namespace(page)
1241 page.append(" {page.show_source(nmodule.location)}</p
>")
1243 page.append("</div
>")
1246 private fun has_mclassdef_for(mclass: MClass): Bool do
1247 for mmodule in self.in_nesting.greaters do
1248 for mclassdef in mmodule.mclassdefs do
1249 if mclassdef.mclass == mclass then return true
1255 private fun has_mclassdef(mclassdef: MClassDef): Bool do
1256 for mmodule in self.in_nesting.greaters do
1257 for oclassdef in mmodule.mclassdefs do
1258 if mclassdef == oclassdef then return true
1266 # Return the HTML escaped name of the module
1267 private fun html_name: String do return name.html_escape
1269 # URL to nitdoc page
1270 # class_owner_name.html
1271 private fun url: String do
1272 return "class_
{public_owner}_
{name}.html
"
1275 # html anchor id for the class in a nitdoc page
1277 private fun anchor: String do
1278 if anchor_cache == null then
1279 anchor_cache = "CLASS_{public_owner.name}_
{name}"
1281 return anchor_cache.as(not null)
1283 private var anchor_cache: nullable String
1285 # Return a link (with signature) to the nitdoc class page
1286 # <a href="url
" title="short_comment
">html_name(signature)</a>
1287 private fun html_link(page: NitdocPage) do
1288 if html_link_cache == null then
1289 var res = new Buffer
1290 res.append("<a href
='{url}'")
1291 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1292 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1293 if nclass isa AStdClassdef then
1294 res.append(" title
=\
"{nclass.short_comment}\"")
1297 res.append(">{html_name}{html_short_signature}</a
>")
1298 html_link_cache = res.to_s
1300 page.append(html_link_cache.as(not null))
1302 private var html_link_cache: nullable String
1304 # Return a short link (without signature) to the nitdoc class page
1305 # <a href="url
" title="short_comment
">html_name</a>
1306 private fun html_short_link(page: NitdocPage) do
1307 if html_short_link_cache == null then
1308 var res = new Buffer
1309 res.append("<a href
='{url}'")
1310 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1311 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1312 if nclass isa AStdClassdef then
1313 res.append(" title
=\
"{nclass.short_comment}\"")
1316 res.append(">{html_name}</a
>")
1317 html_short_link_cache = res.to_s
1319 page.append(html_short_link_cache.as(not null))
1321 private var html_short_link_cache: nullable String
1323 # Return a link (with signature) to the class anchor
1324 # <a href="url
" title="short_comment
">html_name</a>
1325 private fun html_link_anchor(page: NitdocPage) do
1326 if html_link_anchor_cache == null then
1327 var res = new Buffer
1328 res.append("<a href
='#{anchor}'")
1329 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1330 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1331 if nclass isa AStdClassdef then
1332 res.append(" title
=\
"{nclass.short_comment}\"")
1335 res.append(">{html_name}{html_short_signature}</a
>")
1336 html_link_anchor_cache = res.to_s
1338 page.append(html_link_anchor_cache.as(not null))
1340 private var html_link_anchor_cache: nullable String
1342 # Return the generic signature of the class with bounds
1343 # [E: <a>MType</a>, F: <a>MType</a>]
1344 private fun html_signature(page: NitdocPage) do
1347 for i in [0..intro.parameter_names.length[ do
1348 page.append("{intro.parameter_names[i]}: ")
1349 intro.bound_mtype.arguments[i].html_link(page)
1350 if i < intro.parameter_names.length - 1 then page.append(", ")
1356 # Return the generic signature of the class without bounds
1358 private fun html_short_signature: String do
1360 return "[{intro.parameter_names.join(", ")}]"
1366 # Return the class namespace decorated with html
1367 # <span>intro_module::html_short_link</span>
1368 private fun html_namespace(page: NitdocPage) do
1369 intro_mmodule.html_namespace(page)
1370 page.append("::<span
>")
1371 html_short_link(page)
1372 page.append("</span
>")
1375 # Return a list item for the mclass
1376 # <li>html_link</li>
1377 private fun html_sidebar_item(page: NitdocModule) do
1378 if page.mmodule.in_nesting.greaters.has(intro.mmodule) then
1379 page.append("<li
class='intro'>")
1380 page.append("<span title
='Introduced'>I
</span
>")
1381 html_link_anchor(page)
1382 else if page.mmodule.has_mclassdef_for(self) then
1383 page.append("<li
class='redef'>")
1384 page.append("<span title
='Redefined'>R
</span
>")
1385 html_link_anchor(page)
1387 page.append("<li
class='inherit'>")
1388 page.append("<span title
='Inherited'>H
</span
>")
1391 page.append("</li
>")
1394 private fun html_full_desc(page: NitdocModule) do
1395 var is_redef = not page.mmodule.in_nesting.greaters.has(intro.mmodule)
1396 var redefs = mpropdefs_in_module(page)
1397 if not is_redef or not redefs.is_empty then
1398 var classes = new Array[String]
1399 classes.add(kind.to_s)
1400 if is_redef then classes.add("redef")
1401 classes.add(visibility.to_s)
1402 page.append("<article
class='{classes.join(" ")}' id
='{anchor}'>")
1403 page.append("<h3
class='signature' data-untyped-signature
='{html_name}{html_short_signature}'>")
1404 page.append("<span
>")
1405 html_short_link(page)
1406 html_signature(page)
1407 page.append("</span
></h3
>")
1410 page.append("</article
>")
1414 private fun html_info(page: NitdocModule) do
1415 page.append("<div
class='info'>")
1416 if visibility < public_visibility then page.append("{visibility.to_s} ")
1417 if not page.mmodule.in_nesting.greaters.has(intro.mmodule) then page.append("redef ")
1418 page.append("{kind} ")
1419 html_namespace(page)
1420 page.append("{html_short_signature}</div
>")
1423 private fun html_comment(page: NitdocPage) do
1424 page.append("<div
class='description'>")
1425 if page isa NitdocModule then
1426 page.mmodule.linearize_mclassdefs(mclassdefs)
1427 # comments for each mclassdef contained in current mmodule
1428 for mclassdef in mclassdefs do
1429 if not mclassdef.is_intro and not page.mmodule.mclassdefs.has(mclassdef) then continue
1430 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(mclassdef) then
1431 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[mclassdef]
1432 if nclass isa AStdClassdef then
1433 if page.ctx.github_gitdir != null then
1434 var loc = nclass.doc_location.github(page.ctx.github_gitdir.as(not null))
1435 page.append("<textarea
class='baseComment' data-comment-namespace
='{mclassdef.mmodule.full_name}::{name}' data-comment-location
='{loc}'>{nclass.full_comment}</textarea
>")
1437 if nclass.full_comment == "" then
1438 page.append("<p
class='info inheritance'>")
1439 page.append("<span
class=\
"noComment\">no comment
for </span
>")
1441 page.append("<div
class='comment'>{nclass.full_markdown}</div
>")
1442 page.append("<p
class='info inheritance'>")
1444 if mclassdef.is_intro then
1445 page.append("introduction
in ")
1447 page.append("refinement
in ")
1449 mclassdef.mmodule.html_full_namespace(page)
1450 page.append(" {page.show_source(nclass.location)}</p
>")
1455 # comments for intro
1456 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1457 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1458 if nclass isa AStdClassdef then
1459 if page.ctx.github_gitdir != null then
1460 var loc = nclass.doc_location.github(page.ctx.github_gitdir.as(not null))
1461 page.append("<textarea
class='baseComment' data-comment-namespace
='{intro.mmodule.full_name}::{name}' data-comment-location
='{loc}'>{nclass.full_comment}</textarea
>")
1463 if nclass.full_comment == "" then
1464 page.append("<p
class='info inheritance'>")
1465 page.append("<span
class=\
"noComment\">no comment
for </span
>")
1467 page.append("<div
class='comment'>{nclass.full_markdown}</div
>")
1468 page.append("<p
class='info inheritance'>")
1470 page.append("introduction
in ")
1471 intro.mmodule.html_full_namespace(page)
1472 page.append(" {page.show_source(nclass.location)}</p
>")
1476 page.append("</div
>")
1479 private fun mpropdefs_in_module(page: NitdocModule): Array[MPropDef] do
1480 var res = new Array[MPropDef]
1481 page.mmodule.linearize_mclassdefs(mclassdefs)
1482 for mclassdef in mclassdefs do
1483 if not page.mmodule.mclassdefs.has(mclassdef) then continue
1484 if mclassdef.is_intro then continue
1485 for mpropdef in mclassdef.mpropdefs do
1486 if mpropdef.mproperty.visibility < page.ctx.min_visibility then continue
1487 if mpropdef isa MAttributeDef then continue
1495 redef class MProperty
1496 # Escape name for html output
1497 private fun html_name: String do return name.html_escape
1499 # Return the property namespace decorated with html
1500 # <span>intro_module::intro_class::html_link</span>
1501 private fun html_namespace(page: NitdocPage) do
1502 intro_mclassdef.mclass.html_namespace(page)
1503 page.append(intro_mclassdef.mclass.html_short_signature)
1504 page.append("::<span
>")
1505 intro.html_link(page)
1506 page.append("</span
>")
1511 # Link to the type definition in the nitdoc page
1512 private fun html_link(page: NitdocPage) is abstract
1515 redef class MClassType
1516 redef fun html_link(page) do mclass.html_link(page)
1519 redef class MNullableType
1520 redef fun html_link(page) do
1521 page.append("nullable ")
1522 mtype.html_link(page)
1526 redef class MGenericType
1527 redef fun html_link(page) do
1528 page.append("<a href
='{mclass.url}'>{mclass.html_name}</a
>[")
1529 for i in [0..arguments.length[ do
1530 arguments[i].html_link(page)
1531 if i < arguments.length - 1 then page.append(", ")
1537 redef class MParameterType
1538 redef fun html_link(page) do
1539 var name = mclass.intro.parameter_names[rank]
1540 page.append("<a href
='{mclass.url}#FT_{name}' title
='formal type'>{name}</a
>")
1544 redef class MVirtualType
1545 redef fun html_link(page) do mproperty.intro.html_link(page)
1548 redef class MClassDef
1549 # Return the classdef namespace decorated with html
1550 private fun html_namespace(page: NitdocPage) do
1551 mmodule.html_full_namespace(page)
1552 page.append("::<span
>")
1553 mclass.html_link(page)
1554 page.append("</span
>")
1558 redef class MPropDef
1559 # Return the full qualified name of the mpropdef
1560 # module::classdef::name
1561 private fun full_name: String do
1562 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1565 # URL into the nitdoc page
1566 # class_owner_name.html#anchor
1567 private fun url: String do
1568 if url_cache == null then
1569 url_cache = "{mclassdef.mclass.url}#{anchor}"
1571 return url_cache
.as(not null)
1573 private var url_cache
: nullable String
1575 # html anchor id for the property in a nitdoc class page
1576 # PROP_mclass_propertyname
1577 private fun anchor
: String do
1578 if anchor_cache
== null then
1579 anchor_cache
= "PROP_{mclassdef.mclass.public_owner.name}_{mproperty.name.replace(" ", "_")}"
1581 return anchor_cache
.as(not null)
1583 private var anchor_cache
: nullable String
1585 # Return a link to property into the nitdoc class page
1586 # <a href="url" title="short_comment">html_name</a>
1587 private fun html_link
(page
: NitdocPage) do
1588 if html_link_cache
== null then
1589 var res
= new Buffer
1590 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1591 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1592 res
.append
("<a href=\"{url}\
" title=\"{nprop.short_comment}\
">{mproperty.html_name}</a>")
1594 res
.append
("<a href=\"{url}\
">{mproperty.html_name}</a>")
1596 html_link_cache
= res
.to_s
1598 page
.append
(html_link_cache
.as(not null))
1600 private var html_link_cache
: nullable String
1602 # Return a list item for the mpropdef
1603 # <li>html_link</li>
1604 private fun html_sidebar_item
(page
: NitdocClass) do
1605 if is_intro
and mclassdef
.mclass
== page
.mclass
then
1606 page
.append
("<li class='intro'>")
1607 page
.append
("<span title='Introduced'>I</span>")
1608 else if is_intro
and mclassdef
.mclass
!= page
.mclass
then
1609 page
.append
("<li class='inherit'>")
1610 page
.append
("<span title='Inherited'>H</span>")
1612 page
.append
("<li class='redef'>")
1613 page
.append
("<span title='Redefined'>R</span>")
1616 page
.append
("</li>")
1619 private fun html_full_desc
(page
: NitdocPage, ctx
: MClass) is abstract
1620 private fun html_info
(page
: NitdocPage, ctx
: MClass) is abstract
1622 private fun html_comment
(page
: NitdocPage) do
1623 page
.append
("<div class='description'>")
1624 if not is_intro
then
1625 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(mproperty
.intro
) then
1626 var intro_nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[mproperty
.intro
]
1627 if page
.ctx
.github_gitdir
!= null then
1628 var loc
= intro_nprop
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1629 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>")
1631 if intro_nprop
.full_comment
.is_empty
then
1632 page
.append
("<p class='info inheritance'>")
1633 page
.append
("<span class=\"noComment\
">no comment for </span>")
1635 page
.append
("<div class='comment'>{intro_nprop.full_markdown}</div>")
1636 page
.append
("<p class='info inheritance'>")
1638 page
.append
("introduction in ")
1639 mproperty
.intro
.mclassdef
.html_namespace
(page
)
1640 page
.append
(" {page.show_source(intro_nprop.location)}</p>")
1643 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1644 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1645 if page
.ctx
.github_gitdir
!= null then
1646 var loc
= nprop
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1647 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>")
1649 if nprop
.full_comment
== "" then
1650 page
.append
("<p class='info inheritance'>")
1651 page
.append
("<span class=\"noComment\
">no comment for </span>")
1653 page
.append
("<div class='comment'>{nprop.full_markdown}</div>")
1654 page
.append
("<p class='info inheritance'>")
1657 page
.append
("introduction in ")
1659 page
.append
("redefinition in ")
1661 mclassdef
.html_namespace
(page
)
1662 page
.append
(" {page.show_source(nprop.location)}</p>")
1664 page
.append
("</div>")
1668 redef class MMethodDef
1669 redef fun html_full_desc
(page
, ctx
) do
1670 var classes
= new Array[String]
1671 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= ctx
1672 if mproperty
.is_init
then
1677 if is_redef
then classes
.add
("redef")
1678 classes
.add
(mproperty
.visibility
.to_s
)
1679 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1680 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1681 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}{msignature.untyped_signature(page)}'>")
1682 page
.append
("<span>{mproperty.html_name}")
1683 msignature
.html_signature
(page
)
1684 page
.append
("</span></h3>")
1686 page
.append
("<h3 class='signature' data-untyped-signature='init{msignature.untyped_signature(page)}'>")
1687 page
.append
("<span>init")
1688 msignature
.html_signature
(page
)
1689 page
.append
("</span></h3>")
1691 html_info
(page
, ctx
)
1693 page
.append
("</article>")
1696 redef fun html_info
(page
, ctx
) do
1697 page
.append
("<div class='info'>")
1698 if mproperty
.visibility
< public_visibility
then page
.append
("{mproperty.visibility.to_s} ")
1699 if mproperty
.intro_mclassdef
.mclass
!= ctx
then page
.append
("redef ")
1700 if mproperty
.is_init
then
1701 page
.append
("init ")
1705 mproperty
.html_namespace
(page
)
1706 page
.append
("</div>")
1710 redef class MVirtualTypeDef
1711 redef fun html_full_desc
(page
, ctx
) do
1712 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= ctx
1713 var classes
= new Array[String]
1715 if is_redef
then classes
.add
("redef")
1716 classes
.add
(mproperty
.visibility
.to_s
)
1717 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1718 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}'><span>{mproperty.html_name}: ")
1719 bound
.html_link
(page
)
1720 page
.append
("</span></h3>")
1721 html_info
(page
, ctx
)
1723 page
.append
("</article>")
1726 redef fun html_info
(page
, ctx
) do
1727 page
.append
("<div class='info'>")
1728 if mproperty
.intro_mclassdef
.mclass
!= ctx
then page
.append
("redef ")
1729 page
.append
("type ")
1730 mproperty
.html_namespace
(page
)
1731 page
.append
("</div>")
1735 redef class MSignature
1736 private fun html_signature
(page
: NitdocPage) do
1737 if not mparameters
.is_empty
then
1739 for i
in [0..mparameters
.length
[ do
1740 mparameters
[i
].html_link
(page
)
1741 if i
< mparameters
.length
- 1 then page
.append
(", ")
1745 if return_mtype
!= null then
1747 return_mtype
.html_link
(page
)
1751 private fun untyped_signature
(page
: NitdocPage): String do
1752 var res
= new Buffer
1753 if not mparameters
.is_empty
then
1755 for i
in [0..mparameters
.length
[ do
1756 res
.append
(mparameters
[i
].name
)
1757 if i
< mparameters
.length
- 1 then res
.append
(", ")
1765 redef class MParameter
1766 private fun html_link
(page
: NitdocPage) do
1767 page
.append
("{name}: ")
1768 mtype
.html_link
(page
)
1769 if is_vararg
then page
.append
("...")
1777 redef class Location
1778 fun github
(gitdir
: String): String do
1779 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
1780 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
1781 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
1782 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
1787 private fun short_comment
: String do
1788 return n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1791 private fun full_comment
: String do
1792 var res
= new Buffer
1793 for t
in n_comment
do
1795 text
= text
.substring_from
(1)
1796 if text
.first
== ' ' then text
= text
.substring_from
(1)
1797 res
.append
(text
.html_escape
)
1800 return str
.substring
(0, str
.length
- 1)
1805 private fun short_comment
: String do
1806 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1807 return n_moduledecl
.n_doc
.short_comment
1812 private fun full_comment
: String do
1813 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1814 return n_moduledecl
.n_doc
.full_comment
1819 private fun full_markdown
: String do
1820 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1821 return n_moduledecl
.n_doc
.full_markdown
.html
1826 private fun doc_location
: Location do
1827 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1828 return n_moduledecl
.n_doc
.location
1834 redef class AStdClassdef
1835 private fun short_comment
: String do
1836 if n_doc
!= null then return n_doc
.short_comment
1840 private fun full_comment
: String do
1841 if n_doc
!= null then return n_doc
.full_comment
1845 private fun full_markdown
: String do
1846 if n_doc
!= null then return n_doc
.full_markdown
.html
1850 private fun doc_location
: Location do
1851 if n_doc
!= null then return n_doc
.location
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
.html
1872 private fun doc_location
: Location do
1873 if n_doc
!= null then return n_doc
.location
1879 var nitdoc
= new NitdocContext
1880 nitdoc
.generate_nitdoc