nitdoc: extract NitdocContext from Nitdoc generation
[nit.git] / src / nitdoc.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Documentation generator for the nit language.
16 # Generate API documentation in HTML format from nit source code.
17 module nitdoc
18
19 import doc
20
21 # process options
22 var toolcontext = new ToolContext
23 var ctx = new NitdocContext(toolcontext)
24 ctx.process_options(args)
25 var arguments = ctx.toolcontext.option_context.rest
26
27 # build model
28 var model = new Model
29 var mbuilder = new ModelBuilder(model, ctx.toolcontext)
30 var mmodules = mbuilder.parse(arguments)
31
32 if mmodules.is_empty then return
33 mbuilder.run_phases
34 var mainmodule: MModule
35 if mmodules.length == 1 then
36 mainmodule = mmodules.first
37 else
38 mainmodule = new MModule(model, null, "<main>", new Location(null, 0, 0, 0, 0))
39 mainmodule.is_fictive = true
40 mainmodule.set_imported_mmodules(mmodules)
41 end
42
43 # generate doc
44 var nitdoc = new Nitdoc(ctx, model, mainmodule)
45 nitdoc.generate
46