ni_nitdoc: nested modules are not displayed with public option
[nit.git] / src / ni_nitdoc.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2008 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 module ni_nitdoc
18
19 import model_utils
20 import abstract_compiler
21
22 # The NitdocContext contains all the knowledge used for doc generation
23 class NitdocContext
24 super ToolContext
25
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
36
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")
42
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")
47
48 init do
49 super
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)
61 process_options
62
63 if arguments.length < 1 then
64 option_context.usage
65 exit(1)
66 end
67
68 model = new Model
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 mbuilder.full_propdef_semantic_analysis
73 if mmodules.is_empty then return
74
75 if mmodules.length == 1 then
76 mainmodule = mmodules.first
77 else
78 # We need a main module, so we build it by importing all modules
79 mainmodule = new MModule(model, null, "<main>", new Location(null, 0, 0, 0, 0))
80 mainmodule.set_imported_mmodules(mmodules)
81 end
82 self.class_hierarchy = mainmodule.flatten_mclass_hierarchy
83 end
84
85 redef fun process_options do
86 super
87 if not opt_dir.value is null then
88 output_dir = opt_dir.value
89 else
90 output_dir = "doc"
91 end
92 if not opt_sharedir.value is null then
93 share_dir = opt_sharedir.value
94 else
95 var dir = "NIT_DIR".environ
96 if dir.is_empty then
97 dir = "{sys.program_name.dirname}/../share/nitdoc"
98 else
99 dir = "{dir}/share/nitdoc"
100 end
101 share_dir = dir
102 if share_dir is null then
103 print "Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
104 abort
105 end
106 dir = "{share_dir.to_s}/scripts/js-facilities.js"
107 if share_dir is null then
108 print "Error: Invalid nitdoc share files. Check --sharedir or envvar NIT_DIR"
109 abort
110 end
111
112 if opt_private.value then
113 min_visibility = none_visibility
114 else
115 min_visibility = protected_visibility
116 end
117 end
118 source = opt_source.value
119 end
120
121 fun generate_nitdoc do
122 # Create destination dir if it's necessary
123 if not output_dir.file_exists then output_dir.mkdir
124 sys.system("cp -r {share_dir.to_s}/* {output_dir.to_s}/")
125 self.dot_dir = null
126 if not opt_nodot.value then self.dot_dir = output_dir.to_s
127 overview
128 fullindex
129 modules
130 classes
131 quicksearch_list
132 end
133
134 private fun overview do
135 var overviewpage = new NitdocOverview(self, dot_dir)
136 overviewpage.save("{output_dir.to_s}/index.html")
137 end
138
139 private fun fullindex do
140 var fullindex = new NitdocFullindex(self)
141 fullindex.save("{output_dir.to_s}/full-index.html")
142 end
143
144 private fun modules do
145 for mmodule in model.mmodules do
146 if mmodule.name == "<main>" then continue
147 var modulepage = new NitdocModule(mmodule, self, dot_dir)
148 modulepage.save("{output_dir.to_s}/{mmodule.url}")
149 end
150 end
151
152 private fun classes do
153 for mclass in mbuilder.model.mclasses do
154 var classpage = new NitdocClass(mclass, self, dot_dir, source)
155 classpage.save("{output_dir.to_s}/{mclass.url}")
156 end
157 end
158
159 private fun quicksearch_list do
160 var file = new OFStream.open("{output_dir.to_s}/quicksearch-list.js")
161 var content = new Buffer
162 content.append("var entries = \{ ")
163
164 for mmodule in model.mmodules do
165 content.append("\"{mmodule.name}\": [")
166 content.append("\{txt: \"{mmodule.name}\", url:\"{mmodule.url}\" \},")
167 content.append("],")
168 end
169 for mclass in model.mclasses do
170 if mclass.visibility < min_visibility then continue
171 content.append("\"{mclass.name}\": [")
172 content.append("\{txt: \"{mclass.name}\", url:\"{mclass.url}\" \},")
173 content.append("],")
174 end
175 var name2mprops = new HashMap[String, Set[MPropDef]]
176 for mproperty in model.mproperties do
177 if mproperty.visibility < min_visibility then continue
178 if mproperty isa MAttribute then continue
179 if not name2mprops.has_key(mproperty.name) then name2mprops[mproperty.name] = new HashSet[MPropDef]
180 name2mprops[mproperty.name].add_all(mproperty.mpropdefs)
181 end
182 for mproperty, mpropdefs in name2mprops do
183 content.append("\"{mproperty}\": [")
184 for mpropdef in mpropdefs do
185 content.append("\{txt: \"{mpropdef.full_name}\", url:\"{mpropdef.url}\" \},")
186 end
187 content.append("],")
188 end
189
190 content.append(" \};")
191 file.write(content.to_s)
192 file.close
193 end
194
195 end
196
197 # Nitdoc base page
198 abstract class NitdocPage
199 super Buffer
200
201 var dot_dir: nullable String
202 var source: nullable String
203 var ctx: NitdocContext
204
205 init(ctx: NitdocContext) do
206 super
207 self.ctx = ctx
208 end
209
210 protected fun head do
211 append("<meta charset='utf-8'/>")
212 append("<script type='text/javascript' src='scripts/jquery-1.7.1.min.js'></script>")
213 append("<script type='text/javascript' src='quicksearch-list.js'></script>")
214 append("<script type='text/javascript' src='scripts/js-facilities.js'></script>")
215 append("<link rel='stylesheet' href='styles/main.css' type='text/css' media='screen'/>")
216 var title = ""
217 if ctx.opt_custom_title.value != null then
218 title = " | {ctx.opt_custom_title.value.to_s}"
219 end
220 append("<title>{self.title}{title}</title>")
221 end
222
223 protected fun menu do
224 if ctx.opt_custom_menu_items.value != null then
225 append(ctx.opt_custom_menu_items.value.to_s)
226 end
227 end
228
229 protected fun title: String is abstract
230
231 protected fun header do
232 append("<header>")
233 append("<nav class='main'>")
234 append("<ul>")
235 menu
236 append("<li id='liGitHub'>")
237 append("<a class='btn' id='logGitHub'>")
238 append("<img id='imgGitHub' src='resources/icons/github-icon.png' alt='GitHub'/>")
239 append("</a>")
240 append("<div class='popover bottom'>")
241 append("<div class='arrow'>&nbsp;</div>")
242 append("<div class='githubTitle'>")
243 append("<h3>Github Sign In</h3>")
244 append("</div>")
245 append("<div>")
246 append("<label id='lbloginGit'>Username</label>")
247 append("<input id='loginGit' name='login' type='text'/>")
248 append("<label id='logginMessage'>Hello ")
249 append("<a id='githubAccount'><strong id='nickName'></strong></a>")
250 append("</label>")
251 append("</div>")
252 append("<div>")
253 append("<label id='lbpasswordGit'>Password</label>")
254 append("<input id='passwordGit' name='password' type='password'/>")
255 append("<div id='listBranches'>")
256 append("<label id='lbBranches'>Branch</label>")
257 append("<select class='dropdown' id='dropBranches' name='dropBranches' tabindex='1'></select>")
258 append("</div>")
259 append("</div>")
260 append("<div>")
261 append("<label id='lbrepositoryGit'>Repository</label>")
262 append("<input id='repositoryGit' name='repository' type='text'/>")
263 append("</div>")
264 append("<div>")
265 append("<label id='lbbranchGit'>Branch</label>")
266 append("<input id='branchGit' name='branch' type='text'/>")
267 append("</div>")
268 append("<div>")
269 append("<a id='signIn'>Sign In</a>")
270 append("</div>")
271 append("</div>")
272 append("</li>")
273 append("</ul>")
274 append("</nav>")
275 append("</header>")
276 end
277
278 protected fun content is abstract
279
280 protected fun footer do
281 if ctx.opt_custom_footer_text.value != null then
282 append("<footer>{ctx.opt_custom_footer_text.value.to_s}</footer>")
283 end
284 end
285
286 # Generate a clickable graphviz image using a dot content
287 protected fun generate_dot(dot: String, name: String, alt: String) do
288 var output_dir = dot_dir
289 if output_dir == null then return
290 var file = new OFStream.open("{output_dir}/{name}.dot")
291 file.write(dot)
292 file.close
293 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 ; \}")
294 append("<article class='graph'>")
295 append("<img src='{name}.png' usemap='#{name}' style='margin:auto' alt='{alt}'/>")
296 append("</article>")
297 var fmap = new IFStream.open("{output_dir}/{name}.map")
298 append(fmap.read_all)
299 fmap.close
300 end
301
302 # Add a (source) link for a given location
303 protected fun show_source(l: Location): String
304 do
305 if source == null then
306 return "({l.file.filename.simplify_path})"
307 else
308 # THIS IS JUST UGLY ! (but there is no replace yet)
309 var x = source.split_with("%f")
310 source = x.join(l.file.filename.simplify_path)
311 x = source.split_with("%l")
312 source = x.join(l.line_start.to_s)
313 x = source.split_with("%L")
314 source = x.join(l.line_end.to_s)
315 return " (<a href=\"{source.to_s}\">source</a>)"
316 end
317 end
318
319 # Render the page as a html string
320 fun render: String do
321 append("<!DOCTYPE html>")
322 append("<head>")
323 head
324 append("</head>")
325 append("<body>")
326 header
327 append("<div class='page'>")
328 content
329 append("</div>")
330 footer
331 append("</body>")
332 return to_s
333 end
334
335 # Save html page in the specified file
336 fun save(file: String) do
337 var out = new OFStream.open(file)
338 out.write(render)
339 out.close
340 end
341 end
342
343 # The overview page
344 class NitdocOverview
345 super NitdocPage
346 private var mbuilder: ModelBuilder
347 private var mmodules = new Array[MModule]
348
349 init(ctx: NitdocContext, dot_dir: nullable String) do
350 super(ctx)
351 self.mbuilder = ctx.mbuilder
352 self.dot_dir = dot_dir
353 # get modules
354 var mmodules = new HashSet[MModule]
355 for mmodule in mbuilder.model.mmodules do
356 if mmodule.name == "<main>" then continue
357 var owner = mmodule.public_owner
358 if owner != null then
359 mmodules.add(owner)
360 else
361 mmodules.add(mmodule)
362 end
363 end
364 # sort modules
365 var sorter = new ComparableSorter[MModule]
366 self.mmodules.add_all(mmodules)
367 sorter.sort(self.mmodules)
368 end
369
370 redef fun title do return "Overview"
371
372 redef fun menu do
373 super
374 append("<li class='current'>Overview</li>")
375 append("<li><a href='full-index.html'>Full Index</a></li>")
376 end
377
378 redef fun content do
379 append("<div class='content fullpage'>")
380 var title = "Overview"
381 if ctx.opt_custom_title.value != null then
382 title = ctx.opt_custom_title.value.to_s
383 end
384 append("<h1>{title}</h1>")
385 var text = ""
386 if ctx.opt_custom_overview_text.value != null then
387 text = ctx.opt_custom_overview_text.value.to_s
388 end
389 append("<article class='overview'>{text}</article>")
390 append("<article class='overview'>")
391 # module list
392 append("<h2>Modules</h2>")
393 append("<ul>")
394 for mmodule in mmodules do
395 if mbuilder.mmodule2nmodule.has_key(mmodule) then
396 var amodule = mbuilder.mmodule2nmodule[mmodule]
397 append("<li>")
398 mmodule.html_link(self)
399 append("&nbsp;{amodule.short_comment}</li>")
400 end
401 end
402 append("</ul>")
403 # module graph
404 process_generate_dot
405 append("</article>")
406 append("</div>")
407 end
408
409 private fun process_generate_dot do
410 # build poset with public owners
411 var poset = new POSet[MModule]
412 for mmodule in mmodules do
413 poset.add_node(mmodule)
414 for omodule in mmodules do
415 if mmodule == omodule then continue
416 if mmodule.in_importation < omodule then
417 poset.add_node(omodule)
418 poset.add_edge(mmodule, omodule)
419 end
420 end
421 end
422 # build graph
423 var op = new Buffer
424 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")
425 for mmodule in poset do
426 op.append("\"{mmodule.name}\"[URL=\"{mmodule.url}\"];\n")
427 for omodule in poset[mmodule].direct_greaters do
428 op.append("\"{mmodule.name}\"->\"{omodule.name}\";\n")
429 end
430 end
431 op.append("\}\n")
432 generate_dot(op.to_s, "dep", "Modules hierarchy")
433 end
434 end
435
436 # The full index page
437 class NitdocFullindex
438 super NitdocPage
439
440 init(ctx: NitdocContext) do
441 super(ctx)
442 self.dot_dir = null
443 end
444
445 redef fun title do return "Full Index"
446
447 redef fun menu do
448 super
449 append("<li><a href='index.html'>Overview</a></li>")
450 append("<li class='current'>Full Index</li>")
451 end
452
453 redef fun content do
454 append("<div class='content fullpage'>")
455 append("<h1>Full Index</h1>")
456 module_column
457 classes_column
458 properties_column
459 append("</div>")
460 end
461
462 # Add to content modules column
463 private fun module_column do
464 var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
465 var sorter = new ComparableSorter[MModule]
466 sorter.sort(sorted)
467 append("<article class='modules filterable'>")
468 append("<h2>Modules</h2>")
469 append("<ul>")
470 for mmodule in sorted do
471 append("<li>")
472 mmodule.html_link(self)
473 append("</li>")
474 end
475 append("</ul>")
476 append("</article>")
477 end
478
479 # Add to content classes modules
480 private fun classes_column do
481 var sorted = ctx.mbuilder.model.mclasses
482 var sorter = new ComparableSorter[MClass]
483 sorter.sort(sorted)
484 append("<article class='modules filterable'>")
485 append("<h2>Classes</h2>")
486 append("<ul>")
487 for mclass in sorted do
488 if mclass.visibility < ctx.min_visibility then continue
489 append("<li>")
490 mclass.html_link(self)
491 append("</li>")
492 end
493 append("</ul>")
494 append("</article>")
495 end
496
497 # Insert the properties column of fullindex page
498 private fun properties_column do
499 var sorted = ctx.mbuilder.model.mproperties
500 var sorter = new ComparableSorter[MProperty]
501 sorter.sort(sorted)
502 append("<article class='modules filterable'>")
503 append("<h2>Properties</h2>")
504 append("<ul>")
505 for mproperty in sorted do
506 if mproperty.visibility < ctx.min_visibility then continue
507 if mproperty isa MAttribute then continue
508 append("<li>")
509 mproperty.intro.html_link(self)
510 append(" (")
511 mproperty.intro.mclassdef.mclass.html_link(self)
512 append(")</li>")
513 end
514 append("</ul>")
515 append("</article>")
516 end
517
518 end
519
520 # A module page
521 class NitdocModule
522 super NitdocPage
523
524 private var mmodule: MModule
525 private var mbuilder: ModelBuilder
526
527 init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
528 super(ctx)
529 self.mmodule = mmodule
530 self.mbuilder = ctx.mbuilder
531 self.dot_dir = dot_dir
532 end
533
534 redef fun title do
535 if mbuilder.mmodule2nmodule.has_key(mmodule) then
536 var nmodule = mbuilder.mmodule2nmodule[mmodule]
537 return "{mmodule.name} module | {nmodule.short_comment}"
538 else
539 return "{mmodule.name} module"
540 end
541 end
542
543 redef fun menu do
544 super
545 append("<li><a href='index.html'>Overview</a></li>")
546 append("<li class='current'>{mmodule.name}</li>")
547 append("<li><a href='full-index.html'>Full Index</a></li>")
548 end
549
550 redef fun content do
551 sidebar
552 append("<div class='content'>")
553 append("<h1>{mmodule.name}</h1>")
554 append("<div class='subtitle info'>")
555 mmodule.html_signature(self)
556 append("</div>")
557 mmodule.html_full_comment(self)
558 process_generate_dot
559 classes
560 properties
561 append("</div>")
562 end
563
564 private fun process_generate_dot do
565 # build poset with public owners
566 var poset = new POSet[MModule]
567 for mmodule in self.mmodule.in_importation.poset do
568 if mmodule.name == "<main>" then continue
569 if mmodule.public_owner != null then continue
570 if not mmodule.in_importation < self.mmodule and not self.mmodule.in_importation < mmodule and mmodule != self.mmodule then continue
571 poset.add_node(mmodule)
572 for omodule in mmodule.in_importation.poset do
573 if mmodule == omodule then continue
574 if omodule.name == "<main>" then continue
575 if omodule.public_owner != null then continue
576 if mmodule.in_importation < omodule then
577 poset.add_node(omodule)
578 poset.add_edge(mmodule, omodule)
579 end
580 end
581 end
582 # build graph
583 var op = new Buffer
584 var name = "dep_{mmodule.name}"
585 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")
586 for mmodule in poset do
587 if mmodule == self.mmodule then
588 op.append("\"{mmodule.name}\"[shape=box,margin=0.03];\n")
589 else
590 op.append("\"{mmodule.name}\"[URL=\"{mmodule.url}\"];\n")
591 end
592 for omodule in poset[mmodule].direct_greaters do
593 op.append("\"{mmodule.name}\"->\"{omodule.name}\";\n")
594 end
595 end
596 op.append("\}\n")
597 generate_dot(op.to_s, name, "Dependency graph for module {mmodule.name}")
598 end
599
600 private fun sidebar do
601 append("<div class='menu'>")
602 append("<nav>")
603 append("<h3>Module Hierarchy</h3>")
604 var dependencies = new Array[MModule]
605 for dep in mmodule.in_importation.greaters do
606 if dep == mmodule or dep.public_owner != null then continue
607 dependencies.add(dep)
608 end
609 if dependencies.length > 0 then
610 append("<h4>All dependencies</h4>")
611 display_module_list(dependencies)
612 end
613 var clients = new Array[MModule]
614 for dep in mmodule.in_importation.smallers do
615 if dep == mmodule or dep.public_owner != null then continue
616 clients.add(dep)
617 end
618 if clients.length > 0 then
619 append("<h4>All clients</h4>")
620 display_module_list(clients)
621 end
622 append("</nav>")
623 if ctx.min_visibility < protected_visibility then
624 if mmodule.in_nesting.direct_greaters.length > 0 then
625 append("<nav>")
626 append("<h3>Nested Modules</h3>")
627 display_module_list(mmodule.in_nesting.direct_greaters.to_a)
628 append("</nav>")
629 end
630 end
631 append("</div>")
632 end
633
634 private fun display_module_list(list: Array[MModule]) do
635 append("<ul>")
636 var sorter = new ComparableSorter[MModule]
637 sorter.sort(list)
638 for m in list do
639 append("<li>")
640 m.html_link(self)
641 append("</li>")
642 end
643 append("</ul>")
644 end
645
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)
654 end
655 all_mclasses.add_all(intro_mclasses)
656 all_mclasses.add_all(redef_mclasses)
657
658 var sorted = new Array[MClass]
659 sorted.add_all(all_mclasses)
660 var sorter = new ComparableSorter[MClass]
661 sorter.sort(sorted)
662 append("<div class='module'>")
663 append("<article class='classes filterable'>")
664 append("<h2>Classes</h2>")
665 append("<ul>")
666 for c in sorted do
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>")
671 else
672 append("<li class='intro'>")
673 append("<span title='introduced in this module'>I </span>")
674 end
675 c.html_link(self)
676 append("</li>")
677 end
678 append("</ul>")
679 append("</article>")
680 append("</div>")
681 end
682
683 # display the property column
684 private fun properties do
685 # get properties
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)
689 end
690 for c in mmodule.mclassdefs do mpropdefs.add_all(c.mpropdefs)
691 var sorted = mpropdefs.to_a
692 var sorter = new ComparableSorter[MPropDef]
693 sorter.sort(sorted)
694 # display properties in one column
695 append("<article class='properties filterable'>")
696 append("<h2>Properties</h2>")
697 append("<ul>")
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)
702 end
703 append("</ul>")
704 append("</article>")
705 end
706 end
707
708 # A class page
709 class NitdocClass
710 super NitdocPage
711
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]
717
718 init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
719 super(ctx)
720 self.mclass = mclass
721 self.dot_dir = dot_dir
722 self.source = source
723 # load properties
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
730 consts.add(mpropdef)
731 else
732 meths.add(mpropdef)
733 end
734 end
735 end
736 end
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
744 consts.add(mpropdef)
745 else
746 meths.add(mpropdef)
747 end
748 end
749 inherited.add(mpropdef)
750 end
751 end
752
753 redef fun title do
754 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
755 if nclass isa AStdClassdef then
756 return "{mclass.name} class | {nclass.short_comment}"
757 else
758 return "{mclass.name} class"
759 end
760 end
761
762 redef fun menu do
763 super
764 append("<li><a href='index.html'>Overview</a></li>")
765 var public_owner = mclass.public_owner
766 if public_owner is null then
767 append("<li>")
768 mclass.intro_mmodule.html_link(self)
769 append("</li>")
770 else
771 append("<li>")
772 public_owner.html_link(self)
773 append("</li>")
774 end
775 append("<li class='current'>{mclass.name}</li>")
776 append("<li><a href='full-index.html'>Full Index</a></li>")
777 end
778
779 redef fun content do
780 append("<div class='menu'>")
781 properties_column
782 inheritance_column
783 append("</div>")
784 append("<div class='content'>")
785 class_doc
786 append("</div>")
787 end
788
789 private fun properties_column do
790 var sorter = new ComparableSorter[MPropDef]
791 append("<nav class='properties filterable'>")
792 append("<h3>Properties</h3>")
793 # virtual types
794 if vtypes.length > 0 then
795 var vts = new Array[MVirtualTypeDef]
796 vts.add_all(vtypes)
797 sorter.sort(vts)
798 append("<h4>Virtual Types</h4>")
799 append("<ul>")
800 for mprop in vts do
801 mprop.html_sidebar_item(self)
802 end
803 append("</ul>")
804 end
805 # constructors
806 if consts.length > 0 then
807 var cts = new Array[MMethodDef]
808 cts.add_all(consts)
809 sorter.sort(cts)
810 append("<h4>Constructors</h4>")
811 append("<ul>")
812 for mprop in cts do
813 if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
814 mprop.html_sidebar_item(self)
815 end
816 append("</ul>")
817 end
818 # methods
819 if meths.length > 0 then
820 var mts = new Array[MMethodDef]
821 mts.add_all(meths)
822 sorter.sort(mts)
823 append("<h4>Methods</h4>")
824 append("<ul>")
825 for mprop in mts do
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)
828 end
829 append("</ul>")
830 end
831 append("</nav>")
832 end
833
834 private fun inheritance_column do
835 var sorted = new Array[MClass]
836 var sorterp = new ComparableSorter[MClass]
837 append("<nav>")
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>")
843 append("<ul>")
844 for sup in greaters do
845 if sup == mclass then continue
846 append("<li>")
847 sup.html_link(self)
848 append("</li>")
849 end
850 append("</ul>")
851 end
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>")
859 append("<ul>")
860 for sub in smallers do
861 if sub == mclass then continue
862 append("<li>")
863 sub.html_link(self)
864 append("</li>")
865 end
866 append("</ul>")
867 else if direct_smallers.length <= 100 then
868 ctx.mainmodule.linearize_mclasses(direct_smallers)
869 append("<h4>Direct Subclasses Only</h4>")
870 append("<ul>")
871 for sub in direct_smallers do
872 if sub == mclass then continue
873 append("<li>")
874 sub.html_link(self)
875 append("</li>")
876 end
877 append("</ul>")
878 else
879 append("<h4>Too much Subclasses to list</h4>")
880 end
881 append("</nav>")
882 end
883
884 private fun class_doc do
885 # title
886 append("<h1>{mclass.signature}</h1>")
887 append("<div class='subtitle info'>")
888 mclass.html_full_signature(self)
889 append("</div>")
890 # comment
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>")
895 process_generate_dot
896 append("</section>")
897 # concerns
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)
903 for meth in meths do
904 if inherited.has(meth) then continue
905 var mmodule = meth.mclassdef.mmodule
906 if not concern2meths.has_key(mmodule) then
907 sorted.add(mmodule)
908 concern2meths[mmodule] = new Array[MMethodDef]
909 end
910 concern2meths[mmodule].add(meth)
911 end
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)
918 end
919 append("<section class='concerns'>")
920 append("<h2 class='section-header'>Concerns</h2>")
921 append("<ul>")
922 for owner, mmodules in sections do
923 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
924 append("<li>")
925 if nowner.short_comment.is_empty then
926 append("<a href=\"#{owner.anchor}\">{owner.name}</a>")
927 else
928 append("<a href=\"#{owner.anchor}\">{owner.name}</a>: {nowner.short_comment}")
929 end
930 if not mmodules.is_empty then
931 append("<ul>")
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>")
936 else
937 append("<li><a href=\"#{mmodule.anchor}\">{mmodule.name}</a>: {nmodule.short_comment}</li>")
938 end
939 end
940 append("</ul>")
941 end
942 append("</li>")
943 end
944 append("</ul>")
945 append("</section>")
946 # properties
947 var prop_sorter = new ComparableSorter[MPropDef]
948 var sorterprop = new ComparableSorter[MProperty]
949 var sorterc = new ComparableSorter[MClass]
950 var lmmodule = new List[MModule]
951 # virtual and formal types
952 var local_vtypes = new Array[MVirtualTypeDef]
953 for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
954 if local_vtypes.length > 0 or mclass.arity > 0 then
955 append("<section class='types'>")
956 append("<h2>Formal and Virtual Types</h2>")
957 # formal types
958 if mclass.arity > 0 and nclass isa AStdClassdef then
959 for ft, bound in mclass.parameter_types do
960 append("<article id='FT_{ft}'>")
961 append("<h3 class='signature'>{ft}: ")
962 bound.html_link(self)
963 append("</h3>")
964 append("<div class=\"info\">formal generic type</div>")
965 append("</article>")
966 end
967 end
968 # virtual types
969 prop_sorter.sort(local_vtypes)
970 for prop in local_vtypes do prop.html_full_desc(self)
971 append("</section>")
972 end
973 # constructors
974 var local_consts = new Array[MMethodDef]
975 for const in consts do if not inherited.has(const) then local_consts.add(const)
976 prop_sorter.sort(local_consts)
977 if local_consts.length > 0 then
978 append("<section class='constructors'>")
979 append("<h2 class='section-header'>Constructors</h2>")
980 for prop in local_consts do prop.html_full_desc(self)
981 append("</section>")
982 end
983 # methods
984 if not concern2meths.is_empty then
985 append("<section class='methods'>")
986 append("<h2 class='section-header'>Methods</h2>")
987 for owner, mmodules in sections do
988 append("<a id=\"{owner.anchor}\"></a>")
989 if owner != mclass.intro_mmodule and owner != mclass.public_owner then
990 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
991 append("<h3 class=\"concern-toplevel\">Methods refined in ")
992 owner.html_link(self)
993 append("</h3>")
994 append("<p class=\"concern-doc\">")
995 owner.html_link(self)
996 if not nowner.short_comment.is_empty then
997 append(": {nowner.short_comment}")
998 end
999 append("</p>")
1000 end
1001 if concern2meths.has_key(owner) then
1002 var mmethods = concern2meths[owner]
1003 prop_sorter.sort(mmethods)
1004 for prop in mmethods do prop.html_full_desc(self)
1005 end
1006 for mmodule in mmodules do
1007 append("<a id=\"{mmodule.anchor}\"></a>")
1008 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
1009 if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
1010 append("<p class=\"concern-doc\">")
1011 mmodule.html_link(self)
1012 if not nmodule.short_comment.is_empty then
1013 append(": {nmodule.short_comment}")
1014 end
1015 append("</p>")
1016 end
1017 var mmethods = concern2meths[mmodule]
1018 prop_sorter.sort(mmethods)
1019 for prop in mmethods do prop.html_full_desc(self)
1020 end
1021 end
1022 end
1023 # inherited properties
1024 if inherited.length > 0 then
1025 var sorted_inherited = new Array[MPropDef]
1026 sorted_inherited.add_all(inherited)
1027 ctx.mainmodule.linearize_mpropdefs(sorted_inherited)
1028 var classes = new ArrayMap[MClass, Array[MPropDef]]
1029 for mmethod in sorted_inherited.reversed do
1030 var mclass = mmethod.mclassdef.mclass
1031 if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
1032 classes[mclass].add(mmethod)
1033 end
1034 append("<h3>Inherited Properties</h3>")
1035 for c, mmethods in classes do
1036 prop_sorter.sort(mmethods)
1037 append("<p>Defined in ")
1038 c.html_link(self)
1039 append("}: ")
1040 for i in [0..mmethods.length[ do
1041 var mmethod = mmethods[i]
1042 mmethod.html_link(self)
1043 if i <= mmethods.length - 1 then append(", ")
1044 end
1045 append("</p>")
1046 end
1047 end
1048 append("</section>")
1049 end
1050
1051 private fun process_generate_dot do
1052 var pe = ctx.class_hierarchy[mclass]
1053 var cla = new HashSet[MClass]
1054 var sm = new HashSet[MClass]
1055 var sm2 = new HashSet[MClass]
1056 sm.add(mclass)
1057 while cla.length + sm.length < 10 and sm.length > 0 do
1058 cla.add_all(sm)
1059 sm2.clear
1060 for x in sm do
1061 sm2.add_all(pe.poset[x].direct_smallers)
1062 end
1063 var t = sm
1064 sm = sm2
1065 sm2 = t
1066 end
1067 cla.add_all(pe.greaters)
1068
1069 var op = new Buffer
1070 var name = "dep_{mclass.name}"
1071 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 for c in cla do
1073 if c == mclass then
1074 op.append("\"{c.name}\"[shape=box,margin=0.03];\n")
1075 else
1076 op.append("\"{c.name}\"[URL=\"{c.url}\"];\n")
1077 end
1078 for c2 in pe.poset[c].direct_greaters do
1079 if not cla.has(c2) then continue
1080 op.append("\"{c.name}\"->\"{c2.name}\";\n")
1081 end
1082 if not pe.poset[c].direct_smallers.is_empty then
1083 var others = true
1084 for c2 in pe.poset[c].direct_smallers do
1085 if cla.has(c2) then others = false
1086 end
1087 if others then
1088 op.append("\"{c.name}...\"[label=\"\"];\n")
1089 op.append("\"{c.name}...\"->\"{c.name}\"[style=dotted];\n")
1090 end
1091 end
1092 end
1093 op.append("\}\n")
1094 generate_dot(op.to_s, name, "Dependency graph for class {mclass.name}")
1095 end
1096 end
1097
1098 #
1099 # Model redefs
1100 #
1101
1102 redef class MModule
1103 super Comparable
1104 redef type OTHER: MModule
1105 redef fun <(other: OTHER): Bool do return self.name < other.name
1106
1107 # Get the list of all methods in a module
1108 fun imported_methods: Set[MMethod] do
1109 var methods = new HashSet[MMethod]
1110 for mclass in imported_mclasses do
1111 for method in mclass.intro_methods do
1112 methods.add(method)
1113 end
1114 end
1115 return methods
1116 end
1117
1118 # Get the list aof all refined methods in a module
1119 fun redef_methods: Set[MMethod] do
1120 var methods = new HashSet[MMethod]
1121 for mclass in redef_mclasses do
1122 for method in mclass.intro_methods do
1123 methods.add(method)
1124 end
1125 end
1126 return methods
1127 end
1128
1129 # URL to nitdoc page
1130 fun url: String do
1131 var res = new Buffer
1132 res.append("module_")
1133 var mowner = public_owner
1134 if mowner != null then
1135 res.append("{public_owner.name}_")
1136 end
1137 res.append("{self.name}.html")
1138 return res.to_s
1139 end
1140
1141 # html anchor id to the module in a nitdoc page
1142 fun anchor: String do
1143 var res = new Buffer
1144 res.append("MOD_")
1145 var mowner = public_owner
1146 if mowner != null then
1147 res.append("{public_owner.name}_")
1148 end
1149 res.append(self.name)
1150 return res.to_s
1151 end
1152
1153 # Return a link (html a tag) to the nitdoc module page
1154 fun html_link(page: NitdocPage) do
1155 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1156 page.append("<a href='{url}' title='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{name}</a>")
1157 else
1158 page.append("<a href='{url}'>{name}</a>")
1159 end
1160 end
1161
1162 # Return the module signature decorated with html
1163 fun html_signature(page: NitdocPage) do
1164 page.append("<span>module ")
1165 html_full_namespace(page)
1166 page.append("</span>")
1167 end
1168
1169 # Return the module full namespace decorated with html
1170 fun html_full_namespace(page: NitdocPage) do
1171 page.append("<span>")
1172 var mowner = public_owner
1173 if mowner != null then
1174 public_owner.html_namespace(page)
1175 page.append("::")
1176 end
1177 html_link(page)
1178 page.append("</span>")
1179 end
1180
1181 # Return the module full namespace decorated with html
1182 fun html_namespace(page: NitdocPage) do
1183 page.append("<span>")
1184 var mowner = public_owner
1185 if mowner != null then
1186 public_owner.html_namespace(page)
1187 else
1188 html_link(page)
1189 end
1190 page.append("</span>")
1191 end
1192
1193 # Return the full comment of the module decorated with html
1194 fun html_full_comment(page: NitdocPage) do
1195 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1196 page.append("<div id='description'>")
1197 page.append("<pre class='text_label'>{page.ctx.mbuilder.mmodule2nmodule[self].full_comment}</pre>")
1198 page.append("<textarea class='edit' rows='1' cols='76' id='fileContent'></textarea>")
1199 page.append("<a id='cancelBtn'>Cancel</a>")
1200 page.append("<a id='commitBtn'>Commit</a>")
1201 page.append("<pre class='text_label' id='preSave' type='2'></pre>")
1202 page.append("</div>")
1203 end
1204 end
1205 end
1206
1207 redef class MClass
1208 super Comparable
1209 redef type OTHER: MClass
1210 redef fun <(other: OTHER): Bool do return self.name < other.name
1211
1212 # Return the module signature decorated with html
1213 fun html_full_signature(page: NitdocPage) do
1214 if visibility < public_visibility then page.append("{visibility.to_s} ")
1215 page.append("{kind} ")
1216 html_namespace(page)
1217 end
1218
1219 # name with formal parameter
1220 # Foo[A, B]
1221 private fun signature: String do
1222 if arity > 0 then
1223 return "{name}[{intro.parameter_names.join(", ")}]"
1224 else
1225 return name
1226 end
1227 end
1228
1229 # Return a link (html a tag) to the nitdoc class page
1230 fun html_link(page: NitdocPage) do
1231 page.append("<a href='{url}'")
1232 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1233 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1234 if nclass isa AStdClassdef then
1235 page.append(" title=\"{nclass.short_comment}\"")
1236 end
1237 end
1238 page.append(">{signature}</a>")
1239 end
1240
1241 # Return the class namespace decorated with html
1242 fun html_namespace(page: NitdocPage) do
1243 intro_mmodule.html_namespace(page)
1244 page.append("::<span>")
1245 html_link(page)
1246 page.append("</span>")
1247 end
1248
1249 fun url: String do
1250 return "class_{public_owner}_{c_name}.html"
1251 end
1252
1253 # Escape name for html output
1254 redef fun name do return super.html_escape
1255 end
1256
1257 redef class MProperty
1258 super Comparable
1259 redef type OTHER: MProperty
1260 redef fun <(other: OTHER): Bool do return self.name < other.name
1261
1262 # Return the property namespace decorated with html
1263 fun html_namespace(page: NitdocPage) do
1264 intro_mclassdef.mclass.html_namespace(page)
1265 page.append("::<span>")
1266 intro.html_link(page)
1267 page.append("</span>")
1268 end
1269
1270 # Escape name for html output
1271 redef fun name do return super.html_escape
1272 end
1273
1274 redef class MType
1275 fun html_link(page: NitdocPage) is abstract
1276 end
1277
1278 redef class MClassType
1279 redef fun html_link(page) do mclass.html_link(page)
1280 end
1281
1282 redef class MNullableType
1283 redef fun html_link(page) do
1284 page.append("nullable ")
1285 mtype.html_link(page)
1286 end
1287 end
1288
1289 redef class MGenericType
1290 redef fun html_link(page) do
1291 page.append("<a href='{mclass.url}'>{mclass.name}</a>[")
1292 for i in [0..arguments.length[ do
1293 arguments[i].html_link(page)
1294 if i < arguments.length - 1 then page.append(", ")
1295 end
1296 page.append("]")
1297 end
1298 end
1299
1300 redef class MParameterType
1301 redef fun html_link(page) do
1302 var name = mclass.intro.parameter_names[rank]
1303 page.append("<a href='{mclass.url}#FT_{name}' title='formal type'>{name}</a>")
1304 end
1305 end
1306
1307 redef class MVirtualType
1308 redef fun html_link(page) do mproperty.intro.html_link(page)
1309 end
1310
1311 redef class MClassDef
1312 # Return the classdef namespace decorated with html
1313 fun html_namespace(page: NitdocPage) do
1314 mmodule.html_full_namespace(page)
1315 page.append("::<span>")
1316 mclass.html_link(page)
1317 page.append("</span>")
1318 end
1319 end
1320
1321 redef class MPropDef
1322 super Comparable
1323 redef type OTHER: MPropDef
1324 redef fun <(other: OTHER): Bool do return self.mproperty.name < other.mproperty.name
1325
1326 fun url: String do return "{mclassdef.mclass.url}#{anchor}"
1327 fun anchor: String do return "PROP_{mclassdef.mclass.public_owner.name}_{c_name}"
1328
1329 # Return a link (html a tag) to the nitdoc class page
1330 fun html_link(page: NitdocPage) do
1331 if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then
1332 var nprop = page.ctx.mbuilder.mpropdef2npropdef[self]
1333 page.append("<a href=\"{url}\" title=\"{nprop.short_comment}\">{mproperty.name}</a>")
1334 else
1335 page.append("<a href=\"{url}\">{mproperty.name}</a>")
1336 end
1337 end
1338
1339 # Return a list item for the mpropdef
1340 fun html_list_item(page: NitdocPage) do
1341 if is_intro then
1342 page.append("<li class='intro'>")
1343 page.append("<span title='introduction'>I</span>&nbsp;")
1344 else
1345 page.append("<li class='redef'>")
1346 page.append("<span title='redefinition'>R</span>&nbsp;")
1347 end
1348 html_link(page)
1349 page.append("(")
1350 mclassdef.mclass.html_link(page)
1351 page.append(")")
1352 page.append("</li>")
1353 end
1354
1355 # Return a list item for the mpropdef
1356 fun html_sidebar_item(page: NitdocClass) do
1357 if is_intro and mclassdef.mclass == page.mclass then
1358 page.append("<li class='intro'>")
1359 page.append("<span title='Introduced'>I</span>")
1360 else if is_intro and mclassdef.mclass != page.mclass then
1361 page.append("<li class='inherit'>")
1362 page.append("<span title='Inherited'>H</span>")
1363 else
1364 page.append("<li class='redef'>")
1365 page.append("<span title='Redefined'>R</span>")
1366 end
1367 html_link(page)
1368 page.append("</li>")
1369 end
1370
1371 fun html_full_desc(page: NitdocClass) is abstract
1372 fun html_info(page: NitdocClass) is abstract
1373
1374 fun full_name: String do
1375 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1376 end
1377
1378 fun html_inheritance(page: NitdocClass) do
1379 # definitions block
1380 page.append("<p class='info'>")
1381 page.ctx.mainmodule.linearize_mpropdefs(mproperty.mpropdefs)
1382 var previous_defs = new Array[MPropDef]
1383 var next_defs = new Array[MPropDef]
1384 var self_passed = false
1385 for def in mproperty.mpropdefs do
1386 if def == self then
1387 self_passed = true
1388 continue
1389 end
1390 if not self_passed then
1391 if def.mclassdef.mclass.in_hierarchy(page.ctx.mainmodule) < page.mclass then continue
1392 if def.is_intro then continue
1393 previous_defs.add(def)
1394 else
1395 if page.mclass.in_hierarchy(page.ctx.mainmodule) < def.mclassdef.mclass then continue
1396 next_defs.add(def)
1397 end
1398 end
1399 page.append("defined by ")
1400 mclassdef.mmodule.html_full_namespace(page)
1401 if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then
1402 page.append(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1403 end
1404 if not is_intro then
1405 page.append(", introduced by ")
1406 mproperty.intro.mclassdef.mclass.html_link(page)
1407 if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then
1408 page.append(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1409 end
1410 end
1411 if not previous_defs.is_empty then
1412 page.append(", inherited from ")
1413 for i in [0..previous_defs.length[ do
1414 var def = previous_defs[i]
1415 def.mclassdef.mclass.html_link(page)
1416 if page.ctx.mbuilder.mpropdef2npropdef.has_key(def) then
1417 page.append(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1418 end
1419
1420 if i < previous_defs.length - 1 then page.append(", ")
1421 end
1422 end
1423 if not next_defs.is_empty then
1424 page.append(", redefined by ")
1425 for i in [0..next_defs.length[ do
1426 var def = next_defs[i]
1427 def.mclassdef.mclass.html_link(page)
1428 if page.ctx.mbuilder.mpropdef2npropdef.has_key(def) then
1429 page.append(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1430 end
1431 if i < next_defs.length - 1 then page.append(", ")
1432 end
1433 end
1434 page.append(".</p>")
1435 end
1436 end
1437
1438 redef class MMethodDef
1439 redef fun html_full_desc(page) do
1440 if not page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then return
1441 var nprop = page.ctx.mbuilder.mpropdef2npropdef[self]
1442 var classes = new Array[String]
1443 var is_redef = mproperty.intro_mclassdef.mclass != page.mclass
1444 classes.add("fun")
1445 if mproperty.is_init then classes.add("init")
1446 if is_redef then classes.add("redef")
1447 classes.add(mproperty.visibility.to_s)
1448 page.append("<article class='{classes.join(" ")}' id='{anchor}'>")
1449 if nprop isa AAttrPropdef then
1450 if nprop.mreadpropdef == self then
1451 page.append("<h3 class='signature'>{mproperty.name}: ")
1452 nprop.html_signature(page)
1453 page.append("</h3>")
1454 else
1455 page.append("<h3 class='signature'>{mproperty.name}(value: ")
1456 nprop.html_signature(page)
1457 page.append(")</h3>")
1458 end
1459 else
1460 var intro_nprop = page.ctx.mbuilder.mpropdef2npropdef[mproperty.intro]
1461 page.append("<h3 class='signature'>{mproperty.name}")
1462 intro_nprop.html_signature(page)
1463 page.append("</h3>")
1464 end
1465 html_info(page)
1466 page.append("<div class='description'>")
1467 if nprop.full_comment == "" then
1468 page.append("<a class=\"newComment\" title=\"32\" tag=\"\">New Comment</a>")
1469 else
1470 page.append("<pre class=\"text_label\" title=\"\" name=\"\" tag=\"\" type=\"1\">{nprop.full_comment}</pre>")
1471 end
1472 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>")
1473 html_inheritance(page)
1474 page.append("</div>")
1475 page.append("</article>")
1476 end
1477
1478 redef fun html_info(page) do
1479 page.append("<div class='info'>")
1480 if mproperty.visibility < public_visibility then page.append("{mproperty.visibility.to_s} ")
1481 if mproperty.intro_mclassdef.mclass != page.mclass then page.append("redef ")
1482 page.append("fun ")
1483 mproperty.html_namespace(page)
1484 page.append("</div>")
1485 page.append("<div style=\"float: right;\"><a id=\"lblDiffCommit\"></a></div>")
1486 end
1487 end
1488
1489 redef class MVirtualTypeDef
1490 redef fun html_full_desc(page) do
1491 var is_redef = mproperty.intro_mclassdef.mclass != page.mclass
1492 var classes = new Array[String]
1493 classes.add("type")
1494 if is_redef then classes.add("redef")
1495 classes.add(mproperty.visibility.to_s)
1496 page.append("<article class='{classes.join(" ")}' id='{anchor}'>")
1497 page.append("<h3 class='signature'>{mproperty.name}: ")
1498 bound.html_link(page)
1499 page.append("</h3>")
1500 html_info(page)
1501 page.append("<div class='description'>")
1502
1503 if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) and page.ctx.mbuilder.mpropdef2npropdef[self].full_comment != "" then
1504 var nprop = page.ctx.mbuilder.mpropdef2npropdef[self]
1505 page.append("<pre class=\"text_label\" title=\"\" name=\"\" tag=\"\" type=\"1\">{nprop.full_comment}</pre>")
1506 else
1507 page.append("<a class=\"newComment\" title=\"32\" tag=\"\">New Comment</a>")
1508 end
1509 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>")
1510 html_inheritance(page)
1511 page.append("</div>")
1512 page.append("</article>")
1513 end
1514
1515 redef fun html_info(page) do
1516 page.append("<div class='info'>")
1517 if mproperty.intro_mclassdef.mclass != page.mclass then page.append("redef ")
1518 page.append("type ")
1519 mproperty.html_namespace(page)
1520 page.append("</div>")
1521 page.append("<div style=\"float: right;\"><a id=\"lblDiffCommit\"></a></div>")
1522 end
1523 end
1524
1525 #
1526 # Nodes redefs
1527 #
1528
1529 redef class AModule
1530 private fun short_comment: String do
1531 if n_moduledecl != null and n_moduledecl.n_doc != null then
1532 return n_moduledecl.n_doc.n_comment.first.text.substring_from(2).replace("\n", "").html_escape
1533 end
1534 return ""
1535 end
1536
1537 private fun full_comment: String do
1538 var res = new Buffer
1539 if n_moduledecl != null and n_moduledecl.n_doc != null then
1540 for t in n_moduledecl.n_doc.n_comment do
1541 res.append(t.text.substring_from(1).html_escape)
1542 end
1543 end
1544 return res.to_s
1545 end
1546 end
1547
1548 redef class AStdClassdef
1549 private fun short_comment: String do
1550 if n_doc != null then return n_doc.n_comment.first.text.substring_from(2).replace("\n", "").html_escape
1551 return ""
1552 end
1553
1554 private fun full_comment: String do
1555 var res = new Buffer
1556 if n_doc != null then
1557 for t in n_doc.n_comment do res.append(t.text.substring_from(1).html_escape)
1558 end
1559 return res.to_s
1560 end
1561 end
1562
1563 redef class APropdef
1564 private fun short_comment: String is abstract
1565 private fun full_comment: String is abstract
1566 private fun html_signature(page: NitdocPage) is abstract
1567 end
1568
1569 redef class AAttrPropdef
1570 redef fun short_comment do
1571 if n_doc != null then return n_doc.n_comment.first.text.substring_from(2).replace("\n", "").html_escape
1572 return ""
1573 end
1574
1575 redef fun full_comment: String do
1576 var res = new Buffer
1577 if n_doc != null then
1578 for t in n_doc.n_comment do res.append(t.text.substring_from(1).html_escape)
1579 end
1580 return res.to_s
1581 end
1582
1583 redef fun html_signature(page) do
1584 if n_type != null then n_type.mtype.html_link(page)
1585 end
1586 end
1587
1588 redef class AMethPropdef
1589 redef fun short_comment do
1590 if n_doc != null then return n_doc.n_comment.first.text.substring_from(2).replace("\n", "").html_escape
1591 return ""
1592 end
1593
1594 redef fun full_comment do
1595 var res = new Buffer
1596 if n_doc != null then
1597 for t in n_doc.n_comment do res.append(t.text.substring_from(1).html_escape)
1598 end
1599 return res.to_s
1600 end
1601
1602 redef fun html_signature(page) do
1603 if n_signature != null then n_signature.html_link(page)
1604 end
1605 end
1606
1607 redef class ATypePropdef
1608 redef fun short_comment do
1609 if n_doc != null then return n_doc.n_comment.first.text.substring_from(2).replace("\n", "").html_escape
1610 return ""
1611 end
1612
1613 redef fun full_comment do
1614 var res = new Buffer
1615 if n_doc != null then
1616 for t in n_doc.n_comment do res.append(t.text.substring_from(1).html_escape)
1617 end
1618 return res.to_s
1619 end
1620
1621 redef fun html_signature(page) do
1622 mpropdef.bound.html_link(page)
1623 end
1624 end
1625
1626 redef class ASignature
1627 fun html_link(page: NitdocPage) do
1628 #TODO closures
1629 if not n_params.is_empty then
1630 page.append("(")
1631 for i in [0..n_params.length[ do
1632 n_params[i].html_link(page)
1633 if i < n_params.length - 1 then page.append(", ")
1634 end
1635 page.append(")")
1636 end
1637 if n_type != null then
1638 page.append(":")
1639 n_type.mtype.html_link(page)
1640 end
1641 end
1642 end
1643
1644 redef class AParam
1645 fun html_link(page: NitdocPage) do
1646 page.append(n_id.text)
1647 if n_type != null then
1648 page.append(": ")
1649 n_type.mtype.html_link(page)
1650 if n_dotdotdot != null then page.append("...")
1651 end
1652 end
1653 end
1654
1655 var nitdoc = new NitdocContext
1656 nitdoc.generate_nitdoc