nitdoc: use model filters
[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 min_visibility = private_visibility
45 if not toolcontext.opt_private.value then min_visibility = protected_visibility
46 var accept_attribute = true
47 if toolcontext.opt_no_attributes.value then accept_attribute = false
48
49 var filters = new ModelFilter(min_visibility, accept_attribute = accept_attribute)
50 var doc = new DocModel(mainmodule.model, mainmodule, filters)
51
52 var phases = [
53 new IndexingPhase(toolcontext, doc),
54 new MakePagePhase(toolcontext, doc),
55 new POSetPhase(toolcontext, doc),
56 new ConcernsPhase(toolcontext, doc),
57 new StructurePhase(toolcontext, doc),
58 new InheritanceListsPhase(toolcontext, doc),
59 new IntroRedefListPhase(toolcontext, doc),
60 new LinListPhase(toolcontext, doc),
61 new GraphPhase(toolcontext, doc),
62 new ReadmePhase(toolcontext, doc),
63 new RenderHTMLPhase(toolcontext, doc),
64 new DocTestPhase(toolcontext, doc): DocPhase]
65
66 for phase in phases do
67 toolcontext.info("# {phase.class_name}", 1)
68 phase.apply
69 end
70 end
71 end
72
73 # build toolcontext
74 var toolcontext = new ToolContext
75 var tpl = new Template
76 tpl.add "Usage: nitdoc [OPTION]... <file.nit>...\n"
77 tpl.add "Generates HTML pages of API documentation from Nit source files."
78 toolcontext.tooldescription = tpl.write_to_string
79
80 # process options
81 toolcontext.process_options(args)
82 var arguments = toolcontext.option_context.rest
83
84 # build model
85 var model = new Model
86 var mbuilder = new ModelBuilder(model, toolcontext)
87 var mmodules = mbuilder.parse_full(arguments)
88
89 # process
90 if mmodules.is_empty then return
91 mbuilder.run_phases
92 toolcontext.run_global_phases(mmodules)