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 opt_dir
= new OptionString("Directory where doc is generated", "-d", "--dir")
39 private var opt_source
= new OptionString("What link for source (%f for filename, %l for first line, %L for last line)", "--source")
40 private var opt_sharedir
= new OptionString("Directory containing the nitdoc files", "--sharedir")
41 private var opt_nodot
= new OptionBool("Do not generate graphes with graphiviz", "--no-dot")
42 private var opt_private
: OptionBool = new OptionBool("Generate the private API", "--private")
44 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")
45 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")
46 private var opt_custom_overview_text
: OptionString = new OptionString("Text displayed as introduction of Overview page before the modules list", "--custom-overview-text")
47 private var opt_custom_footer_text
: OptionString = new OptionString("Text displayed as footer of all pages", "--custom-footer-text")
49 private var opt_github_base
: OptionString = new OptionString("The branch (or git ref) edited commits will be pulled into (ex: octocat:master)", "--github-base")
50 private var opt_github_head
: OptionString = new OptionString("The reference branch name used to create pull requests (ex: master)", "--github-head")
53 toolcontext
.option_context
.add_option
(opt_dir
)
54 toolcontext
.option_context
.add_option
(opt_source
)
55 toolcontext
.option_context
.add_option
(opt_sharedir
)
56 toolcontext
.option_context
.add_option
(opt_nodot
)
57 toolcontext
.option_context
.add_option
(opt_private
)
58 toolcontext
.option_context
.add_option
(opt_custom_title
)
59 toolcontext
.option_context
.add_option
(opt_custom_footer_text
)
60 toolcontext
.option_context
.add_option
(opt_custom_overview_text
)
61 toolcontext
.option_context
.add_option
(opt_custom_menu_items
)
62 toolcontext
.option_context
.add_option
(opt_github_base
)
63 toolcontext
.option_context
.add_option
(opt_github_head
)
64 toolcontext
.process_options
65 self.arguments
= toolcontext
.option_context
.rest
67 if arguments
.length
< 1 then
68 print
"usage: nitdoc [options] file..."
69 toolcontext
.option_context
.usage
74 mbuilder
= new ModelBuilder(model
, toolcontext
)
75 # Here we load an process all modules passed on the command line
76 var mmodules
= mbuilder
.parse
(arguments
)
77 if mmodules
.is_empty
then return
80 if mmodules
.length
== 1 then
81 mainmodule
= mmodules
.first
83 # We need a main module, so we build it by importing all modules
84 mainmodule
= new MModule(model
, null, "<main>", new Location(null, 0, 0, 0, 0))
85 mainmodule
.set_imported_mmodules
(mmodules
)
87 self.class_hierarchy
= mainmodule
.flatten_mclass_hierarchy
91 private fun process_options
do
92 if not opt_dir
.value
is null then
93 output_dir
= opt_dir
.value
97 if not opt_sharedir
.value
is null then
98 share_dir
= opt_sharedir
.value
100 var dir
= "NIT_DIR".environ
102 dir
= "{sys.program_name.dirname}/../share/ni_nitdoc"
104 dir
= "{dir}/share/ni_nitdoc"
107 if share_dir
is null then
108 print
"Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
111 dir
= "{share_dir.to_s}/scripts/js-facilities.js"
112 if share_dir
is null then
113 print
"Error: Invalid nitdoc share files. Check --sharedir or envvar NIT_DIR"
117 if opt_private
.value
then
118 min_visibility
= none_visibility
120 min_visibility
= protected_visibility
123 source
= opt_source
.value
126 fun generate_nitdoc
do
127 # Create destination dir if it's necessary
128 if not output_dir
.file_exists
then output_dir
.mkdir
129 sys
.system
("cp -r {share_dir.to_s}/* {output_dir.to_s}/")
131 if not opt_nodot
.value
then self.dot_dir
= output_dir
.to_s
139 private fun overview
do
140 var overviewpage
= new NitdocOverview(self, dot_dir
)
141 overviewpage
.save
("{output_dir.to_s}/index.html")
144 private fun search
do
145 var searchpage
= new NitdocSearch(self)
146 searchpage
.save
("{output_dir.to_s}/search.html")
149 private fun modules
do
150 for mmodule
in model
.mmodules
do
151 if mmodule
.name
== "<main>" then continue
152 var modulepage
= new NitdocModule(mmodule
, self, dot_dir
)
153 modulepage
.save
("{output_dir.to_s}/{mmodule.url}")
157 private fun classes
do
158 for mclass
in mbuilder
.model
.mclasses
do
159 var classpage
= new NitdocClass(mclass
, self, dot_dir
, source
)
160 classpage
.save
("{output_dir.to_s}/{mclass.url}")
164 private fun quicksearch_list
do
165 var file
= new OFStream.open
("{output_dir.to_s}/quicksearch-list.js")
166 file
.write
("var nitdocQuickSearchRawList = \{ ")
167 for mmodule
in model
.mmodules
do
168 file
.write
("\"{mmodule.name}\
": [")
169 file
.write
("\{txt: \"{mmodule.full_name}\", url
:\
"{mmodule.url}\" \
},")
172 for mclass in model.mclasses do
173 if mclass.visibility < min_visibility then continue
174 file.write("\
"{mclass.name}\": [")
175 file.write("\
{txt: \"{mclass.full_name}\
", url:\"{mclass.url}\
" \},")
178 var name2mprops
= new HashMap[String, Set[MPropDef]]
179 for mproperty
in model
.mproperties
do
180 if mproperty
.visibility
< min_visibility
then continue
181 if mproperty
isa MAttribute then continue
182 if not name2mprops
.has_key
(mproperty
.name
) then name2mprops
[mproperty
.name
] = new HashSet[MPropDef]
183 name2mprops
[mproperty
.name
].add_all
(mproperty
.mpropdefs
)
185 for mproperty
, mpropdefs
in name2mprops
do
186 file
.write
("\"{mproperty}\
": [")
187 for mpropdef
in mpropdefs
do
188 file
.write
("\{txt: \"{mpropdef.full_name}\", url
:\
"{mpropdef.url}\" \
},")
199 abstract class NitdocPage
201 var dot_dir: nullable String
202 var source: nullable String
203 var ctx: NitdocContext
205 init(ctx: NitdocContext) do
209 protected fun head do
210 append("<meta charset
='utf-8'/>")
211 append("<script
type='text/javascript' src
='scripts/jquery-1.7.1.min.js'></script
>")
212 append("<script
type='text/javascript' src
='scripts/ZeroClipboard.min.js'></script
>")
213 append("<script
type='text/javascript' src
='scripts/Nitdoc.UI.js'></script
>")
214 append("<script
type='text/javascript' src
='scripts/Markdown.Converter.js'></script
>")
215 append("<script
type='text/javascript' src
='scripts/base64.js'></script
>")
216 append("<script
type='text/javascript' src
='scripts/Nitdoc.GitHub.js'></script
>")
217 append("<script
type='text/javascript' src
='quicksearch-list.js'></script
>")
218 append("<script
type='text/javascript' src
='scripts/Nitdoc.QuickSearch.js'></script
>")
219 append("<link rel
='stylesheet' href
='styles/main.css' type='text/css' media
='screen'/>")
220 append("<link rel
='stylesheet' href
='styles/Nitdoc.UI.css' type='text/css' media
='screen'/>")
221 append("<link rel
='stylesheet' href
='styles/Nitdoc.QuickSearch.css' type='text/css' media
='screen'/>")
222 append("<link rel
='stylesheet' href
='styles/Nitdoc.GitHub.css' type='text/css' media
='screen'/>")
224 if ctx.opt_custom_title.value != null then
225 title = " | {ctx.opt_custom_title.value.to_s}"
227 append("<title
>{self.title}{title}</title
>")
230 protected fun menu do
231 if ctx.opt_custom_menu_items.value != null then
232 append(ctx.opt_custom_menu_items.value.to_s)
236 protected fun title: String is abstract
238 protected fun header do
240 append("<nav
class='main'>")
248 protected fun content is abstract
250 protected fun footer do
251 if ctx.opt_custom_footer_text.value != null then
252 append("<footer
>{ctx.opt_custom_footer_text.value.to_s}</footer
>")
256 # Generate a clickable graphviz image using a dot content
257 protected fun generate_dot(dot: String, name: String, alt: String) do
258 var output_dir = dot_dir
259 if output_dir == null then return
260 var file = new OFStream.open("{output_dir}/{name}.dot
")
263 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
; \
}")
264 append("<article
class='graph'>")
265 append("<img src
='{name}.png' usemap
='#{name}' style
='margin:auto' alt
='{alt}'/>")
267 var fmap = new IFStream.open("{output_dir}/{name}.map
")
268 append(fmap.read_all)
272 # Add a (source) link for a given location
273 protected fun show_source(l: Location): String
275 if source == null then
276 return "({l.file.filename.simplify_path})"
278 # THIS IS JUST UGLY ! (but there is no replace yet)
279 var x = source.split_with("%f
")
280 source = x.join(l.file.filename.simplify_path)
281 x = source.split_with("%l
")
282 source = x.join(l.line_start.to_s)
283 x = source.split_with("%L
")
284 source = x.join(l.line_end.to_s)
285 return " (<a target
='_blank' title
='Show source' href
=\
"{source.to_s}\">source
</a
>)"
289 # Render the page as a html string
290 protected fun render do
291 append("<!DOCTYPE html
>")
296 if not ctx.opt_github_base.value == null and not ctx.opt_github_head.value == null then
297 append(" data-github-base
='{ctx.opt_github_base.value.as(not null)}'")
298 append(" data-github-head
='{ctx.opt_github_head.value.as(not null)}'")
303 if ctx.opt_custom_footer_text.value != null then footed = "footed
"
304 append("<div
class='page {footed}'>")
311 # Append a string to the page
312 fun append(s: String) do out.write(s)
314 # Save html page in the specified file
315 fun save(file: String) do
316 self.out = new OFStream.open(file)
320 private var out: nullable OFStream
326 private var mbuilder: ModelBuilder
327 private var mmodules = new Array[MModule]
329 init(ctx: NitdocContext, dot_dir: nullable String) do
331 self.mbuilder = ctx.mbuilder
332 self.dot_dir = dot_dir
334 var mmodules = new HashSet[MModule]
335 for mmodule in mbuilder.model.mmodules do
336 if mmodule.name == "<main
>" then continue
337 var owner = mmodule.public_owner
338 if owner != null then
341 mmodules.add(mmodule)
345 var sorter = new MModuleNameSorter
346 self.mmodules.add_all(mmodules)
347 sorter.sort(self.mmodules)
350 redef fun title do return "Overview"
354 append("<li
class='current'>Overview</li
>")
355 append("<li
><a href
='search.html'>Search</a
></li
>")
359 append("<div
class='content fullpage'>")
360 var title = "Overview"
361 if ctx.opt_custom_title.value != null then
362 title = ctx.opt_custom_title.value.to_s
364 append("<h1
>{title}</h1
>")
366 if ctx.opt_custom_overview_text.value != null then
367 text = ctx.opt_custom_overview_text.value.to_s
369 append("<article
class='overview'>{text}</article
>")
370 append("<article
class='overview'>")
372 append("<h2
>Modules</h2
>")
374 for mmodule in mmodules do
375 if mbuilder.mmodule2nmodule.has_key(mmodule) then
376 var amodule = mbuilder.mmodule2nmodule[mmodule]
378 mmodule.html_link(self)
379 append(" 
;{amodule.short_comment}</li
>")
389 private fun process_generate_dot do
390 # build poset with public owners
391 var poset = new POSet[MModule]
392 for mmodule in mmodules do
393 poset.add_node(mmodule)
394 for omodule in mmodules do
395 if mmodule == omodule then continue
396 if mmodule.in_importation < omodule then
397 poset.add_node(omodule)
398 poset.add_edge(mmodule, omodule)
404 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
")
405 for mmodule in poset do
406 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
407 for omodule in poset[mmodule].direct_greaters do
408 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
412 generate_dot(op.to_s, "dep
", "Modules hierarchy
")
420 init(ctx: NitdocContext) do
425 redef fun title do return "Search"
429 append("<li
><a href
='index.html'>Overview</a
></li
>")
430 append("<li
class='current'>Search</li
>")
434 append("<div
class='content fullpage'>")
435 append("<h1
>{title}</h1
>")
442 # Add to content modules column
443 private fun module_column do
444 var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
445 var sorter = new MModuleNameSorter
447 append("<article
class='modules filterable'>")
448 append("<h2
>Modules</h2
>")
450 for mmodule in sorted do
452 mmodule.html_link(self)
459 # Add to content classes modules
460 private fun classes_column do
461 var sorted = ctx.mbuilder.model.mclasses
462 var sorter = new MClassNameSorter
464 append("<article
class='modules filterable'>")
465 append("<h2
>Classes</h2
>")
467 for mclass in sorted do
468 if mclass.visibility < ctx.min_visibility then continue
470 mclass.html_link(self)
477 # Insert the properties column of fullindex page
478 private fun properties_column do
479 var sorted = ctx.mbuilder.model.mproperties
480 var sorter = new MPropertyNameSorter
482 append("<article
class='modules filterable'>")
483 append("<h2
>Properties</h2
>")
485 for mproperty in sorted do
486 if mproperty.visibility < ctx.min_visibility then continue
487 if mproperty isa MAttribute then continue
489 mproperty.intro.html_link(self)
491 mproperty.intro.mclassdef.mclass.html_link(self)
504 private var mmodule: MModule
505 private var mbuilder: ModelBuilder
506 private var local_mclasses = new HashSet[MClass]
507 private var intro_mclasses = new HashSet[MClass]
508 private var redef_mclasses = new HashSet[MClass]
510 init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
512 self.mmodule = mmodule
513 self.mbuilder = ctx.mbuilder
514 self.dot_dir = dot_dir
516 for m in mmodule.in_nesting.greaters do
517 for mclassdef in m.mclassdefs do
518 if mclassdef.mclass.visibility < ctx.min_visibility then continue
519 if mclassdef.is_intro then
520 intro_mclasses.add(mclassdef.mclass)
522 if mclassdef.mclass.mpropdefs_in_module(self).is_empty then continue
523 redef_mclasses.add(mclassdef.mclass)
525 local_mclasses.add(mclassdef.mclass)
531 if mbuilder.mmodule2nmodule.has_key(mmodule) and not mbuilder.mmodule2nmodule[mmodule].short_comment.is_empty then
532 var nmodule = mbuilder.mmodule2nmodule[mmodule]
533 return "{mmodule.html_name} module | {nmodule.short_comment}"
535 return "{mmodule.html_name} module"
541 append("<li
><a href
='index.html'>Overview</a
></li
>")
542 append("<li
class='current'>{mmodule.html_name}</li
>")
543 append("<li
><a href
='search.html'>Search</a
></li
>")
547 append("<div
class='sidebar'>")
551 append("<div
class='content'>")
556 private fun classes_column do
557 var sorter = new MClassNameSorter
558 var sorted = new Array[MClass]
559 sorted.add_all(intro_mclasses)
560 sorted.add_all(redef_mclasses)
562 if not sorted.is_empty then
563 append("<nav
class='properties filterable'>")
564 append("<h3
>Classes</h3
>")
565 append("<h4
>Classes</h4
>")
567 for mclass in sorted do mclass.html_sidebar_item(self)
573 private fun importation_column do
575 append("<h3
>Module Hierarchy</h3
>")
576 var dependencies = new Array[MModule]
577 for dep in mmodule.in_importation.greaters do
578 if dep == mmodule or dep.direct_owner == mmodule or dep.public_owner == mmodule then continue
579 dependencies.add(dep)
581 if mmodule.in_nesting.direct_greaters.length > 0 then
582 append("<h4
>Nested Modules</h4
>")
583 display_module_list(mmodule.in_nesting.direct_greaters.to_a)
585 if dependencies.length > 0 then
586 append("<h4
>All dependencies
</h4
>")
587 display_module_list(dependencies)
589 var clients = new Array[MModule]
590 for dep in mmodule.in_importation.smallers do
591 if dep.name == "<main
>" then continue
592 if dep == mmodule then continue
595 if clients.length > 0 then
596 append("<h4
>All clients
</h4
>")
597 display_module_list(clients)
602 private fun display_module_list(list: Array[MModule]) do
604 var sorter = new MModuleNameSorter
614 private fun module_doc do
616 append("<h1
>{mmodule.html_name}</h1
>")
617 append("<div
class='subtitle info'>")
618 mmodule.html_signature(self)
621 mmodule.html_comment(self)
624 var class_sorter = new MClassNameSorter
626 if not intro_mclasses.is_empty then
627 var sorted = new Array[MClass]
628 sorted.add_all(intro_mclasses)
629 class_sorter.sort(sorted)
630 append("<section
class='classes'>")
631 append("<h2
class='section-header'>Introduced classes
</h2
>")
632 for mclass in sorted do mclass.html_full_desc(self)
636 var redefs = new Array[MClass]
637 for mclass in redef_mclasses do if not intro_mclasses.has(mclass) then redefs.add(mclass)
638 class_sorter.sort(redefs)
639 if not redefs.is_empty then
640 append("<section
class='classes'>")
641 append("<h2
class='section-header'>Refined classes
</h2
>")
642 for mclass in redefs do mclass.html_full_desc(self)
647 private fun process_generate_dot do
648 # build poset with public owners
649 var poset = new POSet[MModule]
650 for mmodule in self.mmodule.in_importation.poset do
651 if mmodule.name == "<main
>" then continue
652 #if mmodule.public_owner != null then continue
653 if not mmodule.in_importation < self.mmodule and not self.mmodule.in_importation < mmodule and mmodule != self.mmodule then continue
654 poset.add_node(mmodule)
655 for omodule in mmodule.in_importation.poset do
656 if mmodule == omodule then continue
657 if omodule.name == "<main
>" then continue
658 if not omodule.in_importation < self.mmodule and not self.mmodule.in_importation < omodule then continue
659 if omodule.in_importation < mmodule then
660 poset.add_node(omodule)
661 poset.add_edge(omodule, mmodule)
663 if mmodule.in_importation < omodule then
664 poset.add_node(omodule)
665 poset.add_edge(mmodule, omodule)
667 #if omodule.public_owner != null then continue
668 #if mmodule.in_importation < omodule then
669 #poset.add_node(omodule)
670 #poset.add_edge(mmodule, omodule)
676 var name = "dep_
{mmodule.name}"
677 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
")
678 for mmodule in poset do
679 if mmodule == self.mmodule then
680 op.append("\
"{mmodule.name}\"[shape
=box
,margin
=0.03];\n
")
682 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
684 for omodule in poset[mmodule].direct_greaters do
685 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
689 generate_dot(op.to_s, name, "Dependency graph
for module {mmodule.name}")
697 private var mclass: MClass
698 private var vtypes = new HashSet[MVirtualTypeDef]
699 private var consts = new HashSet[MMethodDef]
700 private var meths = new HashSet[MMethodDef]
701 private var inherited = new HashSet[MPropDef]
703 init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
706 self.dot_dir = dot_dir
709 var locals = new HashSet[MProperty]
710 for mclassdef in mclass.mclassdefs do
711 for mpropdef in mclassdef.mpropdefs do
712 if mpropdef.mproperty.visibility < ctx.min_visibility then continue
713 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
714 if mpropdef isa MMethodDef then
715 if mpropdef.mproperty.is_init then
721 locals.add(mpropdef.mproperty)
724 # get inherited properties
725 for pclass in mclass.in_hierarchy(ctx.mainmodule).greaters do
726 if pclass == mclass then continue
727 for pclassdef in pclass.mclassdefs do
728 for mprop in pclassdef.intro_mproperties do
729 var mpropdef = mprop.intro
730 if mprop.visibility < ctx.min_visibility then continue # skip if not correct visibiility
731 if locals.has(mprop) then continue # skip if local
732 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
733 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
734 if mpropdef isa MMethodDef then
735 if mpropdef.mproperty.is_init then
741 inherited.add(mpropdef)
748 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
749 if nclass isa AStdClassdef then
750 return "{mclass.html_name} class | {nclass.short_comment}"
752 return "{mclass.html_name} class"
758 append("<li
><a href
='index.html'>Overview</a
></li
>")
759 var public_owner = mclass.public_owner
760 if public_owner is null then
762 mclass.intro_mmodule.html_link(self)
766 public_owner.html_link(self)
769 append("<li
class='current'>{mclass.html_name}</li
>")
770 append("<li
><a href
='search.html'>Search</a
></li
>")
774 append("<div
class='sidebar'>")
778 append("<div
class='content'>")
783 private fun properties_column do
784 var sorter = new MPropDefNameSorter
785 append("<nav
class='properties filterable'>")
786 append("<h3
>Properties</h3
>")
788 if vtypes.length > 0 then
789 var vts = new Array[MVirtualTypeDef]
792 append("<h4
>Virtual Types</h4
>")
795 mprop.html_sidebar_item(self)
800 if consts.length > 0 then
801 var cts = new Array[MMethodDef]
804 append("<h4
>Constructors</h4
>")
807 if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
808 mprop.html_sidebar_item(self)
813 if meths.length > 0 then
814 var mts = new Array[MMethodDef]
817 append("<h4
>Methods</h4
>")
820 mprop.html_sidebar_item(self)
827 private fun inheritance_column do
828 var sorted = new Array[MClass]
829 var sorterp = new MClassNameSorter
831 append("<h3
>Inheritance</h3
>")
832 var greaters = mclass.in_hierarchy(ctx.mainmodule).greaters.to_a
833 if greaters.length > 1 then
834 ctx.mainmodule.linearize_mclasses(greaters)
835 append("<h4
>Superclasses</h4
>")
837 for sup in greaters do
838 if sup == mclass then continue
845 var smallers = mclass.in_hierarchy(ctx.mainmodule).smallers.to_a
846 var direct_smallers = mclass.in_hierarchy(ctx.mainmodule).direct_smallers.to_a
847 if smallers.length <= 1 then
848 append("<h4
>No Known Subclasses</h4
>")
849 else if smallers.length <= 100 then
850 ctx.mainmodule.linearize_mclasses(smallers)
851 append("<h4
>Subclasses</h4
>")
853 for sub in smallers do
854 if sub == mclass then continue
860 else if direct_smallers.length <= 100 then
861 ctx.mainmodule.linearize_mclasses(direct_smallers)
862 append("<h4
>Direct Subclasses Only</h4
>")
864 for sub in direct_smallers do
865 if sub == mclass then continue
872 append("<h4
>Too much
Subclasses to list
</h4
>")
877 private fun class_doc do
879 append("<h1
>{mclass.html_name}{mclass.html_short_signature}</h1
>")
880 append("<div
class='subtitle info'>")
881 if mclass.visibility < public_visibility then append("{mclass.visibility.to_s} ")
882 append("{mclass.kind.to_s} ")
883 mclass.html_namespace(self)
884 append("{mclass.html_short_signature}</div
>")
886 mclass.html_comment(self)
889 var concern2meths = new ArrayMap[MModule, Array[MMethodDef]]
890 var sorted_meths = new Array[MMethodDef]
891 var sorted = new Array[MModule]
892 sorted_meths.add_all(meths)
893 ctx.mainmodule.linearize_mpropdefs(sorted_meths)
895 if inherited.has(meth) then continue
896 var mmodule = meth.mclassdef.mmodule
897 if not concern2meths.has_key(mmodule) then
899 concern2meths[mmodule] = new Array[MMethodDef]
901 concern2meths[mmodule].add(meth)
903 var sections = new ArrayMap[MModule, Array[MModule]]
904 for mmodule in concern2meths.keys do
905 var owner = mmodule.public_owner
906 if owner == null then owner = mmodule
907 if not sections.has_key(owner) then sections[owner] = new Array[MModule]
908 if owner != mmodule then sections[owner].add(mmodule)
910 append("<section
class='concerns'>")
911 append("<h2
class='section-header'>Concerns</h2
>")
913 for owner, mmodules in sections do
914 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
916 if nowner.short_comment.is_empty then
917 append("<a href
=\
"#{owner.anchor}\">{owner.html_name}</a
>")
919 append("<a href
=\
"#{owner.anchor}\">{owner.html_name}</a
>: {nowner.short_comment}")
921 if not mmodules.is_empty then
923 for mmodule in mmodules do
924 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
925 if nmodule.short_comment.is_empty then
926 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.html_name}</a
></li
>")
928 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.html_name}</a
>: {nmodule.short_comment}</li
>")
938 var prop_sorter = new MPropDefNameSorter
939 var lmmodule = new List[MModule]
940 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
941 # virtual and formal types
942 var local_vtypes = new Array[MVirtualTypeDef]
943 for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
944 if local_vtypes.length > 0 or mclass.arity > 0 then
945 append("<section
class='types'>")
946 append("<h2
>Formal and Virtual Types</h2
>")
948 if mclass.arity > 0 and nclass isa AStdClassdef then
949 for ft, bound in mclass.parameter_types do
950 append("<article id
='FT_{ft}'>")
951 append("<h3
class='signature' data-untyped-signature
='{ft.to_s}'><span
>{ft}: ")
952 bound.html_link(self)
953 append("</span
></h3
>")
954 append("<div
class=\
"info\">formal generic
type</div
>")
959 prop_sorter.sort(local_vtypes)
960 for prop in local_vtypes do prop.html_full_desc(self, self.mclass)
964 var local_consts = new Array[MMethodDef]
965 for const in consts do if not inherited.has(const) then local_consts.add(const)
966 prop_sorter.sort(local_consts)
967 if local_consts.length > 0 then
968 append("<section
class='constructors'>")
969 append("<h2
class='section-header'>Constructors</h2
>")
970 for prop in local_consts do prop.html_full_desc(self, self.mclass)
974 if not concern2meths.is_empty then
975 append("<section
class='methods'>")
976 append("<h2
class='section-header'>Methods</h2
>")
977 for owner, mmodules in sections do
978 append("<a id
=\
"{owner.anchor}\"></a
>")
979 if owner != mclass.intro_mmodule and owner != mclass.public_owner then
980 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
981 append("<h3
class=\
"concern-toplevel\">Methods refined
in ")
982 owner.html_link(self)
984 append("<p
class=\
"concern-doc\">")
985 owner.html_link(self)
986 if not nowner.short_comment.is_empty then
987 append(": {nowner.short_comment}")
991 if concern2meths.has_key(owner) then
992 var mmethods = concern2meths[owner]
993 prop_sorter.sort(mmethods)
994 for prop in mmethods do prop.html_full_desc(self, self.mclass)
996 for mmodule in mmodules do
997 append("<a id
=\
"{mmodule.anchor}\"></a
>")
998 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
999 if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
1000 append("<p
class=\
"concern-doc\">")
1001 mmodule.html_link(self)
1002 if not nmodule.short_comment.is_empty then
1003 append(": {nmodule.short_comment}")
1007 var mmethods = concern2meths[mmodule]
1008 prop_sorter.sort(mmethods)
1009 for prop in mmethods do prop.html_full_desc(self, self.mclass)
1012 append("</section
>")
1014 # inherited properties
1015 if inherited.length > 0 then
1016 var sorted_inherited = new Array[MPropDef]
1017 sorted_inherited.add_all(inherited)
1018 ctx.mainmodule.linearize_mpropdefs(sorted_inherited)
1019 var classes = new ArrayMap[MClass, Array[MPropDef]]
1020 for mmethod in sorted_inherited.reversed do
1021 var mclass = mmethod.mclassdef.mclass
1022 if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
1023 classes[mclass].add(mmethod)
1025 append("<section
class='inherited'>")
1026 append("<h2
class='section-header'>Inherited Properties</h2
>")
1027 for c, mmethods in classes do
1028 prop_sorter.sort(mmethods)
1029 append("<p
>Defined in ")
1032 for i in [0..mmethods.length[ do
1033 var mmethod = mmethods[i]
1034 mmethod.html_link(self)
1035 if i <= mmethods.length - 1 then append(", ")
1039 append("</section
>")
1043 private fun process_generate_dot do
1044 var pe = ctx.class_hierarchy[mclass]
1045 var cla = new HashSet[MClass]
1046 var sm = new HashSet[MClass]
1047 var sm2 = new HashSet[MClass]
1049 while cla.length + sm.length < 10 and sm.length > 0 do
1053 sm2.add_all(pe.poset[x].direct_smallers)
1059 cla.add_all(pe.greaters)
1062 var name = "dep_
{mclass.name}"
1063 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
")
1066 op.append("\
"{c.name}\"[shape
=box
,margin
=0.03];\n
")
1068 op.append("\
"{c.name}\"[URL=\
"{c.url}\"];\n
")
1070 for c2 in pe.poset[c].direct_greaters do
1071 if not cla.has(c2) then continue
1072 op.append("\
"{c.name}\"->\
"{c2.name}\";\n
")
1074 if not pe.poset[c].direct_smallers.is_empty then
1076 for c2 in pe.poset[c].direct_smallers do
1077 if cla.has(c2) then others = false
1080 op.append("\
"{c.name}...\"[label=\
"\"];\n
")
1081 op.append("\
"{c.name}...\"->\
"{c.name}\"[style
=dotted
];\n
")
1086 generate_dot(op.to_s, name, "Dependency graph
for class {mclass.name}")
1095 # Return the HTML escaped name of the module
1096 private fun html_name: String do return name.html_escape
1098 # URL to nitdoc page
1099 # module_owner_name.html
1100 private fun url: String do
1101 if url_cache == null then
1102 var res = new Buffer
1103 res.append("module_
")
1104 var mowner = public_owner
1105 if mowner != null then
1106 res.append("{public_owner.name}_
")
1108 res.append("{self.name}.html
")
1109 url_cache = res.to_s
1111 return url_cache.as(not null)
1113 private var url_cache: nullable String
1115 # html anchor id for the module in a nitdoc page
1117 private fun anchor: String do
1118 if anchor_cache == null then
1119 var res = new Buffer
1121 var mowner = public_owner
1122 if mowner != null then
1123 res.append("{public_owner.name}_
")
1125 res.append(self.name)
1126 anchor_cache = res.to_s
1128 return anchor_cache.as(not null)
1130 private var anchor_cache: nullable String
1132 # Return a link (html a tag) to the nitdoc module page
1133 # <a href="url
" title="short_comment
">html_name</a>
1134 private fun html_link(page: NitdocPage) do
1135 if html_link_cache == null then
1136 var res = new Buffer
1137 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1138 res.append("<a href
='{url}' title
='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{html_name}</a
>")
1140 res.append("<a href
='{url}'>{html_name}</a
>")
1142 html_link_cache = res.to_s
1144 page.append(html_link_cache.as(not null))
1146 private var html_link_cache: nullable String
1148 # Return the module signature decorated with html
1149 # <span>module html_full_namespace</span>
1150 private fun html_signature(page: NitdocPage) do
1151 page.append("<span
>module ")
1152 html_full_namespace(page)
1153 page.append("</span
>")
1156 # Return the module full namespace decorated with html
1157 # <span>public_owner.html_namespace::html_link</span>
1158 private fun html_full_namespace(page: NitdocPage) do
1159 page.append("<span
>")
1160 var mowner = public_owner
1161 if mowner != null then
1162 public_owner.html_namespace(page)
1166 page.append("</span
>")
1169 # Return the module full namespace decorated with html
1170 # <span>public_owner.html_namespace</span>
1171 private fun html_namespace(page: NitdocPage) do
1172 page.append("<span
>")
1173 var mowner = public_owner
1174 if mowner != null then
1175 public_owner.html_namespace(page)
1179 page.append("</span
>")
1182 # Return the full comment of the module decorated with html
1183 private fun html_comment(page: NitdocPage) do
1184 page.append("<div
class='description'>")
1185 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1186 var nmodule = page.ctx.mbuilder.mmodule2nmodule[self]
1187 page.append("<textarea
class='baseComment' data-comment-namespace
='{full_name}' data-comment-location
='{nmodule.doc_location.to_s}'>{nmodule.full_comment}</textarea
>")
1188 if nmodule.full_comment == "" then
1189 page.append("<p
class='info inheritance'>")
1190 page.append("<span
class=\
"noComment\">no comment
for </span
>")
1192 page.append("<div
class='comment'>{nmodule.full_markdown}</div
>")
1193 page.append("<p
class='info inheritance'>")
1195 page.append("definition
in ")
1196 self.html_full_namespace(page)
1197 page.append(" {page.show_source(nmodule.location)}</p
>")
1199 page.append("</div
>")
1202 private fun has_mclassdef_for(mclass: MClass): Bool do
1203 for mmodule in self.in_nesting.greaters do
1204 for mclassdef in mmodule.mclassdefs do
1205 if mclassdef.mclass == mclass then return true
1211 private fun has_mclassdef(mclassdef: MClassDef): Bool do
1212 for mmodule in self.in_nesting.greaters do
1213 for oclassdef in mmodule.mclassdefs do
1214 if mclassdef == oclassdef then return true
1222 # Return the HTML escaped name of the module
1223 private fun html_name: String do return name.html_escape
1225 # URL to nitdoc page
1226 # class_owner_name.html
1227 private fun url: String do
1228 return "class_
{public_owner}_
{name}.html
"
1231 # html anchor id for the class in a nitdoc page
1233 private fun anchor: String do
1234 if anchor_cache == null then
1235 anchor_cache = "CLASS_{public_owner.name}_
{name}"
1237 return anchor_cache.as(not null)
1239 private var anchor_cache: nullable String
1241 # Return a link (with signature) to the nitdoc class page
1242 # <a href="url
" title="short_comment
">html_name(signature)</a>
1243 private fun html_link(page: NitdocPage) do
1244 if html_link_cache == null then
1245 var res = new Buffer
1246 res.append("<a href
='{url}'")
1247 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1248 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1249 if nclass isa AStdClassdef then
1250 res.append(" title
=\
"{nclass.short_comment}\"")
1253 res.append(">{html_name}{html_short_signature}</a
>")
1254 html_link_cache = res.to_s
1256 page.append(html_link_cache.as(not null))
1258 private var html_link_cache: nullable String
1260 # Return a short link (without signature) to the nitdoc class page
1261 # <a href="url
" title="short_comment
">html_name</a>
1262 private fun html_short_link(page: NitdocPage) do
1263 if html_short_link_cache == null then
1264 var res = new Buffer
1265 res.append("<a href
='{url}'")
1266 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1267 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1268 if nclass isa AStdClassdef then
1269 res.append(" title
=\
"{nclass.short_comment}\"")
1272 res.append(">{html_name}</a
>")
1273 html_short_link_cache = res.to_s
1275 page.append(html_short_link_cache.as(not null))
1277 private var html_short_link_cache: nullable String
1279 # Return a link (with signature) to the class anchor
1280 # <a href="url
" title="short_comment
">html_name</a>
1281 private fun html_link_anchor(page: NitdocPage) do
1282 if html_link_anchor_cache == null then
1283 var res = new Buffer
1284 res.append("<a href
='#{anchor}'")
1285 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1286 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1287 if nclass isa AStdClassdef then
1288 res.append(" title
=\
"{nclass.short_comment}\"")
1291 res.append(">{html_name}{html_short_signature}</a
>")
1292 html_link_anchor_cache = res.to_s
1294 page.append(html_link_anchor_cache.as(not null))
1296 private var html_link_anchor_cache: nullable String
1298 # Return the generic signature of the class with bounds
1299 # [E: <a>MType</a>, F: <a>MType</a>]
1300 private fun html_signature(page: NitdocPage) do
1303 for i in [0..intro.parameter_names.length[ do
1304 page.append("{intro.parameter_names[i]}: ")
1305 intro.bound_mtype.arguments[i].html_link(page)
1306 if i < intro.parameter_names.length - 1 then page.append(", ")
1312 # Return the generic signature of the class without bounds
1314 private fun html_short_signature: String do
1316 return "[{intro.parameter_names.join(", ")}]"
1322 # Return the class namespace decorated with html
1323 # <span>intro_module::html_short_link</span>
1324 private fun html_namespace(page: NitdocPage) do
1325 intro_mmodule.html_namespace(page)
1326 page.append("::<span
>")
1327 html_short_link(page)
1328 page.append("</span
>")
1331 # Return a list item for the mclass
1332 # <li>html_link</li>
1333 private fun html_sidebar_item(page: NitdocModule) do
1334 if page.mmodule.in_nesting.greaters.has(intro.mmodule) then
1335 page.append("<li
class='intro'>")
1336 page.append("<span title
='Introduced'>I
</span
>")
1337 html_link_anchor(page)
1338 else if page.mmodule.has_mclassdef_for(self) then
1339 page.append("<li
class='redef'>")
1340 page.append("<span title
='Redefined'>R
</span
>")
1341 html_link_anchor(page)
1343 page.append("<li
class='inherit'>")
1344 page.append("<span title
='Inherited'>H
</span
>")
1347 page.append("</li
>")
1350 private fun html_full_desc(page: NitdocModule) do
1351 var is_redef = not page.mmodule.in_nesting.greaters.has(intro.mmodule)
1352 var redefs = mpropdefs_in_module(page)
1353 if not is_redef or not redefs.is_empty then
1354 var classes = new Array[String]
1355 classes.add(kind.to_s)
1356 if is_redef then classes.add("redef")
1357 classes.add(visibility.to_s)
1358 page.append("<article
class='{classes.join(" ")}' id
='{anchor}'>")
1359 page.append("<h3
class='signature' data-untyped-signature
='{html_name}{html_short_signature}'>")
1360 page.append("<span
>")
1361 html_short_link(page)
1362 html_signature(page)
1363 page.append("</span
></h3
>")
1366 page.append("</article
>")
1370 private fun html_info(page: NitdocModule) do
1371 page.append("<div
class='info'>")
1372 if visibility < public_visibility then page.append("{visibility.to_s} ")
1373 if not page.mmodule.in_nesting.greaters.has(intro.mmodule) then page.append("redef ")
1374 page.append("{kind} ")
1375 html_namespace(page)
1376 page.append("{html_short_signature}</div
>")
1379 private fun html_comment(page: NitdocPage) do
1380 page.append("<div
class='description'>")
1381 if page isa NitdocModule then
1382 page.mmodule.linearize_mclassdefs(mclassdefs)
1383 # comments for each mclassdef contained in current mmodule
1384 for mclassdef in mclassdefs do
1385 if not mclassdef.is_intro and not page.mmodule.mclassdefs.has(mclassdef) then continue
1386 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(mclassdef) then
1387 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[mclassdef]
1388 if nclass isa AStdClassdef then
1389 page.append("<textarea
class='baseComment' data-comment-namespace
='{mclassdef.mmodule.full_name}::{name}' data-comment-location
='{nclass.doc_location.to_s}'>{nclass.full_comment}</textarea
>")
1390 if nclass.full_comment == "" then
1391 page.append("<p
class='info inheritance'>")
1392 page.append("<span
class=\
"noComment\">no comment
for </span
>")
1394 page.append("<div
class='comment'>{nclass.full_markdown}</div
>")
1395 page.append("<p
class='info inheritance'>")
1397 if mclassdef.is_intro then
1398 page.append("introduction
in ")
1400 page.append("refinement
in ")
1402 mclassdef.mmodule.html_full_namespace(page)
1403 page.append(" {page.show_source(nclass.location)}</p
>")
1408 # comments for intro
1409 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1410 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1411 if nclass isa AStdClassdef then
1412 page.append("<textarea
class='baseComment' data-comment-namespace
='{intro.mmodule.full_name}::{name}' data-comment-location
='{nclass.doc_location.to_s}'>{nclass.full_comment}</textarea
>")
1413 if nclass.full_comment == "" then
1414 page.append("<p
class='info inheritance'>")
1415 page.append("<span
class=\
"noComment\">no comment
for </span
>")
1417 page.append("<div
class='comment'>{nclass.full_markdown}</div
>")
1418 page.append("<p
class='info inheritance'>")
1420 page.append("introduction
in ")
1421 intro.mmodule.html_full_namespace(page)
1422 page.append(" {page.show_source(nclass.location)}</p
>")
1426 page.append("</div
>")
1429 private fun mpropdefs_in_module(page: NitdocModule): Array[MPropDef] do
1430 var res = new Array[MPropDef]
1431 page.mmodule.linearize_mclassdefs(mclassdefs)
1432 for mclassdef in mclassdefs do
1433 if not page.mmodule.mclassdefs.has(mclassdef) then continue
1434 if mclassdef.is_intro then continue
1435 for mpropdef in mclassdef.mpropdefs do
1436 if mpropdef.mproperty.visibility < page.ctx.min_visibility then continue
1437 if mpropdef isa MAttributeDef then continue
1445 redef class MProperty
1446 # Escape name for html output
1447 private fun html_name: String do return name.html_escape
1449 # Return the property namespace decorated with html
1450 # <span>intro_module::intro_class::html_link</span>
1451 private fun html_namespace(page: NitdocPage) do
1452 intro_mclassdef.mclass.html_namespace(page)
1453 page.append(intro_mclassdef.mclass.html_short_signature)
1454 page.append("::<span
>")
1455 intro.html_link(page)
1456 page.append("</span
>")
1461 # Link to the type definition in the nitdoc page
1462 private fun html_link(page: NitdocPage) is abstract
1465 redef class MClassType
1466 redef fun html_link(page) do mclass.html_link(page)
1469 redef class MNullableType
1470 redef fun html_link(page) do
1471 page.append("nullable ")
1472 mtype.html_link(page)
1476 redef class MGenericType
1477 redef fun html_link(page) do
1478 page.append("<a href
='{mclass.url}'>{mclass.html_name}</a
>[")
1479 for i in [0..arguments.length[ do
1480 arguments[i].html_link(page)
1481 if i < arguments.length - 1 then page.append(", ")
1487 redef class MParameterType
1488 redef fun html_link(page) do
1489 var name = mclass.intro.parameter_names[rank]
1490 page.append("<a href
='{mclass.url}#FT_{name}' title
='formal type'>{name}</a
>")
1494 redef class MVirtualType
1495 redef fun html_link(page) do mproperty.intro.html_link(page)
1498 redef class MClassDef
1499 # Return the classdef namespace decorated with html
1500 private fun html_namespace(page: NitdocPage) do
1501 mmodule.html_full_namespace(page)
1502 page.append("::<span
>")
1503 mclass.html_link(page)
1504 page.append("</span
>")
1508 redef class MPropDef
1509 # Return the full qualified name of the mpropdef
1510 # module::classdef::name
1511 private fun full_name: String do
1512 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1515 # URL into the nitdoc page
1516 # class_owner_name.html#anchor
1517 private fun url: String do
1518 if url_cache == null then
1519 url_cache = "{mclassdef.mclass.url}#{anchor}"
1521 return url_cache
.as(not null)
1523 private var url_cache
: nullable String
1525 # html anchor id for the property in a nitdoc class page
1526 # PROP_mclass_propertyname
1527 private fun anchor
: String do
1528 if anchor_cache
== null then
1529 anchor_cache
= "PROP_{mclassdef.mclass.public_owner.name}_{mproperty.name.replace(" ", "_")}"
1531 return anchor_cache
.as(not null)
1533 private var anchor_cache
: nullable String
1535 # Return a link to property into the nitdoc class page
1536 # <a href="url" title="short_comment">html_name</a>
1537 private fun html_link
(page
: NitdocPage) do
1538 if html_link_cache
== null then
1539 var res
= new Buffer
1540 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1541 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1542 res
.append
("<a href=\"{url}\
" title=\"{nprop.short_comment}\
">{mproperty.html_name}</a>")
1544 res
.append
("<a href=\"{url}\
">{mproperty.html_name}</a>")
1546 html_link_cache
= res
.to_s
1548 page
.append
(html_link_cache
.as(not null))
1550 private var html_link_cache
: nullable String
1552 # Return a list item for the mpropdef
1553 # <li>html_link</li>
1554 private fun html_sidebar_item
(page
: NitdocClass) do
1555 if is_intro
and mclassdef
.mclass
== page
.mclass
then
1556 page
.append
("<li class='intro'>")
1557 page
.append
("<span title='Introduced'>I</span>")
1558 else if is_intro
and mclassdef
.mclass
!= page
.mclass
then
1559 page
.append
("<li class='inherit'>")
1560 page
.append
("<span title='Inherited'>H</span>")
1562 page
.append
("<li class='redef'>")
1563 page
.append
("<span title='Redefined'>R</span>")
1566 page
.append
("</li>")
1569 private fun html_full_desc
(page
: NitdocPage, ctx
: MClass) is abstract
1570 private fun html_info
(page
: NitdocPage, ctx
: MClass) is abstract
1572 private fun html_comment
(page
: NitdocPage) do
1573 page
.append
("<div class='description'>")
1574 if not is_intro
then
1575 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(mproperty
.intro
) then
1576 var intro_nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[mproperty
.intro
]
1577 page
.append
("<textarea class='baseComment' data-comment-namespace='{mproperty.intro.mclassdef.mmodule.full_name}::{mproperty.intro.mclassdef.mclass.name}::{mproperty.name}' data-comment-location='{intro_nprop.doc_location.to_s}'>{intro_nprop.full_comment}</textarea>")
1578 if intro_nprop
.full_comment
.is_empty
then
1579 page
.append
("<p class='info inheritance'>")
1580 page
.append
("<span class=\"noComment\
">no comment for </span>")
1582 page
.append
("<div class='comment'>{intro_nprop.full_markdown}</div>")
1583 page
.append
("<p class='info inheritance'>")
1585 page
.append
("introduction in ")
1586 mproperty
.intro
.mclassdef
.html_namespace
(page
)
1587 page
.append
(" {page.show_source(intro_nprop.location)}</p>")
1590 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1591 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1592 page
.append
("<textarea class='baseComment' data-comment-namespace='{mclassdef.mmodule.full_name}::{mclassdef.mclass.name}::{mproperty.name}' data-comment-location='{nprop.doc_location.to_s}'>{nprop.full_comment}</textarea>")
1593 if nprop
.full_comment
== "" then
1594 page
.append
("<p class='info inheritance'>")
1595 page
.append
("<span class=\"noComment\
">no comment for </span>")
1597 page
.append
("<div class='comment'>{nprop.full_markdown}</div>")
1598 page
.append
("<p class='info inheritance'>")
1601 page
.append
("introduction in ")
1603 page
.append
("redefinition in ")
1605 mclassdef
.html_namespace
(page
)
1606 page
.append
(" {page.show_source(nprop.location)}</p>")
1608 page
.append
("</div>")
1612 redef class MMethodDef
1613 redef fun html_full_desc
(page
, ctx
) do
1614 var classes
= new Array[String]
1615 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= ctx
1616 if mproperty
.is_init
then
1621 if is_redef
then classes
.add
("redef")
1622 classes
.add
(mproperty
.visibility
.to_s
)
1623 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1624 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1625 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}{msignature.untyped_signature(page)}'>")
1626 page
.append
("<span>{mproperty.html_name}")
1627 msignature
.html_signature
(page
)
1628 page
.append
("</span></h3>")
1630 page
.append
("<h3 class='signature' data-untyped-signature='init{msignature.untyped_signature(page)}'>")
1631 page
.append
("<span>init")
1632 msignature
.html_signature
(page
)
1633 page
.append
("</span></h3>")
1635 html_info
(page
, ctx
)
1637 page
.append
("</article>")
1640 redef fun html_info
(page
, ctx
) do
1641 page
.append
("<div class='info'>")
1642 if mproperty
.visibility
< public_visibility
then page
.append
("{mproperty.visibility.to_s} ")
1643 if mproperty
.intro_mclassdef
.mclass
!= ctx
then page
.append
("redef ")
1644 if mproperty
.is_init
then
1645 page
.append
("init ")
1649 mproperty
.html_namespace
(page
)
1650 page
.append
("</div>")
1654 redef class MVirtualTypeDef
1655 redef fun html_full_desc
(page
, ctx
) do
1656 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= ctx
1657 var classes
= new Array[String]
1659 if is_redef
then classes
.add
("redef")
1660 classes
.add
(mproperty
.visibility
.to_s
)
1661 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1662 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}'><span>{mproperty.html_name}: ")
1663 bound
.html_link
(page
)
1664 page
.append
("</span></h3>")
1665 html_info
(page
, ctx
)
1667 page
.append
("</article>")
1670 redef fun html_info
(page
, ctx
) do
1671 page
.append
("<div class='info'>")
1672 if mproperty
.intro_mclassdef
.mclass
!= ctx
then page
.append
("redef ")
1673 page
.append
("type ")
1674 mproperty
.html_namespace
(page
)
1675 page
.append
("</div>")
1679 redef class MSignature
1680 private fun html_signature
(page
: NitdocPage) do
1681 if not mparameters
.is_empty
then
1683 for i
in [0..mparameters
.length
[ do
1684 mparameters
[i
].html_link
(page
)
1685 if i
< mparameters
.length
- 1 then page
.append
(", ")
1689 if return_mtype
!= null then
1691 return_mtype
.html_link
(page
)
1695 private fun untyped_signature
(page
: NitdocPage): String do
1696 var res
= new Buffer
1697 if not mparameters
.is_empty
then
1699 for i
in [0..mparameters
.length
[ do
1700 res
.append
(mparameters
[i
].name
)
1701 if i
< mparameters
.length
- 1 then res
.append
(", ")
1709 redef class MParameter
1710 private fun html_link
(page
: NitdocPage) do
1711 page
.append
("{name}: ")
1712 mtype
.html_link
(page
)
1713 if is_vararg
then page
.append
("...")
1722 private fun short_comment
: String do
1723 return n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1726 private fun full_comment
: String do
1727 var res
= new Buffer
1728 for t
in n_comment
do
1730 text
= text
.substring_from
(1)
1731 if text
.first
== ' ' then text
= text
.substring_from
(1)
1732 res
.append
(text
.html_escape
)
1735 return str
.substring
(0, str
.length
- 1)
1740 private fun short_comment
: String do
1741 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1742 return n_moduledecl
.n_doc
.short_comment
1747 private fun full_comment
: String do
1748 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1749 return n_moduledecl
.n_doc
.full_comment
1754 private fun full_markdown
: String do
1755 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1756 return n_moduledecl
.n_doc
.full_markdown
.html
1761 private fun doc_location
: Location do
1762 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1763 return n_moduledecl
.n_doc
.location
1769 redef class AStdClassdef
1770 private fun short_comment
: String do
1771 if n_doc
!= null then return n_doc
.short_comment
1775 private fun full_comment
: String do
1776 if n_doc
!= null then return n_doc
.full_comment
1780 private fun full_markdown
: String do
1781 if n_doc
!= null then return n_doc
.full_markdown
.html
1785 private fun doc_location
: Location do
1786 if n_doc
!= null then return n_doc
.location
1791 redef class APropdef
1792 private fun short_comment
: String do
1793 if n_doc
!= null then return n_doc
.short_comment
1797 private fun full_comment
: String do
1798 if n_doc
!= null then return n_doc
.full_comment
1802 private fun full_markdown
: String do
1803 if n_doc
!= null then return n_doc
.full_markdown
.html
1807 private fun doc_location
: Location do
1808 if n_doc
!= null then return n_doc
.location
1814 var nitdoc
= new NitdocContext
1815 nitdoc
.generate_nitdoc