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 abstract_compiler
22 # The NitdocContext contains all the knowledge used for doc generation
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")
50 self.arguments
= option_context
.rest
51 option_context
.options
.clear
52 option_context
.add_option
(opt_dir
)
53 option_context
.add_option
(opt_source
)
54 option_context
.add_option
(opt_sharedir
)
55 option_context
.add_option
(opt_nodot
)
56 option_context
.add_option
(opt_private
)
57 option_context
.add_option
(opt_custom_title
)
58 option_context
.add_option
(opt_custom_footer_text
)
59 option_context
.add_option
(opt_custom_overview_text
)
60 option_context
.add_option
(opt_custom_menu_items
)
63 if arguments
.length
< 1 then
69 mbuilder
= new ModelBuilder(model
, self)
70 # Here we load an process all modules passed on the command line
71 var mmodules
= mbuilder
.parse_and_build
(arguments
)
72 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
84 redef 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 var content
= new Buffer
161 content
.append
("var entries = \{ ")
163 for mmodule
in model
.mmodules
do
164 content
.append
("\"{mmodule.name}\
": [")
165 content
.append
("\{txt: \"{mmodule.name}\", url
:\
"{mmodule.url}\" \
},")
168 for mclass in model.mclasses do
169 if mclass.visibility < min_visibility then continue
170 content.append("\
"{mclass.name}\": [")
171 content.append("\
{txt: \"{mclass.name}\
", url:\"{mclass.url}\
" \},")
174 var name2mprops
= new HashMap[String, Set[MPropDef]]
175 for mproperty
in model
.mproperties
do
176 if mproperty
.visibility
< min_visibility
then continue
177 if mproperty
isa MAttribute then continue
178 if not name2mprops
.has_key
(mproperty
.name
) then name2mprops
[mproperty
.name
] = new HashSet[MPropDef]
179 name2mprops
[mproperty
.name
].add_all
(mproperty
.mpropdefs
)
181 for mproperty
, mpropdefs
in name2mprops
do
182 content
.append
("\"{mproperty}\
": [")
183 for mpropdef
in mpropdefs
do
184 content
.append
("\{txt: \"{mpropdef.full_name}\", url
:\
"{mpropdef.url}\" \
},")
189 content.append(" \
};")
190 file.write(content.to_s)
197 abstract class NitdocPage
200 var dot_dir: nullable String
201 var source: nullable String
202 var ctx: NitdocContext
204 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
='quicksearch-list.js'></script
>")
213 append("<script
type='text/javascript' src
='scripts/js-facilities.js'></script
>")
214 append("<link rel
='stylesheet' href
='styles/main.css' type='text/css' media
='screen'/>")
216 if ctx.opt_custom_title.value != null then
217 title = " | {ctx.opt_custom_title.value.to_s}"
219 append("<title
>{self.title}{title}</title
>")
222 protected fun menu do
223 if ctx.opt_custom_menu_items.value != null then
224 append(ctx.opt_custom_menu_items.value.to_s)
228 protected fun title: String is abstract
230 protected fun header do
232 append("<nav
class='main'>")
235 append("<li id
='liGitHub'>")
236 append("<a
class='btn' id
='logGitHub'>")
237 append("<img id
='imgGitHub' src
='resources/icons/github-icon.png' alt
='GitHub'/>")
239 append("<div
class='popover bottom'>")
240 append("<div
class='arrow'> 
;</div
>")
241 append("<div
class='githubTitle'>")
242 append("<h3
>Github Sign In</h3
>")
245 append("<label id
='lbloginGit'>Username</label>")
246 append("<input id
='loginGit' name
='login' type='text'/>")
247 append("<label id
='logginMessage'>Hello ")
248 append("<a id
='githubAccount'><strong id
='nickName'></strong
></a
>")
252 append("<label id
='lbpasswordGit'>Password</label>")
253 append("<input id
='passwordGit' name
='password' type='password'/>")
254 append("<div id
='listBranches'>")
255 append("<label id
='lbBranches'>Branch</label>")
256 append("<select
class='dropdown' id
='dropBranches' name
='dropBranches' tabindex
='1'></select
>")
260 append("<label id
='lbrepositoryGit'>Repository</label>")
261 append("<input id
='repositoryGit' name
='repository' type='text'/>")
264 append("<label id
='lbbranchGit'>Branch</label>")
265 append("<input id
='branchGit' name
='branch' type='text'/>")
268 append("<a id
='signIn'>Sign In</a
>")
277 protected fun content is abstract
279 protected fun footer do
280 if ctx.opt_custom_footer_text.value != null then
281 append("<footer
>{ctx.opt_custom_footer_text.value.to_s}</footer
>")
285 # Generate a clickable graphviz image using a dot content
286 protected fun generate_dot(dot: String, name: String, alt: String) do
287 var output_dir = dot_dir
288 if output_dir == null then return
289 var file = new OFStream.open("{output_dir}/{name}.dot
")
292 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
; \
}")
293 append("<article
class='graph'>")
294 append("<img src
='{name}.png' usemap
='#{name}' style
='margin:auto' alt
='{alt}'/>")
296 var fmap = new IFStream.open("{output_dir}/{name}.map
")
297 append(fmap.read_all)
301 # Add a (source) link for a given location
302 protected fun show_source(l: Location): String
304 if source == null then
305 return "({l.file.filename.simplify_path})"
307 # THIS IS JUST UGLY ! (but there is no replace yet)
308 var x = source.split_with("%f
")
309 source = x.join(l.file.filename.simplify_path)
310 x = source.split_with("%l
")
311 source = x.join(l.line_start.to_s)
312 x = source.split_with("%L
")
313 source = x.join(l.line_end.to_s)
314 return " (<a href
=\
"{source.to_s}\">source
</a
>)"
318 # Render the page as a html string
319 fun render: String do
320 append("<!DOCTYPE html
>")
326 append("<div
class='page'>")
334 # Save html page in the specified file
335 fun save(file: String) do
336 var out = new OFStream.open(file)
345 private var mbuilder: ModelBuilder
346 private var mmodules = new Array[MModule]
348 init(ctx: NitdocContext, dot_dir: nullable String) do
350 self.mbuilder = ctx.mbuilder
351 self.dot_dir = dot_dir
353 var mmodules = new HashSet[MModule]
354 for mmodule in mbuilder.model.mmodules do
355 if mmodule.name == "<main
>" then continue
356 var owner = mmodule.public_owner
357 if owner != null then
360 mmodules.add(mmodule)
364 var sorter = new MModuleNameSorter
365 self.mmodules.add_all(mmodules)
366 sorter.sort(self.mmodules)
369 redef fun title do return "Overview"
373 append("<li
class='current'>Overview</li
>")
374 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
378 append("<div
class='content fullpage'>")
379 var title = "Overview"
380 if ctx.opt_custom_title.value != null then
381 title = ctx.opt_custom_title.value.to_s
383 append("<h1
>{title}</h1
>")
385 if ctx.opt_custom_overview_text.value != null then
386 text = ctx.opt_custom_overview_text.value.to_s
388 append("<article
class='overview'>{text}</article
>")
389 append("<article
class='overview'>")
391 append("<h2
>Modules</h2
>")
393 for mmodule in mmodules do
394 if mbuilder.mmodule2nmodule.has_key(mmodule) then
395 var amodule = mbuilder.mmodule2nmodule[mmodule]
397 mmodule.html_link(self)
398 append(" 
;{amodule.short_comment}</li
>")
408 private fun process_generate_dot do
409 # build poset with public owners
410 var poset = new POSet[MModule]
411 for mmodule in mmodules do
412 poset.add_node(mmodule)
413 for omodule in mmodules do
414 if mmodule == omodule then continue
415 if mmodule.in_importation < omodule then
416 poset.add_node(omodule)
417 poset.add_edge(mmodule, omodule)
423 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
")
424 for mmodule in poset do
425 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
426 for omodule in poset[mmodule].direct_greaters do
427 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
431 generate_dot(op.to_s, "dep
", "Modules hierarchy
")
435 # The full index page
436 class NitdocFullindex
439 init(ctx: NitdocContext) do
444 redef fun title do return "Full Index"
448 append("<li
><a href
='index.html'>Overview</a
></li
>")
449 append("<li
class='current'>Full Index</li
>")
453 append("<div
class='content fullpage'>")
454 append("<h1
>Full Index</h1
>")
461 # Add to content modules column
462 private fun module_column do
463 var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
464 var sorter = new MModuleNameSorter
466 append("<article
class='modules filterable'>")
467 append("<h2
>Modules</h2
>")
469 for mmodule in sorted do
471 mmodule.html_link(self)
478 # Add to content classes modules
479 private fun classes_column do
480 var sorted = ctx.mbuilder.model.mclasses
481 var sorter = new MClassNameSorter
483 append("<article
class='modules filterable'>")
484 append("<h2
>Classes</h2
>")
486 for mclass in sorted do
487 if mclass.visibility < ctx.min_visibility then continue
489 mclass.html_link(self)
496 # Insert the properties column of fullindex page
497 private fun properties_column do
498 var sorted = ctx.mbuilder.model.mproperties
499 var sorter = new MPropertyNameSorter
501 append("<article
class='modules filterable'>")
502 append("<h2
>Properties</h2
>")
504 for mproperty in sorted do
505 if mproperty.visibility < ctx.min_visibility then continue
506 if mproperty isa MAttribute then continue
508 mproperty.intro.html_link(self)
510 mproperty.intro.mclassdef.mclass.html_link(self)
523 private var mmodule: MModule
524 private var mbuilder: ModelBuilder
526 init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
528 self.mmodule = mmodule
529 self.mbuilder = ctx.mbuilder
530 self.dot_dir = dot_dir
534 if mbuilder.mmodule2nmodule.has_key(mmodule) then
535 var nmodule = mbuilder.mmodule2nmodule[mmodule]
536 return "{mmodule.name} module | {nmodule.short_comment}"
538 return "{mmodule.name} module"
544 append("<li
><a href
='index.html'>Overview</a
></li
>")
545 append("<li
class='current'>{mmodule.name}</li
>")
546 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
551 append("<div
class='content'>")
552 append("<h1
>{mmodule.name}</h1
>")
553 append("<div
class='subtitle info'>")
554 mmodule.html_signature(self)
556 mmodule.html_full_comment(self)
563 private fun process_generate_dot do
564 # build poset with public owners
565 var poset = new POSet[MModule]
566 for mmodule in self.mmodule.in_importation.poset do
567 if mmodule.name == "<main
>" then continue
568 if mmodule.public_owner != null then continue
569 if not mmodule.in_importation < self.mmodule and not self.mmodule.in_importation < mmodule and mmodule != self.mmodule then continue
570 poset.add_node(mmodule)
571 for omodule in mmodule.in_importation.poset do
572 if mmodule == omodule then continue
573 if omodule.name == "<main
>" then continue
574 if omodule.public_owner != null then continue
575 if mmodule.in_importation < omodule then
576 poset.add_node(omodule)
577 poset.add_edge(mmodule, omodule)
583 var name = "dep_
{mmodule.name}"
584 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
")
585 for mmodule in poset do
586 if mmodule == self.mmodule then
587 op.append("\
"{mmodule.name}\"[shape
=box
,margin
=0.03];\n
")
589 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
591 for omodule in poset[mmodule].direct_greaters do
592 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
596 generate_dot(op.to_s, name, "Dependency graph
for module {mmodule.name}")
599 private fun sidebar do
600 append("<div
class='menu'>")
602 append("<h3
>Module Hierarchy</h3
>")
603 var dependencies = new Array[MModule]
604 for dep in mmodule.in_importation.greaters do
605 if dep == mmodule or dep.public_owner != null then continue
606 dependencies.add(dep)
608 if dependencies.length > 0 then
609 append("<h4
>All dependencies
</h4
>")
610 display_module_list(dependencies)
612 var clients = new Array[MModule]
613 for dep in mmodule.in_importation.smallers do
614 if dep.name == "<main
>" then continue
615 if dep == mmodule or dep.public_owner != null then continue
618 if clients.length > 0 then
619 append("<h4
>All clients
</h4
>")
620 display_module_list(clients)
623 if ctx.min_visibility < protected_visibility then
624 if mmodule.in_nesting.direct_greaters.length > 0 then
626 append("<h3
>Nested Modules</h3
>")
627 display_module_list(mmodule.in_nesting.direct_greaters.to_a)
634 private fun display_module_list(list: Array[MModule]) do
636 var sorter = new MModuleNameSorter
646 # display the class column
647 private fun classes do
648 var intro_mclasses = mmodule.intro_mclasses
649 var redef_mclasses = mmodule.redef_mclasses
650 var all_mclasses = new HashSet[MClass]
651 for m in mmodule.in_nesting.greaters do
652 all_mclasses.add_all(m.intro_mclasses)
653 all_mclasses.add_all(m.redef_mclasses)
655 all_mclasses.add_all(intro_mclasses)
656 all_mclasses.add_all(redef_mclasses)
658 var sorted = new Array[MClass]
659 sorted.add_all(all_mclasses)
660 var sorter = new MClassNameSorter
662 append("<div
class='module'>")
663 append("<article
class='classes filterable'>")
664 append("<h2
>Classes</h2
>")
667 if c.visibility < ctx.min_visibility then continue
668 if redef_mclasses.has(c) and c.intro_mmodule.public_owner != mmodule then
669 append("<li
class='redef'>")
670 append("<span title
='refined in this module'>R
</span
>")
672 append("<li
class='intro'>")
673 append("<span title
='introduced in this module'>I
</span
>")
683 # display the property column
684 private fun properties do
686 var mpropdefs = new HashSet[MPropDef]
687 for m in mmodule.in_nesting.greaters do
688 for c in m.mclassdefs do mpropdefs.add_all(c.mpropdefs)
690 for c in mmodule.mclassdefs do mpropdefs.add_all(c.mpropdefs)
691 var sorted = mpropdefs.to_a
692 var sorter = new MPropDefNameSorter
694 # display properties in one column
695 append("<article
class='properties filterable'>")
696 append("<h2
>Properties</h2
>")
698 for mprop in sorted do
699 if mprop isa MAttributeDef then continue
700 if mprop.mproperty.visibility < ctx.min_visibility then continue
701 mprop.html_list_item(self)
712 private var mclass: MClass
713 private var vtypes = new HashSet[MVirtualTypeDef]
714 private var consts = new HashSet[MMethodDef]
715 private var meths = new HashSet[MMethodDef]
716 private var inherited = new HashSet[MPropDef]
718 init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
721 self.dot_dir = dot_dir
724 for mclassdef in mclass.mclassdefs do
725 for mpropdef in mclassdef.mpropdefs do
726 if mpropdef.mproperty.visibility < ctx.min_visibility then continue
727 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
728 if mpropdef isa MMethodDef then
729 if mpropdef.mproperty.is_init then
737 # get inherited properties
738 for mprop in mclass.inherited_mproperties do
739 var mpropdef = mprop.intro
740 if mprop.visibility < ctx.min_visibility then continue
741 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
742 if mpropdef isa MMethodDef then
743 if mpropdef.mproperty.is_init then
749 inherited.add(mpropdef)
754 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
755 if nclass isa AStdClassdef then
756 return "{mclass.name} class | {nclass.short_comment}"
758 return "{mclass.name} class"
764 append("<li
><a href
='index.html'>Overview</a
></li
>")
765 var public_owner = mclass.public_owner
766 if public_owner is null then
768 mclass.intro_mmodule.html_link(self)
772 public_owner.html_link(self)
775 append("<li
class='current'>{mclass.name}</li
>")
776 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
780 append("<div
class='menu'>")
784 append("<div
class='content'>")
789 private fun properties_column do
790 var sorter = new MPropDefNameSorter
791 append("<nav
class='properties filterable'>")
792 append("<h3
>Properties</h3
>")
794 if vtypes.length > 0 then
795 var vts = new Array[MVirtualTypeDef]
798 append("<h4
>Virtual Types</h4
>")
801 mprop.html_sidebar_item(self)
806 if consts.length > 0 then
807 var cts = new Array[MMethodDef]
810 append("<h4
>Constructors</h4
>")
813 if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
814 mprop.html_sidebar_item(self)
819 if meths.length > 0 then
820 var mts = new Array[MMethodDef]
823 append("<h4
>Methods</h4
>")
826 if mclass.name != "Object" and mprop.mproperty.intro_mclassdef.mclass.name == "Object" and mprop.mproperty.visibility <= protected_visibility then continue
827 mprop.html_sidebar_item(self)
834 private fun inheritance_column do
835 var sorted = new Array[MClass]
836 var sorterp = new MClassNameSorter
838 append("<h3
>Inheritance</h3
>")
839 var greaters = mclass.in_hierarchy(ctx.mainmodule).greaters.to_a
840 if greaters.length > 1 then
841 ctx.mainmodule.linearize_mclasses(greaters)
842 append("<h4
>Superclasses</h4
>")
844 for sup in greaters do
845 if sup == mclass then continue
852 var smallers = mclass.in_hierarchy(ctx.mainmodule).smallers.to_a
853 var direct_smallers = mclass.in_hierarchy(ctx.mainmodule).direct_smallers.to_a
854 if smallers.length <= 1 then
855 append("<h4
>No Known Subclasses</h4
>")
856 else if smallers.length <= 100 then
857 ctx.mainmodule.linearize_mclasses(smallers)
858 append("<h4
>Subclasses</h4
>")
860 for sub in smallers do
861 if sub == mclass then continue
867 else if direct_smallers.length <= 100 then
868 ctx.mainmodule.linearize_mclasses(direct_smallers)
869 append("<h4
>Direct Subclasses Only</h4
>")
871 for sub in direct_smallers do
872 if sub == mclass then continue
879 append("<h4
>Too much
Subclasses to list
</h4
>")
884 private fun class_doc do
886 append("<h1
>{mclass.signature}</h1
>")
887 append("<div
class='subtitle info'>")
888 mclass.html_full_signature(self)
891 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
892 append("<div style
=\
"float: right;\"><a id
=\
"lblDiffCommit\"></a
></div
>")
893 append("<section
class='description'>")
894 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
>")
898 var concern2meths = new ArrayMap[MModule, Array[MMethodDef]]
899 var sorted_meths = new Array[MMethodDef]
900 var sorted = new Array[MModule]
901 sorted_meths.add_all(meths)
902 ctx.mainmodule.linearize_mpropdefs(sorted_meths)
904 if inherited.has(meth) then continue
905 var mmodule = meth.mclassdef.mmodule
906 if not concern2meths.has_key(mmodule) then
908 concern2meths[mmodule] = new Array[MMethodDef]
910 concern2meths[mmodule].add(meth)
912 var sections = new ArrayMap[MModule, Array[MModule]]
913 for mmodule in concern2meths.keys do
914 var owner = mmodule.public_owner
915 if owner == null then owner = mmodule
916 if not sections.has_key(owner) then sections[owner] = new Array[MModule]
917 if owner != mmodule then sections[owner].add(mmodule)
919 append("<section
class='concerns'>")
920 append("<h2
class='section-header'>Concerns</h2
>")
922 for owner, mmodules in sections do
923 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
925 if nowner.short_comment.is_empty then
926 append("<a href
=\
"#{owner.anchor}\">{owner.name}</a
>")
928 append("<a href
=\
"#{owner.anchor}\">{owner.name}</a
>: {nowner.short_comment}")
930 if not mmodules.is_empty then
932 for mmodule in mmodules do
933 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
934 if nmodule.short_comment.is_empty then
935 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.name}</a
></li
>")
937 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.name}</a
>: {nmodule.short_comment}</li
>")
947 var prop_sorter = new MPropDefNameSorter
948 var lmmodule = new List[MModule]
949 # virtual and formal types
950 var local_vtypes = new Array[MVirtualTypeDef]
951 for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
952 if local_vtypes.length > 0 or mclass.arity > 0 then
953 append("<section
class='types'>")
954 append("<h2
>Formal and Virtual Types</h2
>")
956 if mclass.arity > 0 and nclass isa AStdClassdef then
957 for ft, bound in mclass.parameter_types do
958 append("<article id
='FT_{ft}'>")
959 append("<h3
class='signature'>{ft}: ")
960 bound.html_link(self)
962 append("<div
class=\
"info\">formal generic
type</div
>")
967 prop_sorter.sort(local_vtypes)
968 for prop in local_vtypes do prop.html_full_desc(self)
972 var local_consts = new Array[MMethodDef]
973 for const in consts do if not inherited.has(const) then local_consts.add(const)
974 prop_sorter.sort(local_consts)
975 if local_consts.length > 0 then
976 append("<section
class='constructors'>")
977 append("<h2
class='section-header'>Constructors</h2
>")
978 for prop in local_consts do prop.html_full_desc(self)
982 if not concern2meths.is_empty then
983 append("<section
class='methods'>")
984 append("<h2
class='section-header'>Methods</h2
>")
985 for owner, mmodules in sections do
986 append("<a id
=\
"{owner.anchor}\"></a
>")
987 if owner != mclass.intro_mmodule and owner != mclass.public_owner then
988 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
989 append("<h3
class=\
"concern-toplevel\">Methods refined
in ")
990 owner.html_link(self)
992 append("<p
class=\
"concern-doc\">")
993 owner.html_link(self)
994 if not nowner.short_comment.is_empty then
995 append(": {nowner.short_comment}")
999 if concern2meths.has_key(owner) then
1000 var mmethods = concern2meths[owner]
1001 prop_sorter.sort(mmethods)
1002 for prop in mmethods do prop.html_full_desc(self)
1004 for mmodule in mmodules do
1005 append("<a id
=\
"{mmodule.anchor}\"></a
>")
1006 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
1007 if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
1008 append("<p
class=\
"concern-doc\">")
1009 mmodule.html_link(self)
1010 if not nmodule.short_comment.is_empty then
1011 append(": {nmodule.short_comment}")
1015 var mmethods = concern2meths[mmodule]
1016 prop_sorter.sort(mmethods)
1017 for prop in mmethods do prop.html_full_desc(self)
1021 # inherited properties
1022 if inherited.length > 0 then
1023 var sorted_inherited = new Array[MPropDef]
1024 sorted_inherited.add_all(inherited)
1025 ctx.mainmodule.linearize_mpropdefs(sorted_inherited)
1026 var classes = new ArrayMap[MClass, Array[MPropDef]]
1027 for mmethod in sorted_inherited.reversed do
1028 var mclass = mmethod.mclassdef.mclass
1029 if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
1030 classes[mclass].add(mmethod)
1032 append("<h3
>Inherited Properties</h3
>")
1033 for c, mmethods in classes do
1034 prop_sorter.sort(mmethods)
1035 append("<p
>Defined in ")
1038 for i in [0..mmethods.length[ do
1039 var mmethod = mmethods[i]
1040 mmethod.html_link(self)
1041 if i <= mmethods.length - 1 then append(", ")
1046 append("</section
>")
1049 private fun process_generate_dot do
1050 var pe = ctx.class_hierarchy[mclass]
1051 var cla = new HashSet[MClass]
1052 var sm = new HashSet[MClass]
1053 var sm2 = new HashSet[MClass]
1055 while cla.length + sm.length < 10 and sm.length > 0 do
1059 sm2.add_all(pe.poset[x].direct_smallers)
1065 cla.add_all(pe.greaters)
1068 var name = "dep_
{mclass.name}"
1069 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
")
1072 op.append("\
"{c.name}\"[shape
=box
,margin
=0.03];\n
")
1074 op.append("\
"{c.name}\"[URL=\
"{c.url}\"];\n
")
1076 for c2 in pe.poset[c].direct_greaters do
1077 if not cla.has(c2) then continue
1078 op.append("\
"{c.name}\"->\
"{c2.name}\";\n
")
1080 if not pe.poset[c].direct_smallers.is_empty then
1082 for c2 in pe.poset[c].direct_smallers do
1083 if cla.has(c2) then others = false
1086 op.append("\
"{c.name}...\"[label=\
"\"];\n
")
1087 op.append("\
"{c.name}...\"->\
"{c.name}\"[style
=dotted
];\n
")
1092 generate_dot(op.to_s, name, "Dependency graph
for class {mclass.name}")
1101 # URL to nitdoc page
1103 var res = new Buffer
1104 res.append("module_
")
1105 var mowner = public_owner
1106 if mowner != null then
1107 res.append("{public_owner.name}_
")
1109 res.append("{self.name}.html
")
1113 # html anchor id to the module in a nitdoc page
1114 fun anchor: String do
1115 var res = new Buffer
1117 var mowner = public_owner
1118 if mowner != null then
1119 res.append("{public_owner.name}_
")
1121 res.append(self.name)
1125 # Return a link (html a tag) to the nitdoc module page
1126 fun html_link(page: NitdocPage) do
1127 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1128 page.append("<a href
='{url}' title
='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{name}</a
>")
1130 page.append("<a href
='{url}'>{name}</a
>")
1134 # Return the module signature decorated with html
1135 fun html_signature(page: NitdocPage) do
1136 page.append("<span
>module ")
1137 html_full_namespace(page)
1138 page.append("</span
>")
1141 # Return the module full namespace decorated with html
1142 fun html_full_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 module full namespace decorated with html
1154 fun html_namespace(page: NitdocPage) do
1155 page.append("<span
>")
1156 var mowner = public_owner
1157 if mowner != null then
1158 public_owner.html_namespace(page)
1162 page.append("</span
>")
1165 # Return the full comment of the module decorated with html
1166 fun html_full_comment(page: NitdocPage) do
1167 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1168 page.append("<div id
='description'>")
1169 page.append("<pre
class='text_label'>{page.ctx.mbuilder.mmodule2nmodule[self].full_comment}</pre
>")
1170 page.append("<textarea
class='edit' rows
='1' cols
='76' id
='fileContent'></textarea
>")
1171 page.append("<a id
='cancelBtn'>Cancel</a
>")
1172 page.append("<a id
='commitBtn'>Commit</a
>")
1173 page.append("<pre
class='text_label' id
='preSave' type='2'></pre
>")
1174 page.append("</div
>")
1180 # Return the module signature decorated with html
1181 fun html_full_signature(page: NitdocPage) do
1182 if visibility < public_visibility then page.append("{visibility.to_s} ")
1183 page.append("{kind} ")
1184 html_namespace(page)
1187 # name with formal parameter
1189 private fun signature: String do
1191 return "{name}[{intro.parameter_names.join(", ")}]"
1197 # Return a link (html a tag) to the nitdoc class page
1198 fun html_link(page: NitdocPage) do
1199 page.append("<a href
='{url}'")
1200 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1201 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1202 if nclass isa AStdClassdef then
1203 page.append(" title
=\
"{nclass.short_comment}\"")
1206 page.append(">{signature}</a
>")
1209 # Return the class namespace decorated with html
1210 fun html_namespace(page: NitdocPage) do
1211 intro_mmodule.html_namespace(page)
1212 page.append("::<span
>")
1214 page.append("</span
>")
1218 return "class_
{public_owner}_
{c_name}.html
"
1221 # Escape name for html output
1222 redef fun name do return super.html_escape
1225 redef class MProperty
1226 # Return the property namespace decorated with html
1227 fun html_namespace(page: NitdocPage) do
1228 intro_mclassdef.mclass.html_namespace(page)
1229 page.append("::<span
>")
1230 intro.html_link(page)
1231 page.append("</span
>")
1234 # Escape name for html output
1235 redef fun name do return super.html_escape
1239 fun html_link(page: NitdocPage) is abstract
1242 redef class MClassType
1243 redef fun html_link(page) do mclass.html_link(page)
1246 redef class MNullableType
1247 redef fun html_link(page) do
1248 page.append("nullable ")
1249 mtype.html_link(page)
1253 redef class MGenericType
1254 redef fun html_link(page) do
1255 page.append("<a href
='{mclass.url}'>{mclass.name}</a
>[")
1256 for i in [0..arguments.length[ do
1257 arguments[i].html_link(page)
1258 if i < arguments.length - 1 then page.append(", ")
1264 redef class MParameterType
1265 redef fun html_link(page) do
1266 var name = mclass.intro.parameter_names[rank]
1267 page.append("<a href
='{mclass.url}#FT_{name}' title
='formal type'>{name}</a
>")
1271 redef class MVirtualType
1272 redef fun html_link(page) do mproperty.intro.html_link(page)
1275 redef class MClassDef
1276 # Return the classdef namespace decorated with html
1277 fun html_namespace(page: NitdocPage) do
1278 mmodule.html_full_namespace(page)
1279 page.append("::<span
>")
1280 mclass.html_link(page)
1281 page.append("</span
>")
1285 redef class MPropDef
1286 fun url: String do return "{mclassdef.mclass.url}#{anchor}"
1287 fun anchor
: String do return "PROP_{mclassdef.mclass.public_owner.name}_{c_name}"
1289 # Return a link (html a tag) to the nitdoc class page
1290 fun html_link
(page
: NitdocPage) do
1291 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1292 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1293 page
.append
("<a href=\"{url}\
" title=\"{nprop.short_comment}\
">{mproperty.name}</a>")
1295 page
.append
("<a href=\"{url}\
">{mproperty.name}</a>")
1299 # Return a list item for the mpropdef
1300 private fun html_list_item
(page
: NitdocPage) do
1302 page
.append
("<li class='intro'>")
1303 page
.append
("<span title='introduction'>I</span> ")
1305 page
.append
("<li class='redef'>")
1306 page
.append
("<span title='redefinition'>R</span> ")
1310 mclassdef
.mclass
.html_link
(page
)
1312 page
.append
("</li>")
1315 # Return a list item for the mpropdef
1316 private fun html_sidebar_item
(page
: NitdocClass) do
1317 if is_intro
and mclassdef
.mclass
== page
.mclass
then
1318 page
.append
("<li class='intro'>")
1319 page
.append
("<span title='Introduced'>I</span>")
1320 else if is_intro
and mclassdef
.mclass
!= page
.mclass
then
1321 page
.append
("<li class='inherit'>")
1322 page
.append
("<span title='Inherited'>H</span>")
1324 page
.append
("<li class='redef'>")
1325 page
.append
("<span title='Redefined'>R</span>")
1328 page
.append
("</li>")
1331 private fun html_full_desc
(page
: NitdocClass) is abstract
1332 private fun html_info
(page
: NitdocClass) is abstract
1334 fun full_name
: String do
1335 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1338 private fun html_inheritance
(page
: NitdocClass) do
1340 page
.append
("<p class='info'>")
1341 page
.ctx
.mainmodule
.linearize_mpropdefs
(mproperty
.mpropdefs
)
1342 var previous_defs
= new Array[MPropDef]
1343 var next_defs
= new Array[MPropDef]
1344 var self_passed
= false
1345 for def
in mproperty
.mpropdefs
do
1350 if not self_passed
then
1351 if def
.mclassdef
.mclass
.in_hierarchy
(page
.ctx
.mainmodule
) < page
.mclass
then continue
1352 if def
.is_intro
then continue
1353 previous_defs
.add
(def
)
1355 if page
.mclass
.in_hierarchy
(page
.ctx
.mainmodule
) < def
.mclassdef
.mclass
then continue
1359 page
.append
("defined by ")
1360 mclassdef
.mmodule
.html_full_namespace
(page
)
1361 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1362 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1364 if not is_intro
then
1365 page
.append
(", introduced by ")
1366 mproperty
.intro
.mclassdef
.mclass
.html_link
(page
)
1367 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1368 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1371 if not previous_defs
.is_empty
then
1372 page
.append
(", inherited from ")
1373 for i
in [0..previous_defs
.length
[ do
1374 var def
= previous_defs
[i
]
1375 def
.mclassdef
.mclass
.html_link
(page
)
1376 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(def
) then
1377 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1380 if i
< previous_defs
.length
- 1 then page
.append
(", ")
1383 if not next_defs
.is_empty
then
1384 page
.append
(", redefined by ")
1385 for i
in [0..next_defs
.length
[ do
1386 var def
= next_defs
[i
]
1387 def
.mclassdef
.mclass
.html_link
(page
)
1388 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(def
) then
1389 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1391 if i
< next_defs
.length
- 1 then page
.append
(", ")
1394 page
.append
(".</p>")
1397 private fun html_comment
(page
: NitdocClass) do
1398 if not page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then return
1399 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1400 page
.append
("<div class='description'>")
1401 if not is_intro
then
1402 var intro_nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[mproperty
.intro
]
1403 page
.append
("<p>from ")
1404 mproperty
.html_namespace
(page
)
1406 if intro_nprop
.full_comment
== "" then
1407 page
.append
("<a class=\"newComment\
" title=\"32\
" tag=\"\
">New Comment</a>")
1409 page
.append
("<pre class=\"text_label\
" title=\"\
" name=\"\
" tag=\"\
" type=\"1\
">{intro_nprop.full_comment}</pre>")
1411 page
.append
("<p>from ")
1412 mclassdef
.html_namespace
(page
)
1415 if nprop
.full_comment
== "" then
1416 page
.append
("<a class=\"newComment\
" title=\"32\
" tag=\"\
">New Comment</a>")
1418 page
.append
("<pre class=\"text_label\
" title=\"\
" name=\"\
" tag=\"\
" type=\"1\
">{nprop.full_comment}</pre>")
1420 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>")
1421 html_inheritance
(page
)
1422 page
.append
("</div>")
1426 redef class MMethodDef
1427 redef fun html_full_desc
(page
) do
1428 var classes
= new Array[String]
1429 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= page
.mclass
1430 if mproperty
.is_init
then
1435 if is_redef
then classes
.add
("redef")
1436 classes
.add
(mproperty
.visibility
.to_s
)
1437 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1438 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1439 page
.append
("<h3 class='signature'>{mproperty.name}")
1440 msignature
.html_signature
(page
)
1441 page
.append
("</h3>")
1443 page
.append
("<h3 class='signature'>init")
1444 msignature
.html_signature
(page
)
1445 page
.append
("</h3>")
1449 page
.append
("</article>")
1452 redef fun html_info
(page
) do
1453 page
.append
("<div class='info'>")
1454 if mproperty
.visibility
< public_visibility
then page
.append
("{mproperty.visibility.to_s} ")
1455 if mproperty
.intro_mclassdef
.mclass
!= page
.mclass
then page
.append
("redef ")
1456 if mproperty
.is_init
then
1457 page
.append
("init ")
1461 mproperty
.html_namespace
(page
)
1462 page
.append
("</div>")
1463 page
.append
("<div style=\"float
: right
;\
"><a id=\"lblDiffCommit\
"></a></div>")
1467 redef class MVirtualTypeDef
1468 redef fun html_full_desc
(page
) do
1469 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= page
.mclass
1470 var classes
= new Array[String]
1472 if is_redef
then classes
.add
("redef")
1473 classes
.add
(mproperty
.visibility
.to_s
)
1474 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1475 page
.append
("<h3 class='signature'>{mproperty.name}: ")
1476 bound
.html_link
(page
)
1477 page
.append
("</h3>")
1480 page
.append
("</article>")
1483 redef fun html_info
(page
) do
1484 page
.append
("<div class='info'>")
1485 if mproperty
.intro_mclassdef
.mclass
!= page
.mclass
then page
.append
("redef ")
1486 page
.append
("type ")
1487 mproperty
.html_namespace
(page
)
1488 page
.append
("</div>")
1489 page
.append
("<div style=\"float
: right
;\
"><a id=\"lblDiffCommit\
"></a></div>")
1493 redef class MSignature
1494 private fun html_signature
(page
: NitdocPage) do
1495 if not mparameters
.is_empty
then
1497 for i
in [0..mparameters
.length
[ do
1498 mparameters
[i
].html_link
(page
)
1499 if i
< mparameters
.length
- 1 then page
.append
(", ")
1503 if return_mtype
!= null then
1505 return_mtype
.html_link
(page
)
1510 redef class MParameter
1511 private fun html_link
(page
: NitdocPage) do
1512 page
.append
("{name}: ")
1513 mtype
.html_link
(page
)
1514 if is_vararg
then page
.append
("...")
1523 private fun short_comment
: String do
1524 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1525 return n_moduledecl
.n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1530 private fun full_comment
: String do
1531 var res
= new Buffer
1532 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1533 for t
in n_moduledecl
.n_doc
.n_comment
do
1534 res
.append
(t
.text
.substring_from
(1).html_escape
)
1541 redef class AStdClassdef
1542 private fun short_comment
: String do
1543 if n_doc
!= null then return n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1547 private fun full_comment
: String do
1548 var res
= new Buffer
1549 if n_doc
!= null then
1550 for t
in n_doc
.n_comment
do res
.append
(t
.text
.substring_from
(1).html_escape
)
1556 redef class APropdef
1557 private fun short_comment
: String do
1558 if n_doc
!= null then return n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1562 private fun full_comment
: String do
1563 var res
= new Buffer
1564 if n_doc
!= null then
1565 for t
in n_doc
.n_comment
do res
.append
(t
.text
.substring_from
(1).html_escape
)
1571 var nitdoc
= new NitdocContext
1572 nitdoc
.generate_nitdoc