ni_nitdoc: filtered imported init
[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 var op = new Buffer
411 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")
412 for mmodule in mmodules do
413 op.append("\"{mmodule.name}\"[URL=\"{mmodule.url}\"];\n")
414 for imported in mmodule.in_importation.direct_greaters do
415 if imported.direct_owner == null then
416 op.append("\"{mmodule.name}\"->\"{imported.name}\";\n")
417 end
418 end
419 end
420 op.append("\}\n")
421 generate_dot(op.to_s, "dep", "Modules hierarchy")
422 end
423 end
424
425 # The full index page
426 class NitdocFullindex
427 super NitdocPage
428
429 init(ctx: NitdocContext) do
430 super(ctx)
431 self.dot_dir = null
432 end
433
434 redef fun title do return "Full Index"
435
436 redef fun menu do
437 super
438 append("<li><a href='index.html'>Overview</a></li>")
439 append("<li class='current'>Full Index</li>")
440 end
441
442 redef fun content do
443 append("<div class='content fullpage'>")
444 append("<h1>Full Index</h1>")
445 module_column
446 classes_column
447 properties_column
448 append("</div>")
449 end
450
451 # Add to content modules column
452 private fun module_column do
453 var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
454 var sorter = new ComparableSorter[MModule]
455 sorter.sort(sorted)
456 append("<article class='modules filterable'>")
457 append("<h2>Modules</h2>")
458 append("<ul>")
459 for mmodule in sorted do
460 append("<li>")
461 mmodule.html_link(self)
462 append("</li>")
463 end
464 append("</ul>")
465 append("</article>")
466 end
467
468 # Add to content classes modules
469 private fun classes_column do
470 var sorted = ctx.mbuilder.model.mclasses
471 var sorter = new ComparableSorter[MClass]
472 sorter.sort(sorted)
473 append("<article class='modules filterable'>")
474 append("<h2>Classes</h2>")
475 append("<ul>")
476 for mclass in sorted do
477 if mclass.visibility < ctx.min_visibility then continue
478 append("<li>")
479 mclass.html_link(self)
480 append("</li>")
481 end
482 append("</ul>")
483 append("</article>")
484 end
485
486 # Insert the properties column of fullindex page
487 private fun properties_column do
488 var sorted = ctx.mbuilder.model.mproperties
489 var sorter = new ComparableSorter[MProperty]
490 sorter.sort(sorted)
491 append("<article class='modules filterable'>")
492 append("<h2>Properties</h2>")
493 append("<ul>")
494 for mproperty in sorted do
495 if mproperty.visibility < ctx.min_visibility then continue
496 if mproperty isa MAttribute then continue
497 append("<li>")
498 mproperty.intro.html_link(self)
499 append(" (")
500 mproperty.intro.mclassdef.mclass.html_link(self)
501 append(")</li>")
502 end
503 append("</ul>")
504 append("</article>")
505 end
506
507 end
508
509 # A module page
510 class NitdocModule
511 super NitdocPage
512
513 private var mmodule: MModule
514 private var mbuilder: ModelBuilder
515
516 init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
517 super(ctx)
518 self.mmodule = mmodule
519 self.mbuilder = ctx.mbuilder
520 self.dot_dir = dot_dir
521 end
522
523 redef fun title do
524 if mbuilder.mmodule2nmodule.has_key(mmodule) then
525 var nmodule = mbuilder.mmodule2nmodule[mmodule]
526 return "{mmodule.name} module | {nmodule.short_comment}"
527 else
528 return "{mmodule.name} module"
529 end
530 end
531
532 redef fun menu do
533 super
534 append("<li><a href='index.html'>Overview</a></li>")
535 append("<li class='current'>{mmodule.name}</li>")
536 append("<li><a href='full-index.html'>Full Index</a></li>")
537 end
538
539 redef fun content do
540 sidebar
541 append("<div class='content'>")
542 append("<h1>{mmodule.name}</h1>")
543 append("<div class='subtitle'>")
544 mmodule.html_signature(self)
545 append("</div>")
546 mmodule.html_full_comment(self)
547 process_generate_dot
548 classes
549 properties
550 append("</div>")
551 end
552
553 private fun process_generate_dot do
554 var name = "dep_{mmodule.name}"
555 var op = new Buffer
556 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")
557 for m in mmodule.in_importation.poset do
558 if m.name == "<main>" then continue
559 var public_owner = m.public_owner
560 if public_owner == null then
561 public_owner = m
562 if m == mmodule then
563 op.append("\"{m.name}\"[shape=box,margin=0.03];\n")
564 else
565 op.append("\"{m.name}\"[URL=\"{m.url}\"];\n")
566 end
567 end
568 for imported in m.in_importation.direct_greaters do
569 if imported.name == "<main>" then continue
570 if imported.public_owner == null then
571 op.append("\"{public_owner.name}\"->\"{imported.name}\";\n")
572 end
573 end
574 end
575 op.append("\}\n")
576 generate_dot(op.to_s, name, "Dependency graph for module {mmodule.name}")
577 end
578
579 private fun sidebar do
580 append("<div class='menu'>")
581 append("<nav>")
582 append("<h3>Module Hierarchy</h3>")
583 var dependencies = new Array[MModule]
584 for dep in mmodule.in_importation.greaters do
585 if dep == mmodule or dep.public_owner != null then continue
586 dependencies.add(dep)
587 end
588 if dependencies.length > 0 then
589 append("<h4>All dependencies</h4>")
590 display_module_list(dependencies)
591 end
592 var clients = new Array[MModule]
593 for dep in mmodule.in_importation.smallers do
594 if dep == mmodule or dep.public_owner != null then continue
595 clients.add(dep)
596 end
597 if clients.length > 0 then
598 append("<h4>All clients</h4>")
599 display_module_list(clients)
600 end
601 append("</nav>")
602 if mmodule.in_nesting.direct_greaters.length > 0 then
603 append("<nav>")
604 append("<h3>Nested Modules</h3>")
605 display_module_list(mmodule.in_nesting.direct_greaters.to_a)
606 append("</nav>")
607 end
608 append("</div>")
609 end
610
611 private fun display_module_list(list: Array[MModule]) do
612 append("<ul>")
613 var sorter = new ComparableSorter[MModule]
614 sorter.sort(list)
615 for m in list do
616 append("<li>")
617 m.html_link(self)
618 append("</li>")
619 end
620 append("</ul>")
621 end
622
623 # display the class column
624 private fun classes do
625 var intro_mclasses = mmodule.intro_mclasses
626 var redef_mclasses = mmodule.redef_mclasses
627 var all_mclasses = new HashSet[MClass]
628 for m in mmodule.in_nesting.greaters do
629 all_mclasses.add_all(m.intro_mclasses)
630 all_mclasses.add_all(m.redef_mclasses)
631 end
632 all_mclasses.add_all(intro_mclasses)
633 all_mclasses.add_all(redef_mclasses)
634
635 var sorted = new Array[MClass]
636 sorted.add_all(all_mclasses)
637 var sorter = new ComparableSorter[MClass]
638 sorter.sort(sorted)
639 append("<div class='module'>")
640 append("<article class='classes filterable'>")
641 append("<h2>Classes</h2>")
642 append("<ul>")
643 for c in sorted do
644 if c.visibility < ctx.min_visibility then continue
645 if redef_mclasses.has(c) and c.intro_mmodule.public_owner != mmodule then
646 append("<li class='redef'>")
647 append("<span title='refined in this module'>R </span>")
648 else
649 append("<li class='intro'>")
650 append("<span title='introduced in this module'>I </span>")
651 end
652 c.html_link(self)
653 append("</li>")
654 end
655 append("</ul>")
656 append("</article>")
657 append("</div>")
658 end
659
660 # display the property column
661 private fun properties do
662 # get properties
663 var mpropdefs = new HashSet[MPropDef]
664 for m in mmodule.in_nesting.greaters do
665 for c in m.mclassdefs do mpropdefs.add_all(c.mpropdefs)
666 end
667 for c in mmodule.mclassdefs do mpropdefs.add_all(c.mpropdefs)
668 var sorted = mpropdefs.to_a
669 var sorter = new ComparableSorter[MPropDef]
670 sorter.sort(sorted)
671 # display properties in one column
672 append("<article class='properties filterable'>")
673 append("<h2>Properties</h2>")
674 append("<ul>")
675 for mprop in sorted do
676 if mprop isa MAttributeDef then continue
677 if mprop.mproperty.visibility < ctx.min_visibility then continue
678 mprop.html_list_item(self)
679 end
680 append("</ul>")
681 append("</article>")
682 end
683 end
684
685 # A class page
686 class NitdocClass
687 super NitdocPage
688
689 private var mclass: MClass
690 private var vtypes = new HashSet[MVirtualTypeDef]
691 private var consts = new HashSet[MMethodDef]
692 private var meths = new HashSet[MMethodDef]
693 private var inherited = new HashSet[MPropDef]
694
695 init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
696 super(ctx)
697 self.mclass = mclass
698 self.dot_dir = dot_dir
699 self.source = source
700 # load properties
701 for mclassdef in mclass.mclassdefs do
702 for mpropdef in mclassdef.mpropdefs do
703 if mpropdef.mproperty.visibility < ctx.min_visibility then continue
704 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
705 if mpropdef isa MMethodDef then
706 if mpropdef.mproperty.is_init then
707 consts.add(mpropdef)
708 else
709 meths.add(mpropdef)
710 end
711 end
712 end
713 end
714 # get inherited properties
715 for mprop in mclass.inherited_mproperties do
716 var mpropdef = mprop.intro
717 if mprop.visibility < ctx.min_visibility then continue
718 if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
719 if mpropdef isa MMethodDef then
720 if mpropdef.mproperty.is_init then
721 consts.add(mpropdef)
722 else
723 meths.add(mpropdef)
724 end
725 end
726 inherited.add(mpropdef)
727 end
728 end
729
730 redef fun title do
731 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
732 if nclass isa AStdClassdef then
733 return "{mclass.name} class | {nclass.short_comment}"
734 else
735 return "{mclass.name} class"
736 end
737 end
738
739 redef fun menu do
740 super
741 append("<li><a href='index.html'>Overview</a></li>")
742 var public_owner = mclass.public_owner
743 if public_owner is null then
744 append("<li>")
745 mclass.intro_mmodule.html_link(self)
746 append("</li>")
747 else
748 append("<li>")
749 public_owner.html_link(self)
750 append("</li>")
751 end
752 append("<li class='current'>{mclass.name}</li>")
753 append("<li><a href='full-index.html'>Full Index</a></li>")
754 end
755
756 redef fun content do
757 append("<div class='menu'>")
758 properties_column
759 inheritance_column
760 append("</div>")
761 append("<div class='content'>")
762 class_doc
763 append("</div>")
764 end
765
766 private fun properties_column do
767 var sorter = new ComparableSorter[MPropDef]
768 append("<nav class='properties filterable'>")
769 append("<h3>Properties</h3>")
770 # virtual types
771 if vtypes.length > 0 then
772 var vts = new Array[MVirtualTypeDef]
773 vts.add_all(vtypes)
774 sorter.sort(vts)
775 append("<h4>Virtual Types</h4>")
776 append("<ul>")
777 for mprop in vts do
778 mprop.html_sidebar_item(self)
779 end
780 append("</ul>")
781 end
782 # constructors
783 if consts.length > 0 then
784 var cts = new Array[MMethodDef]
785 cts.add_all(consts)
786 sorter.sort(cts)
787 append("<h4>Constructors</h4>")
788 append("<ul>")
789 for mprop in cts do
790 if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
791 mprop.html_sidebar_item(self)
792 end
793 append("</ul>")
794 end
795 # methods
796 if meths.length > 0 then
797 var mts = new Array[MMethodDef]
798 mts.add_all(meths)
799 sorter.sort(mts)
800 append("<h4>Methods</h4>")
801 append("<ul>")
802 for mprop in mts do
803 if mclass.name != "Object" and mprop.mproperty.intro_mclassdef.mclass.name == "Object" and mprop.mproperty.visibility <= protected_visibility then continue
804 mprop.html_sidebar_item(self)
805 end
806 append("</ul>")
807 end
808 append("</nav>")
809 end
810
811 private fun inheritance_column do
812 var sorted = new Array[MClass]
813 var sorterp = new ComparableSorter[MClass]
814 append("<nav>")
815 append("<h3>Inheritance</h3>")
816 var greaters = mclass.in_hierarchy(ctx.mainmodule).greaters.to_a
817 if greaters.length > 1 then
818 ctx.mainmodule.linearize_mclasses(greaters)
819 append("<h4>Superclasses</h4>")
820 append("<ul>")
821 for sup in greaters do
822 if sup == mclass then continue
823 append("<li>")
824 sup.html_link(self)
825 append("</li>")
826 end
827 append("</ul>")
828 end
829 var smallers = mclass.in_hierarchy(ctx.mainmodule).smallers.to_a
830 var direct_smallers = mclass.in_hierarchy(ctx.mainmodule).direct_smallers.to_a
831 if smallers.length <= 1 then
832 append("<h4>No Known Subclasses</h4>")
833 else if smallers.length <= 100 then
834 ctx.mainmodule.linearize_mclasses(smallers)
835 append("<h4>Subclasses</h4>")
836 append("<ul>")
837 for sub in smallers do
838 if sub == mclass then continue
839 append("<li>")
840 sub.html_link(self)
841 append("</li>")
842 end
843 append("</ul>")
844 else if direct_smallers.length <= 100 then
845 ctx.mainmodule.linearize_mclasses(direct_smallers)
846 append("<h4>Direct Subclasses Only</h4>")
847 append("<ul>")
848 for sub in direct_smallers do
849 if sub == mclass then continue
850 append("<li>")
851 sub.html_link(self)
852 append("</li>")
853 end
854 append("</ul>")
855 else
856 append("<h4>Too much Subclasses to list</h4>")
857 end
858 append("</nav>")
859 end
860
861 private fun class_doc do
862 # title
863 append("<h1>{mclass.signature}</h1>")
864 append("<div class='subtitle info'>")
865 mclass.html_full_signature(self)
866 append("</div>")
867 # comment
868 var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
869 append("<div style=\"float: right;\"><a id=\"lblDiffCommit\"></a></div>")
870 append("<section class='description'>")
871 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>")
872 process_generate_dot
873 append("</section>")
874 # concerns
875 var concern2meths = new ArrayMap[MModule, Array[MMethodDef]]
876 var sorted_meths = new Array[MMethodDef]
877 var sorted = new Array[MModule]
878 sorted_meths.add_all(meths)
879 ctx.mainmodule.linearize_mpropdefs(sorted_meths)
880 for meth in meths do
881 if inherited.has(meth) then continue
882 var mmodule = meth.mclassdef.mmodule
883 if not concern2meths.has_key(mmodule) then
884 sorted.add(mmodule)
885 concern2meths[mmodule] = new Array[MMethodDef]
886 end
887 concern2meths[mmodule].add(meth)
888 end
889 var sections = new ArrayMap[MModule, Array[MModule]]
890 for mmodule in concern2meths.keys do
891 var owner = mmodule.public_owner
892 if owner == null then owner = mmodule
893 if not sections.has_key(owner) then sections[owner] = new Array[MModule]
894 if owner != mmodule then sections[owner].add(mmodule)
895 end
896 append("<section class='concerns'>")
897 append("<h2 class='section-header'>Concerns</h2>")
898 append("<ul>")
899 for owner, mmodules in sections do
900 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
901 append("<li>")
902 if nowner.short_comment.is_empty then
903 append("<a href=\"#{owner.anchor}\">{owner.name}</a>")
904 else
905 append("<a href=\"#{owner.anchor}\">{owner.name}</a>: {nowner.short_comment}")
906 end
907 if not mmodules.is_empty then
908 append("<ul>")
909 for mmodule in mmodules do
910 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
911 if nmodule.short_comment.is_empty then
912 append("<li><a href=\"#{mmodule.anchor}\">{mmodule.name}</a></li>")
913 else
914 append("<li><a href=\"#{mmodule.anchor}\">{mmodule.name}</a>: {nmodule.short_comment}</li>")
915 end
916 end
917 append("</ul>")
918 end
919 append("</li>")
920 end
921 append("</ul>")
922 append("</section>")
923 # properties
924 var prop_sorter = new ComparableSorter[MPropDef]
925 var sorterprop = new ComparableSorter[MProperty]
926 var sorterc = new ComparableSorter[MClass]
927 var lmmodule = new List[MModule]
928 # virtual and formal types
929 var local_vtypes = new Array[MVirtualTypeDef]
930 for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
931 if local_vtypes.length > 0 or mclass.arity > 0 then
932 append("<section class='types'>")
933 append("<h2>Formal and Virtual Types</h2>")
934 # formal types
935 if mclass.arity > 0 and nclass isa AStdClassdef then
936 for ft, bound in mclass.parameter_types do
937 append("<article id='FT_{ft}'>")
938 append("<h3 class='signature'>{ft}: ")
939 bound.html_link(self)
940 append("</h3>")
941 append("<div class=\"info\">formal generic type</div>")
942 append("</article>")
943 end
944 end
945 # virtual types
946 prop_sorter.sort(local_vtypes)
947 for prop in local_vtypes do prop.html_full_desc(self)
948 append("</section>")
949 end
950 # constructors
951 var local_consts = new Array[MMethodDef]
952 for const in consts do if not inherited.has(const) then local_consts.add(const)
953 prop_sorter.sort(local_consts)
954 if local_consts.length > 0 then
955 append("<section class='constructors'>")
956 append("<h2 class='section-header'>Constructors</h2>")
957 for prop in local_consts do prop.html_full_desc(self)
958 append("</section>")
959 end
960 # methods
961 if not concern2meths.is_empty then
962 append("<section class='methods'>")
963 append("<h2 class='section-header'>Methods</h2>")
964 for owner, mmodules in sections do
965 append("<a id=\"{owner.anchor}\"></a>")
966 if owner != mclass.intro_mmodule and owner != mclass.public_owner then
967 var nowner = ctx.mbuilder.mmodule2nmodule[owner]
968 append("<h3 class=\"concern-toplevel\">Methods refined in ")
969 owner.html_link(self)
970 append("</h3>")
971 append("<p class=\"concern-doc\">")
972 owner.html_link(self)
973 if not nowner.short_comment.is_empty then
974 append(": {nowner.short_comment}")
975 end
976 append("</p>")
977 end
978 if concern2meths.has_key(owner) then
979 var mmethods = concern2meths[owner]
980 prop_sorter.sort(mmethods)
981 for prop in mmethods do prop.html_full_desc(self)
982 end
983 for mmodule in mmodules do
984 append("<a id=\"{mmodule.anchor}\"></a>")
985 var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
986 if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
987 append("<p class=\"concern-doc\">")
988 mmodule.html_link(self)
989 if not nmodule.short_comment.is_empty then
990 append(": {nmodule.short_comment}")
991 end
992 append("</p>")
993 end
994 var mmethods = concern2meths[mmodule]
995 prop_sorter.sort(mmethods)
996 for prop in mmethods do prop.html_full_desc(self)
997 end
998 end
999 end
1000 # inherited properties
1001 if inherited.length > 0 then
1002 var sorted_inherited = new Array[MPropDef]
1003 sorted_inherited.add_all(inherited)
1004 ctx.mainmodule.linearize_mpropdefs(sorted_inherited)
1005 var classes = new ArrayMap[MClass, Array[MPropDef]]
1006 for mmethod in sorted_inherited.reversed do
1007 var mclass = mmethod.mclassdef.mclass
1008 if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
1009 classes[mclass].add(mmethod)
1010 end
1011 append("<h3>Inherited Properties</h3>")
1012 for c, mmethods in classes do
1013 prop_sorter.sort(mmethods)
1014 append("<p>Defined in ")
1015 c.html_link(self)
1016 append("}: ")
1017 for i in [0..mmethods.length[ do
1018 var mmethod = mmethods[i]
1019 mmethod.html_link(self)
1020 if i <= mmethods.length - 1 then append(", ")
1021 end
1022 append("</p>")
1023 end
1024 end
1025 append("</section>")
1026 end
1027
1028 private fun process_generate_dot do
1029 var pe = ctx.class_hierarchy[mclass]
1030 var cla = new HashSet[MClass]
1031 var sm = new HashSet[MClass]
1032 var sm2 = new HashSet[MClass]
1033 sm.add(mclass)
1034 while cla.length + sm.length < 10 and sm.length > 0 do
1035 cla.add_all(sm)
1036 sm2.clear
1037 for x in sm do
1038 sm2.add_all(pe.poset[x].direct_smallers)
1039 end
1040 var t = sm
1041 sm = sm2
1042 sm2 = t
1043 end
1044 cla.add_all(pe.greaters)
1045
1046 var op = new Buffer
1047 var name = "dep_{mclass.name}"
1048 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")
1049 for c in cla do
1050 if c == mclass then
1051 op.append("\"{c.name}\"[shape=box,margin=0.03];\n")
1052 else
1053 op.append("\"{c.name}\"[URL=\"{c.url}\"];\n")
1054 end
1055 for c2 in pe.poset[c].direct_greaters do
1056 if not cla.has(c2) then continue
1057 op.append("\"{c.name}\"->\"{c2.name}\";\n")
1058 end
1059 if not pe.poset[c].direct_smallers.is_empty then
1060 var others = true
1061 for c2 in pe.poset[c].direct_smallers do
1062 if cla.has(c2) then others = false
1063 end
1064 if others then
1065 op.append("\"{c.name}...\"[label=\"\"];\n")
1066 op.append("\"{c.name}...\"->\"{c.name}\"[style=dotted];\n")
1067 end
1068 end
1069 end
1070 op.append("\}\n")
1071 generate_dot(op.to_s, name, "Dependency graph for class {mclass.name}")
1072 end
1073 end
1074
1075 #
1076 # Model redefs
1077 #
1078
1079 redef class MModule
1080 super Comparable
1081 redef type OTHER: MModule
1082 redef fun <(other: OTHER): Bool do return self.name < other.name
1083
1084 # Get the list of all methods in a module
1085 fun imported_methods: Set[MMethod] do
1086 var methods = new HashSet[MMethod]
1087 for mclass in imported_mclasses do
1088 for method in mclass.intro_methods do
1089 methods.add(method)
1090 end
1091 end
1092 return methods
1093 end
1094
1095 # Get the list aof all refined methods in a module
1096 fun redef_methods: Set[MMethod] do
1097 var methods = new HashSet[MMethod]
1098 for mclass in redef_mclasses do
1099 for method in mclass.intro_methods do
1100 methods.add(method)
1101 end
1102 end
1103 return methods
1104 end
1105
1106 # URL to nitdoc page
1107 fun url: String do
1108 var res = new Buffer
1109 res.append("module_")
1110 var mowner = public_owner
1111 if mowner != null then
1112 res.append("{public_owner.name}_")
1113 end
1114 res.append("{self.name}.html")
1115 return res.to_s
1116 end
1117
1118 # html anchor id to the module in a nitdoc page
1119 fun anchor: String do
1120 var res = new Buffer
1121 res.append("MOD_")
1122 var mowner = public_owner
1123 if mowner != null then
1124 res.append("{public_owner.name}_")
1125 end
1126 res.append(self.name)
1127 return res.to_s
1128 end
1129
1130 # Return a link (html a tag) to the nitdoc module page
1131 fun html_link(page: NitdocPage) do
1132 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1133 page.append("<a href='{url}' title='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{name}</a>")
1134 else
1135 page.append("<a href='{url}'>{name}</a>")
1136 end
1137 end
1138
1139 # Return the module signature decorated with html
1140 fun html_signature(page: NitdocPage) do
1141 page.append("<span>module ")
1142 html_full_namespace(page)
1143 page.append("</span>")
1144 end
1145
1146 # Return the module full namespace decorated with html
1147 fun html_full_namespace(page: NitdocPage) do
1148 page.append("<span>")
1149 var mowner = public_owner
1150 if mowner != null then
1151 public_owner.html_namespace(page)
1152 page.append("::")
1153 end
1154 html_link(page)
1155 page.append("</span>")
1156 end
1157
1158 # Return the module full namespace decorated with html
1159 fun html_namespace(page: NitdocPage) do
1160 page.append("<span>")
1161 var mowner = public_owner
1162 if mowner != null then
1163 public_owner.html_namespace(page)
1164 else
1165 html_link(page)
1166 end
1167 page.append("</span>")
1168 end
1169
1170 # Return the full comment of the module decorated with html
1171 fun html_full_comment(page: NitdocPage) do
1172 if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
1173 page.append("<div id='description'>")
1174 page.append("<pre class='text_label'>{page.ctx.mbuilder.mmodule2nmodule[self].full_comment}</pre>")
1175 page.append("<textarea class='edit' rows='1' cols='76' id='fileContent'></textarea>")
1176 page.append("<a id='cancelBtn'>Cancel</a>")
1177 page.append("<a id='commitBtn'>Commit</a>")
1178 page.append("<pre class='text_label' id='preSave' type='2'></pre>")
1179 page.append("</div>")
1180 end
1181 end
1182 end
1183
1184 redef class MClass
1185 super Comparable
1186 redef type OTHER: MClass
1187 redef fun <(other: OTHER): Bool do return self.name < other.name
1188
1189 # Return the module signature decorated with html
1190 fun html_full_signature(page: NitdocPage) do
1191 if visibility < public_visibility then page.append("{visibility.to_s} ")
1192 page.append("{kind} ")
1193 html_namespace(page)
1194 end
1195
1196 # name with formal parameter
1197 # Foo[A, B]
1198 private fun signature: String do
1199 if arity > 0 then
1200 return "{name}[{intro.parameter_names.join(", ")}]"
1201 else
1202 return name
1203 end
1204 end
1205
1206 # Return a link (html a tag) to the nitdoc class page
1207 fun html_link(page: NitdocPage) do
1208 page.append("<a href='{url}'")
1209 if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
1210 var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
1211 if nclass isa AStdClassdef then
1212 page.append(" title=\"{nclass.short_comment}\"")
1213 end
1214 end
1215 page.append(">{signature}</a>")
1216 end
1217
1218 # Return the class namespace decorated with html
1219 fun html_namespace(page: NitdocPage) do
1220 intro_mmodule.html_namespace(page)
1221 page.append("::<span>")
1222 html_link(page)
1223 page.append("</span>")
1224 end
1225
1226 fun url: String do
1227 return "class_{public_owner}_{c_name}.html"
1228 end
1229
1230 # Escape name for html output
1231 redef fun name do return super.html_escape
1232 end
1233
1234 redef class MProperty
1235 super Comparable
1236 redef type OTHER: MProperty
1237 redef fun <(other: OTHER): Bool do return self.name < other.name
1238
1239 # Return the property namespace decorated with html
1240 fun html_namespace(page: NitdocPage) do
1241 intro_mclassdef.mclass.html_namespace(page)
1242 page.append("::<span>")
1243 intro.html_link(page)
1244 page.append("</span>")
1245 end
1246
1247 # Escape name for html output
1248 redef fun name do return super.html_escape
1249 end
1250
1251 redef class MType
1252 fun html_link(page: NitdocPage) is abstract
1253 end
1254
1255 redef class MClassType
1256 redef fun html_link(page) do mclass.html_link(page)
1257 end
1258
1259 redef class MNullableType
1260 redef fun html_link(page) do
1261 page.append("nullable ")
1262 mtype.html_link(page)
1263 end
1264 end
1265
1266 redef class MGenericType
1267 redef fun html_link(page) do
1268 page.append("<a href='{mclass.url}'>{mclass.name}</a>[")
1269 for i in [0..arguments.length[ do
1270 arguments[i].html_link(page)
1271 if i < arguments.length - 1 then page.append(", ")
1272 end
1273 page.append("]")
1274 end
1275 end
1276
1277 redef class MParameterType
1278 redef fun html_link(page) do
1279 var name = mclass.intro.parameter_names[rank]
1280 page.append("<a href='{mclass.url}#FT_{name}' title='formal type'>{name}</a>")
1281 end
1282 end
1283
1284 redef class MVirtualType
1285 redef fun html_link(page) do mproperty.intro.html_link(page)
1286 end
1287
1288 redef class MClassDef
1289 # Return the classdef namespace decorated with html
1290 fun html_namespace(page: NitdocPage) do
1291 mmodule.html_full_namespace(page)
1292 page.append("::<span>")
1293 mclass.html_link(page)
1294 page.append("</span>")
1295 end
1296 end
1297
1298 redef class MPropDef
1299 super Comparable
1300 redef type OTHER: MPropDef
1301 redef fun <(other: OTHER): Bool do return self.mproperty.name < other.mproperty.name
1302
1303 fun url: String do return "{mclassdef.mclass.url}#{anchor}"
1304 fun anchor: String do return "PROP_{mclassdef.mclass.public_owner.name}_{c_name}"
1305
1306 # Return a link (html a tag) to the nitdoc class page
1307 fun html_link(page: NitdocPage) do
1308 if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then
1309 var nprop = page.ctx.mbuilder.mpropdef2npropdef[self]
1310 page.append("<a href=\"{url}\" title=\"{nprop.short_comment}\">{mproperty.name}</a>")
1311 else
1312 page.append("<a href=\"{url}\">{mproperty.name}</a>")
1313 end
1314 end
1315
1316 # Return a list item for the mpropdef
1317 fun html_list_item(page: NitdocPage) do
1318 if is_intro then
1319 page.append("<li class='intro'>")
1320 page.append("<span title='introduction'>I</span>&nbsp;")
1321 else
1322 page.append("<li class='redef'>")
1323 page.append("<span title='redefinition'>R</span>&nbsp;")
1324 end
1325 html_link(page)
1326 page.append("(")
1327 mclassdef.mclass.html_link(page)
1328 page.append(")")
1329 page.append("</li>")
1330 end
1331
1332 # Return a list item for the mpropdef
1333 fun html_sidebar_item(page: NitdocClass) do
1334 if is_intro and mclassdef.mclass == page.mclass then
1335 page.append("<li class='intro'>")
1336 page.append("<span title='Introduced'>I</span>")
1337 else if is_intro and mclassdef.mclass != page.mclass then
1338 page.append("<li class='inherit'>")
1339 page.append("<span title='Inherited'>H</span>")
1340 else
1341 page.append("<li class='redef'>")
1342 page.append("<span title='Redefined'>R</span>")
1343 end
1344 html_link(page)
1345 page.append("</li>")
1346 end
1347
1348 fun html_full_desc(page: NitdocClass) is abstract
1349 fun html_info(page: NitdocClass) is abstract
1350
1351 fun full_name: String do
1352 return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
1353 end
1354
1355 fun html_inheritance(page: NitdocClass) do
1356 # definitions block
1357 page.append("<p class='info'>")
1358 page.ctx.mainmodule.linearize_mpropdefs(mproperty.mpropdefs)
1359 var previous_defs = new Array[MPropDef]
1360 var next_defs = new Array[MPropDef]
1361 var self_passed = false
1362 for def in mproperty.mpropdefs do
1363 if def == self then
1364 self_passed = true
1365 continue
1366 end
1367 if not self_passed then
1368 if def.mclassdef.mclass.in_hierarchy(page.ctx.mainmodule) < page.mclass then continue
1369 if def.is_intro then continue
1370 previous_defs.add(def)
1371 else
1372 if page.mclass.in_hierarchy(page.ctx.mainmodule) < def.mclassdef.mclass then continue
1373 next_defs.add(def)
1374 end
1375 end
1376 page.append("defined by ")
1377 mclassdef.mmodule.html_full_namespace(page)
1378 if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then
1379 page.append(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1380 end
1381 if not is_intro then
1382 page.append(", introduced by ")
1383 mproperty.intro.mclassdef.mclass.html_link(page)
1384 if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then
1385 page.append(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[self].location)}")
1386 end
1387 end
1388 if not previous_defs.is_empty then
1389 page.append(", inherited from ")
1390 for i in [0..previous_defs.length[ do
1391 var def = previous_defs[i]
1392 def.mclassdef.mclass.html_link(page)
1393 if page.ctx.mbuilder.mpropdef2npropdef.has_key(def) then
1394 page.append(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1395 end
1396
1397 if i < previous_defs.length - 1 then page.append(", ")
1398 end
1399 end
1400 if not next_defs.is_empty then
1401 page.append(", redefined by ")
1402 for i in [0..next_defs.length[ do
1403 var def = next_defs[i]
1404 def.mclassdef.mclass.html_link(page)
1405 if page.ctx.mbuilder.mpropdef2npropdef.has_key(def) then
1406 page.append(" {page.show_source(page.ctx.mbuilder.mpropdef2npropdef[def].location)}")
1407 end
1408 if i < next_defs.length - 1 then page.append(", ")
1409 end
1410 end
1411 page.append(".</p>")
1412 end
1413 end
1414
1415 redef class MMethodDef
1416 redef fun html_full_desc(page) do
1417 if not page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then return
1418 var nprop = page.ctx.mbuilder.mpropdef2npropdef[self]
1419 var classes = new Array[String]
1420 var is_redef = mproperty.intro_mclassdef.mclass != page.mclass
1421 classes.add("fun")
1422 if mproperty.is_init then classes.add("init")
1423 if is_redef then classes.add("redef")
1424 classes.add(mproperty.visibility.to_s)
1425 page.append("<article class='{classes.join(" ")}' id='{anchor}'>")
1426 if nprop isa AAttrPropdef then
1427 if nprop.mreadpropdef == self then
1428 page.append("<h3 class='signature'>{mproperty.name}: ")
1429 nprop.html_signature(page)
1430 page.append("</h3>")
1431 else
1432 page.append("<h3 class='signature'>{mproperty.name}(value: ")
1433 nprop.html_signature(page)
1434 page.append(")</h3>")
1435 end
1436 else
1437 var intro_nprop = page.ctx.mbuilder.mpropdef2npropdef[mproperty.intro]
1438 page.append("<h3 class='signature'>{mproperty.name}")
1439 intro_nprop.html_signature(page)
1440 page.append("</h3>")
1441 end
1442 html_info(page)
1443 page.append("<div class='description'>")
1444 if nprop.full_comment == "" then
1445 page.append("<a class=\"newComment\" title=\"32\" tag=\"\">New Comment</a>")
1446 else
1447 page.append("<pre class=\"text_label\" title=\"\" name=\"\" tag=\"\" type=\"1\">{nprop.full_comment}</pre>")
1448 end
1449 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>")
1450 html_inheritance(page)
1451 page.append("</div>")
1452 page.append("</article>")
1453 end
1454
1455 redef fun html_info(page) do
1456 page.append("<div class='info'>")
1457 if mproperty.visibility < public_visibility then page.append("{mproperty.visibility.to_s} ")
1458 if mproperty.intro_mclassdef.mclass != page.mclass then page.append("redef ")
1459 page.append("fun ")
1460 mproperty.html_namespace(page)
1461 page.append("</div>")
1462 page.append("<div style=\"float: right;\"><a id=\"lblDiffCommit\"></a></div>")
1463 end
1464 end
1465
1466 redef class MVirtualTypeDef
1467 redef fun html_full_desc(page) do
1468 var is_redef = mproperty.intro_mclassdef.mclass != page.mclass
1469 var classes = new Array[String]
1470 classes.add("type")
1471 if is_redef then classes.add("redef")
1472 classes.add(mproperty.visibility.to_s)
1473 page.append("<article class='{classes.join(" ")}' id='{anchor}'>")
1474 page.append("<h3 class='signature'>{mproperty.name}: ")
1475 bound.html_link(page)
1476 page.append("</h3>")
1477 html_info(page)
1478 page.append("<div class='description'>")
1479
1480 if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) and page.ctx.mbuilder.mpropdef2npropdef[self].full_comment != "" then
1481 var nprop = page.ctx.mbuilder.mpropdef2npropdef[self]
1482 page.append("<pre class=\"text_label\" title=\"\" name=\"\" tag=\"\" type=\"1\">{nprop.full_comment}</pre>")
1483 else
1484 page.append("<a class=\"newComment\" title=\"32\" tag=\"\">New Comment</a>")
1485 end
1486 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>")
1487 html_inheritance(page)
1488 page.append("</div>")
1489 page.append("</article>")
1490 end
1491
1492 redef fun html_info(page) do
1493 page.append("<div class='info'>")
1494 if mproperty.intro_mclassdef.mclass != page.mclass then page.append("redef ")
1495 page.append("type ")
1496 mproperty.html_namespace(page)
1497 page.append("</div>")
1498 page.append("<div style=\"float: right;\"><a id=\"lblDiffCommit\"></a></div>")
1499 end
1500 end
1501
1502 #
1503 # Nodes redefs
1504 #
1505
1506 redef class AModule
1507 private fun short_comment: String do
1508 if n_moduledecl != null and n_moduledecl.n_doc != null then
1509 return n_moduledecl.n_doc.n_comment.first.text.substring_from(2).replace("\n", "").html_escape
1510 end
1511 return ""
1512 end
1513
1514 private fun full_comment: String do
1515 var res = new Buffer
1516 if n_moduledecl != null and n_moduledecl.n_doc != null then
1517 for t in n_moduledecl.n_doc.n_comment do
1518 res.append(t.text.substring_from(1).html_escape)
1519 end
1520 end
1521 return res.to_s
1522 end
1523 end
1524
1525 redef class AStdClassdef
1526 private fun short_comment: String do
1527 if n_doc != null then return n_doc.n_comment.first.text.substring_from(2).replace("\n", "").html_escape
1528 return ""
1529 end
1530
1531 private fun full_comment: String do
1532 var res = new Buffer
1533 if n_doc != null then
1534 for t in n_doc.n_comment do res.append(t.text.substring_from(1).html_escape)
1535 end
1536 return res.to_s
1537 end
1538 end
1539
1540 redef class APropdef
1541 private fun short_comment: String is abstract
1542 private fun full_comment: String is abstract
1543 private fun html_signature(page: NitdocPage) is abstract
1544 end
1545
1546 redef class AAttrPropdef
1547 redef fun short_comment do
1548 if n_doc != null then return n_doc.n_comment.first.text.substring_from(2).replace("\n", "").html_escape
1549 return ""
1550 end
1551
1552 redef fun full_comment: String do
1553 var res = new Buffer
1554 if n_doc != null then
1555 for t in n_doc.n_comment do res.append(t.text.substring_from(1).html_escape)
1556 end
1557 return res.to_s
1558 end
1559
1560 redef fun html_signature(page) do
1561 if n_type != null then n_type.mtype.html_link(page)
1562 end
1563 end
1564
1565 redef class AMethPropdef
1566 redef fun short_comment do
1567 if n_doc != null then return n_doc.n_comment.first.text.substring_from(2).replace("\n", "").html_escape
1568 return ""
1569 end
1570
1571 redef fun full_comment do
1572 var res = new Buffer
1573 if n_doc != null then
1574 for t in n_doc.n_comment do res.append(t.text.substring_from(1).html_escape)
1575 end
1576 return res.to_s
1577 end
1578
1579 redef fun html_signature(page) do
1580 if n_signature != null then n_signature.html_link(page)
1581 end
1582 end
1583
1584 redef class ATypePropdef
1585 redef fun short_comment do
1586 if n_doc != null then return n_doc.n_comment.first.text.substring_from(2).replace("\n", "").html_escape
1587 return ""
1588 end
1589
1590 redef fun full_comment do
1591 var res = new Buffer
1592 if n_doc != null then
1593 for t in n_doc.n_comment do res.append(t.text.substring_from(1).html_escape)
1594 end
1595 return res.to_s
1596 end
1597
1598 redef fun html_signature(page) do
1599 mpropdef.bound.html_link(page)
1600 end
1601 end
1602
1603 redef class ASignature
1604 fun html_link(page: NitdocPage) do
1605 #TODO closures
1606 if not n_params.is_empty then
1607 page.append("(")
1608 for i in [0..n_params.length[ do
1609 n_params[i].html_link(page)
1610 if i < n_params.length - 1 then page.append(", ")
1611 end
1612 page.append(")")
1613 end
1614 if n_type != null then
1615 page.append(":")
1616 n_type.mtype.html_link(page)
1617 end
1618 end
1619 end
1620
1621 redef class AParam
1622 fun html_link(page: NitdocPage) do
1623 page.append(n_id.text)
1624 if n_type != null then
1625 page.append(": ")
1626 n_type.mtype.html_link(page)
1627 if n_dotdotdot != null then page.append("...")
1628 end
1629 end
1630 end
1631
1632 var nitdoc = new NitdocContext
1633 nitdoc.generate_nitdoc