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
24 private var toolcontext
= new ToolContext
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")
48 self.arguments
= toolcontext
.option_context
.rest
49 toolcontext
.option_context
.options
.clear
50 toolcontext
.option_context
.add_option
(opt_dir
)
51 toolcontext
.option_context
.add_option
(opt_source
)
52 toolcontext
.option_context
.add_option
(opt_sharedir
)
53 toolcontext
.option_context
.add_option
(opt_nodot
)
54 toolcontext
.option_context
.add_option
(opt_private
)
55 toolcontext
.option_context
.add_option
(opt_custom_title
)
56 toolcontext
.option_context
.add_option
(opt_custom_footer_text
)
57 toolcontext
.option_context
.add_option
(opt_custom_overview_text
)
58 toolcontext
.option_context
.add_option
(opt_custom_menu_items
)
59 toolcontext
.process_options
61 if arguments
.length
< 1 then
62 toolcontext
.option_context
.usage
67 mbuilder
= new ModelBuilder(model
, toolcontext
)
68 # Here we load an process all modules passed on the command line
69 var mmodules
= mbuilder
.parse_and_build
(arguments
)
70 if mmodules
.is_empty
then return
72 if mmodules
.length
== 1 then
73 mainmodule
= mmodules
.first
75 # We need a main module, so we build it by importing all modules
76 mainmodule
= new MModule(model
, null, "<main>", new Location(null, 0, 0, 0, 0))
77 mainmodule
.set_imported_mmodules
(mmodules
)
79 self.class_hierarchy
= mainmodule
.flatten_mclass_hierarchy
83 private fun process_options
do
84 if not opt_dir
.value
is null then
85 output_dir
= opt_dir
.value
89 if not opt_sharedir
.value
is null then
90 share_dir
= opt_sharedir
.value
92 var dir
= "NIT_DIR".environ
94 dir
= "{sys.program_name.dirname}/../share/nitdoc"
96 dir
= "{dir}/share/nitdoc"
99 if share_dir
is null then
100 print
"Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
103 dir
= "{share_dir.to_s}/scripts/js-facilities.js"
104 if share_dir
is null then
105 print
"Error: Invalid nitdoc share files. Check --sharedir or envvar NIT_DIR"
109 if opt_private
.value
then
110 min_visibility
= none_visibility
112 min_visibility
= protected_visibility
115 source
= opt_source
.value
118 fun generate_nitdoc
do
119 # Create destination dir if it's necessary
120 if not output_dir
.file_exists
then output_dir
.mkdir
121 sys
.system
("cp -r {share_dir.to_s}/* {output_dir.to_s}/")
123 if not opt_nodot
.value
then self.dot_dir
= output_dir
.to_s
131 private fun overview
do
132 var overviewpage
= new NitdocOverview(self, dot_dir
)
133 overviewpage
.save
("{output_dir.to_s}/index.html")
136 private fun fullindex
do
137 var fullindex
= new NitdocFullindex(self)
138 fullindex
.save
("{output_dir.to_s}/full-index.html")
141 private fun modules
do
142 for mmodule
in model
.mmodules
do
143 if mmodule
.name
== "<main>" then continue
144 var modulepage
= new NitdocModule(mmodule
, self, dot_dir
)
145 modulepage
.save
("{output_dir.to_s}/{mmodule.url}")
149 private fun classes
do
150 for mclass
in mbuilder
.model
.mclasses
do
151 var classpage
= new NitdocClass(mclass
, self, dot_dir
, source
)
152 classpage
.save
("{output_dir.to_s}/{mclass.url}")
156 private fun quicksearch_list
do
157 var file
= new OFStream.open
("{output_dir.to_s}/quicksearch-list.js")
158 var content
= new Buffer
159 content
.append
("var entries = \{ ")
161 for mmodule
in model
.mmodules
do
162 content
.append
("\"{mmodule.name}\
": [")
163 content
.append
("\{txt: \"{mmodule.name}\", url
:\
"{mmodule.url}\" \
},")
166 for mclass in model.mclasses do
167 if mclass.visibility < min_visibility then continue
168 content.append("\
"{mclass.name}\": [")
169 content.append("\
{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 content
.append
("\"{mproperty}\
": [")
181 for mpropdef
in mpropdefs
do
182 content
.append
("\{txt: \"{mpropdef.full_name}\", url
:\
"{mpropdef.url}\" \
},")
187 content.append(" \
};")
188 file.write(content.to_s)
195 abstract class NitdocPage
198 var dot_dir: nullable String
199 var source: nullable String
200 var ctx: NitdocContext
202 init(ctx: NitdocContext) do
207 protected fun head do
208 append("<meta charset
='utf-8'/>")
209 append("<script
type='text/javascript' src
='scripts/jquery-1.7.1.min.js'></script
>")
210 append("<script
type='text/javascript' src
='quicksearch-list.js'></script
>")
211 append("<script
type='text/javascript' src
='scripts/js-facilities.js'></script
>")
212 append("<link rel
='stylesheet' href
='styles/main.css' type='text/css' media
='screen'/>")
214 if ctx.opt_custom_title.value != null then
215 title = " | {ctx.opt_custom_title.value.to_s}"
217 append("<title
>{self.title}{title}</title
>")
220 protected fun menu do
221 if ctx.opt_custom_menu_items.value != null then
222 append(ctx.opt_custom_menu_items.value.to_s)
226 protected fun title: String is abstract
228 protected fun header do
230 append("<nav
class='main'>")
233 append("<li id
='liGitHub'>")
234 append("<a
class='btn' id
='logGitHub'>")
235 append("<img id
='imgGitHub' src
='resources/icons/github-icon.png' alt
='GitHub'/>")
237 append("<div
class='popover bottom'>")
238 append("<div
class='arrow'> 
;</div
>")
239 append("<div
class='githubTitle'>")
240 append("<h3
>Github Sign In</h3
>")
243 append("<label id
='lbloginGit'>Username</label>")
244 append("<input id
='loginGit' name
='login' type='text'/>")
245 append("<label id
='logginMessage'>Hello ")
246 append("<a id
='githubAccount'><strong id
='nickName'></strong
></a
>")
250 append("<label id
='lbpasswordGit'>Password</label>")
251 append("<input id
='passwordGit' name
='password' type='password'/>")
252 append("<div id
='listBranches'>")
253 append("<label id
='lbBranches'>Branch</label>")
254 append("<select
class='dropdown' id
='dropBranches' name
='dropBranches' tabindex
='1'></select
>")
258 append("<label id
='lbrepositoryGit'>Repository</label>")
259 append("<input id
='repositoryGit' name
='repository' type='text'/>")
262 append("<label id
='lbbranchGit'>Branch</label>")
263 append("<input id
='branchGit' name
='branch' type='text'/>")
266 append("<a id
='signIn'>Sign In</a
>")
275 protected fun content is abstract
277 protected fun footer do
278 if ctx.opt_custom_footer_text.value != null then
279 append("<footer
>{ctx.opt_custom_footer_text.value.to_s}</footer
>")
283 # Generate a clickable graphviz image using a dot content
284 protected fun generate_dot(dot: String, name: String, alt: String) do
285 var output_dir = dot_dir
286 if output_dir == null then return
287 var file = new OFStream.open("{output_dir}/{name}.dot
")
290 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
; \
}")
291 append("<article
class='graph'>")
292 append("<img src
='{name}.png' usemap
='#{name}' style
='margin:auto' alt
='{alt}'/>")
294 var fmap = new IFStream.open("{output_dir}/{name}.map
")
295 append(fmap.read_all)
299 # Add a (source) link for a given location
300 protected fun show_source(l: Location): String
302 if source == null then
303 return "({l.file.filename.simplify_path})"
305 # THIS IS JUST UGLY ! (but there is no replace yet)
306 var x = source.split_with("%f
")
307 source = x.join(l.file.filename.simplify_path)
308 x = source.split_with("%l
")
309 source = x.join(l.line_start.to_s)
310 x = source.split_with("%L
")
311 source = x.join(l.line_end.to_s)
312 return " (<a href
=\
"{source.to_s}\">source
</a
>)"
316 # Render the page as a html string
317 fun render: String do
318 append("<!DOCTYPE html
>")
324 append("<div
class='page'>")
332 # Save html page in the specified file
333 fun save(file: String) do
334 var out = new OFStream.open(file)
343 private var mbuilder: ModelBuilder
344 private var mmodules = new Array[MModule]
346 init(ctx: NitdocContext, dot_dir: nullable String) do
348 self.mbuilder = ctx.mbuilder
349 self.dot_dir = dot_dir
351 var mmodules = new HashSet[MModule]
352 for mmodule in mbuilder.model.mmodules do
353 if mmodule.name == "<main
>" then continue
354 var owner = mmodule.public_owner
355 if owner != null then
358 mmodules.add(mmodule)
362 var sorter = new MModuleNameSorter
363 self.mmodules.add_all(mmodules)
364 sorter.sort(self.mmodules)
367 redef fun title do return "Overview"
371 append("<li
class='current'>Overview</li
>")
372 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
376 append("<div
class='content fullpage'>")
377 var title = "Overview"
378 if ctx.opt_custom_title.value != null then
379 title = ctx.opt_custom_title.value.to_s
381 append("<h1
>{title}</h1
>")
383 if ctx.opt_custom_overview_text.value != null then
384 text = ctx.opt_custom_overview_text.value.to_s
386 append("<article
class='overview'>{text}</article
>")
387 append("<article
class='overview'>")
389 append("<h2
>Modules</h2
>")
391 for mmodule in mmodules do
392 if mbuilder.mmodule2nmodule.has_key(mmodule) then
393 var amodule = mbuilder.mmodule2nmodule[mmodule]
395 mmodule.html_link(self)
396 append(" 
;{amodule.short_comment}</li
>")
406 private fun process_generate_dot do
407 # build poset with public owners
408 var poset = new POSet[MModule]
409 for mmodule in mmodules do
410 poset.add_node(mmodule)
411 for omodule in mmodules do
412 if mmodule == omodule then continue
413 if mmodule.in_importation < omodule then
414 poset.add_node(omodule)
415 poset.add_edge(mmodule, omodule)
421 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
")
422 for mmodule in poset do
423 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
424 for omodule in poset[mmodule].direct_greaters do
425 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
429 generate_dot(op.to_s, "dep
", "Modules hierarchy
")
433 # The full index page
434 class NitdocFullindex
437 init(ctx: NitdocContext) do
442 redef fun title do return "Full Index"
446 append("<li
><a href
='index.html'>Overview</a
></li
>")
447 append("<li
class='current'>Full Index</li
>")
451 append("<div
class='content fullpage'>")
452 append("<h1
>Full Index</h1
>")
459 # Add to content modules column
460 private fun module_column do
461 var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
462 var sorter = new MModuleNameSorter
464 append("<article
class='modules filterable'>")
465 append("<h2
>Modules</h2
>")
467 for mmodule in sorted do
469 mmodule.html_link(self)
476 # Add to content classes modules
477 private fun classes_column do
478 var sorted = ctx.mbuilder.model.mclasses
479 var sorter = new MClassNameSorter
481 append("<article
class='modules filterable'>")
482 append("<h2
>Classes</h2
>")
484 for mclass in sorted do
485 if mclass.visibility < ctx.min_visibility then continue
487 mclass.html_link(self)
494 # Insert the properties column of fullindex page
495 private fun properties_column do
496 var sorted = ctx.mbuilder.model.mproperties
497 var sorter = new MPropertyNameSorter
499 append("<article
class='modules filterable'>")
500 append("<h2
>Properties</h2
>")
502 for mproperty in sorted do
503 if mproperty.visibility < ctx.min_visibility then continue
504 if mproperty isa MAttribute then continue
506 mproperty.intro.html_link(self)
508 mproperty.intro.mclassdef.mclass.html_link(self)
521 private var mmodule: MModule
522 private var mbuilder: ModelBuilder
524 init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
526 self.mmodule = mmodule
527 self.mbuilder = ctx.mbuilder
528 self.dot_dir = dot_dir
532 if mbuilder.mmodule2nmodule.has_key(mmodule) then
533 var nmodule = mbuilder.mmodule2nmodule[mmodule]
534 return "{mmodule.name} module | {nmodule.short_comment}"
536 return "{mmodule.name} module"
542 append("<li
><a href
='index.html'>Overview</a
></li
>")
543 append("<li
class='current'>{mmodule.name}</li
>")
544 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
549 append("<div
class='content'>")
550 append("<h1
>{mmodule.name}</h1
>")
551 append("<div
class='subtitle info'>")
552 mmodule.html_signature(self)
554 mmodule.html_full_comment(self)
561 private fun process_generate_dot do
562 # build poset with public owners
563 var poset = new POSet[MModule]
564 for mmodule in self.mmodule.in_importation.poset do
565 if mmodule.name == "<main
>" then continue
566 if mmodule.public_owner != null then continue
567 if not mmodule.in_importation < self.mmodule and not self.mmodule.in_importation < mmodule and mmodule != self.mmodule then continue
568 poset.add_node(mmodule)
569 for omodule in mmodule.in_importation.poset do
570 if mmodule == omodule then continue
571 if omodule.name == "<main
>" then continue
572 if omodule.public_owner != null then continue
573 if mmodule.in_importation < omodule then
574 poset.add_node(omodule)
575 poset.add_edge(mmodule, omodule)
581 var name = "dep_
{mmodule.name}"
582 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
")
583 for mmodule in poset do
584 if mmodule == self.mmodule then
585 op.append("\
"{mmodule.name}\"[shape
=box
,margin
=0.03];\n
")
587 op.append("\
"{mmodule.name}\"[URL=\
"{mmodule.url}\"];\n
")
589 for omodule in poset[mmodule].direct_greaters do
590 op.append("\
"{mmodule.name}\"->\
"{omodule.name}\";\n
")
594 generate_dot(op.to_s, name, "Dependency graph
for module {mmodule.name}")
597 private fun sidebar do
598 append("<div
class='menu'>")
600 append("<h3
>Module Hierarchy</h3
>")
601 var dependencies = new Array[MModule]
602 for dep in mmodule.in_importation.greaters do
603 if dep == mmodule or dep.public_owner != null then continue
604 dependencies.add(dep)
606 if dependencies.length > 0 then
607 append("<h4
>All dependencies
</h4
>")
608 display_module_list(dependencies)
610 var clients = new Array[MModule]
611 for dep in mmodule.in_importation.smallers do
612 if dep.name == "<main
>" then continue
613 if dep == mmodule or dep.public_owner != null then continue
616 if clients.length > 0 then
617 append("<h4
>All clients
</h4
>")
618 display_module_list(clients)
621 if ctx.min_visibility < protected_visibility then
622 if mmodule.in_nesting.direct_greaters.length > 0 then
624 append("<h3
>Nested Modules</h3
>")
625 display_module_list(mmodule.in_nesting.direct_greaters.to_a)
632 private fun display_module_list(list: Array[MModule]) do
634 var sorter = new MModuleNameSorter
644 # display the class column
645 private fun classes do
646 var intro_mclasses = mmodule.intro_mclasses
647 var redef_mclasses = mmodule.redef_mclasses
648 var all_mclasses = new HashSet[MClass]
649 for m in mmodule.in_nesting.greaters do
650 all_mclasses.add_all(m.intro_mclasses)
651 all_mclasses.add_all(m.redef_mclasses)
653 all_mclasses.add_all(intro_mclasses)
654 all_mclasses.add_all(redef_mclasses)
656 var sorted = new Array[MClass]
657 sorted.add_all(all_mclasses)
658 var sorter = new MClassNameSorter
660 append("<div
class='module'>")
661 append("<article
class='classes filterable'>")
662 append("<h2
>Classes</h2
>")
665 if c.visibility < ctx.min_visibility then continue
666 if redef_mclasses.has(c) and c.intro_mmodule.public_owner != mmodule then
667 append("<li
class='redef'>")
668 append("<span title
='refined in this module'>R
</span
>")
670 append("<li
class='intro'>")
671 append("<span title
='introduced in this module'>I
</span
>")
681 # display the property column
682 private fun properties do
684 var mpropdefs = new HashSet[MPropDef]
685 for m in mmodule.in_nesting.greaters do
686 for c in m.mclassdefs do mpropdefs.add_all(c.mpropdefs)
688 for c in mmodule.mclassdefs do mpropdefs.add_all(c.mpropdefs)
689 var sorted = mpropdefs.to_a
690 var sorter = new MPropDefNameSorter
692 # display properties in one column
693 append("<article
class='properties filterable'>")
694 append("<h2
>Properties</h2
>")
696 for mprop in sorted do
697 if mprop isa MAttributeDef then continue
698 if mprop.mproperty.visibility < ctx.min_visibility then continue
699 mprop.html_list_item(self)
710 private var mclass: MClass
711 private var vtypes = new HashSet[MVirtualTypeDef]
712 private var consts = new HashSet[MMethodDef]
713 private var meths = new HashSet[MMethodDef]
714 private var inherited = new HashSet[MPropDef]
716 init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
719 self.dot_dir = dot_dir
722 for mclassdef in mclass.mclassdefs do
723 for mpropdef in mclassdef.mpropdefs do
724 if mpropdef.mproperty.visibility < ctx.min_visibility then continue
725 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
726 if mpropdef isa MMethodDef then
727 if mpropdef.mproperty.is_init then
735 # get inherited properties
736 for mprop in mclass.inherited_mproperties do
737 var mpropdef = mprop.intro
738 if mprop.visibility < ctx.min_visibility then continue
739 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
740 if mpropdef isa MMethodDef then
741 if mpropdef.mproperty.is_init then
747 inherited.add(mpropdef)
752 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
753 if nclass isa AStdClassdef then
754 return "{mclass.name} class | {nclass.short_comment}"
756 return "{mclass.name} class"
762 append("<li
><a href
='index.html'>Overview</a
></li
>")
763 var public_owner = mclass.public_owner
764 if public_owner is null then
766 mclass.intro_mmodule.html_link(self)
770 public_owner.html_link(self)
773 append("<li
class='current'>{mclass.name}</li
>")
774 append("<li
><a href
='full-index.html'>Full Index</a
></li
>")
778 append("<div
class='menu'>")
782 append("<div
class='content'>")
787 private fun properties_column do
788 var sorter = new MPropDefNameSorter
789 append("<nav
class='properties filterable'>")
790 append("<h3
>Properties</h3
>")
792 if vtypes.length > 0 then
793 var vts = new Array[MVirtualTypeDef]
796 append("<h4
>Virtual Types</h4
>")
799 mprop.html_sidebar_item(self)
804 if consts.length > 0 then
805 var cts = new Array[MMethodDef]
808 append("<h4
>Constructors</h4
>")
811 if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
812 mprop.html_sidebar_item(self)
817 if meths.length > 0 then
818 var mts = new Array[MMethodDef]
821 append("<h4
>Methods</h4
>")
824 if mclass.name != "Object" and mprop.mproperty.intro_mclassdef.mclass.name == "Object" and mprop.mproperty.visibility <= protected_visibility then continue
825 mprop.html_sidebar_item(self)
832 private fun inheritance_column do
833 var sorted = new Array[MClass]
834 var sorterp = new MClassNameSorter
836 append("<h3
>Inheritance</h3
>")
837 var greaters = mclass.in_hierarchy(ctx.mainmodule).greaters.to_a
838 if greaters.length > 1 then
839 ctx.mainmodule.linearize_mclasses(greaters)
840 append("<h4
>Superclasses</h4
>")
842 for sup in greaters do
843 if sup == mclass then continue
850 var smallers = mclass.in_hierarchy(ctx.mainmodule).smallers.to_a
851 var direct_smallers = mclass.in_hierarchy(ctx.mainmodule).direct_smallers.to_a
852 if smallers.length <= 1 then
853 append("<h4
>No Known Subclasses</h4
>")
854 else if smallers.length <= 100 then
855 ctx.mainmodule.linearize_mclasses(smallers)
856 append("<h4
>Subclasses</h4
>")
858 for sub in smallers do
859 if sub == mclass then continue
865 else if direct_smallers.length <= 100 then
866 ctx.mainmodule.linearize_mclasses(direct_smallers)
867 append("<h4
>Direct Subclasses Only</h4
>")
869 for sub in direct_smallers do
870 if sub == mclass then continue
877 append("<h4
>Too much
Subclasses to list
</h4
>")
882 private fun class_doc do
884 append("<h1
>{mclass.signature}</h1
>")
885 append("<div
class='subtitle info'>")
886 mclass.html_full_signature(self)
889 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
890 append("<div style
=\
"float: right;\"><a id
=\
"lblDiffCommit\"></a
></div
>")
891 append("<section
class='description'>")
892 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
>")
896 var concern2meths = new ArrayMap[MModule, Array[MMethodDef]]
897 var sorted_meths = new Array[MMethodDef]
898 var sorted = new Array[MModule]
899 sorted_meths.add_all(meths)
900 ctx.mainmodule.linearize_mpropdefs(sorted_meths)
902 if inherited.has(meth) then continue
903 var mmodule = meth.mclassdef.mmodule
904 if not concern2meths.has_key(mmodule) then
906 concern2meths[mmodule] = new Array[MMethodDef]
908 concern2meths[mmodule].add(meth)
910 var sections = new ArrayMap[MModule, Array[MModule]]
911 for mmodule in concern2meths.keys do
912 var owner = mmodule.public_owner
913 if owner == null then owner = mmodule
914 if not sections.has_key(owner) then sections[owner] = new Array[MModule]
915 if owner != mmodule then sections[owner].add(mmodule)
917 append("<section
class='concerns'>")
918 append("<h2
class='section-header'>Concerns</h2
>")
920 for owner, mmodules in sections do
921 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
923 if nowner.short_comment.is_empty then
924 append("<a href
=\
"#{owner.anchor}\">{owner.name}</a
>")
926 append("<a href
=\
"#{owner.anchor}\">{owner.name}</a
>: {nowner.short_comment}")
928 if not mmodules.is_empty then
930 for mmodule in mmodules do
931 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
932 if nmodule.short_comment.is_empty then
933 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.name}</a
></li
>")
935 append("<li
><a href
=\
"#{mmodule.anchor}\">{mmodule.name}</a
>: {nmodule.short_comment}</li
>")
945 var prop_sorter = new MPropDefNameSorter
946 var lmmodule = new List[MModule]
947 # virtual and formal types
948 var local_vtypes = new Array[MVirtualTypeDef]
949 for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
950 if local_vtypes.length > 0 or mclass.arity > 0 then
951 append("<section
class='types'>")
952 append("<h2
>Formal and Virtual Types</h2
>")
954 if mclass.arity > 0 and nclass isa AStdClassdef then
955 for ft, bound in mclass.parameter_types do
956 append("<article id
='FT_{ft}'>")
957 append("<h3
class='signature'>{ft}: ")
958 bound.html_link(self)
960 append("<div
class=\
"info\">formal generic
type</div
>")
965 prop_sorter.sort(local_vtypes)
966 for prop in local_vtypes do prop.html_full_desc(self)
970 var local_consts = new Array[MMethodDef]
971 for const in consts do if not inherited.has(const) then local_consts.add(const)
972 prop_sorter.sort(local_consts)
973 if local_consts.length > 0 then
974 append("<section
class='constructors'>")
975 append("<h2
class='section-header'>Constructors</h2
>")
976 for prop in local_consts do prop.html_full_desc(self)
980 if not concern2meths.is_empty then
981 append("<section
class='methods'>")
982 append("<h2
class='section-header'>Methods</h2
>")
983 for owner, mmodules in sections do
984 append("<a id
=\
"{owner.anchor}\"></a
>")
985 if owner != mclass.intro_mmodule and owner != mclass.public_owner then
986 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
987 append("<h3
class=\
"concern-toplevel\">Methods refined
in ")
988 owner.html_link(self)
990 append("<p
class=\
"concern-doc\">")
991 owner.html_link(self)
992 if not nowner.short_comment.is_empty then
993 append(": {nowner.short_comment}")
997 if concern2meths.has_key(owner) then
998 var mmethods = concern2meths[owner]
999 prop_sorter.sort(mmethods)
1000 for prop in mmethods do prop.html_full_desc(self)
1002 for mmodule in mmodules do
1003 append("<a id
=\
"{mmodule.anchor}\"></a
>")
1004 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
1005 if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
1006 append("<p
class=\
"concern-doc\">")
1007 mmodule.html_link(self)
1008 if not nmodule.short_comment.is_empty then
1009 append(": {nmodule.short_comment}")
1013 var mmethods = concern2meths[mmodule]
1014 prop_sorter.sort(mmethods)
1015 for prop in mmethods do prop.html_full_desc(self)
1019 # inherited properties
1020 if inherited.length > 0 then
1021 var sorted_inherited = new Array[MPropDef]
1022 sorted_inherited.add_all(inherited)
1023 ctx.mainmodule.linearize_mpropdefs(sorted_inherited)
1024 var classes = new ArrayMap[MClass, Array[MPropDef]]
1025 for mmethod in sorted_inherited.reversed do
1026 var mclass = mmethod.mclassdef.mclass
1027 if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
1028 classes[mclass].add(mmethod)
1030 append("<h3
>Inherited Properties</h3
>")
1031 for c, mmethods in classes do
1032 prop_sorter.sort(mmethods)
1033 append("<p
>Defined in ")
1036 for i in [0..mmethods.length[ do
1037 var mmethod = mmethods[i]
1038 mmethod.html_link(self)
1039 if i <= mmethods.length - 1 then append(", ")
1044 append("</section
>")
1047 private fun process_generate_dot do
1048 var pe = ctx.class_hierarchy[mclass]
1049 var cla = new HashSet[MClass]
1050 var sm = new HashSet[MClass]
1051 var sm2 = new HashSet[MClass]
1053 while cla.length + sm.length < 10 and sm.length > 0 do
1057 sm2.add_all(pe.poset[x].direct_smallers)
1063 cla.add_all(pe.greaters)
1066 var name = "dep_
{mclass.name}"
1067 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
")
1070 op.append("\
"{c.name}\"[shape
=box
,margin
=0.03];\n
")
1072 op.append("\
"{c.name}\"[URL=\
"{c.url}\"];\n
")
1074 for c2 in pe.poset[c].direct_greaters do
1075 if not cla.has(c2) then continue
1076 op.append("\
"{c.name}\"->\
"{c2.name}\";\n
")
1078 if not pe.poset[c].direct_smallers.is_empty then
1080 for c2 in pe.poset[c].direct_smallers do
1081 if cla.has(c2) then others = false
1084 op.append("\
"{c.name}...\"[label=\
"\"];\n
")
1085 op.append("\
"{c.name}...\"->\
"{c.name}\"[style
=dotted
];\n
")
1090 generate_dot(op.to_s, name, "Dependency graph
for class {mclass.name}")
1099 # URL to nitdoc page
1101 var res = new Buffer
1102 res.append("module_
")
1103 var mowner = public_owner
1104 if mowner != null then
1105 res.append("{public_owner.name}_
")
1107 res.append("{self.name}.html
")
1111 # html anchor id to the module in a nitdoc page
1112 fun anchor: String do
1113 var res = new Buffer
1115 var mowner = public_owner
1116 if mowner != null then
1117 res.append("{public_owner.name}_
")
1119 res.append(self.name)
1123 # Return a link (html a tag) to the nitdoc module page
1124 fun html_link(page: NitdocPage) do
1125 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1126 page.append("<a href
='{url}' title
='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{name}</a
>")
1128 page.append("<a href
='{url}'>{name}</a
>")
1132 # Return the module signature decorated with html
1133 fun html_signature(page: NitdocPage) do
1134 page.append("<span
>module ")
1135 html_full_namespace(page)
1136 page.append("</span
>")
1139 # Return the module full namespace decorated with html
1140 fun html_full_namespace(page: NitdocPage) do
1141 page.append("<span
>")
1142 var mowner = public_owner
1143 if mowner != null then
1144 public_owner.html_namespace(page)
1148 page.append("</span
>")
1151 # Return the module full namespace decorated with html
1152 fun html_namespace(page: NitdocPage) do
1153 page.append("<span
>")
1154 var mowner = public_owner
1155 if mowner != null then
1156 public_owner.html_namespace(page)
1160 page.append("</span
>")
1163 # Return the full comment of the module decorated with html
1164 fun html_full_comment(page: NitdocPage) do
1165 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1166 page.append("<div id
='description'>")
1167 page.append("<pre
class='text_label'>{page.ctx.mbuilder.mmodule2nmodule[self].full_comment}</pre
>")
1168 page.append("<textarea
class='edit' rows
='1' cols
='76' id
='fileContent'></textarea
>")
1169 page.append("<a id
='cancelBtn'>Cancel</a
>")
1170 page.append("<a id
='commitBtn'>Commit</a
>")
1171 page.append("<pre
class='text_label' id
='preSave' type='2'></pre
>")
1172 page.append("</div
>")
1178 # Return the module signature decorated with html
1179 fun html_full_signature(page: NitdocPage) do
1180 if visibility < public_visibility then page.append("{visibility.to_s} ")
1181 page.append("{kind} ")
1182 html_namespace(page)
1185 # name with formal parameter
1187 private fun signature: String do
1189 return "{name}[{intro.parameter_names.join(", ")}]"
1195 # Return a link (html a tag) to the nitdoc class page
1196 fun html_link(page: NitdocPage) do
1197 page.append("<a href
='{url}'")
1198 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1199 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1200 if nclass isa AStdClassdef then
1201 page.append(" title
=\
"{nclass.short_comment}\"")
1204 page.append(">{signature}</a
>")
1207 # Return the class namespace decorated with html
1208 fun html_namespace(page: NitdocPage) do
1209 intro_mmodule.html_namespace(page)
1210 page.append("::<span
>")
1212 page.append("</span
>")
1216 return "class_
{public_owner}_
{name}.html
"
1219 # Escape name for html output
1220 redef fun name do return super.html_escape
1223 redef class MProperty
1224 # Return the property namespace decorated with html
1225 fun html_namespace(page: NitdocPage) do
1226 intro_mclassdef.mclass.html_namespace(page)
1227 page.append("::<span
>")
1228 intro.html_link(page)
1229 page.append("</span
>")
1232 # Escape name for html output
1233 redef fun name do return super.html_escape
1237 fun html_link(page: NitdocPage) is abstract
1240 redef class MClassType
1241 redef fun html_link(page) do mclass.html_link(page)
1244 redef class MNullableType
1245 redef fun html_link(page) do
1246 page.append("nullable ")
1247 mtype.html_link(page)
1251 redef class MGenericType
1252 redef fun html_link(page) do
1253 page.append("<a href
='{mclass.url}'>{mclass.name}</a
>[")
1254 for i in [0..arguments.length[ do
1255 arguments[i].html_link(page)
1256 if i < arguments.length - 1 then page.append(", ")
1262 redef class MParameterType
1263 redef fun html_link(page) do
1264 var name = mclass.intro.parameter_names[rank]
1265 page.append("<a href
='{mclass.url}#FT_{name}' title
='formal type'>{name}</a
>")
1269 redef class MVirtualType
1270 redef fun html_link(page) do mproperty.intro.html_link(page)
1273 redef class MClassDef
1274 # Return the classdef namespace decorated with html
1275 fun html_namespace(page: NitdocPage) do
1276 mmodule.html_full_namespace(page)
1277 page.append("::<span
>")
1278 mclass.html_link(page)
1279 page.append("</span
>")
1283 redef class MPropDef
1284 fun url: String do return "{mclassdef.mclass.url}#{anchor}"
1285 fun anchor
: String do return "PROP_{mclassdef.mclass.public_owner.name}_{mproperty.name}"
1287 # Return a link (html a tag) to the nitdoc class page
1288 fun html_link
(page
: NitdocPage) do
1289 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1290 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1291 page
.append
("<a href=\"{url}\
" title=\"{nprop.short_comment}\
">{mproperty.name}</a>")
1293 page
.append
("<a href=\"{url}\
">{mproperty.name}</a>")
1297 # Return a list item for the mpropdef
1298 private fun html_list_item
(page
: NitdocPage) do
1300 page
.append
("<li class='intro'>")
1301 page
.append
("<span title='introduction'>I</span> ")
1303 page
.append
("<li class='redef'>")
1304 page
.append
("<span title='redefinition'>R</span> ")
1308 mclassdef
.mclass
.html_link
(page
)
1310 page
.append
("</li>")
1313 # Return a list item for the mpropdef
1314 private fun html_sidebar_item
(page
: NitdocClass) do
1315 if is_intro
and mclassdef
.mclass
== page
.mclass
then
1316 page
.append
("<li class='intro'>")
1317 page
.append
("<span title='Introduced'>I</span>")
1318 else if is_intro
and mclassdef
.mclass
!= page
.mclass
then
1319 page
.append
("<li class='inherit'>")
1320 page
.append
("<span title='Inherited'>H</span>")
1322 page
.append
("<li class='redef'>")
1323 page
.append
("<span title='Redefined'>R</span>")
1326 page
.append
("</li>")
1329 private fun html_full_desc
(page
: NitdocClass) is abstract
1330 private fun html_info
(page
: NitdocClass) is abstract
1332 fun full_name
: String do
1333 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1336 private fun html_inheritance
(page
: NitdocClass) do
1338 page
.append
("<p class='info'>")
1339 page
.ctx
.mainmodule
.linearize_mpropdefs
(mproperty
.mpropdefs
)
1340 var previous_defs
= new Array[MPropDef]
1341 var next_defs
= new Array[MPropDef]
1342 var self_passed
= false
1343 for def
in mproperty
.mpropdefs
do
1348 if not self_passed
then
1349 if def
.mclassdef
.mclass
.in_hierarchy
(page
.ctx
.mainmodule
) < page
.mclass
then continue
1350 if def
.is_intro
then continue
1351 previous_defs
.add
(def
)
1353 if page
.mclass
.in_hierarchy
(page
.ctx
.mainmodule
) < def
.mclassdef
.mclass
then continue
1357 page
.append
("defined by ")
1358 mclassdef
.mmodule
.html_full_namespace
(page
)
1359 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1360 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1362 if not is_intro
then
1363 page
.append
(", introduced by ")
1364 mproperty
.intro
.mclassdef
.mclass
.html_link
(page
)
1365 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1366 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1369 if not previous_defs
.is_empty
then
1370 page
.append
(", inherited from ")
1371 for i
in [0..previous_defs
.length
[ do
1372 var def
= previous_defs
[i
]
1373 def
.mclassdef
.mclass
.html_link
(page
)
1374 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(def
) then
1375 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1378 if i
< previous_defs
.length
- 1 then page
.append
(", ")
1381 if not next_defs
.is_empty
then
1382 page
.append
(", redefined by ")
1383 for i
in [0..next_defs
.length
[ do
1384 var def
= next_defs
[i
]
1385 def
.mclassdef
.mclass
.html_link
(page
)
1386 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(def
) then
1387 page
.append
(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1389 if i
< next_defs
.length
- 1 then page
.append
(", ")
1392 page
.append
(".</p>")
1395 private fun html_comment
(page
: NitdocClass) do
1396 if not page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then return
1397 var nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[self]
1398 page
.append
("<div class='description'>")
1399 if not is_intro
then
1400 var intro_nprop
= page
.ctx
.mbuilder
.mpropdef2npropdef
[mproperty
.intro
]
1401 page
.append
("<p>from ")
1402 mproperty
.html_namespace
(page
)
1404 if intro_nprop
.full_comment
== "" then
1405 page
.append
("<a class=\"newComment\
" title=\"32\
" tag=\"\
">New Comment</a>")
1407 page
.append
("<pre class=\"text_label\
" title=\"\
" name=\"\
" tag=\"\
" type=\"1\
">{intro_nprop.full_comment}</pre>")
1409 page
.append
("<p>from ")
1410 mclassdef
.html_namespace
(page
)
1413 if nprop
.full_comment
== "" then
1414 page
.append
("<a class=\"newComment\
" title=\"32\
" tag=\"\
">New Comment</a>")
1416 page
.append
("<pre class=\"text_label\
" title=\"\
" name=\"\
" tag=\"\
" type=\"1\
">{nprop.full_comment}</pre>")
1418 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>")
1419 html_inheritance
(page
)
1420 page
.append
("</div>")
1424 redef class MMethodDef
1425 redef fun html_full_desc
(page
) do
1426 var classes
= new Array[String]
1427 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= page
.mclass
1428 if mproperty
.is_init
then
1433 if is_redef
then classes
.add
("redef")
1434 classes
.add
(mproperty
.visibility
.to_s
)
1435 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1436 if page
.ctx
.mbuilder
.mpropdef2npropdef
.has_key
(self) then
1437 page
.append
("<h3 class='signature'>{mproperty.name}")
1438 msignature
.html_signature
(page
)
1439 page
.append
("</h3>")
1441 page
.append
("<h3 class='signature'>init")
1442 msignature
.html_signature
(page
)
1443 page
.append
("</h3>")
1447 page
.append
("</article>")
1450 redef fun html_info
(page
) do
1451 page
.append
("<div class='info'>")
1452 if mproperty
.visibility
< public_visibility
then page
.append
("{mproperty.visibility.to_s} ")
1453 if mproperty
.intro_mclassdef
.mclass
!= page
.mclass
then page
.append
("redef ")
1454 if mproperty
.is_init
then
1455 page
.append
("init ")
1459 mproperty
.html_namespace
(page
)
1460 page
.append
("</div>")
1461 page
.append
("<div style=\"float
: right
;\
"><a id=\"lblDiffCommit\
"></a></div>")
1465 redef class MVirtualTypeDef
1466 redef fun html_full_desc
(page
) do
1467 var is_redef
= mproperty
.intro_mclassdef
.mclass
!= page
.mclass
1468 var classes
= new Array[String]
1470 if is_redef
then classes
.add
("redef")
1471 classes
.add
(mproperty
.visibility
.to_s
)
1472 page
.append
("<article class='{classes.join(" ")}' id='{anchor}'>")
1473 page
.append
("<h3 class='signature'>{mproperty.name}: ")
1474 bound
.html_link
(page
)
1475 page
.append
("</h3>")
1478 page
.append
("</article>")
1481 redef fun html_info
(page
) do
1482 page
.append
("<div class='info'>")
1483 if mproperty
.intro_mclassdef
.mclass
!= page
.mclass
then page
.append
("redef ")
1484 page
.append
("type ")
1485 mproperty
.html_namespace
(page
)
1486 page
.append
("</div>")
1487 page
.append
("<div style=\"float
: right
;\
"><a id=\"lblDiffCommit\
"></a></div>")
1491 redef class MSignature
1492 private fun html_signature
(page
: NitdocPage) do
1493 if not mparameters
.is_empty
then
1495 for i
in [0..mparameters
.length
[ do
1496 mparameters
[i
].html_link
(page
)
1497 if i
< mparameters
.length
- 1 then page
.append
(", ")
1501 if return_mtype
!= null then
1503 return_mtype
.html_link
(page
)
1508 redef class MParameter
1509 private fun html_link
(page
: NitdocPage) do
1510 page
.append
("{name}: ")
1511 mtype
.html_link
(page
)
1512 if is_vararg
then page
.append
("...")
1521 private fun short_comment
: String do
1522 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1523 return n_moduledecl
.n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1528 private fun full_comment
: String do
1529 var res
= new Buffer
1530 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
1531 for t
in n_moduledecl
.n_doc
.n_comment
do
1532 res
.append
(t
.text
.substring_from
(1).html_escape
)
1539 redef class AStdClassdef
1540 private fun short_comment
: String do
1541 if n_doc
!= null then return n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1545 private fun full_comment
: String do
1546 var res
= new Buffer
1547 if n_doc
!= null then
1548 for t
in n_doc
.n_comment
do res
.append
(t
.text
.substring_from
(1).html_escape
)
1554 redef class APropdef
1555 private fun short_comment
: String do
1556 if n_doc
!= null then return n_doc
.n_comment
.first
.text
.substring_from
(2).replace
("\n", "").html_escape
1560 private fun full_comment
: String do
1561 var res
= new Buffer
1562 if n_doc
!= null then
1563 for t
in n_doc
.n_comment
do res
.append
(t
.text
.substring_from
(1).html_escape
)
1569 var nitdoc
= new NitdocContext
1570 nitdoc
.generate_nitdoc