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
='quicksearch-list.js'></script
>")
207 append("<script
type='text/javascript' src
='scripts/base64.js'></script
>")
208 append("<script
type='text/javascript' src
='scripts/github.js'></script
>")
209 append("<script
type='text/javascript' src
='scripts/js-facilities.js'></script
>")
210 append("<link rel
='stylesheet' href
='styles/main.css' type='text/css' media
='screen'/>")
212 if ctx.opt_custom_title.value != null then
213 title = " | {ctx.opt_custom_title.value.to_s}"
215 append("<title
>{self.title}{title}</title
>")
218 protected fun menu do
219 if ctx.opt_custom_menu_items.value != null then
220 append(ctx.opt_custom_menu_items.value.to_s)
224 protected fun title: String is abstract
226 protected fun header do
228 append("<nav
class='main'>")
236 protected fun content is abstract
238 protected fun footer do
239 if ctx.opt_custom_footer_text.value != null then
240 append("<footer
>{ctx.opt_custom_footer_text.value.to_s}</footer
>")
244 # Generate a clickable graphviz image using a dot content
245 protected fun generate_dot(dot: String, name: String, alt: String) do
246 var output_dir = dot_dir
247 if output_dir == null then return
248 var file = new OFStream.open("{output_dir}/{name}.dot
")
251 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
; \
}")
252 append("<article
class='graph'>")
253 append("<img src
='{name}.png' usemap
='#{name}' style
='margin:auto' alt
='{alt}'/>")
255 var fmap = new IFStream.open("{output_dir}/{name}.map
")
256 append(fmap.read_all)
260 # Add a (source) link for a given location
261 protected fun show_source(l: Location): String
263 if source == null then
264 return "({l.file.filename.simplify_path})"
266 # THIS IS JUST UGLY ! (but there is no replace yet)
267 var x = source.split_with("%f
")
268 source = x.join(l.file.filename.simplify_path)
269 x = source.split_with("%l
")
270 source = x.join(l.line_start.to_s)
271 x = source.split_with("%L
")
272 source = x.join(l.line_end.to_s)
273 return " (<a href
=\
"{source.to_s}\">source
</a
>)"
277 # Render the page as a html string
278 protected fun render do
279 append("<!DOCTYPE html
>")
285 append("<div
class='page'>")
292 # Append a string to the page
293 fun append(s: String) do out.write(s)
295 # Save html page in the specified file
296 fun save(file: String) do
297 self.out = new OFStream.open(file)
301 private var out: nullable OFStream
307 private var mbuilder: ModelBuilder
308 private var mmodules = new Array[MModule]
310 init(ctx: NitdocContext, dot_dir: nullable String) do
312 self.mbuilder = ctx.mbuilder
313 self.dot_dir = dot_dir
315 var mmodules = new HashSet[MModule]
316 for mmodule in mbuilder.model.mmodules do
317 if mmodule.name == "<main
>" then continue
318 var owner = mmodule.public_owner
319 if owner != null then
322 mmodules.add(mmodule)
326 var sorter = new MModuleNameSorter
327 self.mmodules.add_all(mmodules)
328 sorter.sort(self.mmodules)
331 redef fun title do return "Overview"
335 append("<li
class='current'>Overview</li
>")
336 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
340 append("<div
class='content fullpage'>")
341 var title = "Overview"
342 if ctx.opt_custom_title.value != null then
343 title = ctx.opt_custom_title.value.to_s
345 append("<h1
>{title}</h1
>")
347 if ctx.opt_custom_overview_text.value != null then
348 text = ctx.opt_custom_overview_text.value.to_s
350 append("<article
class='overview'>{text}</article
>")
351 append("<article
class='overview'>")
353 append("<h2
>Modules</h2
>")
355 for mmodule in mmodules do
356 if mbuilder.mmodule2nmodule.has_key(mmodule) then
357 var amodule = mbuilder.mmodule2nmodule[mmodule]
359 mmodule.html_link(self)
360 append(" 
;{amodule.short_comment}</li
>")
370 private fun process_generate_dot do
371 # build poset with public owners
372 var poset = new POSet[MModule]
373 for mmodule in mmodules do
374 poset.add_node(mmodule)
375 for omodule in mmodules do
376 if mmodule == omodule then continue
377 if mmodule.in_importation < omodule then
378 poset.add_node(omodule)
379 poset.add_edge(mmodule, omodule)
385 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
")
386 for mmodule in poset do
387 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
388 for omodule in poset[mmodule].direct_greaters do
389 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
393 generate_dot(op.to_s, "dep
", "Modules hierarchy
")
397 # The full index page
398 class NitdocFullindex
401 init(ctx: NitdocContext) do
406 redef fun title do return "Full Index"
410 append("<li
><a href
='index.html'>Overview</a
></li
>")
411 append("<li
class='current'>Full Index</li
>")
415 append("<div
class='content fullpage'>")
416 append("<h1
>Full Index</h1
>")
423 # Add to content modules column
424 private fun module_column do
425 var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
426 var sorter = new MModuleNameSorter
428 append("<article
class='modules filterable'>")
429 append("<h2
>Modules</h2
>")
431 for mmodule in sorted do
433 mmodule.html_link(self)
440 # Add to content classes modules
441 private fun classes_column do
442 var sorted = ctx.mbuilder.model.mclasses
443 var sorter = new MClassNameSorter
445 append("<article
class='modules filterable'>")
446 append("<h2
>Classes</h2
>")
448 for mclass in sorted do
449 if mclass.visibility < ctx.min_visibility then continue
451 mclass.html_link(self)
458 # Insert the properties column of fullindex page
459 private fun properties_column do
460 var sorted = ctx.mbuilder.model.mproperties
461 var sorter = new MPropertyNameSorter
463 append("<article
class='modules filterable'>")
464 append("<h2
>Properties</h2
>")
466 for mproperty in sorted do
467 if mproperty.visibility < ctx.min_visibility then continue
468 if mproperty isa MAttribute then continue
470 mproperty.intro.html_link(self)
472 mproperty.intro.mclassdef.mclass.html_link(self)
485 private var mmodule: MModule
486 private var mbuilder: ModelBuilder
488 init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
490 self.mmodule = mmodule
491 self.mbuilder = ctx.mbuilder
492 self.dot_dir = dot_dir
496 if mbuilder.mmodule2nmodule.has_key(mmodule) then
497 var nmodule = mbuilder.mmodule2nmodule[mmodule]
498 return "{mmodule.name} module | {nmodule.short_comment}"
500 return "{mmodule.name} module"
506 append("<li
><a href
='index.html'>Overview</a
></li
>")
507 append("<li
class='current'>{mmodule.name}</li
>")
508 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
513 append("<div
class='content'>")
514 append("<h1
>{mmodule.name}</h1
>")
515 append("<div
class='subtitle info'>")
516 mmodule.html_signature(self)
518 mmodule.html_full_comment(self)
525 private fun process_generate_dot do
526 # build poset with public owners
527 var poset = new POSet[MModule]
528 for mmodule in self.mmodule.in_importation.poset do
529 if mmodule.name == "<main
>" then continue
530 if mmodule.public_owner != null then continue
531 if not mmodule.in_importation < self.mmodule and not self.mmodule.in_importation < mmodule and mmodule != self.mmodule then continue
532 poset.add_node(mmodule)
533 for omodule in mmodule.in_importation.poset do
534 if mmodule == omodule then continue
535 if omodule.name == "<main
>" then continue
536 if omodule.public_owner != null then continue
537 if mmodule.in_importation < omodule then
538 poset.add_node(omodule)
539 poset.add_edge(mmodule, omodule)
545 var name = "dep_
{mmodule.name}"
546 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
")
547 for mmodule in poset do
548 if mmodule == self.mmodule then
549 op.append("\
"{mmodule.name}\"[shape
=box
,margin
=0.03];\n
")
551 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
553 for omodule in poset[mmodule].direct_greaters do
554 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
558 generate_dot(op.to_s, name, "Dependency graph
for module {mmodule.name}")
561 private fun sidebar do
562 append("<div
class='menu'>")
564 append("<h3
>Module Hierarchy</h3
>")
565 var dependencies = new Array[MModule]
566 for dep in mmodule.in_importation.greaters do
567 if dep == mmodule or dep.public_owner != null then continue
568 dependencies.add(dep)
570 if dependencies.length > 0 then
571 append("<h4
>All dependencies
</h4
>")
572 display_module_list(dependencies)
574 var clients = new Array[MModule]
575 for dep in mmodule.in_importation.smallers do
576 if dep.name == "<main
>" then continue
577 if dep == mmodule or dep.public_owner != null then continue
580 if clients.length > 0 then
581 append("<h4
>All clients
</h4
>")
582 display_module_list(clients)
585 if ctx.min_visibility < protected_visibility then
586 if mmodule.in_nesting.direct_greaters.length > 0 then
588 append("<h3
>Nested Modules</h3
>")
589 display_module_list(mmodule.in_nesting.direct_greaters.to_a)
596 private fun display_module_list(list: Array[MModule]) do
598 var sorter = new MModuleNameSorter
608 # display the class column
609 private fun classes do
610 var intro_mclasses = mmodule.intro_mclasses
611 var redef_mclasses = mmodule.redef_mclasses
612 var all_mclasses = new HashSet[MClass]
613 for m in mmodule.in_nesting.greaters do
614 all_mclasses.add_all(m.intro_mclasses)
615 all_mclasses.add_all(m.redef_mclasses)
617 all_mclasses.add_all(intro_mclasses)
618 all_mclasses.add_all(redef_mclasses)
620 var sorted = new Array[MClass]
621 sorted.add_all(all_mclasses)
622 var sorter = new MClassNameSorter
624 append("<div
class='module'>")
625 append("<article
class='classes filterable'>")
626 append("<h2
>Classes</h2
>")
629 if c.visibility < ctx.min_visibility then continue
630 if redef_mclasses.has(c) and c.intro_mmodule.public_owner != mmodule then
631 append("<li
class='redef'>")
632 append("<span title
='refined in this module'>R
</span
>")
634 append("<li
class='intro'>")
635 append("<span title
='introduced in this module'>I
</span
>")
645 # display the property column
646 private fun properties do
648 var mpropdefs = new HashSet[MPropDef]
649 for m in mmodule.in_nesting.greaters do
650 for c in m.mclassdefs do mpropdefs.add_all(c.mpropdefs)
652 for c in mmodule.mclassdefs do mpropdefs.add_all(c.mpropdefs)
653 var sorted = mpropdefs.to_a
654 var sorter = new MPropDefNameSorter
656 # display properties in one column
657 append("<article
class='properties filterable'>")
658 append("<h2
>Properties</h2
>")
660 for mprop in sorted do
661 if mprop isa MAttributeDef then continue
662 if mprop.mproperty.visibility < ctx.min_visibility then continue
663 mprop.html_list_item(self)
674 private var mclass: MClass
675 private var vtypes = new HashSet[MVirtualTypeDef]
676 private var consts = new HashSet[MMethodDef]
677 private var meths = new HashSet[MMethodDef]
678 private var inherited = new HashSet[MPropDef]
680 init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
683 self.dot_dir = dot_dir
686 for mclassdef in mclass.mclassdefs do
687 for mpropdef in mclassdef.mpropdefs do
688 if mpropdef.mproperty.visibility < ctx.min_visibility then continue
689 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
690 if mpropdef isa MMethodDef then
691 if mpropdef.mproperty.is_init then
699 # get inherited properties
700 for pclass in mclass.in_hierarchy(ctx.mainmodule).greaters do
701 if pclass == mclass then continue
702 for pclassdef in pclass.mclassdefs do
703 for mprop in pclassdef.intro_mproperties do
704 var mpropdef = mprop.intro
705 if mprop.visibility < ctx.min_visibility then continue
706 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
707 if mpropdef isa MMethodDef then
708 if mpropdef.mproperty.is_init then
714 inherited.add(mpropdef)
721 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
722 if nclass isa AStdClassdef then
723 return "{mclass.name} class | {nclass.short_comment}"
725 return "{mclass.name} class"
731 append("<li
><a href
='index.html'>Overview</a
></li
>")
732 var public_owner = mclass.public_owner
733 if public_owner is null then
735 mclass.intro_mmodule.html_link(self)
739 public_owner.html_link(self)
742 append("<li
class='current'>{mclass.name}</li
>")
743 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
747 append("<div
class='menu'>")
751 append("<div
class='content'>")
756 private fun properties_column do
757 var sorter = new MPropDefNameSorter
758 append("<nav
class='properties filterable'>")
759 append("<h3
>Properties</h3
>")
761 if vtypes.length > 0 then
762 var vts = new Array[MVirtualTypeDef]
765 append("<h4
>Virtual Types</h4
>")
768 mprop.html_sidebar_item(self)
773 if consts.length > 0 then
774 var cts = new Array[MMethodDef]
777 append("<h4
>Constructors</h4
>")
780 if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
781 mprop.html_sidebar_item(self)
786 if meths.length > 0 then
787 var mts = new Array[MMethodDef]
790 append("<h4
>Methods</h4
>")
793 if mclass.name != "Object" and mprop.mproperty.intro_mclassdef.mclass.name == "Object" and mprop.mproperty.visibility <= protected_visibility then continue
794 mprop.html_sidebar_item(self)
801 private fun inheritance_column do
802 var sorted = new Array[MClass]
803 var sorterp = new MClassNameSorter
805 append("<h3
>Inheritance</h3
>")
806 var greaters = mclass.in_hierarchy(ctx.mainmodule).greaters.to_a
807 if greaters.length > 1 then
808 ctx.mainmodule.linearize_mclasses(greaters)
809 append("<h4
>Superclasses</h4
>")
811 for sup in greaters do
812 if sup == mclass then continue
819 var smallers = mclass.in_hierarchy(ctx.mainmodule).smallers.to_a
820 var direct_smallers = mclass.in_hierarchy(ctx.mainmodule).direct_smallers.to_a
821 if smallers.length <= 1 then
822 append("<h4
>No Known Subclasses</h4
>")
823 else if smallers.length <= 100 then
824 ctx.mainmodule.linearize_mclasses(smallers)
825 append("<h4
>Subclasses</h4
>")
827 for sub in smallers do
828 if sub == mclass then continue
834 else if direct_smallers.length <= 100 then
835 ctx.mainmodule.linearize_mclasses(direct_smallers)
836 append("<h4
>Direct Subclasses Only</h4
>")
838 for sub in direct_smallers do
839 if sub == mclass then continue
846 append("<h4
>Too much
Subclasses to list
</h4
>")
851 private fun class_doc do
853 append("<h1
>{mclass.signature}</h1
>")
854 append("<div
class='subtitle info'>")
855 mclass.html_full_signature(self)
858 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
859 append("<div style
=\
"float: right;\"><a id
=\
"lblDiffCommit\"></a
></div
>")
860 append("<section
class='description'>")
861 if nclass isa AStdClassdef and not nclass.full_comment.is_empty then append("<pre
class=\
"text_label\" title
=\
"122\" name
=\
"\" tag
=\
"{mclass.mclassdefs.first.location.to_s}\" type=\
"2\">{nclass.full_comment}</pre
><textarea id
=\
"fileContent\" class=\
"edit\" cols
=\
"76\" rows
=\
"1\" style
=\
"display: none;\"></textarea
><a id
=\
"cancelBtn\" style
=\
"display: none;\">Cancel</a
><a id
=\
"commitBtn\" style
=\
"display: none;\">Commit</a
><pre id
=\
"preSave\" class=\
"text_label\" type=\
"2\"></pre
>")
865 var concern2meths = new ArrayMap[MModule, Array[MMethodDef]]
866 var sorted_meths = new Array[MMethodDef]
867 var sorted = new Array[MModule]
868 sorted_meths.add_all(meths)
869 ctx.mainmodule.linearize_mpropdefs(sorted_meths)
871 if inherited.has(meth) then continue
872 var mmodule = meth.mclassdef.mmodule
873 if not concern2meths.has_key(mmodule) then
875 concern2meths[mmodule] = new Array[MMethodDef]
877 concern2meths[mmodule].add(meth)
879 var sections = new ArrayMap[MModule, Array[MModule]]
880 for mmodule in concern2meths.keys do
881 var owner = mmodule.public_owner
882 if owner == null then owner = mmodule
883 if not sections.has_key(owner) then sections[owner] = new Array[MModule]
884 if owner != mmodule then sections[owner].add(mmodule)
886 append("<section
class='concerns'>")
887 append("<h2
class='section-header'>Concerns</h2
>")
889 for owner, mmodules in sections do
890 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
892 if nowner.short_comment.is_empty then
893 append("<a href
=\
"#{owner.anchor}\">{owner.name}</a
>")
895 append("<a href
=\
"#{owner.anchor}\">{owner.name}</a
>: {nowner.short_comment}")
897 if not mmodules.is_empty then
899 for mmodule in mmodules do
900 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
901 if nmodule.short_comment.is_empty then
902 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.name}</a
></li
>")
904 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.name}</a
>: {nmodule.short_comment}</li
>")
914 var prop_sorter = new MPropDefNameSorter
915 var lmmodule = new List[MModule]
916 # virtual and formal types
917 var local_vtypes = new Array[MVirtualTypeDef]
918 for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
919 if local_vtypes.length > 0 or mclass.arity > 0 then
920 append("<section
class='types'>")
921 append("<h2
>Formal and Virtual Types</h2
>")
923 if mclass.arity > 0 and nclass isa AStdClassdef then
924 for ft, bound in mclass.parameter_types do
925 append("<article id
='FT_{ft}'>")
926 append("<h3
class='signature'>{ft}: ")
927 bound.html_link(self)
929 append("<div
class=\
"info\">formal generic
type</div
>")
934 prop_sorter.sort(local_vtypes)
935 for prop in local_vtypes do prop.html_full_desc(self)
939 var local_consts = new Array[MMethodDef]
940 for const in consts do if not inherited.has(const) then local_consts.add(const)
941 prop_sorter.sort(local_consts)
942 if local_consts.length > 0 then
943 append("<section
class='constructors'>")
944 append("<h2
class='section-header'>Constructors</h2
>")
945 for prop in local_consts do prop.html_full_desc(self)
949 if not concern2meths.is_empty then
950 append("<section
class='methods'>")
951 append("<h2
class='section-header'>Methods</h2
>")
952 for owner, mmodules in sections do
953 append("<a id
=\
"{owner.anchor}\"></a
>")
954 if owner != mclass.intro_mmodule and owner != mclass.public_owner then
955 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
956 append("<h3
class=\
"concern-toplevel\">Methods refined
in ")
957 owner.html_link(self)
959 append("<p
class=\
"concern-doc\">")
960 owner.html_link(self)
961 if not nowner.short_comment.is_empty then
962 append(": {nowner.short_comment}")
966 if concern2meths.has_key(owner) then
967 var mmethods = concern2meths[owner]
968 prop_sorter.sort(mmethods)
969 for prop in mmethods do prop.html_full_desc(self)
971 for mmodule in mmodules do
972 append("<a id
=\
"{mmodule.anchor}\"></a
>")
973 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
974 if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
975 append("<p
class=\
"concern-doc\">")
976 mmodule.html_link(self)
977 if not nmodule.short_comment.is_empty then
978 append(": {nmodule.short_comment}")
982 var mmethods = concern2meths[mmodule]
983 prop_sorter.sort(mmethods)
984 for prop in mmethods do prop.html_full_desc(self)
988 # inherited properties
989 if inherited.length > 0 then
990 var sorted_inherited = new Array[MPropDef]
991 sorted_inherited.add_all(inherited)
992 ctx.mainmodule.linearize_mpropdefs(sorted_inherited)
993 var classes = new ArrayMap[MClass, Array[MPropDef]]
994 for mmethod in sorted_inherited.reversed do
995 var mclass = mmethod.mclassdef.mclass
996 if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
997 classes[mclass].add(mmethod)
999 append("<h3
>Inherited Properties</h3
>")
1000 for c, mmethods in classes do
1001 prop_sorter.sort(mmethods)
1002 append("<p
>Defined in ")
1005 for i in [0..mmethods.length[ do
1006 var mmethod = mmethods[i]
1007 mmethod.html_link(self)
1008 if i <= mmethods.length - 1 then append(", ")
1013 append("</section
>")
1016 private fun process_generate_dot do
1017 var pe = ctx.class_hierarchy[mclass]
1018 var cla = new HashSet[MClass]
1019 var sm = new HashSet[MClass]
1020 var sm2 = new HashSet[MClass]
1022 while cla.length + sm.length < 10 and sm.length > 0 do
1026 sm2.add_all(pe.poset[x].direct_smallers)
1032 cla.add_all(pe.greaters)
1035 var name = "dep_
{mclass.name}"
1036 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
")
1039 op.append("\
"{c.name}\"[shape
=box
,margin
=0.03];\n
")
1041 op.append("\
"{c.name}\"[URL=\
"{c.url}\"];\n
")
1043 for c2 in pe.poset[c].direct_greaters do
1044 if not cla.has(c2) then continue
1045 op.append("\
"{c.name}\"->\
"{c2.name}\";\n
")
1047 if not pe.poset[c].direct_smallers.is_empty then
1049 for c2 in pe.poset[c].direct_smallers do
1050 if cla.has(c2) then others = false
1053 op.append("\
"{c.name}...\"[label=\
"\"];\n
")
1054 op.append("\
"{c.name}...\"->\
"{c.name}\"[style
=dotted
];\n
")
1059 generate_dot(op.to_s, name, "Dependency graph
for class {mclass.name}")
1068 # URL to nitdoc page
1070 if url_cache == null then
1071 var res = new Buffer
1072 res.append("module_
")
1073 var mowner = public_owner
1074 if mowner != null then
1075 res.append("{public_owner.name}_
")
1077 res.append("{self.name}.html
")
1078 url_cache = res.to_s
1080 return url_cache.as(not null)
1082 private var url_cache: nullable String
1084 # html anchor id to the module in a nitdoc page
1085 fun anchor: String do
1086 if anchor_cache == null then
1087 var res = new Buffer
1089 var mowner = public_owner
1090 if mowner != null then
1091 res.append("{public_owner.name}_
")
1093 res.append(self.name)
1094 anchor_cache = res.to_s
1096 return anchor_cache.as(not null)
1098 private var anchor_cache: nullable String
1100 # Return a link (html a tag) to the nitdoc module page
1101 fun html_link(page: NitdocPage) do
1102 if html_link_cache == null then
1103 var res = new Buffer
1104 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1105 res.append("<a href
='{url}' title
='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{name}</a
>")
1107 res.append("<a href
='{url}'>{name}</a
>")
1109 html_link_cache = res.to_s
1111 page.append(html_link_cache.as(not null))
1113 private var html_link_cache: nullable String
1115 # Return the module signature decorated with html
1116 fun html_signature(page: NitdocPage) do
1117 page.append("<span
>module ")
1118 html_full_namespace(page)
1119 page.append("</span
>")
1122 # Return the module full namespace decorated with html
1123 fun html_full_namespace(page: NitdocPage) do
1124 page.append("<span
>")
1125 var mowner = public_owner
1126 if mowner != null then
1127 public_owner.html_namespace(page)
1131 page.append("</span
>")
1134 # Return the module full namespace decorated with html
1135 fun html_namespace(page: NitdocPage) do
1136 page.append("<span
>")
1137 var mowner = public_owner
1138 if mowner != null then
1139 public_owner.html_namespace(page)
1143 page.append("</span
>")
1146 # Return the full comment of the module decorated with html
1147 fun html_full_comment(page: NitdocPage) do
1148 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1149 page.append("<div id
='description'>")
1150 page.append("<pre
class='text_label'>{page.ctx.mbuilder.mmodule2nmodule[self].full_comment}</pre
>")
1151 page.append("<textarea
class='edit' rows
='1' cols
='76' id
='fileContent'></textarea
>")
1152 page.append("<a id
='cancelBtn'>Cancel</a
>")
1153 page.append("<a id
='commitBtn'>Commit</a
>")
1154 page.append("<pre
class='text_label' id
='preSave' type='2'></pre
>")
1155 page.append("</div
>")
1161 # Return the module signature decorated with html
1162 fun html_full_signature(page: NitdocPage) do
1163 if visibility < public_visibility then page.append("{visibility.to_s} ")
1164 page.append("{kind} ")
1165 html_namespace(page)
1168 # name with formal parameter
1170 private fun signature: String do
1172 return "{name}[{intro.parameter_names.join(", ")}]"
1178 # Return a link (html a tag) to the nitdoc class page
1179 fun html_link(page: NitdocPage) do
1180 if html_link_cache == null then
1181 var res = new Buffer
1182 res.append("<a href
='{url}'")
1183 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1184 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1185 if nclass isa AStdClassdef then
1186 res.append(" title
=\
"{nclass.short_comment}\"")
1189 res.append(">{signature}</a
>")
1190 html_link_cache = res.to_s
1192 page.append(html_link_cache.as(not null))
1194 private var html_link_cache: nullable String
1196 # Return the class namespace decorated with html
1197 fun html_namespace(page: NitdocPage) do
1198 intro_mmodule.html_namespace(page)
1199 page.append("::<span
>")
1201 page.append("</span
>")
1205 return "class_
{public_owner}_
{name}.html
"
1208 # Escape name for html output
1209 redef fun name do return super.html_escape
1212 redef class MProperty
1213 # Return the property namespace decorated with html
1214 fun html_namespace(page: NitdocPage) do
1215 intro_mclassdef.mclass.html_namespace(page)
1216 page.append("::<span
>")
1217 intro.html_link(page)
1218 page.append("</span
>")
1221 # Escape name for html output
1222 redef fun name do return super.html_escape
1226 fun html_link(page: NitdocPage) is abstract
1229 redef class MClassType
1230 redef fun html_link(page) do mclass.html_link(page)
1233 redef class MNullableType
1234 redef fun html_link(page) do
1235 page.append("nullable ")
1236 mtype.html_link(page)
1240 redef class MGenericType
1241 redef fun html_link(page) do
1242 page.append("<a href
='{mclass.url}'>{mclass.name}</a
>[")
1243 for i in [0..arguments.length[ do
1244 arguments[i].html_link(page)
1245 if i < arguments.length - 1 then page.append(", ")
1251 redef class MParameterType
1252 redef fun html_link(page) do
1253 var name = mclass.intro.parameter_names[rank]
1254 page.append("<a href
='{mclass.url}#FT_{name}' title
='formal type'>{name}</a
>")
1258 redef class MVirtualType
1259 redef fun html_link(page) do mproperty.intro.html_link(page)
1262 redef class MClassDef
1263 # Return the classdef namespace decorated with html
1264 fun html_namespace(page: NitdocPage) do
1265 mmodule.html_full_namespace(page)
1266 page.append("::<span
>")
1267 mclass.html_link(page)
1268 page.append("</span
>")
1272 redef class MPropDef
1274 if url_cache == null then
1275 url_cache = "{mclassdef.mclass.url}#{anchor}"
1277 return url_cache
.as(not null)
1279 private var url_cache
: nullable String
1281 fun anchor
: String do
1282 if anchor_cache
== null then
1283 anchor_cache
= "PROP_{mclassdef.mclass.public_owner.name}_{mproperty.name}"
1285 return anchor_cache
.as(not null)
1287 private var anchor_cache
: nullable String
1289 # Return a link (html a tag) to the nitdoc class page
1290 fun html_link
(page
: NitdocPage) do
1291 if html_link_cache
== null then
1292 var res
= new Buffer
1293 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1294 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1295 res
.append
("<a href=\"{url}\
" title=\"{nprop.short_comment}\
">{mproperty.name}</a>")
1297 res
.append
("<a href=\"{url}\
">{mproperty.name}</a>")
1299 html_link_cache
= res
.to_s
1301 page
.append
(html_link_cache
.as(not null))
1303 private var html_link_cache
: nullable String
1305 # Return a list item for the mpropdef
1306 private fun html_list_item
(page
: NitdocPage) do
1308 page
.append
("<li class='intro'>")
1309 page
.append
("<span title='introduction'>I</span> ")
1311 page
.append
("<li class='redef'>")
1312 page
.append
("<span title='redefinition'>R</span> ")
1316 mclassdef
.mclass
.html_link
(page
)
1318 page
.append
("</li>")
1321 # Return a list item for the mpropdef
1322 private fun html_sidebar_item
(page
: NitdocClass) do
1323 if is_intro
and mclassdef
.mclass
== page
.mclass
then
1324 page
.append
("<li class='intro'>")
1325 page
.append
("<span title='Introduced'>I</span>")
1326 else if is_intro
and mclassdef
.mclass
!= page
.mclass
then
1327 page
.append
("<li class='inherit'>")
1328 page
.append
("<span title='Inherited'>H</span>")
1330 page
.append
("<li class='redef'>")
1331 page
.append
("<span title='Redefined'>R</span>")
1334 page
.append
("</li>")
1337 private fun html_full_desc
(page
: NitdocClass) is abstract
1338 private fun html_info
(page
: NitdocClass) is abstract
1340 fun full_name
: String do
1341 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1344 private fun html_inheritance
(page
: NitdocClass) do
1346 page
.append
("<p class='info'>")
1347 page
.ctx
.mainmodule
.linearize_mpropdefs
(mproperty
.mpropdefs
)
1348 var previous_defs
= new Array[MPropDef]
1349 var next_defs
= new Array[MPropDef]
1350 var self_passed
= false
1351 for def
in mproperty
.mpropdefs
do
1356 if not self_passed
then
1357 if def
.mclassdef
.mclass
.in_hierarchy
(page
.ctx
.mainmodule
) < page
.mclass
then continue
1358 if def
.is_intro
then continue
1359 previous_defs
.add
(def
)
1361 if page
.mclass
.in_hierarchy
(page
.ctx
.mainmodule
) < def
.mclassdef
.mclass
then continue
1365 page
.append
("defined by ")
1366 mclassdef
.mmodule
.html_full_namespace
(page
)
1367 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1368 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1370 if not is_intro
then
1371 page
.append
(", introduced by ")
1372 mproperty
.intro
.mclassdef
.mclass
.html_link
(page
)
1373 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1374 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1377 if not previous_defs
.is_empty
then
1378 page
.append
(", inherited from ")
1379 for i
in [0..previous_defs
.length
[ do
1380 var def
= previous_defs
[i
]
1381 def
.mclassdef
.mclass
.html_link
(page
)
1382 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(def
) then
1383 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1386 if i
< previous_defs
.length
- 1 then page
.append
(", ")
1389 if not next_defs
.is_empty
then
1390 page
.append
(", redefined by ")
1391 for i
in [0..next_defs
.length
[ do
1392 var def
= next_defs
[i
]
1393 def
.mclassdef
.mclass
.html_link
(page
)
1394 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(def
) then
1395 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1397 if i
< next_defs
.length
- 1 then page
.append
(", ")
1400 page
.append
(".</p>")
1403 private fun html_comment
(page
: NitdocClass) do
1404 if not page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then return
1405 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1406 page
.append
("<div class='description'>")
1407 if not is_intro
and page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(mproperty
.intro
) then
1408 var intro_nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[mproperty
.intro
]
1409 page
.append
("<p>from ")
1410 mproperty
.html_namespace
(page
)
1412 if intro_nprop
.full_comment
== "" then
1413 page
.append
("<a class=\"newComment\
" title=\"32\
" tag=\"\
">New Comment</a>")
1415 page
.append
("<pre class=\"text_label\
" title=\"\
" name=\"\
" tag=\"\
" type=\"1\
">{intro_nprop.full_comment}</pre>")
1417 page
.append
("<p>from ")
1418 mclassdef
.html_namespace
(page
)
1421 if nprop
.full_comment
== "" then
1422 page
.append
("<a class=\"newComment\
" title=\"32\
" tag=\"\
">New Comment</a>")
1424 page
.append
("<pre class=\"text_label\
" title=\"\
" name=\"\
" tag=\"\
" type=\"1\
">{nprop.full_comment}</pre>")
1426 page
.append
("<textarea id=\"fileContent\
" class=\"edit\
" cols=\"76\
" rows=\"1\
" style=\"display
: none
;\
"></textarea><a id=\"cancelBtn\
" style=\"display
: none
;\
">Cancel</a><a id=\"commitBtn\
" style=\"display
: none
;\
">Commit</a><pre id=\"preSave\
" class=\"text_label\
" type=\"2\
"></pre>")
1427 html_inheritance
(page
)
1428 page
.append
("</div>")
1432 redef class MMethodDef
1433 redef fun html_full_desc
(page
) do
1434 var classes
= new Array[String]
1435 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= page
.mclass
1436 if mproperty
.is_init
then
1441 if is_redef
then classes
.add
("redef")
1442 classes
.add
(mproperty
.visibility
.to_s
)
1443 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1444 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1445 page
.append
("<h3 class='signature'>{mproperty.name}")
1446 msignature
.html_signature
(page
)
1447 page
.append
("</h3>")
1449 page
.append
("<h3 class='signature'>init")
1450 msignature
.html_signature
(page
)
1451 page
.append
("</h3>")
1455 page
.append
("</article>")
1458 redef fun html_info
(page
) do
1459 page
.append
("<div class='info'>")
1460 if mproperty
.visibility
< public_visibility
then page
.append
("{mproperty.visibility.to_s} ")
1461 if mproperty
.intro_mclassdef
.mclass
!= page
.mclass
then page
.append
("redef ")
1462 if mproperty
.is_init
then
1463 page
.append
("init ")
1467 mproperty
.html_namespace
(page
)
1468 page
.append
("</div>")
1469 page
.append
("<div style=\"float
: right
;\
"><a id=\"lblDiffCommit\
"></a></div>")
1473 redef class MVirtualTypeDef
1474 redef fun html_full_desc
(page
) do
1475 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= page
.mclass
1476 var classes
= new Array[String]
1478 if is_redef
then classes
.add
("redef")
1479 classes
.add
(mproperty
.visibility
.to_s
)
1480 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1481 page
.append
("<h3 class='signature'>{mproperty.name}: ")
1482 bound
.html_link
(page
)
1483 page
.append
("</h3>")
1486 page
.append
("</article>")
1489 redef fun html_info
(page
) do
1490 page
.append
("<div class='info'>")
1491 if mproperty
.intro_mclassdef
.mclass
!= page
.mclass
then page
.append
("redef ")
1492 page
.append
("type ")
1493 mproperty
.html_namespace
(page
)
1494 page
.append
("</div>")
1495 page
.append
("<div style=\"float
: right
;\
"><a id=\"lblDiffCommit\
"></a></div>")
1499 redef class MSignature
1500 private fun html_signature
(page
: NitdocPage) do
1501 if not mparameters
.is_empty
then
1503 for i
in [0..mparameters
.length
[ do
1504 mparameters
[i
].html_link
(page
)
1505 if i
< mparameters
.length
- 1 then page
.append
(", ")
1509 if return_mtype
!= null then
1511 return_mtype
.html_link
(page
)
1516 redef class MParameter
1517 private fun html_link
(page
: NitdocPage) do
1518 page
.append
("{name}: ")
1519 mtype
.html_link
(page
)
1520 if is_vararg
then page
.append
("...")
1529 private fun short_comment
: String do
1530 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1531 return n_moduledecl
.n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1536 private fun full_comment
: String do
1537 var res
= new Buffer
1538 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1539 for t
in n_moduledecl
.n_doc
.n_comment
do
1540 res
.append
(t
.text
.substring_from
(1).html_escape
)
1547 redef class AStdClassdef
1548 private fun short_comment
: String do
1549 if n_doc
!= null then return n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1553 private fun full_comment
: String do
1554 var res
= new Buffer
1555 if n_doc
!= null then
1556 for t
in n_doc
.n_comment
do res
.append
(t
.text
.substring_from
(1).html_escape
)
1562 redef class APropdef
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 var nitdoc
= new NitdocContext
1578 nitdoc
.generate_nitdoc