Merge: lib/config: fix doc
[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 #
17 # Generate API documentation in HTML format from nit source code.
18 module nitdoc
19
20 import modelbuilder
21 import doc
22
23 redef class ToolContext
24 # Nitdoc generation phase.
25 var docphase: Phase = new Nitdoc(self, null)
26
27 # Do not generate documentation for attributes.
28 var opt_no_attributes = new OptionBool("Ignore the attributes", "--no-attributes")
29
30 # Do not generate documentation for private properties.
31 var opt_private = new OptionBool("Also generate private API", "--private")
32
33 redef init do
34 super
35 option_context.add_option(opt_no_attributes, opt_private)
36 end
37 end
38
39 # Nitdoc phase explores the model and generate pages for each mentities found
40 private class Nitdoc
41 super Phase
42 redef fun process_mainmodule(mainmodule, mmodules)
43 do
44 var doc = new DocModel(mainmodule.model, mainmodule)
45 if not toolcontext.opt_private.value then doc.min_visibility = protected_visibility
46 if not toolcontext.opt_no_attributes.value then doc.include_attribute = false
47
48 var phases = [
49 new IndexingPhase(toolcontext, doc),
50 new MakePagePhase(toolcontext, doc),
51 new POSetPhase(toolcontext, doc),
52 new ConcernsPhase(toolcontext, doc),
53 new StructurePhase(toolcontext, doc),
54 new InheritanceListsPhase(toolcontext, doc),
55 new IntroRedefListPhase(toolcontext, doc),
56 new LinListPhase(toolcontext, doc),
57 new GraphPhase(toolcontext, doc),
58 new ReadmePhase(toolcontext, doc),
59 new RenderHTMLPhase(toolcontext, doc),
60 new DocTestPhase(toolcontext, doc): DocPhase]
61
62 for phase in phases do
63 toolcontext.info("# {phase.class_name}", 1)
64 phase.apply
65 end
66 end
67 end
68
69 # build toolcontext
70 var toolcontext = new ToolContext
71 var tpl = new Template
72 tpl.add "Usage: nitdoc [OPTION]... <file.nit>...\n"
73 tpl.add "Generates HTML pages of API documentation from Nit source files."
74 toolcontext.tooldescription = tpl.write_to_string
75
76 # process options
77 toolcontext.process_options(args)
78 var arguments = toolcontext.option_context.rest
79
80 # build model
81 var model = new Model
82 var mbuilder = new ModelBuilder(model, toolcontext)
83 var mmodules = mbuilder.parse_full(arguments)
84
85 # process
86 if mmodules.is_empty then return
87 mbuilder.run_phases
88 toolcontext.run_global_phases(mmodules)