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
22 # The NitdocContext contains all the knowledge used for doc generation
25 private var toolcontext
= new ToolContext
26 private var model
: Model
27 private var mbuilder
: ModelBuilder
28 private var mainmodule
: MModule
29 private var class_hierarchy
: POSet[MClass]
30 private var arguments
: Array[String]
31 private var output_dir
: nullable String
32 private var dot_dir
: nullable String
33 private var share_dir
: nullable String
34 private var source
: nullable String
35 private var min_visibility
: MVisibility
37 private var opt_dir
= new OptionString("Directory where doc is generated", "-d", "--dir")
38 private var opt_source
= new OptionString("What link for source (%f for filename, %l for first line, %L for last line)", "--source")
39 private var opt_sharedir
= new OptionString("Directory containing the nitdoc files", "--sharedir")
40 private var opt_nodot
= new OptionBool("Do not generate graphes with graphiviz", "--no-dot")
41 private var opt_private
: OptionBool = new OptionBool("Generate the private API", "--private")
43 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")
44 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")
45 private var opt_custom_overview_text
: OptionString = new OptionString("Text displayed as introduction of Overview page before the modules list", "--custom-overview-text")
46 private var opt_custom_footer_text
: OptionString = new OptionString("Text displayed as footer of all pages", "--custom-footer-text")
49 self.arguments
= toolcontext
.option_context
.rest
50 toolcontext
.option_context
.options
.clear
51 toolcontext
.option_context
.add_option
(opt_dir
)
52 toolcontext
.option_context
.add_option
(opt_source
)
53 toolcontext
.option_context
.add_option
(opt_sharedir
)
54 toolcontext
.option_context
.add_option
(opt_nodot
)
55 toolcontext
.option_context
.add_option
(opt_private
)
56 toolcontext
.option_context
.add_option
(opt_custom_title
)
57 toolcontext
.option_context
.add_option
(opt_custom_footer_text
)
58 toolcontext
.option_context
.add_option
(opt_custom_overview_text
)
59 toolcontext
.option_context
.add_option
(opt_custom_menu_items
)
60 toolcontext
.process_options
62 if arguments
.length
< 1 then
63 toolcontext
.option_context
.usage
68 mbuilder
= new ModelBuilder(model
, toolcontext
)
69 # Here we load an process all modules passed on the command line
70 var mmodules
= mbuilder
.parse
(arguments
)
71 if mmodules
.is_empty
then return
74 if mmodules
.length
== 1 then
75 mainmodule
= mmodules
.first
77 # We need a main module, so we build it by importing all modules
78 mainmodule
= new MModule(model
, null, "<main>", new Location(null, 0, 0, 0, 0))
79 mainmodule
.set_imported_mmodules
(mmodules
)
81 self.class_hierarchy
= mainmodule
.flatten_mclass_hierarchy
85 private fun process_options
do
86 if not opt_dir
.value
is null then
87 output_dir
= opt_dir
.value
91 if not opt_sharedir
.value
is null then
92 share_dir
= opt_sharedir
.value
94 var dir
= "NIT_DIR".environ
96 dir
= "{sys.program_name.dirname}/../share/nitdoc"
98 dir
= "{dir}/share/nitdoc"
101 if share_dir
is null then
102 print
"Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
105 dir
= "{share_dir.to_s}/scripts/js-facilities.js"
106 if share_dir
is null then
107 print
"Error: Invalid nitdoc share files. Check --sharedir or envvar NIT_DIR"
111 if opt_private
.value
then
112 min_visibility
= none_visibility
114 min_visibility
= protected_visibility
117 source
= opt_source
.value
120 fun generate_nitdoc
do
121 # Create destination dir if it's necessary
122 if not output_dir
.file_exists
then output_dir
.mkdir
123 sys
.system
("cp -r {share_dir.to_s}/* {output_dir.to_s}/")
125 if not opt_nodot
.value
then self.dot_dir
= output_dir
.to_s
133 private fun overview
do
134 var overviewpage
= new NitdocOverview(self, dot_dir
)
135 overviewpage
.save
("{output_dir.to_s}/index.html")
138 private fun fullindex
do
139 var fullindex
= new NitdocFullindex(self)
140 fullindex
.save
("{output_dir.to_s}/full-index.html")
143 private fun modules
do
144 for mmodule
in model
.mmodules
do
145 if mmodule
.name
== "<main>" then continue
146 var modulepage
= new NitdocModule(mmodule
, self, dot_dir
)
147 modulepage
.save
("{output_dir.to_s}/{mmodule.url}")
151 private fun classes
do
152 for mclass
in mbuilder
.model
.mclasses
do
153 var classpage
= new NitdocClass(mclass
, self, dot_dir
, source
)
154 classpage
.save
("{output_dir.to_s}/{mclass.url}")
158 private fun quicksearch_list
do
159 var file
= new OFStream.open
("{output_dir.to_s}/quicksearch-list.js")
160 file
.write
("var entries = \{ ")
161 for mmodule
in model
.mmodules
do
162 file
.write
("\"{mmodule.name}\
": [")
163 file
.write
("\{txt: \"{mmodule.name}\", url
:\
"{mmodule.url}\" \
},")
166 for mclass in model.mclasses do
167 if mclass.visibility < min_visibility then continue
168 file.write("\
"{mclass.name}\": [")
169 file.write("\
{txt: \"{mclass.name}\
", url:\"{mclass.url}\
" \},")
172 var name2mprops
= new HashMap[String, Set[MPropDef]]
173 for mproperty
in model
.mproperties
do
174 if mproperty
.visibility
< min_visibility
then continue
175 if mproperty
isa MAttribute then continue
176 if not name2mprops
.has_key
(mproperty
.name
) then name2mprops
[mproperty
.name
] = new HashSet[MPropDef]
177 name2mprops
[mproperty
.name
].add_all
(mproperty
.mpropdefs
)
179 for mproperty
, mpropdefs
in name2mprops
do
180 file
.write
("\"{mproperty}\
": [")
181 for mpropdef
in mpropdefs
do
182 file
.write
("\{txt: \"{mpropdef.full_name}\", url
:\
"{mpropdef.url}\" \
},")
193 abstract class NitdocPage
195 var dot_dir: nullable String
196 var source: nullable String
197 var ctx: NitdocContext
199 init(ctx: NitdocContext) do
203 protected fun head do
204 append("<meta charset
='utf-8'/>")
205 append("<script
type='text/javascript' src
='scripts/jquery-1.7.1.min.js'></script
>")
206 append("<script
type='text/javascript' src
='scripts/ZeroClipboard.min.js'></script
>")
207 append("<script
type='text/javascript' src
='quicksearch-list.js'></script
>")
208 append("<script
type='text/javascript' src
='scripts/base64.js'></script
>")
209 append("<script
type='text/javascript' src
='scripts/github.js'></script
>")
210 append("<script
type='text/javascript' src
='scripts/js-facilities.js'></script
>")
211 append("<link rel
='stylesheet' href
='styles/main.css' type='text/css' media
='screen'/>")
213 if ctx.opt_custom_title.value != null then
214 title = " | {ctx.opt_custom_title.value.to_s}"
216 append("<title
>{self.title}{title}</title
>")
219 protected fun menu do
220 if ctx.opt_custom_menu_items.value != null then
221 append(ctx.opt_custom_menu_items.value.to_s)
225 protected fun title: String is abstract
227 protected fun header do
229 append("<nav
class='main'>")
237 protected fun content is abstract
239 protected fun footer do
240 if ctx.opt_custom_footer_text.value != null then
241 append("<footer
>{ctx.opt_custom_footer_text.value.to_s}</footer
>")
245 # Generate a clickable graphviz image using a dot content
246 protected fun generate_dot(dot: String, name: String, alt: String) do
247 var output_dir = dot_dir
248 if output_dir == null then return
249 var file = new OFStream.open("{output_dir}/{name}.dot
")
252 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
; \
}")
253 append("<article
class='graph'>")
254 append("<img src
='{name}.png' usemap
='#{name}' style
='margin:auto' alt
='{alt}'/>")
256 var fmap = new IFStream.open("{output_dir}/{name}.map
")
257 append(fmap.read_all)
261 # Add a (source) link for a given location
262 protected fun show_source(l: Location): String
264 if source == null then
265 return "({l.file.filename.simplify_path})"
267 # THIS IS JUST UGLY ! (but there is no replace yet)
268 var x = source.split_with("%f
")
269 source = x.join(l.file.filename.simplify_path)
270 x = source.split_with("%l
")
271 source = x.join(l.line_start.to_s)
272 x = source.split_with("%L
")
273 source = x.join(l.line_end.to_s)
274 return " (<a target
='_blank' title
='Show source' href
=\
"{source.to_s}\">source
</a
>)"
278 # Render the page as a html string
279 protected fun render do
280 append("<!DOCTYPE html
>")
286 append("<div
class='page'>")
293 # Append a string to the page
294 fun append(s: String) do out.write(s)
296 # Save html page in the specified file
297 fun save(file: String) do
298 self.out = new OFStream.open(file)
302 private var out: nullable OFStream
308 private var mbuilder: ModelBuilder
309 private var mmodules = new Array[MModule]
311 init(ctx: NitdocContext, dot_dir: nullable String) do
313 self.mbuilder = ctx.mbuilder
314 self.dot_dir = dot_dir
316 var mmodules = new HashSet[MModule]
317 for mmodule in mbuilder.model.mmodules do
318 if mmodule.name == "<main
>" then continue
319 var owner = mmodule.public_owner
320 if owner != null then
323 mmodules.add(mmodule)
327 var sorter = new MModuleNameSorter
328 self.mmodules.add_all(mmodules)
329 sorter.sort(self.mmodules)
332 redef fun title do return "Overview"
336 append("<li
class='current'>Overview</li
>")
337 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
342 if ctx.opt_custom_footer_text.value != null then footed = "footed
"
343 append("<div
class='content fullpage {footed}'>")
344 var title = "Overview"
345 if ctx.opt_custom_title.value != null then
346 title = ctx.opt_custom_title.value.to_s
348 append("<h1
>{title}</h1
>")
350 if ctx.opt_custom_overview_text.value != null then
351 text = ctx.opt_custom_overview_text.value.to_s
353 append("<article
class='overview'>{text}</article
>")
354 append("<article
class='overview'>")
356 append("<h2
>Modules</h2
>")
358 for mmodule in mmodules do
359 if mbuilder.mmodule2nmodule.has_key(mmodule) then
360 var amodule = mbuilder.mmodule2nmodule[mmodule]
362 mmodule.html_link(self)
363 append(" 
;{amodule.short_comment}</li
>")
373 private fun process_generate_dot do
374 # build poset with public owners
375 var poset = new POSet[MModule]
376 for mmodule in mmodules do
377 poset.add_node(mmodule)
378 for omodule in mmodules do
379 if mmodule == omodule then continue
380 if mmodule.in_importation < omodule then
381 poset.add_node(omodule)
382 poset.add_edge(mmodule, omodule)
388 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
")
389 for mmodule in poset do
390 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
391 for omodule in poset[mmodule].direct_greaters do
392 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
396 generate_dot(op.to_s, "dep
", "Modules hierarchy
")
400 # The full index page
401 class NitdocFullindex
404 init(ctx: NitdocContext) do
409 redef fun title do return "Full Index"
413 append("<li
><a href
='index.html'>Overview</a
></li
>")
414 append("<li
class='current'>Full Index</li
>")
419 if ctx.opt_custom_footer_text.value != null then footed = "footed
"
420 append("<div
class='content fullpage {footed}'>")
421 append("<h1
>Full Index</h1
>")
428 # Add to content modules column
429 private fun module_column do
430 var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
431 var sorter = new MModuleNameSorter
433 append("<article
class='modules filterable'>")
434 append("<h2
>Modules</h2
>")
436 for mmodule in sorted do
438 mmodule.html_link(self)
445 # Add to content classes modules
446 private fun classes_column do
447 var sorted = ctx.mbuilder.model.mclasses
448 var sorter = new MClassNameSorter
450 append("<article
class='modules filterable'>")
451 append("<h2
>Classes</h2
>")
453 for mclass in sorted do
454 if mclass.visibility < ctx.min_visibility then continue
456 mclass.html_link(self)
463 # Insert the properties column of fullindex page
464 private fun properties_column do
465 var sorted = ctx.mbuilder.model.mproperties
466 var sorter = new MPropertyNameSorter
468 append("<article
class='modules filterable'>")
469 append("<h2
>Properties</h2
>")
471 for mproperty in sorted do
472 if mproperty.visibility < ctx.min_visibility then continue
473 if mproperty isa MAttribute then continue
475 mproperty.intro.html_link(self)
477 mproperty.intro.mclassdef.mclass.html_link(self)
490 private var mmodule: MModule
491 private var mbuilder: ModelBuilder
493 init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
495 self.mmodule = mmodule
496 self.mbuilder = ctx.mbuilder
497 self.dot_dir = dot_dir
501 if mbuilder.mmodule2nmodule.has_key(mmodule) then
502 var nmodule = mbuilder.mmodule2nmodule[mmodule]
503 return "{mmodule.name} module | {nmodule.short_comment}"
505 return "{mmodule.name} module"
511 append("<li
><a href
='index.html'>Overview</a
></li
>")
512 append("<li
class='current'>{mmodule.name}</li
>")
513 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
519 if ctx.opt_custom_footer_text.value != null then footed = "footed
"
520 append("<div
class='content {footed}'>")
521 append("<h1
>{mmodule.name}</h1
>")
522 append("<div
class='subtitle info'>")
523 mmodule.html_signature(self)
525 mmodule.html_full_comment(self)
532 private fun process_generate_dot do
533 # build poset with public owners
534 var poset = new POSet[MModule]
535 for mmodule in self.mmodule.in_importation.poset do
536 if mmodule.name == "<main
>" then continue
537 if mmodule.public_owner != null then continue
538 if not mmodule.in_importation < self.mmodule and not self.mmodule.in_importation < mmodule and mmodule != self.mmodule then continue
539 poset.add_node(mmodule)
540 for omodule in mmodule.in_importation.poset do
541 if mmodule == omodule then continue
542 if omodule.name == "<main
>" then continue
543 if omodule.public_owner != null then continue
544 if mmodule.in_importation < omodule then
545 poset.add_node(omodule)
546 poset.add_edge(mmodule, omodule)
552 var name = "dep_
{mmodule.name}"
553 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
")
554 for mmodule in poset do
555 if mmodule == self.mmodule then
556 op.append("\
"{mmodule.name}\"[shape
=box
,margin
=0.03];\n
")
558 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
560 for omodule in poset[mmodule].direct_greaters do
561 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
565 generate_dot(op.to_s, name, "Dependency graph
for module {mmodule.name}")
568 private fun sidebar do
569 append("<div
class='menu'>")
571 append("<h3
>Module Hierarchy</h3
>")
572 var dependencies = new Array[MModule]
573 for dep in mmodule.in_importation.greaters do
574 if dep == mmodule or dep.public_owner != null then continue
575 dependencies.add(dep)
577 if dependencies.length > 0 then
578 append("<h4
>All dependencies
</h4
>")
579 display_module_list(dependencies)
581 var clients = new Array[MModule]
582 for dep in mmodule.in_importation.smallers do
583 if dep.name == "<main
>" then continue
584 if dep == mmodule or dep.public_owner != null then continue
587 if clients.length > 0 then
588 append("<h4
>All clients
</h4
>")
589 display_module_list(clients)
592 if ctx.min_visibility < protected_visibility then
593 if mmodule.in_nesting.direct_greaters.length > 0 then
595 append("<h3
>Nested Modules</h3
>")
596 display_module_list(mmodule.in_nesting.direct_greaters.to_a)
603 private fun display_module_list(list: Array[MModule]) do
605 var sorter = new MModuleNameSorter
615 # display the class column
616 private fun classes do
617 var intro_mclasses = mmodule.intro_mclasses
618 var redef_mclasses = mmodule.redef_mclasses
619 var all_mclasses = new HashSet[MClass]
620 for m in mmodule.in_nesting.greaters do
621 all_mclasses.add_all(m.intro_mclasses)
622 all_mclasses.add_all(m.redef_mclasses)
624 all_mclasses.add_all(intro_mclasses)
625 all_mclasses.add_all(redef_mclasses)
627 var sorted = new Array[MClass]
628 sorted.add_all(all_mclasses)
629 var sorter = new MClassNameSorter
631 append("<div
class='module'>")
632 append("<article
class='classes filterable'>")
633 append("<h2
>Classes</h2
>")
636 if c.visibility < ctx.min_visibility then continue
637 if redef_mclasses.has(c) and c.intro_mmodule.public_owner != mmodule then
638 append("<li
class='redef'>")
639 append("<span title
='refined in this module'>R
</span
>")
641 append("<li
class='intro'>")
642 append("<span title
='introduced in this module'>I
</span
>")
652 # display the property column
653 private fun properties do
655 var mpropdefs = new HashSet[MPropDef]
656 for m in mmodule.in_nesting.greaters do
657 for c in m.mclassdefs do mpropdefs.add_all(c.mpropdefs)
659 for c in mmodule.mclassdefs do mpropdefs.add_all(c.mpropdefs)
660 var sorted = mpropdefs.to_a
661 var sorter = new MPropDefNameSorter
663 # display properties in one column
664 append("<article
class='properties filterable'>")
665 append("<h2
>Properties</h2
>")
667 for mprop in sorted do
668 if mprop isa MAttributeDef then continue
669 if mprop.mproperty.visibility < ctx.min_visibility then continue
670 mprop.html_list_item(self)
681 private var mclass: MClass
682 private var vtypes = new HashSet[MVirtualTypeDef]
683 private var consts = new HashSet[MMethodDef]
684 private var meths = new HashSet[MMethodDef]
685 private var inherited = new HashSet[MPropDef]
687 init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
690 self.dot_dir = dot_dir
693 for mclassdef in mclass.mclassdefs do
694 for mpropdef in mclassdef.mpropdefs do
695 if mpropdef.mproperty.visibility < ctx.min_visibility then continue
696 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
697 if mpropdef isa MMethodDef then
698 if mpropdef.mproperty.is_init then
706 # get inherited properties
707 for pclass in mclass.in_hierarchy(ctx.mainmodule).greaters do
708 if pclass == mclass then continue
709 for pclassdef in pclass.mclassdefs do
710 for mprop in pclassdef.intro_mproperties do
711 var mpropdef = mprop.intro
712 if mprop.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 inherited.add(mpropdef)
728 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
729 if nclass isa AStdClassdef then
730 return "{mclass.name} class | {nclass.short_comment}"
732 return "{mclass.name} class"
738 append("<li
><a href
='index.html'>Overview</a
></li
>")
739 var public_owner = mclass.public_owner
740 if public_owner is null then
742 mclass.intro_mmodule.html_link(self)
746 public_owner.html_link(self)
749 append("<li
class='current'>{mclass.name}</li
>")
750 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
754 append("<div
class='menu'>")
759 if ctx.opt_custom_footer_text.value != null then footed = "footed
"
760 append("<div
class='content {footed}'>")
765 private fun properties_column do
766 var sorter = new MPropDefNameSorter
767 append("<nav
class='properties filterable'>")
768 append("<h3
>Properties</h3
>")
770 if vtypes.length > 0 then
771 var vts = new Array[MVirtualTypeDef]
774 append("<h4
>Virtual Types</h4
>")
777 mprop.html_sidebar_item(self)
782 if consts.length > 0 then
783 var cts = new Array[MMethodDef]
786 append("<h4
>Constructors</h4
>")
789 if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
790 mprop.html_sidebar_item(self)
795 if meths.length > 0 then
796 var mts = new Array[MMethodDef]
799 append("<h4
>Methods</h4
>")
802 if mclass.name != "Object" and mprop.mproperty.intro_mclassdef.mclass.name == "Object" and mprop.mproperty.visibility <= protected_visibility then continue
803 mprop.html_sidebar_item(self)
810 private fun inheritance_column do
811 var sorted = new Array[MClass]
812 var sorterp = new MClassNameSorter
814 append("<h3
>Inheritance</h3
>")
815 var greaters = mclass.in_hierarchy(ctx.mainmodule).greaters.to_a
816 if greaters.length > 1 then
817 ctx.mainmodule.linearize_mclasses(greaters)
818 append("<h4
>Superclasses</h4
>")
820 for sup in greaters do
821 if sup == mclass then continue
828 var smallers = mclass.in_hierarchy(ctx.mainmodule).smallers.to_a
829 var direct_smallers = mclass.in_hierarchy(ctx.mainmodule).direct_smallers.to_a
830 if smallers.length <= 1 then
831 append("<h4
>No Known Subclasses</h4
>")
832 else if smallers.length <= 100 then
833 ctx.mainmodule.linearize_mclasses(smallers)
834 append("<h4
>Subclasses</h4
>")
836 for sub in smallers do
837 if sub == mclass then continue
843 else if direct_smallers.length <= 100 then
844 ctx.mainmodule.linearize_mclasses(direct_smallers)
845 append("<h4
>Direct Subclasses Only</h4
>")
847 for sub in direct_smallers do
848 if sub == mclass then continue
855 append("<h4
>Too much
Subclasses to list
</h4
>")
860 private fun class_doc do
862 append("<h1
>{mclass.signature}</h1
>")
863 append("<div
class='subtitle info'>")
864 mclass.html_full_signature(self)
867 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
868 append("<section
class='description'>")
872 var concern2meths = new ArrayMap[MModule, Array[MMethodDef]]
873 var sorted_meths = new Array[MMethodDef]
874 var sorted = new Array[MModule]
875 sorted_meths.add_all(meths)
876 ctx.mainmodule.linearize_mpropdefs(sorted_meths)
878 if inherited.has(meth) then continue
879 var mmodule = meth.mclassdef.mmodule
880 if not concern2meths.has_key(mmodule) then
882 concern2meths[mmodule] = new Array[MMethodDef]
884 concern2meths[mmodule].add(meth)
886 var sections = new ArrayMap[MModule, Array[MModule]]
887 for mmodule in concern2meths.keys do
888 var owner = mmodule.public_owner
889 if owner == null then owner = mmodule
890 if not sections.has_key(owner) then sections[owner] = new Array[MModule]
891 if owner != mmodule then sections[owner].add(mmodule)
893 append("<section
class='concerns'>")
894 append("<h2
class='section-header'>Concerns</h2
>")
896 for owner, mmodules in sections do
897 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
899 if nowner.short_comment.is_empty then
900 append("<a href
=\
"#{owner.anchor}\">{owner.name}</a
>")
902 append("<a href
=\
"#{owner.anchor}\">{owner.name}</a
>: {nowner.short_comment}")
904 if not mmodules.is_empty then
906 for mmodule in mmodules do
907 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
908 if nmodule.short_comment.is_empty then
909 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.name}</a
></li
>")
911 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.name}</a
>: {nmodule.short_comment}</li
>")
921 var prop_sorter = new MPropDefNameSorter
922 var lmmodule = new List[MModule]
923 # virtual and formal types
924 var local_vtypes = new Array[MVirtualTypeDef]
925 for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
926 if local_vtypes.length > 0 or mclass.arity > 0 then
927 append("<section
class='types'>")
928 append("<h2
>Formal and Virtual Types</h2
>")
930 if mclass.arity > 0 and nclass isa AStdClassdef then
931 for ft, bound in mclass.parameter_types do
932 append("<article id
='FT_{ft}'>")
933 append("<h3
class='signature' data-untyped-signature
='{ft.to_s}'><span
>{ft}: ")
934 bound.html_link(self)
935 append("</span
></h3
>")
936 append("<div
class=\
"info\">formal generic
type</div
>")
941 prop_sorter.sort(local_vtypes)
942 for prop in local_vtypes do prop.html_full_desc(self)
946 var local_consts = new Array[MMethodDef]
947 for const in consts do if not inherited.has(const) then local_consts.add(const)
948 prop_sorter.sort(local_consts)
949 if local_consts.length > 0 then
950 append("<section
class='constructors'>")
951 append("<h2
class='section-header'>Constructors</h2
>")
952 for prop in local_consts do prop.html_full_desc(self)
956 if not concern2meths.is_empty then
957 append("<section
class='methods'>")
958 append("<h2
class='section-header'>Methods</h2
>")
959 for owner, mmodules in sections do
960 append("<a id
=\
"{owner.anchor}\"></a
>")
961 if owner != mclass.intro_mmodule and owner != mclass.public_owner then
962 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
963 append("<h3
class=\
"concern-toplevel\">Methods refined
in ")
964 owner.html_link(self)
966 append("<p
class=\
"concern-doc\">")
967 owner.html_link(self)
968 if not nowner.short_comment.is_empty then
969 append(": {nowner.short_comment}")
973 if concern2meths.has_key(owner) then
974 var mmethods = concern2meths[owner]
975 prop_sorter.sort(mmethods)
976 for prop in mmethods do prop.html_full_desc(self)
978 for mmodule in mmodules do
979 append("<a id
=\
"{mmodule.anchor}\"></a
>")
980 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
981 if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
982 append("<p
class=\
"concern-doc\">")
983 mmodule.html_link(self)
984 if not nmodule.short_comment.is_empty then
985 append(": {nmodule.short_comment}")
989 var mmethods = concern2meths[mmodule]
990 prop_sorter.sort(mmethods)
991 for prop in mmethods do prop.html_full_desc(self)
995 # inherited properties
996 if inherited.length > 0 then
997 var sorted_inherited = new Array[MPropDef]
998 sorted_inherited.add_all(inherited)
999 ctx.mainmodule.linearize_mpropdefs(sorted_inherited)
1000 var classes = new ArrayMap[MClass, Array[MPropDef]]
1001 for mmethod in sorted_inherited.reversed do
1002 var mclass = mmethod.mclassdef.mclass
1003 if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
1004 classes[mclass].add(mmethod)
1006 append("<h3
>Inherited Properties</h3
>")
1007 for c, mmethods in classes do
1008 prop_sorter.sort(mmethods)
1009 append("<p
>Defined in ")
1012 for i in [0..mmethods.length[ do
1013 var mmethod = mmethods[i]
1014 mmethod.html_link(self)
1015 if i <= mmethods.length - 1 then append(", ")
1020 append("</section
>")
1023 private fun process_generate_dot do
1024 var pe = ctx.class_hierarchy[mclass]
1025 var cla = new HashSet[MClass]
1026 var sm = new HashSet[MClass]
1027 var sm2 = new HashSet[MClass]
1029 while cla.length + sm.length < 10 and sm.length > 0 do
1033 sm2.add_all(pe.poset[x].direct_smallers)
1039 cla.add_all(pe.greaters)
1042 var name = "dep_
{mclass.name}"
1043 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
")
1046 op.append("\
"{c.name}\"[shape
=box
,margin
=0.03];\n
")
1048 op.append("\
"{c.name}\"[URL=\
"{c.url}\"];\n
")
1050 for c2 in pe.poset[c].direct_greaters do
1051 if not cla.has(c2) then continue
1052 op.append("\
"{c.name}\"->\
"{c2.name}\";\n
")
1054 if not pe.poset[c].direct_smallers.is_empty then
1056 for c2 in pe.poset[c].direct_smallers do
1057 if cla.has(c2) then others = false
1060 op.append("\
"{c.name}...\"[label=\
"\"];\n
")
1061 op.append("\
"{c.name}...\"->\
"{c.name}\"[style
=dotted
];\n
")
1066 generate_dot(op.to_s, name, "Dependency graph
for class {mclass.name}")
1075 # URL to nitdoc page
1077 if url_cache == null then
1078 var res = new Buffer
1079 res.append("module_
")
1080 var mowner = public_owner
1081 if mowner != null then
1082 res.append("{public_owner.name}_
")
1084 res.append("{self.name}.html
")
1085 url_cache = res.to_s
1087 return url_cache.as(not null)
1089 private var url_cache: nullable String
1091 # html anchor id to the module in a nitdoc page
1092 fun anchor: String do
1093 if anchor_cache == null then
1094 var res = new Buffer
1096 var mowner = public_owner
1097 if mowner != null then
1098 res.append("{public_owner.name}_
")
1100 res.append(self.name)
1101 anchor_cache = res.to_s
1103 return anchor_cache.as(not null)
1105 private var anchor_cache: nullable String
1107 # Return a link (html a tag) to the nitdoc module page
1108 fun html_link(page: NitdocPage) do
1109 if html_link_cache == null then
1110 var res = new Buffer
1111 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1112 res.append("<a href
='{url}' title
='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{name}</a
>")
1114 res.append("<a href
='{url}'>{name}</a
>")
1116 html_link_cache = res.to_s
1118 page.append(html_link_cache.as(not null))
1120 private var html_link_cache: nullable String
1122 # Return the module signature decorated with html
1123 fun html_signature(page: NitdocPage) do
1124 page.append("<span
>module ")
1125 html_full_namespace(page)
1126 page.append("</span
>")
1129 # Return the module full namespace decorated with html
1130 fun html_full_namespace(page: NitdocPage) do
1131 page.append("<span
>")
1132 var mowner = public_owner
1133 if mowner != null then
1134 public_owner.html_namespace(page)
1138 page.append("</span
>")
1141 # Return the module full namespace decorated with html
1142 fun html_namespace(page: NitdocPage) do
1143 page.append("<span
>")
1144 var mowner = public_owner
1145 if mowner != null then
1146 public_owner.html_namespace(page)
1150 page.append("</span
>")
1153 # Return the full comment of the module decorated with html
1154 fun html_full_comment(page: NitdocPage) do
1155 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1156 page.append("<div id
='description'>")
1157 page.append("<pre
class='text_label'>{page.ctx.mbuilder.mmodule2nmodule[self].full_comment}</pre
>")
1158 page.append("</div
>")
1164 # Return the module signature decorated with html
1165 fun html_full_signature(page: NitdocPage) do
1166 if visibility < public_visibility then page.append("{visibility.to_s} ")
1167 page.append("{kind} ")
1168 html_namespace(page)
1171 # name with formal parameter
1173 private fun signature: String do
1175 return "{name}[{intro.parameter_names.join(", ")}]"
1181 # Return a link (html a tag) to the nitdoc class page
1182 fun html_link(page: NitdocPage) do
1183 if html_link_cache == null then
1184 var res = new Buffer
1185 res.append("<a href
='{url}'")
1186 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1187 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1188 if nclass isa AStdClassdef then
1189 res.append(" title
=\
"{nclass.short_comment}\"")
1192 res.append(">{signature}</a
>")
1193 html_link_cache = res.to_s
1195 page.append(html_link_cache.as(not null))
1197 private var html_link_cache: nullable String
1199 # Return the class namespace decorated with html
1200 fun html_namespace(page: NitdocPage) do
1201 intro_mmodule.html_namespace(page)
1202 page.append("::<span
>")
1204 page.append("</span
>")
1208 return "class_
{public_owner}_
{name}.html
"
1211 # Escape name for html output
1212 redef fun name do return super.html_escape
1215 redef class MProperty
1216 # Return the property namespace decorated with html
1217 fun html_namespace(page: NitdocPage) do
1218 intro_mclassdef.mclass.html_namespace(page)
1219 page.append("::<span
>")
1220 intro.html_link(page)
1221 page.append("</span
>")
1224 # Escape name for html output
1225 redef fun name do return super.html_escape
1229 fun html_link(page: NitdocPage) is abstract
1232 redef class MClassType
1233 redef fun html_link(page) do mclass.html_link(page)
1236 redef class MNullableType
1237 redef fun html_link(page) do
1238 page.append("nullable ")
1239 mtype.html_link(page)
1243 redef class MGenericType
1244 redef fun html_link(page) do
1245 page.append("<a href
='{mclass.url}'>{mclass.name}</a
>[")
1246 for i in [0..arguments.length[ do
1247 arguments[i].html_link(page)
1248 if i < arguments.length - 1 then page.append(", ")
1254 redef class MParameterType
1255 redef fun html_link(page) do
1256 var name = mclass.intro.parameter_names[rank]
1257 page.append("<a href
='{mclass.url}#FT_{name}' title
='formal type'>{name}</a
>")
1261 redef class MVirtualType
1262 redef fun html_link(page) do mproperty.intro.html_link(page)
1265 redef class MClassDef
1266 # Return the classdef namespace decorated with html
1267 fun html_namespace(page: NitdocPage) do
1268 mmodule.html_full_namespace(page)
1269 page.append("::<span
>")
1270 mclass.html_link(page)
1271 page.append("</span
>")
1275 redef class MPropDef
1277 if url_cache == null then
1278 url_cache = "{mclassdef.mclass.url}#{anchor}"
1280 return url_cache
.as(not null)
1282 private var url_cache
: nullable String
1284 fun anchor
: String do
1285 if anchor_cache
== null then
1286 anchor_cache
= "PROP_{mclassdef.mclass.public_owner.name}_{mproperty.name}"
1288 return anchor_cache
.as(not null)
1290 private var anchor_cache
: nullable String
1292 # Return a link (html a tag) to the nitdoc class page
1293 fun html_link
(page
: NitdocPage) do
1294 if html_link_cache
== null then
1295 var res
= new Buffer
1296 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1297 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1298 res
.append
("<a href=\"{url}\
" title=\"{nprop.short_comment}\
">{mproperty.name}</a>")
1300 res
.append
("<a href=\"{url}\
">{mproperty.name}</a>")
1302 html_link_cache
= res
.to_s
1304 page
.append
(html_link_cache
.as(not null))
1306 private var html_link_cache
: nullable String
1308 # Return a list item for the mpropdef
1309 private fun html_list_item
(page
: NitdocPage) do
1311 page
.append
("<li class='intro'>")
1312 page
.append
("<span title='introduction'>I</span> ")
1314 page
.append
("<li class='redef'>")
1315 page
.append
("<span title='redefinition'>R</span> ")
1319 mclassdef
.mclass
.html_link
(page
)
1321 page
.append
("</li>")
1324 # Return a list item for the mpropdef
1325 private fun html_sidebar_item
(page
: NitdocClass) do
1326 if is_intro
and mclassdef
.mclass
== page
.mclass
then
1327 page
.append
("<li class='intro'>")
1328 page
.append
("<span title='Introduced'>I</span>")
1329 else if is_intro
and mclassdef
.mclass
!= page
.mclass
then
1330 page
.append
("<li class='inherit'>")
1331 page
.append
("<span title='Inherited'>H</span>")
1333 page
.append
("<li class='redef'>")
1334 page
.append
("<span title='Redefined'>R</span>")
1337 page
.append
("</li>")
1340 private fun html_full_desc
(page
: NitdocClass) is abstract
1341 private fun html_info
(page
: NitdocClass) is abstract
1343 fun full_name
: String do
1344 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1347 private fun html_inheritance
(page
: NitdocClass) do
1349 page
.append
("<p class='info'>")
1350 page
.ctx
.mainmodule
.linearize_mpropdefs
(mproperty
.mpropdefs
)
1351 var previous_defs
= new Array[MPropDef]
1352 var next_defs
= new Array[MPropDef]
1353 var self_passed
= false
1354 for def
in mproperty
.mpropdefs
do
1359 if not self_passed
then
1360 if def
.mclassdef
.mclass
.in_hierarchy
(page
.ctx
.mainmodule
) < page
.mclass
then continue
1361 if def
.is_intro
then continue
1362 previous_defs
.add
(def
)
1364 if page
.mclass
.in_hierarchy
(page
.ctx
.mainmodule
) < def
.mclassdef
.mclass
then continue
1368 page
.append
("defined by ")
1369 mclassdef
.mmodule
.html_full_namespace
(page
)
1370 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1371 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1373 if not is_intro
then
1374 page
.append
(", introduced by ")
1375 mproperty
.intro
.mclassdef
.mclass
.html_link
(page
)
1376 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1377 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1380 if not previous_defs
.is_empty
then
1381 page
.append
(", inherited from ")
1382 for i
in [0..previous_defs
.length
[ do
1383 var def
= previous_defs
[i
]
1384 def
.mclassdef
.mclass
.html_link
(page
)
1385 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(def
) then
1386 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1389 if i
< previous_defs
.length
- 1 then page
.append
(", ")
1392 if not next_defs
.is_empty
then
1393 page
.append
(", redefined by ")
1394 for i
in [0..next_defs
.length
[ do
1395 var def
= next_defs
[i
]
1396 def
.mclassdef
.mclass
.html_link
(page
)
1397 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(def
) then
1398 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1400 if i
< next_defs
.length
- 1 then page
.append
(", ")
1403 page
.append
(".</p>")
1406 private fun html_comment
(page
: NitdocClass) do
1407 if not page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then return
1408 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1409 page
.append
("<div class='description'>")
1410 if not is_intro
and page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(mproperty
.intro
) then
1411 var intro_nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[mproperty
.intro
]
1412 page
.append
("<p class='info'>from ")
1413 mproperty
.html_namespace
(page
)
1415 if intro_nprop
.full_comment
== "" then
1416 page
.append
("<span class=\"noComment\
">No comment</span>")
1418 page
.append
("<pre>{intro_nprop.full_comment}</pre>")
1420 page
.append
("<p class='info'>from ")
1421 mclassdef
.html_namespace
(page
)
1424 if nprop
.full_comment
== "" then
1425 page
.append
("<span class=\"noComment\
">No comment</span>")
1427 page
.append
("<pre>{nprop.full_comment}</pre>")
1429 html_inheritance
(page
)
1430 page
.append
("</div>")
1434 redef class MMethodDef
1435 redef fun html_full_desc
(page
) do
1436 var classes
= new Array[String]
1437 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= page
.mclass
1438 if mproperty
.is_init
then
1443 if is_redef
then classes
.add
("redef")
1444 classes
.add
(mproperty
.visibility
.to_s
)
1445 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1446 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1447 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}{msignature.untyped_signature(page)}'>")
1448 page
.append
("<span>{mproperty.name}")
1449 msignature
.html_signature
(page
)
1450 page
.append
("</span></h3>")
1452 page
.append
("<h3 class='signature' data-untyped-signature='init{msignature.untyped_signature(page)}'>")
1453 page
.append
("<span>init")
1454 msignature
.html_signature
(page
)
1455 page
.append
("</span></h3>")
1459 page
.append
("</article>")
1462 redef fun html_info
(page
) do
1463 page
.append
("<div class='info'>")
1464 if mproperty
.visibility
< public_visibility
then page
.append
("{mproperty.visibility.to_s} ")
1465 if mproperty
.intro_mclassdef
.mclass
!= page
.mclass
then page
.append
("redef ")
1466 if mproperty
.is_init
then
1467 page
.append
("init ")
1471 mproperty
.html_namespace
(page
)
1472 page
.append
("</div>")
1476 redef class MVirtualTypeDef
1477 redef fun html_full_desc
(page
) do
1478 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= page
.mclass
1479 var classes
= new Array[String]
1481 if is_redef
then classes
.add
("redef")
1482 classes
.add
(mproperty
.visibility
.to_s
)
1483 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1484 page
.append
("<h3 class='signature' data-untyped-signature='{mproperty.name}'><span>{mproperty.name}: ")
1485 bound
.html_link
(page
)
1486 page
.append
("</span></h3>")
1489 page
.append
("</article>")
1492 redef fun html_info
(page
) do
1493 page
.append
("<div class='info'>")
1494 if mproperty
.intro_mclassdef
.mclass
!= page
.mclass
then page
.append
("redef ")
1495 page
.append
("type ")
1496 mproperty
.html_namespace
(page
)
1497 page
.append
("</div>")
1501 redef class MSignature
1502 private fun html_signature
(page
: NitdocPage) do
1503 if not mparameters
.is_empty
then
1505 for i
in [0..mparameters
.length
[ do
1506 mparameters
[i
].html_link
(page
)
1507 if i
< mparameters
.length
- 1 then page
.append
(", ")
1511 if return_mtype
!= null then
1513 return_mtype
.html_link
(page
)
1517 private fun untyped_signature
(page
: NitdocPage): String do
1518 var res
= new Buffer
1519 if not mparameters
.is_empty
then
1521 for i
in [0..mparameters
.length
[ do
1522 res
.append
(mparameters
[i
].name
)
1523 if i
< mparameters
.length
- 1 then res
.append
(", ")
1531 redef class MParameter
1532 private fun html_link
(page
: NitdocPage) do
1533 page
.append
("{name}: ")
1534 mtype
.html_link
(page
)
1535 if is_vararg
then page
.append
("...")
1544 private fun short_comment
: String do
1545 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1546 return n_moduledecl
.n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1551 private fun full_comment
: String do
1552 var res
= new Buffer
1553 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1554 for t
in n_moduledecl
.n_doc
.n_comment
do
1555 res
.append
(t
.text
.substring_from
(1).html_escape
)
1562 redef class AStdClassdef
1563 private fun short_comment
: String do
1564 if n_doc
!= null then return n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1568 private fun full_comment
: String do
1569 var res
= new Buffer
1570 if n_doc
!= null then
1571 for t
in n_doc
.n_comment
do res
.append
(t
.text
.substring_from
(1).html_escape
)
1577 redef class APropdef
1578 private fun short_comment
: String do
1579 if n_doc
!= null then return n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1583 private fun full_comment
: String do
1584 var res
= new Buffer
1585 if n_doc
!= null then
1586 for t
in n_doc
.n_comment
do res
.append
(t
.text
.substring_from
(1).html_escape
)
1592 var nitdoc
= new NitdocContext
1593 nitdoc
.generate_nitdoc