1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2008 Jean Privat <jean@pryen.org>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 import abstract_compiler
24 private var toolcontext
: ToolContext
25 private var model
: Model
26 private var modelbuilder
: ModelBuilder
27 private var mainmodule
: MModule
28 private var arguments
: Array[String]
29 private var destinationdir
: nullable String
30 private var sharedir
: nullable String
32 private var opt_dir
= new OptionString("Directory where doc is generated", "-d", "--dir")
33 private var opt_source
= new OptionString("What link for source (%f for filename, %l for first line, %L for last line)", "--source")
34 private var opt_sharedir
= new OptionString("Directory containing the nitdoc files", "--sharedir")
35 private var opt_nodot
= new OptionBool("Do not generate graphes with graphiviz", "--no-dot")
37 init(toolcontext
: ToolContext) do
38 # We need a model to collect stufs
39 self.toolcontext
= toolcontext
40 self.arguments
= toolcontext
.option_context
.rest
41 toolcontext
.option_context
.add_option
(opt_dir
)
42 toolcontext
.option_context
.add_option
(opt_source
)
43 toolcontext
.option_context
.add_option
(opt_sharedir
)
44 toolcontext
.option_context
.add_option
(opt_nodot
)
47 if arguments
.length
< 1 then
48 toolcontext
.option_context
.usage
53 modelbuilder
= new ModelBuilder(model
, toolcontext
)
55 # Here we load an process std modules
56 var mmodules
= modelbuilder
.parse_and_build
([arguments
.first
])
57 if mmodules
.is_empty
then return
58 modelbuilder
.full_propdef_semantic_analysis
59 assert mmodules
.length
== 1
60 self.mainmodule
= mmodules
.first
63 private fun process_options
do
64 if not opt_dir
.value
is null then
65 destinationdir
= opt_dir
.value
67 destinationdir
= "nitdoc_directory"
69 if not opt_sharedir
.value
is null then
70 sharedir
= opt_sharedir
.value
72 var dir
= "NIT_DIR".environ
74 dir
= "{sys.program_name.dirname}/../share/nitdoc"
76 dir
= "{dir}/share/nitdoc"
79 if sharedir
is null then
80 print
"Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
83 dir
= "{sharedir.to_s}/scripts/js-facilities.js"
84 if sharedir
is null then
85 print
"Error: Invalid nitdoc share files. Check --sharedir or envvar NIT_DIR"
92 if arguments
.length
== 1 then
93 # Create destination dir if it's necessary
94 if not destinationdir
.file_exists
then destinationdir
.mkdir
95 sys
.system
("cp -r {sharedir.to_s}/* {destinationdir.to_s}/")
104 var overviewpage
= new NitdocOverview.with
(modelbuilder
.nmodules
, self.opt_nodot
.value
, destinationdir
.to_s
)
105 overviewpage
.save
("{destinationdir.to_s}/index.html")
109 var fullindex
= new NitdocFullindex.with
(model
.mmodules
)
110 fullindex
.save
("{destinationdir.to_s}/full-index.html")
114 for mod
in modelbuilder
.nmodules
do
115 var modulepage
= new NitdocModules.with
(mod
)
116 modulepage
.save
("{destinationdir.to_s}/{mod.mmodule.name}.html")
121 for amodule
in modelbuilder
.nmodules
do
122 for mclass
, aclassdef
in amodule
.mclass2nclassdef
do
123 mclass
.amodule
(modelbuilder
.mmodule2nmodule
)
124 mclass
.mmethod
(aclassdef
.mprop2npropdef
)
125 var classpage
= new NitdocMClasses.with
(mclass
, aclassdef
)
126 classpage
.save
("{destinationdir.to_s}/{mclass.name}.html")
136 var amodules
: Array[AModule]
138 # Init with Array[AModule] to get all ifnormations about each MModule containt in a program
139 # opt_nodot to inform about the graph gen
140 # destination: to know where will be saved dot files
141 init with
(modules
: Array[AModule], opt_nodot
: Bool, destination
: String) do
142 self.amodules
= modules
143 self.opt_nodot
= opt_nodot
144 self.destinationdir
= destination
149 add
("title").text
("Overview | Nit Standard Library")
154 open
("nav").add_class
("main")
156 add
("li").add_class
("current").text
("Overview")
158 add_html
("<a href=\"full-index
.html\
">Full Index</a>")
160 open
("li").attr
("id", "liGitHub")
161 open
("a").add_class
("btn").attr
("id", "logGitHub")
162 add
("img").attr
("id", "imgGitHub").attr
("src", "resources/icons/github-icon.png")
164 open
("div").add_class
("popover bottom")
165 add
("div").add_class
("arrow").text
(" ")
166 open
("div").add_class
("githubTitle")
167 add
("h3").text
("Github Sign In")
170 add
("label").attr
("id", "lbloginGit").text
("Username")
171 add
("input").attr
("id", "loginGit").attr
("name", "login").attr
("type", "text")
172 open
("label").attr
("id", "logginMessage").text
("Hello ")
173 open
("a").attr
("id", "githubAccount")
174 add
("strong").attr
("id", "nickName").text
(" ")
179 add
("label").attr
("id", "lbpasswordGit").text
("Password")
180 add
("input").attr
("id", "passwordGit").attr
("name", "password").attr
("type", "password")
181 open
("div").attr
("id", "listBranches")
182 add
("label").attr
("id", "lbBranches").text
("Branch")
183 add
("select").add_class
("dropdown").attr
("id", "dropBranches").attr
("name", "dropBranches").attr
("tabindex", "1").text
(" ")
187 add
("label").attr
("id", "lbrepositoryGit").text
("Repository")
188 add
("input").attr
("id", "repositoryGit").attr
("name", "repository").attr
("type", "text")
191 add
("label").attr
("id", "lbbranchGit").text
("Branch")
192 add
("input").attr
("id", "branchGit").attr
("name", "branch").attr
("type", "text")
195 add
("a").attr
("id", "signIn").text
("Sign In")
206 open
("div").add_class
("page")
207 open
("div").add_class
("content fullpage")
208 add
("h1").text
("Nit Standard Library")
209 open
("article").add_class
("overview")
210 add_html
("<p>Documentation for the standard library of Nit<br />Version jenkins-component=stdlib-19<br />Date: TODAY</p>")
212 open
("article").add_class
("overview")
213 add
("h2").text
("Modules")
221 add
("footer").text
("Nit standard library. Version jenkins-component=stdlib-19.")
225 var ls
= new List[nullable MModule]
226 for amodule
in amodules
do
227 var mmodule
= amodule
.mmodule
.public_owner
228 if mmodule
!= null and not ls
.has
(mmodule
) then
230 add
("a").attr
("href", "{mmodule.name}.html").text
("{mmodule.to_s} ")
231 add_html
(amodule
.comment
)
238 fun process_generate_dot
do
240 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")
241 for amodule
in amodules
do
242 op
.append
("\"{amodule.mmodule.name}\
"[URL=\"{amodule.mmodule.name}.html\
"];\n")
243 for mmodule2
in amodule
.mmodule
.in_importation
.direct_greaters
do
244 op
.append
("\"{amodule.mmodule.name}\
"->\"{mmodule2.name}\
";\n")
248 generate_dot
(op
.to_s
, "dep", "Modules hierarchy")
253 class NitdocFullindex
256 var mmodules
: Array[MModule]
258 init with
(mmodules
: Array[MModule]) do
259 self.mmodules
= mmodules
266 add
("title").text
("Full Index | Nit Standard Library")
271 open
("nav").add_class
("main")
274 add_html
("<a href=\"index
.html\
">Overview</a>")
276 add
("li").add_class
("current").text
("Full Index")
277 open
("li").attr
("id", "liGitHub")
278 open
("a").add_class
("btn").attr
("id", "logGitHub")
279 add
("img").attr
("id", "imgGitHub").attr
("src", "resources/icons/github-icon.png")
281 open
("div").add_class
("popover bottom")
282 add
("div").add_class
("arrow").text
(" ")
283 open
("div").add_class
("githubTitle")
284 add
("h3").text
("Github Sign In")
287 add
("label").attr
("id", "lbloginGit").text
("Username")
288 add
("input").attr
("id", "loginGit").attr
("name", "login").attr
("type", "text")
289 open
("label").attr
("id", "logginMessage").text
("Hello ")
290 open
("a").attr
("id", "githubAccount")
291 add
("strong").attr
("id", "nickName").text
(" ")
296 add
("label").attr
("id", "lbpasswordGit").text
("Password")
297 add
("input").attr
("id", "passwordGit").attr
("name", "password").attr
("type", "password")
298 open
("div").attr
("id", "listBranches")
299 add
("label").attr
("id", "lbBranches").text
("Branch")
300 add
("select").add_class
("dropdown").attr
("id", "dropBranches").attr
("name", "dropBranches").attr
("tabindex", "1").text
(" ")
304 add
("label").attr
("id", "lbrepositoryGit").text
("Repository")
305 add
("input").attr
("id", "repositoryGit").attr
("name", "repository").attr
("type", "text")
308 add
("label").attr
("id", "lbbranchGit").text
("Branch")
309 add
("input").attr
("id", "branchGit").attr
("name", "branch").attr
("type", "text")
312 add
("a").attr
("id", "signIn").text
("Sign In")
323 open
("div").add_class
("page")
324 open
("div").add_class
("content fullpage")
325 add
("h1").text
("Full Index")
329 add
("footer").text
("Nit standard library. Version jenkins-component=stdlib-19.")
338 # Add to content modules column
340 var ls
= new List[nullable MModule]
341 open
("article").add_class
("modules filterable")
342 add
("h2").text
("Modules")
344 for mmodule
in mmodules
do
345 if mmodule
.public_owner
!= null and not ls
.has
(mmodule
.public_owner
) then
346 ls
.add
(mmodule
.public_owner
)
348 add
("a").attr
("href", "{mmodule.public_owner.name}.html").text
(mmodule
.public_owner
.name
)
356 # Add to content classes modules
357 fun classes_column
do
358 open
("article").add_class
("classes filterable")
359 add
("h2").text
("Classes")
362 for mclass
in mmodules
.first
.imported_mclasses
do
364 add
("a").attr
("href", "{mclass.name}.html").text
(mclass
.name
)
372 # Insert the properties column of fullindex page
373 fun properties_column
do
374 open
("article").add_class
("properties filterable")
375 add
("h2").text
("Properties")
378 for method
in mmodules
.first
.imported_methods
do
379 if method
.visibility
is none_visibility
or method
.visibility
is intrude_visibility
then continue
380 open
("li").add_class
("intro")
381 add
("span").attr
("title", "introduction").text
("I")
383 add
("a").attr
("href", "{method.local_class.name}.html").attr
("title", "").text
("{method.name} ({method.local_class.name})")
387 for method
in mmodules
.first
.redef_methods
do
388 if method
.visibility
is none_visibility
or method
.visibility
is intrude_visibility
then continue
389 open
("li").add_class
("redef")
390 add
("span").attr
("title", "redefinition").text
("R")
392 add
("a").attr
("href", "{method.local_class.name}.html").attr
("title", "").text
("{method.name} ({method.local_class.name})")
406 var modulename
: String
407 init with
(amodule
: AModule) do
408 self.amodule
= amodule
409 self.modulename
= self.amodule
.mmodule
.name
416 add
("title").text
("{modulename} module | {amodule.short_comment}")
421 open
("nav").add_class
("main")
424 add_html
("<a href=\"index
.html\
">Overview</a>")
426 add
("li").add_class
("current").text
(modulename
)
428 add_html
("<a href=\"full-index
.html\
" >Full Index</a>")
430 open
("li").attr
("id", "liGitHub")
431 open
("a").add_class
("btn").attr
("id", "logGitHub")
432 add
("img").attr
("id", "imgGitHub").attr
("src", "resources/icons/github-icon.png")
434 open
("div").add_class
("popover bottom")
435 add
("div").add_class
("arrow").text
(" ")
436 open
("div").add_class
("githubTitle")
437 add
("h3").text
("Github Sign In")
440 add
("label").attr
("id", "lbloginGit").text
("Username")
441 add
("input").attr
("id", "loginGit").attr
("name", "login").attr
("type", "text")
442 open
("label").attr
("id", "logginMessage").text
("Hello ")
443 open
("a").attr
("id", "githubAccount")
444 add
("strong").attr
("id", "nickName").text
(" ")
449 add
("label").attr
("id", "lbpasswordGit").text
("Password")
450 add
("input").attr
("id", "passwordGit").attr
("name", "password").attr
("type", "password")
451 open
("div").attr
("id", "listBranches")
452 add
("label").attr
("id", "lbBranches").text
("Branch")
453 add
("select").add_class
("dropdown").attr
("id", "dropBranches").attr
("name", "dropBranches").attr
("tabindex", "1").text
(" ")
457 add
("label").attr
("id", "lbrepositoryGit").text
("Repository")
458 add
("input").attr
("id", "repositoryGit").attr
("name", "repository").attr
("type", "text")
461 add
("label").attr
("id", "lbbranchGit").text
("Branch")
462 add
("input").attr
("id", "branchGit").attr
("name", "branch").attr
("type", "text")
465 add
("a").attr
("id", "signIn").text
("Sign In")
476 open
("div").add_class
("page")
480 add
("footer").text
("Nit standard library. Version jenkins-component=stdlib-19.")
483 # Insert all tags in content part
485 open
("div").add_class
("content")
486 add
("h1").text
(modulename
)
487 add
("div").add_class
("subtitle").text
("module {modulename}")
494 # Insert module comment in the content
495 fun module_comment
do
496 var doc
= amodule
.comment
497 open
("div").attr
("id", "description")
498 add
("pre").add_class
("text_label").text
(doc
)
499 add
("textarea").add_class
("edit").attr
("rows", "1").attr
("cols", "76").attr
("id", "fileContent").text
(" ")
500 add
("a").attr
("id", "cancelBtn").text
("Cancel")
501 add
("a").attr
("id", "commitBtn").text
("Commit")
502 add
("pre").add_class
("text_label").attr
("id", "preSave").attr
("type", "2")
507 var mmodule
= amodule
.mmodule
508 open
("div").add_class
("menu")
510 add
("h3").text
("Module Hierarchy").attr
("style","cursor: pointer;")
511 if mmodule
.in_importation
.direct_greaters
.length
> 0 then
512 add_html
("<h4>All dependencies</h4><ul>")
513 for m
in mmodule
.in_importation
.direct_greaters
do
514 if m
== mmodule
or mmodule
== m
.public_owner
then continue
516 add
("a").attr
("href", "{m.name}.html").text
(m
.name
)
521 if mmodule
.in_importation
.greaters
.length
> 0 then
522 add_html
("<h4>All clients</h4><ul>")
523 for m
in mmodule
.in_importation
.greaters
do
524 if m
== mmodule
then continue
526 add
("a").attr
("href", "{m.name}.html").text
(m
.name
)
532 if mmodule
.in_nesting
.direct_greaters
.length
> 0 then
534 add
("h3").text
("Nested Modules").attr
("style","cursor: pointer;")
536 for m
in mmodule
.in_nesting
.direct_greaters
do
538 add
("a").attr
("href", "{m.name}.html").text
(m
.name
)
549 open
("div").add_class
("module")
550 open
("article").add_class
("classes filterable")
551 add
("h2").text
("Classes")
553 for c
, state
in amodule
.mmodule
.mclasses
do
555 if state
== c_is_intro
or state
== c_is_imported
then
556 open
("li").add_class
("intro")
557 add
("span").attr
("title", "introduced in this module").text
("I ")
559 open
("li").add_class
("redef")
560 add
("span").attr
("title", "refined in this module").text
("R ")
562 add
("a").attr
("href", "{name}.html").text
(name
)
571 open
("article").add_class
("properties filterable")
572 add_html
("<h2>Properties</h2>")
574 for method
in amodule
.mmodule
.imported_methods
do
575 if method
.visibility
is none_visibility
or method
.visibility
is intrude_visibility
then continue
576 open
("li").add_class
("intro")
577 add
("span").attr
("title", "introduction").text
("I")
579 add
("a").attr
("href", "{method.local_class.name}.html").attr
("title", "").text
("{method.name} ({method.local_class.name})")
583 for method
in amodule
.mmodule
.redef_methods
do
584 if method
.visibility
is none_visibility
or method
.visibility
is intrude_visibility
then continue
585 open
("li").add_class
("redef")
586 add
("span").attr
("title", "redefinition").text
("R")
588 add
("a").attr
("href", "{method.local_class.name}.html").attr
("title", "").text
("{method.name} ({method.local_class.name})")
598 # Nit Standard Library
603 var aclassdef
: AClassdef
604 var stdclassdef
: nullable AStdClassdef
605 var public_owner
: nullable MModule
607 init with
(mclass
: MClass, aclassdef
: AClassdef) do
609 self.aclassdef
= aclassdef
610 if aclassdef
isa AStdClassdef then self.stdclassdef
= aclassdef
611 self.public_owner
= mclass
.intro_mmodule
.public_owner
618 add
("title").text
("{self.mclass.name} class | Nit Standard Library")
623 open
("nav").add_class
("main")
626 add_html
("<a href=\"index
.html\
">Overview</a>")
629 if public_owner
is null then
630 add_html
("<a href=\"{mclass.intro_mmodule.name}.html\
">{mclass.intro_mmodule.name}</a>")
632 add_html
("<a href=\"{public_owner.name}.html\
">{public_owner.name}</a>")
635 add
("li").add_class
("current").text
(mclass
.name
)
637 add_html
("<a href=\"full-index
.html\
" >Full Index</a>")
639 open
("li").attr
("id", "liGitHub")
640 open
("a").add_class
("btn").attr
("id", "logGitHub")
641 add
("img").attr
("id", "imgGitHub").attr
("src", "resources/icons/github-icon.png")
643 open
("div").add_class
("popover bottom")
644 add
("div").add_class
("arrow").text
(" ")
645 open
("div").add_class
("githubTitle")
646 add
("h3").text
("Github Sign In")
649 add
("label").attr
("id", "lbloginGit").text
("Username")
650 add
("input").attr
("id", "loginGit").attr
("name", "login").attr
("type", "text")
651 open
("label").attr
("id", "logginMessage").text
("Hello ")
652 open
("a").attr
("id", "githubAccount")
653 add
("strong").attr
("id", "nickName").text
(" ")
658 add
("label").attr
("id", "lbpasswordGit").text
("Password")
659 add
("input").attr
("id", "passwordGit").attr
("name", "password").attr
("type", "password")
660 open
("div").attr
("id", "listBranches")
661 add
("label").attr
("id", "lbBranches").text
("Branch")
662 add
("select").add_class
("dropdown").attr
("id", "dropBranches").attr
("name", "dropBranches").attr
("tabindex", "1").text
(" ")
666 add
("label").attr
("id", "lbrepositoryGit").text
("Repository")
667 add
("input").attr
("id", "repositoryGit").attr
("name", "repository").attr
("type", "text")
670 add
("label").attr
("id", "lbbranchGit").text
("Branch")
671 add
("input").attr
("id", "branchGit").attr
("name", "branch").attr
("type", "text")
674 add
("a").attr
("id", "signIn").text
("Sign In")
685 open
("div").add_class
("page")
688 add
("footer").text
("Nit standard library. Version jenkins-component=stdlib-19.")
691 # Insert all tags in content part
693 open
("div").add_class
("menu")
697 open
("div").add_class
("content")
702 fun properties_column
do
703 open
("nav").add_class
("properties filterable")
704 add
("h3").text
("Properties")
706 if mclass
.virtual_types
.length
> 0 then
707 add
("h4").text
("Virtual Types")
709 for prop
in mclass
.virtual_types
do
710 add_html
("<li class=\"redef\
"><span title=\"Redefined\
">R</span><a href=\"{prop.link_anchor}\
">{prop.name}</a></li>")
714 if mclass
.constructors
.length
> 0 then
715 add
("h4").text
("Constructors")
717 for prop
in mclass
.constructors
do
718 add_html
("<li class=\"intro\
"><span title=\"Introduced\
">I</span><a href=\"{prop.link_anchor}\
">{prop.name}</a></li>")
722 add
("h4").text
("Methods")
724 if mclass
.intro_methods
.length
> 0 then
725 for prop
in mclass
.intro_methods
do
726 if prop
.visibility
is public_visibility
or prop
.visibility
is protected_visibility
then add_html
("<li class=\"intro\
"><span title=\"Introduced\
">I</span><a href=\"{prop.link_anchor}\
">{prop.name}</a></li>")
729 if mclass
.inherited_methods
.length
> 0 then
730 for prop
in mclass
.inherited_methods
do
731 if prop
.visibility
is public_visibility
or prop
.visibility
is protected_visibility
then add_html
("<li class=\"inherit\
"><span title=\"Inherited\
">H</span><a href=\"{prop.link_anchor}\
">{prop.name}</a></li>")
734 if mclass
.redef_methods
.length
> 0 then
735 for prop
in mclass
.redef_methods
do
736 if prop
.visibility
is public_visibility
or prop
.visibility
is protected_visibility
then add_html
("<li class=\"redef\
"><span title=\"Refined\
">R</span><a href=\"{prop.link_anchor}\
">{prop.name}</a></li>")
743 fun inheritance_column
do
745 add
("h3").text
("Inheritance")
746 if mclass
.parents
.length
> 0 then
747 add
("h4").text
("Superclasses")
749 for sup
in mclass
.parents
do add_html
("<li><a href=\"{sup.name}.html\
">{sup.name}</a></li>")
753 if mclass
.descendants
.length
is 0 then
754 add
("h4").text
("No Known Subclasses")
755 else if mclass
.descendants
.length
<= 100 then
756 add
("h4").text
("Subclasses")
758 for sub
in mclass
.descendants
do add_html
("<li><a href=\"{sub.name}\
">{sub.name}</a></li>")
760 else if mclass
.children
.length
<= 100 then
761 add
("h4").text
("Direct Subclasses Only")
763 for sub
in mclass
.children
do add_html
("<li><a href=\"{sub.name}\
">{sub.name}</a></li>")
766 add
("h4").text
("Too much Subclasses to list")
773 var lmmodule
= new List[MModule]
774 # Insert the subtitle part
775 add
("h1").text
(mclass
.name
)
776 open
("div").add_class
("subtitle")
777 if mclass
.visibility
is none_visibility
then subtitle
+= "private "
778 subtitle
+= "{mclass.kind} <a href=\"{mclass.public_owner.name}.html\
">{mclass.public_owner.name}</a>::{mclass.name}"
781 add_html
("<div style=\"float
: right
;\
"><a id=\"lblDiffCommit\
"></a></div>")
782 # We add the class description
783 open
("section").add_class
("description")
784 if not stdclassdef
is null and not stdclassdef
.comment
.is_empty
then add_html
("<pre class=\"text_label\
" title=\"122\
" name=\"\
" tag=\"{mclass.mclassdefs.first.location.to_s}\
" type=\"2\
">{stdclassdef.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>")
786 open
("section").add_class
("concerns")
787 add
("h2").add_class
("section-header").text
("Concerns")
789 for owner
, childs
in mclass
.concerns
do
791 add_html
("<a href=\"#MOD_{owner.name}\">{owner.name}</a>: {owner.amodule.short_comment}")
792 if not childs
is null then
794 for child
in childs
.as(not null) do add_html
("<li><a href=\"#MOD_{child.name}\">{child.name}</a>: {child.amodule.short_comment} </li>")
801 # Insert virtual types if there is almost one
802 if mclass
.virtual_types
.length
> 0 or (stdclassdef
!= null and stdclassdef
.n_formaldefs
.length
> 0) then
803 open
("section").add_class
("types")
804 add
("h2").text
("Formal and Virtual Types")
805 if mclass
.virtual_types
.length
> 0 then for prop
in mclass
.virtual_types
do description
(prop
)
806 if stdclassdef
.n_formaldefs
.length
> 0 then
807 for prop
in stdclassdef
.n_formaldefs
do
808 open
("article").attr
("id", "FT_Object_{prop.collect_text}")
809 open
("h3").add_class
("signature").text
("{prop.collect_text}: nullable ")
810 add_html
("<a title=\"The root of the
class hierarchy
.\
" href=\"Object.html\
">Object</a>")
812 add_html
("<div class=\"info\
">formal generic type</div>")
818 # Insert constructors if there is almost one
819 if mclass
.constructors
.length
> 0 then
820 open
("section").add_class
("constructors")
821 add
("h2").add_class
("section-header").text
("Constructors")
822 for prop
in mclass
.constructors
do description
(prop
)
827 # Insert description tags for 'prop'
828 fun description
(prop
: MProperty) do
829 open
("article").add_class
("fun public {if prop.is_redef then "redef" else ""}").attr
("id", "{prop.anchor}")
831 if prop
.apropdef
!= null then sign
+= prop
.apropdef
.signature
832 add_html
("<h3 class=\"signature\
">{sign}</h3>")
833 add_html
("<div class=\"info\
">{if prop.is_redef then "redef" else ""} fun {prop.intro_mclassdef.namespace(mclass)}::{prop.name}</div><div style=\"float
: right
;\
"><a id=\"lblDiffCommit\
"></a></div>")
835 open
("div").add_class
("description")
836 if prop
.apropdef
is null or prop
.apropdef
.comment
== "" then
837 add_html
("<a class=\"newComment\
" title=\"32\
" tag=\"\
">New Comment</a>")
839 add_html
("<pre class=\"text_label\
" title=\"\
" name=\"\
" tag=\"\
" type=\"1\
">{prop.apropdef.comment}</pre>")
841 add_html
("<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>")
843 if prop
.local_class
!= mclass
then add_html
("inherited from {prop.local_class.intro_mmodule.name} ")
844 #TODO display show code if doc github
845 add_html
("defined by the module <a href=\"{prop.intro_mclassdef.mmodule.name}.html\
">{prop.intro_mclassdef.mmodule.name}</a> (<a href=\"\
">show code</a>).")
847 for parent
in mclass
.parents
do
848 if prop
isa MMethod then if parent
.constructors
.has
(prop
) then add_html
(" Previously defined by: <a href=\"{parent.intro_mmodule.name}.html\
">{parent.intro_mmodule.name}</a> for <a href=\"{parent.name}.html\
">{parent.name}</a>.")
862 var destinationdir
: String
865 add
("meta").attr
("charset", "utf-8")
866 add
("script").attr
("type", "text/javascript").attr
("src", "scripts/jquery-1.7.1.min.js")
867 add
("script").attr
("type", "text/javascript").attr
("src", "quicksearch-list.js")
868 add
("script").attr
("type", "text/javascript").attr
("src", "scripts/js-facilities.js")
869 add
("link").attr
("rel", "stylesheet").attr
("href", "styles/main.css").attr
("type", "text/css").attr
("media", "screen")
872 redef fun body
do header
875 # Generate a clickable graphviz image using a dot content
876 fun generate_dot
(dot
: String, name
: String, alt
: String) do
877 if opt_nodot
then return
878 var file
= new OFStream.open
("{self.destinationdir}/{name}.dot")
881 sys
.system
("\{ test -f {self.destinationdir}/{name}.png && test -f {self.destinationdir}/{name}.s.dot && diff {self.destinationdir}/{name}.dot {self.destinationdir}/{name}.s.dot >/dev/null 2>&1 ; \} || \{ cp {self.destinationdir}/{name}.dot {self.destinationdir}/{name}.s.dot && dot -Tpng -o{self.destinationdir}/{name}.png -Tcmapx -o{self.destinationdir}/{name}.map {self.destinationdir}/{name}.s.dot ; \}")
882 open
("article").add_class
("graph")
883 add
("img").attr
("src", "{name}.png").attr
("usemap", "#{name}").attr
("style", "margin:auto").attr
("alt", "{alt}")
885 var fmap
= new IFStream.open
("{self.destinationdir}/{name}.map")
886 add_html
(fmap
.read_all
)
893 private fun comment
: String do
895 if n_moduledecl
is null or n_moduledecl
.n_doc
is null then ret
896 if n_moduledecl
.n_doc
is null then return ""
897 for t
in n_moduledecl
.n_doc
.n_comment
do
898 ret
+= "{t.text.replace("# ", "")}"
903 private fun short_comment
: String do
905 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
906 var txt
= n_moduledecl
.n_doc
.n_comment
.first
.text
907 txt
= txt
.replace
("# ", "")
908 txt
= txt
.replace
("\n", "")
917 var amodule
: nullable AModule
919 # Get the list of all methods in a module
920 fun imported_methods
: Set[MMethod] do
921 var methods
= new HashSet[MMethod]
922 for mclass
in imported_mclasses
do
923 for method
in mclass
.intro_methods
do
930 # Get the list aof all refined methods in a module
931 fun redef_methods
: Set[MMethod] do
932 var methods
= new HashSet[MMethod]
933 for mclass
in redef_mclasses
do
934 for method
in mclass
.intro_methods
do
942 redef class MProperty
945 var apropdef
: nullable APropdef
947 redef init(intro_mclassdef
: MClassDef, name
: String, visibility
: MVisibility)
953 fun local_class
: MClass do
954 var classdef
= self.intro_mclassdef
955 return classdef
.mclass
958 fun class_text
: String do
959 return local_class
.name
962 fun link_anchor
: String do
963 return "{class_text}.html#{anchor}"
966 fun anchor
: String do
967 return "PROP_{c_name}"
974 # Associate all MMethods to each MModule concerns
975 fun all_methods
: HashMap[MModule, Set[MMethod]] do
976 var hm
= new HashMap[MModule, Set[MMethod]]
977 for mmodule
, childs
in concerns
do
978 if not hm
.has_key
(mmodule
) then hm
[mmodule
] = new HashSet[MMethod]
979 for prop
in intro_methods
do
980 if mmodule
== prop
.intro_mclassdef
.mmodule
then
981 prop
.is_redef
= false
982 hm
[mmodule
].add
(prop
)
985 for prop
in redef_methods
do
986 if mmodule
== prop
.intro_mclassdef
.mmodule
then
988 hm
[mmodule
].add
(prop
)
992 if childs
!= null then
993 for child
in childs
do
994 if not hm
.has_key
(child
) then hm
[child
] = new HashSet[MMethod]
995 for prop
in intro_methods
do
996 if child
== prop
.intro_mclassdef
.mmodule
then
997 prop
.is_redef
= false
1001 for prop
in redef_methods
do
1002 if child
== prop
.intro_mclassdef
.mmodule
then
1003 prop
.is_redef
= true
1013 fun public_owner
: MModule do
1014 var owner
= intro_mmodule
1015 if owner
.public_owner
is null then
1018 return owner
.public_owner
.as(not null)
1022 # Associate Amodule to all MModule concern by 'self'
1023 fun amodule
(amodules
: HashMap[MModule, AModule]) do
1024 for owner
, childs
in concerns
do
1025 if childs
!= null then for child
in childs
do child
.amodule
= amodules
[child
]
1026 owner
.amodule
= amodules
[owner
]
1030 # Associate MClass to all MMethod include in 'inherited_methods'
1031 fun inherited
: HashMap[MClass, Set[MMethod]] do
1032 var hm
= new HashMap[MClass, Set[MMethod]]
1033 for method
in inherited_methods
do
1034 var mclass
= method
.intro_mclassdef
.mclass
1035 if not hm
.has_key
(mclass
) then hm
[mclass
] = new HashSet[MMethod]
1036 hm
[mclass
].add
(method
)
1041 # Return true if MModule concern contain subMModule
1042 fun has_mmodule
(sub
: MModule): Bool do
1043 for mmodule
, childs
in concerns
do
1044 if childs
is null then continue
1045 if childs
.has
(sub
) then return true
1050 fun mmethod
(mprop2npropdef
: Map[MProperty, APropdef]) do
1051 for const
in constructors
do
1052 if mprop2npropdef
.has_key
(const
)then
1053 const
.apropdef
= mprop2npropdef
[const
].as(AMethPropdef)
1057 for intro
in intro_methods
do
1058 if mprop2npropdef
.has_key
(intro
)then
1059 if mprop2npropdef
[intro
] isa AMethPropdef then intro
.apropdef
= mprop2npropdef
[intro
].as(AMethPropdef)
1063 for rd
in redef_methods
do
1064 if mprop2npropdef
.has_key
(rd
)then
1065 if mprop2npropdef
[rd
] isa AMethPropdef then rd
.apropdef
= mprop2npropdef
[rd
].as(AMethPropdef)
1072 redef class AStdClassdef
1073 private fun comment
: String do
1075 if n_doc
!= null then
1076 for t
in n_doc
.n_comment
do
1077 var txt
= t
.text
.replace
("# ", "")
1078 txt
= txt
.replace
("#", "")
1085 private fun short_comment
: String do
1087 if n_doc
!= null then
1088 var txt
= n_doc
.n_comment
.first
.text
1089 txt
= txt
.replace
("# ", "")
1090 txt
= txt
.replace
("\n", "")
1097 redef class ASignature
1101 if not n_params
.is_empty
then
1102 ret
= "{ret}({n_params.join(", ")})"
1104 if n_type
!= null and n_type
.to_s
!= "" then ret
+= " {n_type.to_s}"
1111 var ret
= "{n_id.text}"
1112 if n_type
!= null then
1113 ret
= "{ret}: {n_type.to_s}"
1114 if n_dotdotdot
!= null then ret
= "{ret}..."
1122 var ret
= "<a href=\"{n_id.text}.html\
">{n_id.text}</a>"
1123 if n_kwnullable
!= null then ret
= "nullable {ret}"
1124 if not n_types
.is_empty
then ret
= "{ret}[{n_types.join(", ")}]"
1129 redef class APropdef
1130 private fun short_comment
: String is abstract
1131 private fun signature
: String is abstract
1132 private fun comment
: String is abstract
1135 redef class AAttrPropdef
1136 redef fun short_comment
do
1138 if n_doc
!= null then
1139 var txt
= n_doc
.n_comment
.first
.text
1140 txt
= txt
.replace
("# ", "")
1141 txt
= txt
.replace
("\n", "")
1148 redef class AMethPropdef
1149 redef fun short_comment
do
1151 if n_doc
!= null then
1152 var txt
= n_doc
.n_comment
.first
.text
1153 txt
= txt
.replace
("# ", "")
1154 txt
= txt
.replace
("\n", "")
1160 redef fun signature
: String do
1162 if n_signature
!= null then sign
= " {n_signature.to_s}"
1166 redef private fun comment
: String do
1168 if n_doc
!= null then
1169 for t
in n_doc
.n_comment
do
1170 var txt
= t
.text
.replace
("# ", "")
1171 txt
= txt
.replace
("#", "")
1179 redef class MClassDef
1180 private fun namespace
(mclass
: MClass): String do
1182 if mmodule
.public_owner
is null then
1183 return "{mmodule.full_name}::{mclass.name}"
1184 else if mclass
is self.mclass
then
1185 return "{mmodule.public_owner.name}::{mclass.name}"
1187 return "{mmodule.public_owner.name}::<a href=\"{mclass.name}.html\
">{mclass.name}</a>"
1192 # Create a tool context to handle options and paths
1193 var toolcontext
= new ToolContext
1194 toolcontext
.process_options
1196 # Here we launch the nit index
1197 var nitdoc
= new Nitdoc(toolcontext
)