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")
58 toolcontext
.option_context
.add_option
(opt_dir
)
59 toolcontext
.option_context
.add_option
(opt_source
)
60 toolcontext
.option_context
.add_option
(opt_sharedir
)
61 toolcontext
.option_context
.add_option
(opt_nodot
)
62 toolcontext
.option_context
.add_option
(opt_private
)
63 toolcontext
.option_context
.add_option
(opt_custom_title
)
64 toolcontext
.option_context
.add_option
(opt_custom_footer_text
)
65 toolcontext
.option_context
.add_option
(opt_custom_overview_text
)
66 toolcontext
.option_context
.add_option
(opt_custom_menu_items
)
67 toolcontext
.option_context
.add_option
(opt_github_upstream
)
68 toolcontext
.option_context
.add_option
(opt_github_base_sha1
)
69 toolcontext
.option_context
.add_option
(opt_github_gitdir
)
70 toolcontext
.process_options
71 self.arguments
= toolcontext
.option_context
.rest
73 if arguments
.length
< 1 then
74 print
"usage: nitdoc [options] file..."
75 toolcontext
.option_context
.usage
81 mbuilder
= new ModelBuilder(model
, toolcontext
)
82 # Here we load and process all modules passed on the command line
83 var mmodules
= mbuilder
.parse
(arguments
)
84 if mmodules
.is_empty
then return
87 if mmodules
.length
== 1 then
88 mainmodule
= mmodules
.first
90 # We need a main module, so we build it by importing all modules
91 mainmodule
= new MModule(model
, null, "<main>", new Location(null, 0, 0, 0, 0))
92 mainmodule
.set_imported_mmodules
(mmodules
)
94 self.class_hierarchy
= mainmodule
.flatten_mclass_hierarchy
97 private fun process_options
do
98 if not opt_dir
.value
is null then
99 output_dir
= opt_dir
.value
103 if not opt_sharedir
.value
is null then
104 share_dir
= opt_sharedir
.value
106 var dir
= "NIT_DIR".environ
108 dir
= "{sys.program_name.dirname}/../share/nitdoc"
110 dir
= "{dir}/share/nitdoc"
113 if share_dir
is null then
114 print
"Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
117 dir
= "{share_dir.to_s}/scripts/js-facilities.js"
118 if share_dir
is null then
119 print
"Error: Invalid nitdoc share files. Check --sharedir or envvar NIT_DIR"
123 if opt_private
.value
then
124 min_visibility
= none_visibility
126 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 sys
.system
("cp -r {share_dir.to_s}/* {output_dir.to_s}/")
150 if not opt_nodot
.value
then self.dot_dir
= output_dir
.to_s
158 private fun overview
do
159 var overviewpage
= new NitdocOverview(self, dot_dir
)
160 overviewpage
.save
("{output_dir.to_s}/index.html")
163 private fun search
do
164 var searchpage
= new NitdocSearch(self)
165 searchpage
.save
("{output_dir.to_s}/search.html")
168 private fun modules
do
169 for mmodule
in model
.mmodules
do
170 if mmodule
.name
== "<main>" then continue
171 var modulepage
= new NitdocModule(mmodule
, self, dot_dir
)
172 modulepage
.save
("{output_dir.to_s}/{mmodule.url}")
176 private fun classes
do
177 for mclass
in mbuilder
.model
.mclasses
do
178 var classpage
= new NitdocClass(mclass
, self, dot_dir
, source
)
179 classpage
.save
("{output_dir.to_s}/{mclass.url}")
183 private fun quicksearch_list
do
184 var file
= new OFStream.open
("{output_dir.to_s}/quicksearch-list.js")
185 file
.write
("var nitdocQuickSearchRawList = \{ ")
186 for mmodule
in model
.mmodules
do
187 if mmodule
.name
== "<main>" then continue
188 file
.write
("\"{mmodule.name}\
": [")
189 file
.write
("\{txt: \"{mmodule.full_name}\", url
:\
"{mmodule.url}\" \
},")
192 for mclass in model.mclasses do
193 if mclass.visibility < min_visibility then continue
194 file.write("\
"{mclass.name}\": [")
195 file.write("\
{txt: \"{mclass.full_name}\
", url:\"{mclass.url}\
" \},")
198 var name2mprops
= new HashMap[String, Set[MPropDef]]
199 for mproperty
in model
.mproperties
do
200 if mproperty
.visibility
< min_visibility
then continue
201 if mproperty
isa MAttribute then continue
202 if not name2mprops
.has_key
(mproperty
.name
) then name2mprops
[mproperty
.name
] = new HashSet[MPropDef]
203 name2mprops
[mproperty
.name
].add_all
(mproperty
.mpropdefs
)
205 for mproperty
, mpropdefs
in name2mprops
do
206 file
.write
("\"{mproperty}\
": [")
207 for mpropdef
in mpropdefs
do
208 file
.write
("\{txt: \"{mpropdef.full_name}\", url
:\
"{mpropdef.url}\" \
},")
219 abstract class NitdocPage
221 var dot_dir: nullable String
222 var source: nullable String
223 var ctx: NitdocContext
225 init(ctx: NitdocContext) do
229 protected fun head do
230 append("<meta charset
='utf-8'/>")
231 append("<script
type='text/javascript' src
='scripts/jquery-1.7.1.min.js'></script
>")
232 append("<script
type='text/javascript' src
='scripts/ZeroClipboard.min.js'></script
>")
233 append("<script
type='text/javascript' src
='scripts/Nitdoc.UI.js'></script
>")
234 append("<script
type='text/javascript' src
='scripts/Markdown.Converter.js'></script
>")
235 append("<script
type='text/javascript' src
='scripts/base64.js'></script
>")
236 append("<script
type='text/javascript' src
='scripts/Nitdoc.GitHub.js'></script
>")
237 append("<script
type='text/javascript' src
='quicksearch-list.js'></script
>")
238 append("<script
type='text/javascript' src
='scripts/Nitdoc.QuickSearch.js'></script
>")
239 append("<link rel
='stylesheet' href
='styles/main.css' type='text/css' media
='screen'/>")
240 append("<link rel
='stylesheet' href
='styles/Nitdoc.UI.css' type='text/css' media
='screen'/>")
241 append("<link rel
='stylesheet' href
='styles/Nitdoc.QuickSearch.css' type='text/css' media
='screen'/>")
242 append("<link rel
='stylesheet' href
='styles/Nitdoc.GitHub.css' type='text/css' media
='screen'/>")
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 if ctx.opt_github_upstream.value != null and ctx.opt_github_base_sha1.value != null then
317 append(" data-github-upstream
='{ctx.opt_github_upstream.value.as(not null)}'")
318 append(" data-github-base-sha1
='{ctx.opt_github_base_sha1.value.as(not null)}'")
323 if ctx.opt_custom_footer_text.value != null then footed = "footed
"
324 append("<div
class='page {footed}'>")
331 # Append a string to the page
332 fun append(s: String) do out.write(s)
334 # Save html page in the specified file
335 fun save(file: String) do
336 self.out = new OFStream.open(file)
340 private var out: nullable OFStream
346 private var mbuilder: ModelBuilder
347 private var mmodules = new Array[MModule]
349 init(ctx: NitdocContext, dot_dir: nullable String) do
351 self.mbuilder = ctx.mbuilder
352 self.dot_dir = dot_dir
354 var mmodules = new HashSet[MModule]
355 for mmodule in mbuilder.model.mmodule_importation_hierarchy do
356 if mmodule.name == "<main
>" then continue
357 var owner = mmodule.public_owner
358 if owner != null then
361 mmodules.add(mmodule)
365 var sorter = new MModuleNameSorter
366 self.mmodules.add_all(mmodules)
367 sorter.sort(self.mmodules)
370 redef fun title do return "Overview"
374 append("<li
class='current'>Overview</li
>")
375 append("<li
><a href
='search.html'>Search</a
></li
>")
379 append("<div
class='content fullpage'>")
380 var title = "Overview"
381 if ctx.opt_custom_title.value != null then
382 title = ctx.opt_custom_title.value.to_s
384 append("<h1
>{title}</h1
>")
386 if ctx.opt_custom_overview_text.value != null then
387 text = ctx.opt_custom_overview_text.value.to_s
389 append("<article
class='overview'>{text}</article
>")
390 append("<article
class='overview'>")
392 append("<h2
>Modules</h2
>")
394 for mmodule in mmodules do
395 if mbuilder.mmodule2nmodule.has_key(mmodule) then
396 var amodule = mbuilder.mmodule2nmodule[mmodule]
398 mmodule.html_link(self)
399 append(" 
;{amodule.short_comment}</li
>")
409 private fun process_generate_dot do
410 # build poset with public owners
411 var poset = new POSet[MModule]
412 for mmodule in mmodules do
413 poset.add_node(mmodule)
414 for omodule in mmodules do
415 if mmodule == omodule then continue
416 if mmodule.in_importation < omodule then
417 poset.add_node(omodule)
418 poset.add_edge(mmodule, omodule)
424 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
")
425 for mmodule in poset do
426 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
427 for omodule in poset[mmodule].direct_greaters do
428 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
432 generate_dot(op.to_s, "dep
", "Modules hierarchy
")
440 init(ctx: NitdocContext) do
445 redef fun title do return "Search"
449 append("<li
><a href
='index.html'>Overview</a
></li
>")
450 append("<li
class='current'>Search</li
>")
454 append("<div
class='content fullpage'>")
455 append("<h1
>{title}</h1
>")
462 # Add to content modules column
463 private fun module_column do
464 var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
465 var sorter = new MModuleNameSorter
467 append("<article
class='modules filterable'>")
468 append("<h2
>Modules</h2
>")
470 for mmodule in sorted do
471 if mmodule.name == "<main
>" then continue
473 mmodule.html_link(self)
480 # Add to content classes modules
481 private fun classes_column do
482 var sorted = ctx.mbuilder.model.mclasses
483 var sorter = new MClassNameSorter
485 append("<article
class='modules filterable'>")
486 append("<h2
>Classes</h2
>")
488 for mclass in sorted do
489 if mclass.visibility < ctx.min_visibility then continue
491 mclass.html_link(self)
498 # Insert the properties column of fullindex page
499 private fun properties_column do
500 var sorted = ctx.mbuilder.model.mproperties
501 var sorter = new MPropertyNameSorter
503 append("<article
class='modules filterable'>")
504 append("<h2
>Properties</h2
>")
506 for mproperty in sorted do
507 if mproperty.visibility < ctx.min_visibility then continue
508 if mproperty isa MAttribute then continue
510 mproperty.intro.html_link(self)
512 mproperty.intro.mclassdef.mclass.html_link(self)
525 private var mmodule: MModule
526 private var mbuilder: ModelBuilder
527 private var local_mclasses = new HashSet[MClass]
528 private var intro_mclasses = new HashSet[MClass]
529 private var redef_mclasses = new HashSet[MClass]
531 init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
533 self.mmodule = mmodule
534 self.mbuilder = ctx.mbuilder
535 self.dot_dir = dot_dir
537 for m in mmodule.in_nesting.greaters do
538 for mclassdef in m.mclassdefs do
539 if mclassdef.mclass.visibility < ctx.min_visibility then continue
540 if mclassdef.is_intro then
541 intro_mclasses.add(mclassdef.mclass)
543 if mclassdef.mclass.mpropdefs_in_module(self).is_empty then continue
544 redef_mclasses.add(mclassdef.mclass)
546 local_mclasses.add(mclassdef.mclass)
552 if mbuilder.mmodule2nmodule.has_key(mmodule) and not mbuilder.mmodule2nmodule[mmodule].short_comment.is_empty then
553 var nmodule = mbuilder.mmodule2nmodule[mmodule]
554 return "{mmodule.html_name} module | {nmodule.short_comment}"
556 return "{mmodule.html_name} module"
562 append("<li
><a href
='index.html'>Overview</a
></li
>")
563 append("<li
class='current'>{mmodule.html_name}</li
>")
564 append("<li
><a href
='search.html'>Search</a
></li
>")
568 append("<div
class='sidebar'>")
572 append("<div
class='content'>")
577 private fun classes_column do
578 var sorter = new MClassNameSorter
579 var sorted = new Array[MClass]
580 sorted.add_all(intro_mclasses)
581 sorted.add_all(redef_mclasses)
583 if not sorted.is_empty then
584 append("<nav
class='properties filterable'>")
585 append("<h3
>Classes</h3
>")
586 append("<h4
>Classes</h4
>")
588 for mclass in sorted do mclass.html_sidebar_item(self)
594 private fun importation_column do
596 append("<h3
>Module Hierarchy</h3
>")
597 var dependencies = new Array[MModule]
598 for dep in mmodule.in_importation.greaters do
599 if dep == mmodule or dep.direct_owner == mmodule or dep.public_owner == mmodule then continue
600 dependencies.add(dep)
602 if mmodule.in_nesting.direct_greaters.length > 0 then
603 append("<h4
>Nested Modules</h4
>")
604 display_module_list(mmodule.in_nesting.direct_greaters.to_a)
606 if dependencies.length > 0 then
607 append("<h4
>All dependencies
</h4
>")
608 display_module_list(dependencies)
610 var clients = new Array[MModule]
611 for dep in mmodule.in_importation.smallers do
612 if dep.name == "<main
>" then continue
613 if dep == mmodule then continue
616 if clients.length > 0 then
617 append("<h4
>All clients
</h4
>")
618 display_module_list(clients)
623 private fun display_module_list(list: Array[MModule]) do
625 var sorter = new MModuleNameSorter
635 private fun module_doc do
637 append("<h1
>{mmodule.html_name}</h1
>")
638 append("<div
class='subtitle info'>")
639 mmodule.html_signature(self)
642 mmodule.html_comment(self)
645 var class_sorter = new MClassNameSorter
647 if not intro_mclasses.is_empty then
648 var sorted = new Array[MClass]
649 sorted.add_all(intro_mclasses)
650 class_sorter.sort(sorted)
651 append("<section
class='classes'>")
652 append("<h2
class='section-header'>Introduced classes
</h2
>")
653 for mclass in sorted do mclass.html_full_desc(self)
657 var redefs = new Array[MClass]
658 for mclass in redef_mclasses do if not intro_mclasses.has(mclass) then redefs.add(mclass)
659 class_sorter.sort(redefs)
660 if not redefs.is_empty then
661 append("<section
class='classes'>")
662 append("<h2
class='section-header'>Refined classes
</h2
>")
663 for mclass in redefs do mclass.html_full_desc(self)
668 private fun process_generate_dot do
669 # build poset with public owners
670 var poset = new POSet[MModule]
671 for mmodule in self.mmodule.in_importation.poset do
672 if mmodule.name == "<main
>" then continue
673 #if mmodule.public_owner != null then continue
674 if not mmodule.in_importation < self.mmodule and not self.mmodule.in_importation < mmodule and mmodule != self.mmodule then continue
675 poset.add_node(mmodule)
676 for omodule in mmodule.in_importation.poset do
677 if mmodule == omodule then continue
678 if omodule.name == "<main
>" then continue
679 if not omodule.in_importation < self.mmodule and not self.mmodule.in_importation < omodule then continue
680 if omodule.in_importation < mmodule then
681 poset.add_node(omodule)
682 poset.add_edge(omodule, mmodule)
684 if mmodule.in_importation < omodule then
685 poset.add_node(omodule)
686 poset.add_edge(mmodule, omodule)
688 #if omodule.public_owner != null then continue
689 #if mmodule.in_importation < omodule then
690 #poset.add_node(omodule)
691 #poset.add_edge(mmodule, omodule)
697 var name = "dep_
{mmodule.name}"
698 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
")
699 for mmodule in poset do
700 if mmodule == self.mmodule then
701 op.append("\
"{mmodule.name}\"[shape
=box
,margin
=0.03];\n
")
703 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
705 for omodule in poset[mmodule].direct_greaters do
706 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
710 generate_dot(op.to_s, name, "Dependency graph
for module {mmodule.name}")
718 private var mclass: MClass
719 private var vtypes = new HashSet[MVirtualTypeDef]
720 private var consts = new HashSet[MMethodDef]
721 private var meths = new HashSet[MMethodDef]
722 private var inherited = new HashSet[MPropDef]
724 init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
727 self.dot_dir = dot_dir
730 var locals = new HashSet[MProperty]
731 for mclassdef in mclass.mclassdefs do
732 for mpropdef in mclassdef.mpropdefs do
733 if mpropdef.mproperty.visibility < ctx.min_visibility then continue
734 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
735 if mpropdef isa MMethodDef then
736 if mpropdef.mproperty.is_init then
742 locals.add(mpropdef.mproperty)
745 # get inherited properties
746 for pclass in mclass.in_hierarchy(ctx.mainmodule).greaters do
747 if pclass == mclass then continue
748 for pclassdef in pclass.mclassdefs do
749 for mprop in pclassdef.intro_mproperties do
750 var mpropdef = mprop.intro
751 if mprop.visibility < ctx.min_visibility then continue # skip if not correct visibiility
752 if locals.has(mprop) then continue # skip if local
753 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
754 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
755 if mpropdef isa MMethodDef then
756 if mpropdef.mproperty.is_init then
762 inherited.add(mpropdef)
769 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
770 if nclass isa AStdClassdef then
771 return "{mclass.html_name} class | {nclass.short_comment}"
773 return "{mclass.html_name} class"
779 append("<li
><a href
='index.html'>Overview</a
></li
>")
780 var public_owner = mclass.public_owner
781 if public_owner is null then
783 mclass.intro_mmodule.html_link(self)
787 public_owner.html_link(self)
790 append("<li
class='current'>{mclass.html_name}</li
>")
791 append("<li
><a href
='search.html'>Search</a
></li
>")
795 append("<div
class='sidebar'>")
799 append("<div
class='content'>")
804 private fun properties_column do
805 var sorter = new MPropDefNameSorter
806 append("<nav
class='properties filterable'>")
807 append("<h3
>Properties</h3
>")
809 if vtypes.length > 0 then
810 var vts = new Array[MVirtualTypeDef]
813 append("<h4
>Virtual Types</h4
>")
816 mprop.html_sidebar_item(self)
821 if consts.length > 0 then
822 var cts = new Array[MMethodDef]
825 append("<h4
>Constructors</h4
>")
828 if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
829 mprop.html_sidebar_item(self)
834 if meths.length > 0 then
835 var mts = new Array[MMethodDef]
838 append("<h4
>Methods</h4
>")
841 mprop.html_sidebar_item(self)
848 private fun inheritance_column do
849 var sorted = new Array[MClass]
850 var sorterp = new MClassNameSorter
852 append("<h3
>Inheritance</h3
>")
853 var greaters = mclass.in_hierarchy(ctx.mainmodule).greaters.to_a
854 if greaters.length > 1 then
855 ctx.mainmodule.linearize_mclasses(greaters)
856 append("<h4
>Superclasses</h4
>")
858 for sup in greaters do
859 if sup == mclass then continue
866 var smallers = mclass.in_hierarchy(ctx.mainmodule).smallers.to_a
867 var direct_smallers = mclass.in_hierarchy(ctx.mainmodule).direct_smallers.to_a
868 if smallers.length <= 1 then
869 append("<h4
>No Known Subclasses</h4
>")
870 else if smallers.length <= 100 then
871 ctx.mainmodule.linearize_mclasses(smallers)
872 append("<h4
>Subclasses</h4
>")
874 for sub in smallers do
875 if sub == mclass then continue
881 else if direct_smallers.length <= 100 then
882 ctx.mainmodule.linearize_mclasses(direct_smallers)
883 append("<h4
>Direct Subclasses Only</h4
>")
885 for sub in direct_smallers do
886 if sub == mclass then continue
893 append("<h4
>Too much
Subclasses to list
</h4
>")
898 private fun class_doc do
900 append("<h1
>{mclass.html_name}{mclass.html_short_signature}</h1
>")
901 append("<div
class='subtitle info'>")
902 if mclass.visibility < public_visibility then append("{mclass.visibility.to_s} ")
903 append("{mclass.kind.to_s} ")
904 mclass.html_namespace(self)
905 append("{mclass.html_short_signature}</div
>")
907 mclass.html_comment(self)
910 var concern2meths = new ArrayMap[MModule, Array[MMethodDef]]
911 var sorted_meths = new Array[MMethodDef]
912 var sorted = new Array[MModule]
913 sorted_meths.add_all(meths)
914 ctx.mainmodule.linearize_mpropdefs(sorted_meths)
916 if inherited.has(meth) then continue
917 var mmodule = meth.mclassdef.mmodule
918 if not concern2meths.has_key(mmodule) then
920 concern2meths[mmodule] = new Array[MMethodDef]
922 concern2meths[mmodule].add(meth)
924 var sections = new ArrayMap[MModule, Array[MModule]]
925 for mmodule in concern2meths.keys do
926 var owner = mmodule.public_owner
927 if owner == null then owner = mmodule
928 if not sections.has_key(owner) then sections[owner] = new Array[MModule]
929 if owner != mmodule then sections[owner].add(mmodule)
931 append("<section
class='concerns'>")
932 append("<h2
class='section-header'>Concerns</h2
>")
934 for owner, mmodules in sections do
935 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
937 if nowner.short_comment.is_empty then
938 append("<a href
=\
"#{owner.anchor}\">{owner.html_name}</a
>")
940 append("<a href
=\
"#{owner.anchor}\">{owner.html_name}</a
>: {nowner.short_comment}")
942 if not mmodules.is_empty then
944 for mmodule in mmodules do
945 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
946 if nmodule.short_comment.is_empty then
947 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.html_name}</a
></li
>")
949 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.html_name}</a
>: {nmodule.short_comment}</li
>")
959 var prop_sorter = new MPropDefNameSorter
960 var lmmodule = new List[MModule]
961 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
962 # virtual and formal types
963 var local_vtypes = new Array[MVirtualTypeDef]
964 for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
965 if local_vtypes.length > 0 or mclass.arity > 0 then
966 append("<section
class='types'>")
967 append("<h2
>Formal and Virtual Types</h2
>")
969 if mclass.arity > 0 and nclass isa AStdClassdef then
970 for ft, bound in mclass.parameter_types do
971 append("<article id
='FT_{ft}'>")
972 append("<h3
class='signature' data-untyped-signature
='{ft.to_s}'><span
>{ft}: ")
973 bound.html_link(self)
974 append("</span
></h3
>")
975 append("<div
class=\
"info\">formal generic
type</div
>")
980 prop_sorter.sort(local_vtypes)
981 for prop in local_vtypes do prop.html_full_desc(self, self.mclass)
985 var local_consts = new Array[MMethodDef]
986 for const in consts do if not inherited.has(const) then local_consts.add(const)
987 prop_sorter.sort(local_consts)
988 if local_consts.length > 0 then
989 append("<section
class='constructors'>")
990 append("<h2
class='section-header'>Constructors</h2
>")
991 for prop in local_consts do prop.html_full_desc(self, self.mclass)
995 if not concern2meths.is_empty then
996 append("<section
class='methods'>")
997 append("<h2
class='section-header'>Methods</h2
>")
998 for owner, mmodules in sections do
999 append("<a id
=\
"{owner.anchor}\"></a
>")
1000 if owner != mclass.intro_mmodule and owner != mclass.public_owner then
1001 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
1002 append("<h3
class=\
"concern-toplevel\">Methods refined
in ")
1003 owner.html_link(self)
1005 append("<p
class=\
"concern-doc\">")
1006 owner.html_link(self)
1007 if not nowner.short_comment.is_empty then
1008 append(": {nowner.short_comment}")
1012 if concern2meths.has_key(owner) then
1013 var mmethods = concern2meths[owner]
1014 prop_sorter.sort(mmethods)
1015 for prop in mmethods do prop.html_full_desc(self, self.mclass)
1017 for mmodule in mmodules do
1018 append("<a id
=\
"{mmodule.anchor}\"></a
>")
1019 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
1020 if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
1021 append("<p
class=\
"concern-doc\">")
1022 mmodule.html_link(self)
1023 if not nmodule.short_comment.is_empty then
1024 append(": {nmodule.short_comment}")
1028 var mmethods = concern2meths[mmodule]
1029 prop_sorter.sort(mmethods)
1030 for prop in mmethods do prop.html_full_desc(self, self.mclass)
1033 append("</section
>")
1035 # inherited properties
1036 if inherited.length > 0 then
1037 var sorted_inherited = new Array[MPropDef]
1038 sorted_inherited.add_all(inherited)
1039 ctx.mainmodule.linearize_mpropdefs(sorted_inherited)
1040 var classes = new ArrayMap[MClass, Array[MPropDef]]
1041 for mmethod in sorted_inherited.reversed do
1042 var mclass = mmethod.mclassdef.mclass
1043 if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
1044 classes[mclass].add(mmethod)
1046 append("<section
class='inherited'>")
1047 append("<h2
class='section-header'>Inherited Properties</h2
>")
1048 for c, mmethods in classes do
1049 prop_sorter.sort(mmethods)
1050 append("<p
>Defined in ")
1053 for i in [0..mmethods.length[ do
1054 var mmethod = mmethods[i]
1055 mmethod.html_link(self)
1056 if i <= mmethods.length - 1 then append(", ")
1060 append("</section
>")
1064 private fun process_generate_dot do
1065 var pe = ctx.class_hierarchy[mclass]
1066 var cla = new HashSet[MClass]
1067 var sm = new HashSet[MClass]
1068 var sm2 = new HashSet[MClass]
1070 while cla.length + sm.length < 10 and sm.length > 0 do
1074 sm2.add_all(pe.poset[x].direct_smallers)
1080 cla.add_all(pe.greaters)
1083 var name = "dep_
{mclass.name}"
1084 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
")
1087 op.append("\
"{c.name}\"[shape
=box
,margin
=0.03];\n
")
1089 op.append("\
"{c.name}\"[URL=\
"{c.url}\"];\n
")
1091 for c2 in pe.poset[c].direct_greaters do
1092 if not cla.has(c2) then continue
1093 op.append("\
"{c.name}\"->\
"{c2.name}\";\n
")
1095 if not pe.poset[c].direct_smallers.is_empty then
1097 for c2 in pe.poset[c].direct_smallers do
1098 if cla.has(c2) then others = false
1101 op.append("\
"{c.name}...\"[label=\
"\"];\n
")
1102 op.append("\
"{c.name}...\"->\
"{c.name}\"[style
=dotted
];\n
")
1107 generate_dot(op.to_s, name, "Dependency graph
for class {mclass.name}")
1116 # Return the HTML escaped name of the module
1117 private fun html_name: String do return name.html_escape
1119 # URL to nitdoc page
1120 # module_owner_name.html
1121 private fun url: String do
1122 if url_cache == null then
1123 var res = new Buffer
1124 res.append("module_
")
1125 var mowner = public_owner
1126 if mowner != null then
1127 res.append("{public_owner.name}_
")
1129 res.append("{self.name}.html
")
1130 url_cache = res.to_s
1132 return url_cache.as(not null)
1134 private var url_cache: nullable String
1136 # html anchor id for the module in a nitdoc page
1138 private fun anchor: String do
1139 if anchor_cache == null then
1140 var res = new Buffer
1142 var mowner = public_owner
1143 if mowner != null then
1144 res.append("{public_owner.name}_
")
1146 res.append(self.name)
1147 anchor_cache = res.to_s
1149 return anchor_cache.as(not null)
1151 private var anchor_cache: nullable String
1153 # Return a link (html a tag) to the nitdoc module page
1154 # <a href="url
" title="short_comment
">html_name</a>
1155 private fun html_link(page: NitdocPage) do
1156 if html_link_cache == null then
1157 var res = new Buffer
1158 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1159 res.append("<a href
='{url}' title
='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{html_name}</a
>")
1161 res.append("<a href
='{url}'>{html_name}</a
>")
1163 html_link_cache = res.to_s
1165 page.append(html_link_cache.as(not null))
1167 private var html_link_cache: nullable String
1169 # Return the module signature decorated with html
1170 # <span>module html_full_namespace</span>
1171 private fun html_signature(page: NitdocPage) do
1172 page.append("<span
>module ")
1173 html_full_namespace(page)
1174 page.append("</span
>")
1177 # Return the module full namespace decorated with html
1178 # <span>public_owner.html_namespace::html_link</span>
1179 private fun html_full_namespace(page: NitdocPage) do
1180 page.append("<span
>")
1181 var mowner = public_owner
1182 if mowner != null then
1183 public_owner.html_namespace(page)
1187 page.append("</span
>")
1190 # Return the module full namespace decorated with html
1191 # <span>public_owner.html_namespace</span>
1192 private fun html_namespace(page: NitdocPage) do
1193 page.append("<span
>")
1194 var mowner = public_owner
1195 if mowner != null then
1196 public_owner.html_namespace(page)
1200 page.append("</span
>")
1203 # Return the full comment of the module decorated with html
1204 private fun html_comment(page: NitdocPage) do
1205 page.append("<div
class='description'>")
1206 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1207 var nmodule = page.ctx.mbuilder.mmodule2nmodule[self]
1208 if not page.ctx.github_gitdir is null then
1209 var loc = nmodule.doc_location.github(page.ctx.github_gitdir.as(not null))
1210 page.append("<textarea
class='baseComment' data-comment-namespace
='{full_name}' data-comment-location
='{loc}'>{nmodule.full_comment}</textarea
>")
1212 if nmodule.full_comment == "" then
1213 page.append("<p
class='info inheritance'>")
1214 page.append("<span
class=\
"noComment\">no comment
for </span
>")
1216 page.append("<div
class='comment'>{nmodule.full_markdown}</div
>")
1217 page.append("<p
class='info inheritance'>")
1219 page.append("definition
in ")
1220 self.html_full_namespace(page)
1221 page.append(" {page.show_source(nmodule.location)}</p
>")
1223 page.append("</div
>")
1226 private fun has_mclassdef_for(mclass: MClass): Bool do
1227 for mmodule in self.in_nesting.greaters do
1228 for mclassdef in mmodule.mclassdefs do
1229 if mclassdef.mclass == mclass then return true
1235 private fun has_mclassdef(mclassdef: MClassDef): Bool do
1236 for mmodule in self.in_nesting.greaters do
1237 for oclassdef in mmodule.mclassdefs do
1238 if mclassdef == oclassdef then return true
1246 # Return the HTML escaped name of the module
1247 private fun html_name: String do return name.html_escape
1249 # URL to nitdoc page
1250 # class_owner_name.html
1251 private fun url: String do
1252 return "class_
{public_owner}_
{name}.html
"
1255 # html anchor id for the class in a nitdoc page
1257 private fun anchor: String do
1258 if anchor_cache == null then
1259 anchor_cache = "CLASS_{public_owner.name}_
{name}"
1261 return anchor_cache.as(not null)
1263 private var anchor_cache: nullable String
1265 # Return a link (with signature) to the nitdoc class page
1266 # <a href="url
" title="short_comment
">html_name(signature)</a>
1267 private fun html_link(page: NitdocPage) do
1268 if html_link_cache == null then
1269 var res = new Buffer
1270 res.append("<a href
='{url}'")
1271 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1272 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1273 if nclass isa AStdClassdef then
1274 res.append(" title
=\
"{nclass.short_comment}\"")
1277 res.append(">{html_name}{html_short_signature}</a
>")
1278 html_link_cache = res.to_s
1280 page.append(html_link_cache.as(not null))
1282 private var html_link_cache: nullable String
1284 # Return a short link (without signature) to the nitdoc class page
1285 # <a href="url
" title="short_comment
">html_name</a>
1286 private fun html_short_link(page: NitdocPage) do
1287 if html_short_link_cache == null then
1288 var res = new Buffer
1289 res.append("<a href
='{url}'")
1290 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1291 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1292 if nclass isa AStdClassdef then
1293 res.append(" title
=\
"{nclass.short_comment}\"")
1296 res.append(">{html_name}</a
>")
1297 html_short_link_cache = res.to_s
1299 page.append(html_short_link_cache.as(not null))
1301 private var html_short_link_cache: nullable String
1303 # Return a link (with signature) to the class anchor
1304 # <a href="url
" title="short_comment
">html_name</a>
1305 private fun html_link_anchor(page: NitdocPage) do
1306 if html_link_anchor_cache == null then
1307 var res = new Buffer
1308 res.append("<a href
='#{anchor}'")
1309 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1310 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1311 if nclass isa AStdClassdef then
1312 res.append(" title
=\
"{nclass.short_comment}\"")
1315 res.append(">{html_name}{html_short_signature}</a
>")
1316 html_link_anchor_cache = res.to_s
1318 page.append(html_link_anchor_cache.as(not null))
1320 private var html_link_anchor_cache: nullable String
1322 # Return the generic signature of the class with bounds
1323 # [E: <a>MType</a>, F: <a>MType</a>]
1324 private fun html_signature(page: NitdocPage) do
1327 for i in [0..intro.parameter_names.length[ do
1328 page.append("{intro.parameter_names[i]}: ")
1329 intro.bound_mtype.arguments[i].html_link(page)
1330 if i < intro.parameter_names.length - 1 then page.append(", ")
1336 # Return the generic signature of the class without bounds
1338 private fun html_short_signature: String do
1340 return "[{intro.parameter_names.join(", ")}]"
1346 # Return the class namespace decorated with html
1347 # <span>intro_module::html_short_link</span>
1348 private fun html_namespace(page: NitdocPage) do
1349 intro_mmodule.html_namespace(page)
1350 page.append("::<span
>")
1351 html_short_link(page)
1352 page.append("</span
>")
1355 # Return a list item for the mclass
1356 # <li>html_link</li>
1357 private fun html_sidebar_item(page: NitdocModule) do
1358 if page.mmodule.in_nesting.greaters.has(intro.mmodule) then
1359 page.append("<li
class='intro'>")
1360 page.append("<span title
='Introduced'>I
</span
>")
1361 html_link_anchor(page)
1362 else if page.mmodule.has_mclassdef_for(self) then
1363 page.append("<li
class='redef'>")
1364 page.append("<span title
='Redefined'>R
</span
>")
1365 html_link_anchor(page)
1367 page.append("<li
class='inherit'>")
1368 page.append("<span title
='Inherited'>H
</span
>")
1371 page.append("</li
>")
1374 private fun html_full_desc(page: NitdocModule) do
1375 var is_redef = not page.mmodule.in_nesting.greaters.has(intro.mmodule)
1376 var redefs = mpropdefs_in_module(page)
1377 if not is_redef or not redefs.is_empty then
1378 var classes = new Array[String]
1379 classes.add(kind.to_s)
1380 if is_redef then classes.add("redef")
1381 classes.add(visibility.to_s)
1382 page.append("<article
class='{classes.join(" ")}' id
='{anchor}'>")
1383 page.append("<h3
class='signature' data-untyped-signature
='{html_name}{html_short_signature}'>")
1384 page.append("<span
>")
1385 html_short_link(page)
1386 html_signature(page)
1387 page.append("</span
></h3
>")
1390 page.append("</article
>")
1394 private fun html_info(page: NitdocModule) do
1395 page.append("<div
class='info'>")
1396 if visibility < public_visibility then page.append("{visibility.to_s} ")
1397 if not page.mmodule.in_nesting.greaters.has(intro.mmodule) then page.append("redef ")
1398 page.append("{kind} ")
1399 html_namespace(page)
1400 page.append("{html_short_signature}</div
>")
1403 private fun html_comment(page: NitdocPage) do
1404 page.append("<div
class='description'>")
1405 if page isa NitdocModule then
1406 page.mmodule.linearize_mclassdefs(mclassdefs)
1407 # comments for each mclassdef contained in current mmodule
1408 for mclassdef in mclassdefs do
1409 if not mclassdef.is_intro and not page.mmodule.mclassdefs.has(mclassdef) then continue
1410 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(mclassdef) then
1411 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[mclassdef]
1412 if nclass isa AStdClassdef then
1413 if not page.ctx.github_gitdir is null then
1414 var loc = nclass.doc_location.github(page.ctx.github_gitdir.as(not null))
1415 page.append("<textarea
class='baseComment' data-comment-namespace
='{mclassdef.mmodule.full_name}::{name}' data-comment-location
='{loc}'>{nclass.full_comment}</textarea
>")
1417 if nclass.full_comment == "" then
1418 page.append("<p
class='info inheritance'>")
1419 page.append("<span
class=\
"noComment\">no comment
for </span
>")
1421 page.append("<div
class='comment'>{nclass.full_markdown}</div
>")
1422 page.append("<p
class='info inheritance'>")
1424 if mclassdef.is_intro then
1425 page.append("introduction
in ")
1427 page.append("refinement
in ")
1429 mclassdef.mmodule.html_full_namespace(page)
1430 page.append(" {page.show_source(nclass.location)}</p
>")
1435 # comments for intro
1436 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1437 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1438 if nclass isa AStdClassdef then
1439 if not page.ctx.github_gitdir is null then
1440 var loc = nclass.doc_location.github(page.ctx.github_gitdir.as(not null))
1441 page.append("<textarea
class='baseComment' data-comment-namespace
='{intro.mmodule.full_name}::{name}' data-comment-location
='{loc}'>{nclass.full_comment}</textarea
>")
1443 if nclass.full_comment == "" then
1444 page.append("<p
class='info inheritance'>")
1445 page.append("<span
class=\
"noComment\">no comment
for </span
>")
1447 page.append("<div
class='comment'>{nclass.full_markdown}</div
>")
1448 page.append("<p
class='info inheritance'>")
1450 page.append("introduction
in ")
1451 intro.mmodule.html_full_namespace(page)
1452 page.append(" {page.show_source(nclass.location)}</p
>")
1456 page.append("</div
>")
1459 private fun mpropdefs_in_module(page: NitdocModule): Array[MPropDef] do
1460 var res = new Array[MPropDef]
1461 page.mmodule.linearize_mclassdefs(mclassdefs)
1462 for mclassdef in mclassdefs do
1463 if not page.mmodule.mclassdefs.has(mclassdef) then continue
1464 if mclassdef.is_intro then continue
1465 for mpropdef in mclassdef.mpropdefs do
1466 if mpropdef.mproperty.visibility < page.ctx.min_visibility then continue
1467 if mpropdef isa MAttributeDef then continue
1475 redef class MProperty
1476 # Escape name for html output
1477 private fun html_name: String do return name.html_escape
1479 # Return the property namespace decorated with html
1480 # <span>intro_module::intro_class::html_link</span>
1481 private fun html_namespace(page: NitdocPage) do
1482 intro_mclassdef.mclass.html_namespace(page)
1483 page.append(intro_mclassdef.mclass.html_short_signature)
1484 page.append("::<span
>")
1485 intro.html_link(page)
1486 page.append("</span
>")
1491 # Link to the type definition in the nitdoc page
1492 private fun html_link(page: NitdocPage) is abstract
1495 redef class MClassType
1496 redef fun html_link(page) do mclass.html_link(page)
1499 redef class MNullableType
1500 redef fun html_link(page) do
1501 page.append("nullable ")
1502 mtype.html_link(page)
1506 redef class MGenericType
1507 redef fun html_link(page) do
1508 page.append("<a href
='{mclass.url}'>{mclass.html_name}</a
>[")
1509 for i in [0..arguments.length[ do
1510 arguments[i].html_link(page)
1511 if i < arguments.length - 1 then page.append(", ")
1517 redef class MParameterType
1518 redef fun html_link(page) do
1519 var name = mclass.intro.parameter_names[rank]
1520 page.append("<a href
='{mclass.url}#FT_{name}' title
='formal type'>{name}</a
>")
1524 redef class MVirtualType
1525 redef fun html_link(page) do mproperty.intro.html_link(page)
1528 redef class MClassDef
1529 # Return the classdef namespace decorated with html
1530 private fun html_namespace(page: NitdocPage) do
1531 mmodule.html_full_namespace(page)
1532 page.append("::<span
>")
1533 mclass.html_link(page)
1534 page.append("</span
>")
1538 redef class MPropDef
1539 # Return the full qualified name of the mpropdef
1540 # module::classdef::name
1541 private fun full_name: String do
1542 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1545 # URL into the nitdoc page
1546 # class_owner_name.html#anchor
1547 private fun url: String do
1548 if url_cache == null then
1549 url_cache = "{mclassdef.mclass.url}#{anchor}"
1551 return url_cache
.as(not null)
1553 private var url_cache
: nullable String
1555 # html anchor id for the property in a nitdoc class page
1556 # PROP_mclass_propertyname
1557 private fun anchor
: String do
1558 if anchor_cache
== null then
1559 anchor_cache
= "PROP_{mclassdef.mclass.public_owner.name}_{mproperty.name.replace(" ", "_")}"
1561 return anchor_cache
.as(not null)
1563 private var anchor_cache
: nullable String
1565 # Return a link to property into the nitdoc class page
1566 # <a href="url" title="short_comment">html_name</a>
1567 private fun html_link
(page
: NitdocPage) do
1568 if html_link_cache
== null then
1569 var res
= new Buffer
1570 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1571 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1572 res
.append
("<a href=\"{url}\
" title=\"{nprop.short_comment}\
">{mproperty.html_name}</a>")
1574 res
.append
("<a href=\"{url}\
">{mproperty.html_name}</a>")
1576 html_link_cache
= res
.to_s
1578 page
.append
(html_link_cache
.as(not null))
1580 private var html_link_cache
: nullable String
1582 # Return a list item for the mpropdef
1583 # <li>html_link</li>
1584 private fun html_sidebar_item
(page
: NitdocClass) do
1585 if is_intro
and mclassdef
.mclass
== page
.mclass
then
1586 page
.append
("<li class='intro'>")
1587 page
.append
("<span title='Introduced'>I</span>")
1588 else if is_intro
and mclassdef
.mclass
!= page
.mclass
then
1589 page
.append
("<li class='inherit'>")
1590 page
.append
("<span title='Inherited'>H</span>")
1592 page
.append
("<li class='redef'>")
1593 page
.append
("<span title='Redefined'>R</span>")
1596 page
.append
("</li>")
1599 private fun html_full_desc
(page
: NitdocPage, ctx
: MClass) is abstract
1600 private fun html_info
(page
: NitdocPage, ctx
: MClass) is abstract
1602 private fun html_comment
(page
: NitdocPage) do
1603 page
.append
("<div class='description'>")
1604 if not is_intro
then
1605 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(mproperty
.intro
) then
1606 var intro_nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[mproperty
.intro
]
1607 if page
.ctx
.github_gitdir
!= null then
1608 var loc
= intro_nprop
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1609 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>")
1611 if intro_nprop
.full_comment
.is_empty
then
1612 page
.append
("<p class='info inheritance'>")
1613 page
.append
("<span class=\"noComment\
">no comment for </span>")
1615 page
.append
("<div class='comment'>{intro_nprop.full_markdown}</div>")
1616 page
.append
("<p class='info inheritance'>")
1618 page
.append
("introduction in ")
1619 mproperty
.intro
.mclassdef
.html_namespace
(page
)
1620 page
.append
(" {page.show_source(intro_nprop.location)}</p>")
1623 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1624 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1625 if page
.ctx
.github_gitdir
!= null then
1626 var loc
= nprop
.doc_location
.github
(page
.ctx
.github_gitdir
.as(not null))
1627 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>")
1629 if nprop
.full_comment
== "" then
1630 page
.append
("<p class='info inheritance'>")
1631 page
.append
("<span class=\"noComment\
">no comment for </span>")
1633 page
.append
("<div class='comment'>{nprop.full_markdown}</div>")
1634 page
.append
("<p class='info inheritance'>")
1637 page
.append
("introduction in ")
1639 page
.append
("redefinition in ")
1641 mclassdef
.html_namespace
(page
)
1642 page
.append
(" {page.show_source(nprop.location)}</p>")
1644 page
.append
("</div>")
1648 redef class MMethodDef
1649 redef fun html_full_desc
(page
, ctx
) do
1650 var classes
= new Array[String]
1651 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= ctx
1652 if mproperty
.is_init
then
1657 if is_redef
then classes
.add
("redef")
1658 classes
.add
(mproperty
.visibility
.to_s
)
1659 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1660 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1661 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}{msignature.untyped_signature(page)}'>")
1662 page
.append
("<span>{mproperty.html_name}")
1663 msignature
.html_signature
(page
)
1664 page
.append
("</span></h3>")
1666 page
.append
("<h3 class='signature' data-untyped-signature='init{msignature.untyped_signature(page)}'>")
1667 page
.append
("<span>init")
1668 msignature
.html_signature
(page
)
1669 page
.append
("</span></h3>")
1671 html_info
(page
, ctx
)
1673 page
.append
("</article>")
1676 redef fun html_info
(page
, ctx
) do
1677 page
.append
("<div class='info'>")
1678 if mproperty
.visibility
< public_visibility
then page
.append
("{mproperty.visibility.to_s} ")
1679 if mproperty
.intro_mclassdef
.mclass
!= ctx
then page
.append
("redef ")
1680 if mproperty
.is_init
then
1681 page
.append
("init ")
1685 mproperty
.html_namespace
(page
)
1686 page
.append
("</div>")
1690 redef class MVirtualTypeDef
1691 redef fun html_full_desc
(page
, ctx
) do
1692 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= ctx
1693 var classes
= new Array[String]
1695 if is_redef
then classes
.add
("redef")
1696 classes
.add
(mproperty
.visibility
.to_s
)
1697 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1698 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}'><span>{mproperty.html_name}: ")
1699 bound
.html_link
(page
)
1700 page
.append
("</span></h3>")
1701 html_info
(page
, ctx
)
1703 page
.append
("</article>")
1706 redef fun html_info
(page
, ctx
) do
1707 page
.append
("<div class='info'>")
1708 if mproperty
.intro_mclassdef
.mclass
!= ctx
then page
.append
("redef ")
1709 page
.append
("type ")
1710 mproperty
.html_namespace
(page
)
1711 page
.append
("</div>")
1715 redef class MSignature
1716 private fun html_signature
(page
: NitdocPage) do
1717 if not mparameters
.is_empty
then
1719 for i
in [0..mparameters
.length
[ do
1720 mparameters
[i
].html_link
(page
)
1721 if i
< mparameters
.length
- 1 then page
.append
(", ")
1725 if return_mtype
!= null then
1727 return_mtype
.html_link
(page
)
1731 private fun untyped_signature
(page
: NitdocPage): String do
1732 var res
= new Buffer
1733 if not mparameters
.is_empty
then
1735 for i
in [0..mparameters
.length
[ do
1736 res
.append
(mparameters
[i
].name
)
1737 if i
< mparameters
.length
- 1 then res
.append
(", ")
1745 redef class MParameter
1746 private fun html_link
(page
: NitdocPage) do
1747 page
.append
("{name}: ")
1748 mtype
.html_link
(page
)
1749 if is_vararg
then page
.append
("...")
1757 redef class Location
1758 fun github
(gitdir
: String): String do
1759 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
1760 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
1761 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
1762 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
1767 private fun short_comment
: String do
1768 return n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1771 private fun full_comment
: String do
1772 var res
= new Buffer
1773 for t
in n_comment
do
1775 text
= text
.substring_from
(1)
1776 if text
.first
== ' ' then text
= text
.substring_from
(1)
1777 res
.append
(text
.html_escape
)
1780 return str
.substring
(0, str
.length
- 1)
1785 private fun short_comment
: String do
1786 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1787 return n_moduledecl
.n_doc
.short_comment
1792 private fun full_comment
: String do
1793 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1794 return n_moduledecl
.n_doc
.full_comment
1799 private fun full_markdown
: String do
1800 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1801 return n_moduledecl
.n_doc
.full_markdown
.html
1806 private fun doc_location
: Location do
1807 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1808 return n_moduledecl
.n_doc
.location
1814 redef class AStdClassdef
1815 private fun short_comment
: String do
1816 if n_doc
!= null then return n_doc
.short_comment
1820 private fun full_comment
: String do
1821 if n_doc
!= null then return n_doc
.full_comment
1825 private fun full_markdown
: String do
1826 if n_doc
!= null then return n_doc
.full_markdown
.html
1830 private fun doc_location
: Location do
1831 if n_doc
!= null then return n_doc
.location
1836 redef class APropdef
1837 private fun short_comment
: String do
1838 if n_doc
!= null then return n_doc
.short_comment
1842 private fun full_comment
: String do
1843 if n_doc
!= null then return n_doc
.full_comment
1847 private fun full_markdown
: String do
1848 if n_doc
!= null then return n_doc
.full_markdown
.html
1852 private fun doc_location
: Location do
1853 if n_doc
!= null then return n_doc
.location
1859 var nitdoc
= new NitdocContext
1860 nitdoc
.generate_nitdoc