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.
21 # The NitdocContext contains all the knowledge used for doc generation
25 private var model
: Model
26 private var mbuilder
: ModelBuilder
27 private var mainmodule
: MModule
28 private var class_hierarchy
: POSet[MClass]
29 private var arguments
: Array[String]
30 private var output_dir
: nullable String
31 private var dot_dir
: nullable String
32 private var share_dir
: nullable String
33 private var source
: nullable String
34 private var min_visibility
: MVisibility
36 private var opt_dir
= new OptionString("Directory where doc is generated", "-d", "--dir")
37 private var opt_source
= new OptionString("What link for source (%f for filename, %l for first line, %L for last line)", "--source")
38 private var opt_sharedir
= new OptionString("Directory containing the nitdoc files", "--sharedir")
39 private var opt_nodot
= new OptionBool("Do not generate graphes with graphiviz", "--no-dot")
40 private var opt_private
: OptionBool = new OptionBool("Generate the private API", "--private")
42 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")
43 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")
44 private var opt_custom_overview_text
: OptionString = new OptionString("Text displayed as introduction of Overview page before the modules list", "--custom-overview-text")
45 private var opt_custom_footer_text
: OptionString = new OptionString("Text displayed as footer of all pages", "--custom-footer-text")
49 self.arguments
= option_context
.rest
50 option_context
.options
.clear
51 option_context
.add_option
(opt_dir
)
52 option_context
.add_option
(opt_source
)
53 option_context
.add_option
(opt_sharedir
)
54 option_context
.add_option
(opt_nodot
)
55 option_context
.add_option
(opt_private
)
56 option_context
.add_option
(opt_custom_title
)
57 option_context
.add_option
(opt_custom_footer_text
)
58 option_context
.add_option
(opt_custom_overview_text
)
59 option_context
.add_option
(opt_custom_menu_items
)
62 if arguments
.length
< 1 then
68 mbuilder
= new ModelBuilder(model
, self)
69 # Here we load an process all modules passed on the command line
70 var mmodules
= mbuilder
.parse_and_build
(arguments
)
71 if mmodules
.is_empty
then return
73 if mmodules
.length
== 1 then
74 mainmodule
= mmodules
.first
76 # We need a main module, so we build it by importing all modules
77 mainmodule
= new MModule(model
, null, "<main>", new Location(null, 0, 0, 0, 0))
78 mainmodule
.set_imported_mmodules
(mmodules
)
80 self.class_hierarchy
= mainmodule
.flatten_mclass_hierarchy
83 redef fun process_options
do
85 if not opt_dir
.value
is null then
86 output_dir
= opt_dir
.value
90 if not opt_sharedir
.value
is null then
91 share_dir
= opt_sharedir
.value
93 var dir
= "NIT_DIR".environ
95 dir
= "{sys.program_name.dirname}/../share/nitdoc"
97 dir
= "{dir}/share/nitdoc"
100 if share_dir
is null then
101 print
"Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
104 dir
= "{share_dir.to_s}/scripts/js-facilities.js"
105 if share_dir
is null then
106 print
"Error: Invalid nitdoc share files. Check --sharedir or envvar NIT_DIR"
110 if opt_private
.value
then
111 min_visibility
= none_visibility
113 min_visibility
= protected_visibility
116 source
= opt_source
.value
119 fun generate_nitdoc
do
120 # Create destination dir if it's necessary
121 if not output_dir
.file_exists
then output_dir
.mkdir
122 sys
.system
("cp -r {share_dir.to_s}/* {output_dir.to_s}/")
124 if not opt_nodot
.value
then self.dot_dir
= output_dir
.to_s
132 private fun overview
do
133 var overviewpage
= new NitdocOverview(self, dot_dir
)
134 overviewpage
.save
("{output_dir.to_s}/index.html")
137 private fun fullindex
do
138 var fullindex
= new NitdocFullindex(self)
139 fullindex
.save
("{output_dir.to_s}/full-index.html")
142 private fun modules
do
143 for mmodule
in model
.mmodules
do
144 if mmodule
.name
== "<main>" then continue
145 var modulepage
= new NitdocModule(mmodule
, self, dot_dir
)
146 modulepage
.save
("{output_dir.to_s}/{mmodule.url}")
150 private fun classes
do
151 for mclass
in mbuilder
.model
.mclasses
do
152 var classpage
= new NitdocClass(mclass
, self, dot_dir
, source
)
153 classpage
.save
("{output_dir.to_s}/{mclass.url}")
157 private fun quicksearch_list
do
158 var file
= new OFStream.open
("{output_dir.to_s}/quicksearch-list.js")
159 var content
= new Buffer
160 content
.append
("var entries = \{ ")
162 for mmodule
in model
.mmodules
do
163 content
.append
("\"{mmodule.name}\
": [")
164 content
.append
("\{txt: \"{mmodule.name}\", url
:\
"{mmodule.url}\" \
},")
167 for mclass in model.mclasses do
168 if mclass.visibility < min_visibility then continue
169 content.append("\
"{mclass.name}\": [")
170 content.append("\
{txt: \"{mclass.name}\
", url:\"{mclass.url}\
" \},")
173 var name2mprops
= new HashMap[String, Set[MPropDef]]
174 for mproperty
in model
.mproperties
do
175 if mproperty
.visibility
< min_visibility
then continue
176 if mproperty
isa MAttribute then continue
177 if not name2mprops
.has_key
(mproperty
.name
) then name2mprops
[mproperty
.name
] = new HashSet[MPropDef]
178 name2mprops
[mproperty
.name
].add_all
(mproperty
.mpropdefs
)
180 for mproperty
, mpropdefs
in name2mprops
do
181 content
.append
("\"{mproperty}\
": [")
182 for mpropdef
in mpropdefs
do
183 content
.append
("\{txt: \"{mpropdef.full_name}\", url
:\
"{mpropdef.url}\" \
},")
188 content.append(" \
};")
189 file.write(content.to_s)
196 abstract class NitdocPage
199 var dot_dir: nullable String
200 var source: nullable String
201 var ctx: NitdocContext
203 init(ctx: NitdocContext) do
208 protected fun head do
209 append("<meta charset
='utf-8'/>")
210 append("<script
type='text/javascript' src
='scripts/jquery-1.7.1.min.js'></script
>")
211 append("<script
type='text/javascript' src
='quicksearch-list.js'></script
>")
212 append("<script
type='text/javascript' src
='scripts/js-facilities.js'></script
>")
213 append("<link rel
='stylesheet' href
='styles/main.css' type='text/css' media
='screen'/>")
215 if ctx.opt_custom_title.value != null then
216 title = " | {ctx.opt_custom_title.value.to_s}"
218 append("<title
>{self.title}{title}</title
>")
221 protected fun menu do
222 if ctx.opt_custom_menu_items.value != null then
223 append(ctx.opt_custom_menu_items.value.to_s)
227 protected fun title: String is abstract
229 protected fun header do
231 append("<nav
class='main'>")
234 append("<li id
='liGitHub'>")
235 append("<a
class='btn' id
='logGitHub'>")
236 append("<img id
='imgGitHub' src
='resources/icons/github-icon.png' alt
='GitHub'/>")
238 append("<div
class='popover bottom'>")
239 append("<div
class='arrow'> 
;</div
>")
240 append("<div
class='githubTitle'>")
241 append("<h3
>Github Sign In</h3
>")
244 append("<label id
='lbloginGit'>Username</label>")
245 append("<input id
='loginGit' name
='login' type='text'/>")
246 append("<label id
='logginMessage'>Hello ")
247 append("<a id
='githubAccount'><strong id
='nickName'></strong
></a
>")
251 append("<label id
='lbpasswordGit'>Password</label>")
252 append("<input id
='passwordGit' name
='password' type='password'/>")
253 append("<div id
='listBranches'>")
254 append("<label id
='lbBranches'>Branch</label>")
255 append("<select
class='dropdown' id
='dropBranches' name
='dropBranches' tabindex
='1'></select
>")
259 append("<label id
='lbrepositoryGit'>Repository</label>")
260 append("<input id
='repositoryGit' name
='repository' type='text'/>")
263 append("<label id
='lbbranchGit'>Branch</label>")
264 append("<input id
='branchGit' name
='branch' type='text'/>")
267 append("<a id
='signIn'>Sign In</a
>")
276 protected fun content is abstract
278 protected fun footer do
279 if ctx.opt_custom_footer_text.value != null then
280 append("<footer
>{ctx.opt_custom_footer_text.value.to_s}</footer
>")
284 # Generate a clickable graphviz image using a dot content
285 protected fun generate_dot(dot: String, name: String, alt: String) do
286 var output_dir = dot_dir
287 if output_dir == null then return
288 var file = new OFStream.open("{output_dir}/{name}.dot
")
291 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
; \
}")
292 append("<article
class='graph'>")
293 append("<img src
='{name}.png' usemap
='#{name}' style
='margin:auto' alt
='{alt}'/>")
295 var fmap = new IFStream.open("{output_dir}/{name}.map
")
296 append(fmap.read_all)
300 # Add a (source) link for a given location
301 protected fun show_source(l: Location): String
303 if source == null then
304 return "({l.file.filename.simplify_path})"
306 # THIS IS JUST UGLY ! (but there is no replace yet)
307 var x = source.split_with("%f
")
308 source = x.join(l.file.filename.simplify_path)
309 x = source.split_with("%l
")
310 source = x.join(l.line_start.to_s)
311 x = source.split_with("%L
")
312 source = x.join(l.line_end.to_s)
313 return " (<a href
=\
"{source.to_s}\">source
</a
>)"
317 # Render the page as a html string
318 fun render: String do
319 append("<!DOCTYPE html
>")
325 append("<div
class='page'>")
333 # Save html page in the specified file
334 fun save(file: String) do
335 var out = new OFStream.open(file)
344 private var mbuilder: ModelBuilder
345 private var mmodules = new Array[MModule]
347 init(ctx: NitdocContext, dot_dir: nullable String) do
349 self.mbuilder = ctx.mbuilder
350 self.dot_dir = dot_dir
352 var mmodules = new HashSet[MModule]
353 for mmodule in mbuilder.model.mmodules do
354 if mmodule.name == "<main
>" then continue
355 var owner = mmodule.public_owner
356 if owner != null then
359 mmodules.add(mmodule)
363 var sorter = new MModuleNameSorter
364 self.mmodules.add_all(mmodules)
365 sorter.sort(self.mmodules)
368 redef fun title do return "Overview"
372 append("<li
class='current'>Overview</li
>")
373 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
377 append("<div
class='content fullpage'>")
378 var title = "Overview"
379 if ctx.opt_custom_title.value != null then
380 title = ctx.opt_custom_title.value.to_s
382 append("<h1
>{title}</h1
>")
384 if ctx.opt_custom_overview_text.value != null then
385 text = ctx.opt_custom_overview_text.value.to_s
387 append("<article
class='overview'>{text}</article
>")
388 append("<article
class='overview'>")
390 append("<h2
>Modules</h2
>")
392 for mmodule in mmodules do
393 if mbuilder.mmodule2nmodule.has_key(mmodule) then
394 var amodule = mbuilder.mmodule2nmodule[mmodule]
396 mmodule.html_link(self)
397 append(" 
;{amodule.short_comment}</li
>")
407 private fun process_generate_dot do
408 # build poset with public owners
409 var poset = new POSet[MModule]
410 for mmodule in mmodules do
411 poset.add_node(mmodule)
412 for omodule in mmodules do
413 if mmodule == omodule then continue
414 if mmodule.in_importation < omodule then
415 poset.add_node(omodule)
416 poset.add_edge(mmodule, omodule)
422 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
")
423 for mmodule in poset do
424 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
425 for omodule in poset[mmodule].direct_greaters do
426 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
430 generate_dot(op.to_s, "dep
", "Modules hierarchy
")
434 # The full index page
435 class NitdocFullindex
438 init(ctx: NitdocContext) do
443 redef fun title do return "Full Index"
447 append("<li
><a href
='index.html'>Overview</a
></li
>")
448 append("<li
class='current'>Full Index</li
>")
452 append("<div
class='content fullpage'>")
453 append("<h1
>Full Index</h1
>")
460 # Add to content modules column
461 private fun module_column do
462 var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
463 var sorter = new MModuleNameSorter
465 append("<article
class='modules filterable'>")
466 append("<h2
>Modules</h2
>")
468 for mmodule in sorted do
470 mmodule.html_link(self)
477 # Add to content classes modules
478 private fun classes_column do
479 var sorted = ctx.mbuilder.model.mclasses
480 var sorter = new MClassNameSorter
482 append("<article
class='modules filterable'>")
483 append("<h2
>Classes</h2
>")
485 for mclass in sorted do
486 if mclass.visibility < ctx.min_visibility then continue
488 mclass.html_link(self)
495 # Insert the properties column of fullindex page
496 private fun properties_column do
497 var sorted = ctx.mbuilder.model.mproperties
498 var sorter = new MPropertyNameSorter
500 append("<article
class='modules filterable'>")
501 append("<h2
>Properties</h2
>")
503 for mproperty in sorted do
504 if mproperty.visibility < ctx.min_visibility then continue
505 if mproperty isa MAttribute then continue
507 mproperty.intro.html_link(self)
509 mproperty.intro.mclassdef.mclass.html_link(self)
522 private var mmodule: MModule
523 private var mbuilder: ModelBuilder
525 init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
527 self.mmodule = mmodule
528 self.mbuilder = ctx.mbuilder
529 self.dot_dir = dot_dir
533 if mbuilder.mmodule2nmodule.has_key(mmodule) then
534 var nmodule = mbuilder.mmodule2nmodule[mmodule]
535 return "{mmodule.name} module | {nmodule.short_comment}"
537 return "{mmodule.name} module"
543 append("<li
><a href
='index.html'>Overview</a
></li
>")
544 append("<li
class='current'>{mmodule.name}</li
>")
545 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
550 append("<div
class='content'>")
551 append("<h1
>{mmodule.name}</h1
>")
552 append("<div
class='subtitle info'>")
553 mmodule.html_signature(self)
555 mmodule.html_full_comment(self)
562 private fun process_generate_dot do
563 # build poset with public owners
564 var poset = new POSet[MModule]
565 for mmodule in self.mmodule.in_importation.poset do
566 if mmodule.name == "<main
>" then continue
567 if mmodule.public_owner != null then continue
568 if not mmodule.in_importation < self.mmodule and not self.mmodule.in_importation < mmodule and mmodule != self.mmodule then continue
569 poset.add_node(mmodule)
570 for omodule in mmodule.in_importation.poset do
571 if mmodule == omodule then continue
572 if omodule.name == "<main
>" then continue
573 if omodule.public_owner != null then continue
574 if mmodule.in_importation < omodule then
575 poset.add_node(omodule)
576 poset.add_edge(mmodule, omodule)
582 var name = "dep_
{mmodule.name}"
583 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
")
584 for mmodule in poset do
585 if mmodule == self.mmodule then
586 op.append("\
"{mmodule.name}\"[shape
=box
,margin
=0.03];\n
")
588 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
590 for omodule in poset[mmodule].direct_greaters do
591 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
595 generate_dot(op.to_s, name, "Dependency graph
for module {mmodule.name}")
598 private fun sidebar do
599 append("<div
class='menu'>")
601 append("<h3
>Module Hierarchy</h3
>")
602 var dependencies = new Array[MModule]
603 for dep in mmodule.in_importation.greaters do
604 if dep == mmodule or dep.public_owner != null then continue
605 dependencies.add(dep)
607 if dependencies.length > 0 then
608 append("<h4
>All dependencies
</h4
>")
609 display_module_list(dependencies)
611 var clients = new Array[MModule]
612 for dep in mmodule.in_importation.smallers do
613 if dep.name == "<main
>" then continue
614 if dep == mmodule or dep.public_owner != null then continue
617 if clients.length > 0 then
618 append("<h4
>All clients
</h4
>")
619 display_module_list(clients)
622 if ctx.min_visibility < protected_visibility then
623 if mmodule.in_nesting.direct_greaters.length > 0 then
625 append("<h3
>Nested Modules</h3
>")
626 display_module_list(mmodule.in_nesting.direct_greaters.to_a)
633 private fun display_module_list(list: Array[MModule]) do
635 var sorter = new MModuleNameSorter
645 # display the class column
646 private fun classes do
647 var intro_mclasses = mmodule.intro_mclasses
648 var redef_mclasses = mmodule.redef_mclasses
649 var all_mclasses = new HashSet[MClass]
650 for m in mmodule.in_nesting.greaters do
651 all_mclasses.add_all(m.intro_mclasses)
652 all_mclasses.add_all(m.redef_mclasses)
654 all_mclasses.add_all(intro_mclasses)
655 all_mclasses.add_all(redef_mclasses)
657 var sorted = new Array[MClass]
658 sorted.add_all(all_mclasses)
659 var sorter = new MClassNameSorter
661 append("<div
class='module'>")
662 append("<article
class='classes filterable'>")
663 append("<h2
>Classes</h2
>")
666 if c.visibility < ctx.min_visibility then continue
667 if redef_mclasses.has(c) and c.intro_mmodule.public_owner != mmodule then
668 append("<li
class='redef'>")
669 append("<span title
='refined in this module'>R
</span
>")
671 append("<li
class='intro'>")
672 append("<span title
='introduced in this module'>I
</span
>")
682 # display the property column
683 private fun properties do
685 var mpropdefs = new HashSet[MPropDef]
686 for m in mmodule.in_nesting.greaters do
687 for c in m.mclassdefs do mpropdefs.add_all(c.mpropdefs)
689 for c in mmodule.mclassdefs do mpropdefs.add_all(c.mpropdefs)
690 var sorted = mpropdefs.to_a
691 var sorter = new MPropDefNameSorter
693 # display properties in one column
694 append("<article
class='properties filterable'>")
695 append("<h2
>Properties</h2
>")
697 for mprop in sorted do
698 if mprop isa MAttributeDef then continue
699 if mprop.mproperty.visibility < ctx.min_visibility then continue
700 mprop.html_list_item(self)
711 private var mclass: MClass
712 private var vtypes = new HashSet[MVirtualTypeDef]
713 private var consts = new HashSet[MMethodDef]
714 private var meths = new HashSet[MMethodDef]
715 private var inherited = new HashSet[MPropDef]
717 init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
720 self.dot_dir = dot_dir
723 for mclassdef in mclass.mclassdefs do
724 for mpropdef in mclassdef.mpropdefs do
725 if mpropdef.mproperty.visibility < ctx.min_visibility then continue
726 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
727 if mpropdef isa MMethodDef then
728 if mpropdef.mproperty.is_init then
736 # get inherited properties
737 for mprop in mclass.inherited_mproperties do
738 var mpropdef = mprop.intro
739 if mprop.visibility < ctx.min_visibility then continue
740 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
741 if mpropdef isa MMethodDef then
742 if mpropdef.mproperty.is_init then
748 inherited.add(mpropdef)
753 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
754 if nclass isa AStdClassdef then
755 return "{mclass.name} class | {nclass.short_comment}"
757 return "{mclass.name} class"
763 append("<li
><a href
='index.html'>Overview</a
></li
>")
764 var public_owner = mclass.public_owner
765 if public_owner is null then
767 mclass.intro_mmodule.html_link(self)
771 public_owner.html_link(self)
774 append("<li
class='current'>{mclass.name}</li
>")
775 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
779 append("<div
class='menu'>")
783 append("<div
class='content'>")
788 private fun properties_column do
789 var sorter = new MPropDefNameSorter
790 append("<nav
class='properties filterable'>")
791 append("<h3
>Properties</h3
>")
793 if vtypes.length > 0 then
794 var vts = new Array[MVirtualTypeDef]
797 append("<h4
>Virtual Types</h4
>")
800 mprop.html_sidebar_item(self)
805 if consts.length > 0 then
806 var cts = new Array[MMethodDef]
809 append("<h4
>Constructors</h4
>")
812 if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
813 mprop.html_sidebar_item(self)
818 if meths.length > 0 then
819 var mts = new Array[MMethodDef]
822 append("<h4
>Methods</h4
>")
825 if mclass.name != "Object" and mprop.mproperty.intro_mclassdef.mclass.name == "Object" and mprop.mproperty.visibility <= protected_visibility then continue
826 mprop.html_sidebar_item(self)
833 private fun inheritance_column do
834 var sorted = new Array[MClass]
835 var sorterp = new MClassNameSorter
837 append("<h3
>Inheritance</h3
>")
838 var greaters = mclass.in_hierarchy(ctx.mainmodule).greaters.to_a
839 if greaters.length > 1 then
840 ctx.mainmodule.linearize_mclasses(greaters)
841 append("<h4
>Superclasses</h4
>")
843 for sup in greaters do
844 if sup == mclass then continue
851 var smallers = mclass.in_hierarchy(ctx.mainmodule).smallers.to_a
852 var direct_smallers = mclass.in_hierarchy(ctx.mainmodule).direct_smallers.to_a
853 if smallers.length <= 1 then
854 append("<h4
>No Known Subclasses</h4
>")
855 else if smallers.length <= 100 then
856 ctx.mainmodule.linearize_mclasses(smallers)
857 append("<h4
>Subclasses</h4
>")
859 for sub in smallers do
860 if sub == mclass then continue
866 else if direct_smallers.length <= 100 then
867 ctx.mainmodule.linearize_mclasses(direct_smallers)
868 append("<h4
>Direct Subclasses Only</h4
>")
870 for sub in direct_smallers do
871 if sub == mclass then continue
878 append("<h4
>Too much
Subclasses to list
</h4
>")
883 private fun class_doc do
885 append("<h1
>{mclass.signature}</h1
>")
886 append("<div
class='subtitle info'>")
887 mclass.html_full_signature(self)
890 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
891 append("<div style
=\
"float: right;\"><a id
=\
"lblDiffCommit\"></a
></div
>")
892 append("<section
class='description'>")
893 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
>")
897 var concern2meths = new ArrayMap[MModule, Array[MMethodDef]]
898 var sorted_meths = new Array[MMethodDef]
899 var sorted = new Array[MModule]
900 sorted_meths.add_all(meths)
901 ctx.mainmodule.linearize_mpropdefs(sorted_meths)
903 if inherited.has(meth) then continue
904 var mmodule = meth.mclassdef.mmodule
905 if not concern2meths.has_key(mmodule) then
907 concern2meths[mmodule] = new Array[MMethodDef]
909 concern2meths[mmodule].add(meth)
911 var sections = new ArrayMap[MModule, Array[MModule]]
912 for mmodule in concern2meths.keys do
913 var owner = mmodule.public_owner
914 if owner == null then owner = mmodule
915 if not sections.has_key(owner) then sections[owner] = new Array[MModule]
916 if owner != mmodule then sections[owner].add(mmodule)
918 append("<section
class='concerns'>")
919 append("<h2
class='section-header'>Concerns</h2
>")
921 for owner, mmodules in sections do
922 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
924 if nowner.short_comment.is_empty then
925 append("<a href
=\
"#{owner.anchor}\">{owner.name}</a
>")
927 append("<a href
=\
"#{owner.anchor}\">{owner.name}</a
>: {nowner.short_comment}")
929 if not mmodules.is_empty then
931 for mmodule in mmodules do
932 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
933 if nmodule.short_comment.is_empty then
934 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.name}</a
></li
>")
936 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.name}</a
>: {nmodule.short_comment}</li
>")
946 var prop_sorter = new MPropDefNameSorter
947 var lmmodule = new List[MModule]
948 # virtual and formal types
949 var local_vtypes = new Array[MVirtualTypeDef]
950 for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
951 if local_vtypes.length > 0 or mclass.arity > 0 then
952 append("<section
class='types'>")
953 append("<h2
>Formal and Virtual Types</h2
>")
955 if mclass.arity > 0 and nclass isa AStdClassdef then
956 for ft, bound in mclass.parameter_types do
957 append("<article id
='FT_{ft}'>")
958 append("<h3
class='signature'>{ft}: ")
959 bound.html_link(self)
961 append("<div
class=\
"info\">formal generic
type</div
>")
966 prop_sorter.sort(local_vtypes)
967 for prop in local_vtypes do prop.html_full_desc(self)
971 var local_consts = new Array[MMethodDef]
972 for const in consts do if not inherited.has(const) then local_consts.add(const)
973 prop_sorter.sort(local_consts)
974 if local_consts.length > 0 then
975 append("<section
class='constructors'>")
976 append("<h2
class='section-header'>Constructors</h2
>")
977 for prop in local_consts do prop.html_full_desc(self)
981 if not concern2meths.is_empty then
982 append("<section
class='methods'>")
983 append("<h2
class='section-header'>Methods</h2
>")
984 for owner, mmodules in sections do
985 append("<a id
=\
"{owner.anchor}\"></a
>")
986 if owner != mclass.intro_mmodule and owner != mclass.public_owner then
987 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
988 append("<h3
class=\
"concern-toplevel\">Methods refined
in ")
989 owner.html_link(self)
991 append("<p
class=\
"concern-doc\">")
992 owner.html_link(self)
993 if not nowner.short_comment.is_empty then
994 append(": {nowner.short_comment}")
998 if concern2meths.has_key(owner) then
999 var mmethods = concern2meths[owner]
1000 prop_sorter.sort(mmethods)
1001 for prop in mmethods do prop.html_full_desc(self)
1003 for mmodule in mmodules do
1004 append("<a id
=\
"{mmodule.anchor}\"></a
>")
1005 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
1006 if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
1007 append("<p
class=\
"concern-doc\">")
1008 mmodule.html_link(self)
1009 if not nmodule.short_comment.is_empty then
1010 append(": {nmodule.short_comment}")
1014 var mmethods = concern2meths[mmodule]
1015 prop_sorter.sort(mmethods)
1016 for prop in mmethods do prop.html_full_desc(self)
1020 # inherited properties
1021 if inherited.length > 0 then
1022 var sorted_inherited = new Array[MPropDef]
1023 sorted_inherited.add_all(inherited)
1024 ctx.mainmodule.linearize_mpropdefs(sorted_inherited)
1025 var classes = new ArrayMap[MClass, Array[MPropDef]]
1026 for mmethod in sorted_inherited.reversed do
1027 var mclass = mmethod.mclassdef.mclass
1028 if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
1029 classes[mclass].add(mmethod)
1031 append("<h3
>Inherited Properties</h3
>")
1032 for c, mmethods in classes do
1033 prop_sorter.sort(mmethods)
1034 append("<p
>Defined in ")
1037 for i in [0..mmethods.length[ do
1038 var mmethod = mmethods[i]
1039 mmethod.html_link(self)
1040 if i <= mmethods.length - 1 then append(", ")
1045 append("</section
>")
1048 private fun process_generate_dot do
1049 var pe = ctx.class_hierarchy[mclass]
1050 var cla = new HashSet[MClass]
1051 var sm = new HashSet[MClass]
1052 var sm2 = new HashSet[MClass]
1054 while cla.length + sm.length < 10 and sm.length > 0 do
1058 sm2.add_all(pe.poset[x].direct_smallers)
1064 cla.add_all(pe.greaters)
1067 var name = "dep_
{mclass.name}"
1068 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
")
1071 op.append("\
"{c.name}\"[shape
=box
,margin
=0.03];\n
")
1073 op.append("\
"{c.name}\"[URL=\
"{c.url}\"];\n
")
1075 for c2 in pe.poset[c].direct_greaters do
1076 if not cla.has(c2) then continue
1077 op.append("\
"{c.name}\"->\
"{c2.name}\";\n
")
1079 if not pe.poset[c].direct_smallers.is_empty then
1081 for c2 in pe.poset[c].direct_smallers do
1082 if cla.has(c2) then others = false
1085 op.append("\
"{c.name}...\"[label=\
"\"];\n
")
1086 op.append("\
"{c.name}...\"->\
"{c.name}\"[style
=dotted
];\n
")
1091 generate_dot(op.to_s, name, "Dependency graph
for class {mclass.name}")
1100 # URL to nitdoc page
1102 var res = new Buffer
1103 res.append("module_
")
1104 var mowner = public_owner
1105 if mowner != null then
1106 res.append("{public_owner.name}_
")
1108 res.append("{self.name}.html
")
1112 # html anchor id to the module in a nitdoc page
1113 fun anchor: String do
1114 var res = new Buffer
1116 var mowner = public_owner
1117 if mowner != null then
1118 res.append("{public_owner.name}_
")
1120 res.append(self.name)
1124 # Return a link (html a tag) to the nitdoc module page
1125 fun html_link(page: NitdocPage) do
1126 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1127 page.append("<a href
='{url}' title
='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{name}</a
>")
1129 page.append("<a href
='{url}'>{name}</a
>")
1133 # Return the module signature decorated with html
1134 fun html_signature(page: NitdocPage) do
1135 page.append("<span
>module ")
1136 html_full_namespace(page)
1137 page.append("</span
>")
1140 # Return the module full namespace decorated with html
1141 fun html_full_namespace(page: NitdocPage) do
1142 page.append("<span
>")
1143 var mowner = public_owner
1144 if mowner != null then
1145 public_owner.html_namespace(page)
1149 page.append("</span
>")
1152 # Return the module full namespace decorated with html
1153 fun html_namespace(page: NitdocPage) do
1154 page.append("<span
>")
1155 var mowner = public_owner
1156 if mowner != null then
1157 public_owner.html_namespace(page)
1161 page.append("</span
>")
1164 # Return the full comment of the module decorated with html
1165 fun html_full_comment(page: NitdocPage) do
1166 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1167 page.append("<div id
='description'>")
1168 page.append("<pre
class='text_label'>{page.ctx.mbuilder.mmodule2nmodule[self].full_comment}</pre
>")
1169 page.append("<textarea
class='edit' rows
='1' cols
='76' id
='fileContent'></textarea
>")
1170 page.append("<a id
='cancelBtn'>Cancel</a
>")
1171 page.append("<a id
='commitBtn'>Commit</a
>")
1172 page.append("<pre
class='text_label' id
='preSave' type='2'></pre
>")
1173 page.append("</div
>")
1179 # Return the module signature decorated with html
1180 fun html_full_signature(page: NitdocPage) do
1181 if visibility < public_visibility then page.append("{visibility.to_s} ")
1182 page.append("{kind} ")
1183 html_namespace(page)
1186 # name with formal parameter
1188 private fun signature: String do
1190 return "{name}[{intro.parameter_names.join(", ")}]"
1196 # Return a link (html a tag) to the nitdoc class page
1197 fun html_link(page: NitdocPage) do
1198 page.append("<a href
='{url}'")
1199 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1200 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1201 if nclass isa AStdClassdef then
1202 page.append(" title
=\
"{nclass.short_comment}\"")
1205 page.append(">{signature}</a
>")
1208 # Return the class namespace decorated with html
1209 fun html_namespace(page: NitdocPage) do
1210 intro_mmodule.html_namespace(page)
1211 page.append("::<span
>")
1213 page.append("</span
>")
1217 return "class_
{public_owner}_
{name}.html
"
1220 # Escape name for html output
1221 redef fun name do return super.html_escape
1224 redef class MProperty
1225 # Return the property namespace decorated with html
1226 fun html_namespace(page: NitdocPage) do
1227 intro_mclassdef.mclass.html_namespace(page)
1228 page.append("::<span
>")
1229 intro.html_link(page)
1230 page.append("</span
>")
1233 # Escape name for html output
1234 redef fun name do return super.html_escape
1238 fun html_link(page: NitdocPage) is abstract
1241 redef class MClassType
1242 redef fun html_link(page) do mclass.html_link(page)
1245 redef class MNullableType
1246 redef fun html_link(page) do
1247 page.append("nullable ")
1248 mtype.html_link(page)
1252 redef class MGenericType
1253 redef fun html_link(page) do
1254 page.append("<a href
='{mclass.url}'>{mclass.name}</a
>[")
1255 for i in [0..arguments.length[ do
1256 arguments[i].html_link(page)
1257 if i < arguments.length - 1 then page.append(", ")
1263 redef class MParameterType
1264 redef fun html_link(page) do
1265 var name = mclass.intro.parameter_names[rank]
1266 page.append("<a href
='{mclass.url}#FT_{name}' title
='formal type'>{name}</a
>")
1270 redef class MVirtualType
1271 redef fun html_link(page) do mproperty.intro.html_link(page)
1274 redef class MClassDef
1275 # Return the classdef namespace decorated with html
1276 fun html_namespace(page: NitdocPage) do
1277 mmodule.html_full_namespace(page)
1278 page.append("::<span
>")
1279 mclass.html_link(page)
1280 page.append("</span
>")
1284 redef class MPropDef
1285 fun url: String do return "{mclassdef.mclass.url}#{anchor}"
1286 fun anchor
: String do return "PROP_{mclassdef.mclass.public_owner.name}_{mproperty.name}"
1288 # Return a link (html a tag) to the nitdoc class page
1289 fun html_link
(page
: NitdocPage) do
1290 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1291 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1292 page
.append
("<a href=\"{url}\
" title=\"{nprop.short_comment}\
">{mproperty.name}</a>")
1294 page
.append
("<a href=\"{url}\
">{mproperty.name}</a>")
1298 # Return a list item for the mpropdef
1299 private fun html_list_item
(page
: NitdocPage) do
1301 page
.append
("<li class='intro'>")
1302 page
.append
("<span title='introduction'>I</span> ")
1304 page
.append
("<li class='redef'>")
1305 page
.append
("<span title='redefinition'>R</span> ")
1309 mclassdef
.mclass
.html_link
(page
)
1311 page
.append
("</li>")
1314 # Return a list item for the mpropdef
1315 private fun html_sidebar_item
(page
: NitdocClass) do
1316 if is_intro
and mclassdef
.mclass
== page
.mclass
then
1317 page
.append
("<li class='intro'>")
1318 page
.append
("<span title='Introduced'>I</span>")
1319 else if is_intro
and mclassdef
.mclass
!= page
.mclass
then
1320 page
.append
("<li class='inherit'>")
1321 page
.append
("<span title='Inherited'>H</span>")
1323 page
.append
("<li class='redef'>")
1324 page
.append
("<span title='Redefined'>R</span>")
1327 page
.append
("</li>")
1330 private fun html_full_desc
(page
: NitdocClass) is abstract
1331 private fun html_info
(page
: NitdocClass) is abstract
1333 fun full_name
: String do
1334 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1337 private fun html_inheritance
(page
: NitdocClass) do
1339 page
.append
("<p class='info'>")
1340 page
.ctx
.mainmodule
.linearize_mpropdefs
(mproperty
.mpropdefs
)
1341 var previous_defs
= new Array[MPropDef]
1342 var next_defs
= new Array[MPropDef]
1343 var self_passed
= false
1344 for def
in mproperty
.mpropdefs
do
1349 if not self_passed
then
1350 if def
.mclassdef
.mclass
.in_hierarchy
(page
.ctx
.mainmodule
) < page
.mclass
then continue
1351 if def
.is_intro
then continue
1352 previous_defs
.add
(def
)
1354 if page
.mclass
.in_hierarchy
(page
.ctx
.mainmodule
) < def
.mclassdef
.mclass
then continue
1358 page
.append
("defined by ")
1359 mclassdef
.mmodule
.html_full_namespace
(page
)
1360 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1361 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1363 if not is_intro
then
1364 page
.append
(", introduced by ")
1365 mproperty
.intro
.mclassdef
.mclass
.html_link
(page
)
1366 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1367 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1370 if not previous_defs
.is_empty
then
1371 page
.append
(", inherited from ")
1372 for i
in [0..previous_defs
.length
[ do
1373 var def
= previous_defs
[i
]
1374 def
.mclassdef
.mclass
.html_link
(page
)
1375 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(def
) then
1376 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1379 if i
< previous_defs
.length
- 1 then page
.append
(", ")
1382 if not next_defs
.is_empty
then
1383 page
.append
(", redefined by ")
1384 for i
in [0..next_defs
.length
[ do
1385 var def
= next_defs
[i
]
1386 def
.mclassdef
.mclass
.html_link
(page
)
1387 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(def
) then
1388 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1390 if i
< next_defs
.length
- 1 then page
.append
(", ")
1393 page
.append
(".</p>")
1396 private fun html_comment
(page
: NitdocClass) do
1397 if not page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then return
1398 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1399 page
.append
("<div class='description'>")
1400 if not is_intro
then
1401 var intro_nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[mproperty
.intro
]
1402 page
.append
("<p>from ")
1403 mproperty
.html_namespace
(page
)
1405 if intro_nprop
.full_comment
== "" then
1406 page
.append
("<a class=\"newComment\
" title=\"32\
" tag=\"\
">New Comment</a>")
1408 page
.append
("<pre class=\"text_label\
" title=\"\
" name=\"\
" tag=\"\
" type=\"1\
">{intro_nprop.full_comment}</pre>")
1410 page
.append
("<p>from ")
1411 mclassdef
.html_namespace
(page
)
1414 if nprop
.full_comment
== "" then
1415 page
.append
("<a class=\"newComment\
" title=\"32\
" tag=\"\
">New Comment</a>")
1417 page
.append
("<pre class=\"text_label\
" title=\"\
" name=\"\
" tag=\"\
" type=\"1\
">{nprop.full_comment}</pre>")
1419 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>")
1420 html_inheritance
(page
)
1421 page
.append
("</div>")
1425 redef class MMethodDef
1426 redef fun html_full_desc
(page
) do
1427 var classes
= new Array[String]
1428 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= page
.mclass
1429 if mproperty
.is_init
then
1434 if is_redef
then classes
.add
("redef")
1435 classes
.add
(mproperty
.visibility
.to_s
)
1436 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1437 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1438 page
.append
("<h3 class='signature'>{mproperty.name}")
1439 msignature
.html_signature
(page
)
1440 page
.append
("</h3>")
1442 page
.append
("<h3 class='signature'>init")
1443 msignature
.html_signature
(page
)
1444 page
.append
("</h3>")
1448 page
.append
("</article>")
1451 redef fun html_info
(page
) do
1452 page
.append
("<div class='info'>")
1453 if mproperty
.visibility
< public_visibility
then page
.append
("{mproperty.visibility.to_s} ")
1454 if mproperty
.intro_mclassdef
.mclass
!= page
.mclass
then page
.append
("redef ")
1455 if mproperty
.is_init
then
1456 page
.append
("init ")
1460 mproperty
.html_namespace
(page
)
1461 page
.append
("</div>")
1462 page
.append
("<div style=\"float
: right
;\
"><a id=\"lblDiffCommit\
"></a></div>")
1466 redef class MVirtualTypeDef
1467 redef fun html_full_desc
(page
) do
1468 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= page
.mclass
1469 var classes
= new Array[String]
1471 if is_redef
then classes
.add
("redef")
1472 classes
.add
(mproperty
.visibility
.to_s
)
1473 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1474 page
.append
("<h3 class='signature'>{mproperty.name}: ")
1475 bound
.html_link
(page
)
1476 page
.append
("</h3>")
1479 page
.append
("</article>")
1482 redef fun html_info
(page
) do
1483 page
.append
("<div class='info'>")
1484 if mproperty
.intro_mclassdef
.mclass
!= page
.mclass
then page
.append
("redef ")
1485 page
.append
("type ")
1486 mproperty
.html_namespace
(page
)
1487 page
.append
("</div>")
1488 page
.append
("<div style=\"float
: right
;\
"><a id=\"lblDiffCommit\
"></a></div>")
1492 redef class MSignature
1493 private fun html_signature
(page
: NitdocPage) do
1494 if not mparameters
.is_empty
then
1496 for i
in [0..mparameters
.length
[ do
1497 mparameters
[i
].html_link
(page
)
1498 if i
< mparameters
.length
- 1 then page
.append
(", ")
1502 if return_mtype
!= null then
1504 return_mtype
.html_link
(page
)
1509 redef class MParameter
1510 private fun html_link
(page
: NitdocPage) do
1511 page
.append
("{name}: ")
1512 mtype
.html_link
(page
)
1513 if is_vararg
then page
.append
("...")
1522 private fun short_comment
: String do
1523 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1524 return n_moduledecl
.n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1529 private fun full_comment
: String do
1530 var res
= new Buffer
1531 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1532 for t
in n_moduledecl
.n_doc
.n_comment
do
1533 res
.append
(t
.text
.substring_from
(1).html_escape
)
1540 redef class AStdClassdef
1541 private fun short_comment
: String do
1542 if n_doc
!= null then return n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1546 private fun full_comment
: String do
1547 var res
= new Buffer
1548 if n_doc
!= null then
1549 for t
in n_doc
.n_comment
do res
.append
(t
.text
.substring_from
(1).html_escape
)
1555 redef class APropdef
1556 private fun short_comment
: String do
1557 if n_doc
!= null then return n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1561 private fun full_comment
: String do
1562 var res
= new Buffer
1563 if n_doc
!= null then
1564 for t
in n_doc
.n_comment
do res
.append
(t
.text
.substring_from
(1).html_escape
)
1570 var nitdoc
= new NitdocContext
1571 nitdoc
.generate_nitdoc