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}/")
102 var overviewpage
= new NitdocOverview.with
(modelbuilder
.nmodules
, self.opt_nodot
.value
, destinationdir
.to_s
)
103 overviewpage
.save
("{destinationdir.to_s}/index.html")
107 var fullindex
= new NitdocFullindex.with
(model
.mmodules
)
108 fullindex
.save
("{destinationdir.to_s}/full-index.html")
116 var amodules
: Array[AModule]
118 # Init with Array[AModule] to get all ifnormations about each MModule containt in a program
119 # opt_nodot to inform about the graph gen
120 # destination: to know where will be saved dot files
121 init with
(modules
: Array[AModule], opt_nodot
: Bool, destination
: String) do
122 self.amodules
= modules
123 self.opt_nodot
= opt_nodot
124 self.destinationdir
= destination
129 add
("title").text
("Overview | Nit Standard Library")
134 open
("nav").add_class
("main")
136 add
("li").add_class
("current").text
("Overview")
138 add_html
("<a href=\"full-index
.html\
">Full Index</a>")
140 open
("li").attr
("id", "liGitHub")
141 open
("a").add_class
("btn").attr
("id", "logGitHub")
142 add
("img").attr
("id", "imgGitHub").attr
("src", "resources/icons/github-icon.png")
144 open
("div").add_class
("popover bottom")
145 add
("div").add_class
("arrow").text
(" ")
146 open
("div").add_class
("githubTitle")
147 add
("h3").text
("Github Sign In")
150 add
("label").attr
("id", "lbloginGit").text
("Username")
151 add
("input").attr
("id", "loginGit").attr
("name", "login").attr
("type", "text")
152 open
("label").attr
("id", "logginMessage").text
("Hello ")
153 open
("a").attr
("id", "githubAccount")
154 add
("strong").attr
("id", "nickName").text
(" ")
159 add
("label").attr
("id", "lbpasswordGit").text
("Password")
160 add
("input").attr
("id", "passwordGit").attr
("name", "password").attr
("type", "password")
161 open
("div").attr
("id", "listBranches")
162 add
("label").attr
("id", "lbBranches").text
("Branch")
163 add
("select").add_class
("dropdown").attr
("id", "dropBranches").attr
("name", "dropBranches").attr
("tabindex", "1").text
(" ")
167 add
("label").attr
("id", "lbrepositoryGit").text
("Repository")
168 add
("input").attr
("id", "repositoryGit").attr
("name", "repository").attr
("type", "text")
171 add
("label").attr
("id", "lbbranchGit").text
("Branch")
172 add
("input").attr
("id", "branchGit").attr
("name", "branch").attr
("type", "text")
175 add
("a").attr
("id", "signIn").text
("Sign In")
186 open
("div").add_class
("page")
187 open
("div").add_class
("content fullpage")
188 add
("h1").text
("Nit Standard Library")
189 open
("article").add_class
("overview")
190 add_html
("<p>Documentation for the standard library of Nit<br />Version jenkins-component=stdlib-19<br />Date: TODAY</p>")
192 open
("article").add_class
("overview")
193 add
("h2").text
("Modules")
201 add
("footer").text
("Nit standard library. Version jenkins-component=stdlib-19.")
205 var ls
= new List[nullable MModule]
206 for amodule
in amodules
do
207 var mmodule
= amodule
.mmodule
.public_owner
208 if mmodule
!= null and not ls
.has
(mmodule
) then
210 add
("a").attr
("href", "{mmodule.name}.html").text
("{mmodule.to_s} ")
211 add_html
(amodule
.comment
)
218 fun process_generate_dot
do
220 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")
221 for amodule
in amodules
do
222 op
.append
("\"{amodule.mmodule.name}\
"[URL=\"{amodule.mmodule.name}.html\
"];\n")
223 for mmodule2
in amodule
.mmodule
.in_importation
.direct_greaters
do
224 op
.append
("\"{amodule.mmodule.name}\
"->\"{mmodule2.name}\
";\n")
228 generate_dot
(op
.to_s
, "dep", "Modules hierarchy")
233 class NitdocFullindex
236 var mmodules
: Array[MModule]
238 init with
(mmodules
: Array[MModule]) do
239 self.mmodules
= mmodules
246 add
("title").text
("Full Index | Nit Standard Library")
251 open
("nav").add_class
("main")
254 add_html
("<a href=\"index
.html\
">Overview</a>")
256 add
("li").add_class
("current").text
("Full Index")
257 open
("li").attr
("id", "liGitHub")
258 open
("a").add_class
("btn").attr
("id", "logGitHub")
259 add
("img").attr
("id", "imgGitHub").attr
("src", "resources/icons/github-icon.png")
261 open
("div").add_class
("popover bottom")
262 add
("div").add_class
("arrow").text
(" ")
263 open
("div").add_class
("githubTitle")
264 add
("h3").text
("Github Sign In")
267 add
("label").attr
("id", "lbloginGit").text
("Username")
268 add
("input").attr
("id", "loginGit").attr
("name", "login").attr
("type", "text")
269 open
("label").attr
("id", "logginMessage").text
("Hello ")
270 open
("a").attr
("id", "githubAccount")
271 add
("strong").attr
("id", "nickName").text
(" ")
276 add
("label").attr
("id", "lbpasswordGit").text
("Password")
277 add
("input").attr
("id", "passwordGit").attr
("name", "password").attr
("type", "password")
278 open
("div").attr
("id", "listBranches")
279 add
("label").attr
("id", "lbBranches").text
("Branch")
280 add
("select").add_class
("dropdown").attr
("id", "dropBranches").attr
("name", "dropBranches").attr
("tabindex", "1").text
(" ")
284 add
("label").attr
("id", "lbrepositoryGit").text
("Repository")
285 add
("input").attr
("id", "repositoryGit").attr
("name", "repository").attr
("type", "text")
288 add
("label").attr
("id", "lbbranchGit").text
("Branch")
289 add
("input").attr
("id", "branchGit").attr
("name", "branch").attr
("type", "text")
292 add
("a").attr
("id", "signIn").text
("Sign In")
303 open
("div").add_class
("page")
304 open
("div").add_class
("content fullpage")
305 add
("h1").text
("Full Index")
309 add
("footer").text
("Nit standard library. Version jenkins-component=stdlib-19.")
321 var destinationdir
: String
324 add
("meta").attr
("charset", "utf-8")
325 add
("script").attr
("type", "text/javascript").attr
("src", "scripts/jquery-1.7.1.min.js")
326 add
("script").attr
("type", "text/javascript").attr
("src", "quicksearch-list.js")
327 add
("script").attr
("type", "text/javascript").attr
("src", "scripts/js-facilities.js")
328 add
("link").attr
("rel", "stylesheet").attr
("href", "styles/main.css").attr
("type", "text/css").attr
("media", "screen")
331 redef fun body
do header
334 # Generate a clickable graphviz image using a dot content
335 fun generate_dot
(dot
: String, name
: String, alt
: String) do
336 if opt_nodot
then return
337 var file
= new OFStream.open
("{self.destinationdir}/{name}.dot")
340 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 ; \}")
341 open
("article").add_class
("graph")
342 add
("img").attr
("src", "{name}.png").attr
("usemap", "#{name}").attr
("style", "margin:auto").attr
("alt", "{alt}")
344 var fmap
= new IFStream.open
("{self.destinationdir}/{name}.map")
345 add_html
(fmap
.read_all
)
352 private fun comment
: String do
354 if n_moduledecl
is null or n_moduledecl
.n_doc
is null then ret
355 if n_moduledecl
.n_doc
is null then return ""
356 for t
in n_moduledecl
.n_doc
.n_comment
do
357 ret
+= "{t.text.replace("# ", "")}"
362 private fun short_comment
: String do
364 if n_moduledecl
!= null and n_moduledecl
.n_doc
!= null then
365 var txt
= n_moduledecl
.n_doc
.n_comment
.first
.text
366 txt
= txt
.replace
("# ", "")
367 txt
= txt
.replace
("\n", "")
374 # Create a tool context to handle options and paths
375 var toolcontext
= new ToolContext
376 toolcontext
.process_options
378 # Here we launch the nit index
379 var nitdoc
= new Nitdoc(toolcontext
)