1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Documentation generator for the nit language.
17 # Generate API documentation in HTML format from nit source code.
23 redef class ToolContext
24 # Nitdoc generation phase.
25 var docphase
: Phase = new Nitdoc(self, null)
27 # Do not generate documentation for attributes.
28 var opt_no_attributes
= new OptionBool("Ignore the attributes", "--no-attributes")
30 # Do not generate documentation for private properties.
31 var opt_private
= new OptionBool("Also generate private API", "--private")
35 option_context
.add_option
(opt_no_attributes
, opt_private
)
39 # Nitdoc phase explores the model and generate pages for each mentities found
42 redef fun process_mainmodule
(mainmodule
, mmodules
)
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
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]
62 for phase
in phases
do
63 toolcontext
.info
("# {phase.class_name}", 1)
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
77 toolcontext
.process_options
(args
)
78 var arguments
= toolcontext
.option_context
.rest
82 var mbuilder
= new ModelBuilder(model
, toolcontext
)
83 var mmodules
= mbuilder
.parse_full
(arguments
)
86 if mmodules
.is_empty
then return
88 toolcontext
.run_global_phases
(mmodules
)