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