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 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
49 var filters
= new ModelFilter(
51 accept_attribute
= accept_attribute
,
52 accept_fictive
= false)
53 var doc
= new DocModel(mainmodule
.model
, mainmodule
, filters
)
56 new IndexingPhase(toolcontext
, doc
),
57 new MakePagePhase(toolcontext
, doc
),
58 new POSetPhase(toolcontext
, doc
),
59 new ConcernsPhase(toolcontext
, doc
),
60 new StructurePhase(toolcontext
, doc
),
61 new InheritanceListsPhase(toolcontext
, doc
),
62 new IntroRedefListPhase(toolcontext
, doc
),
63 new LinListPhase(toolcontext
, doc
),
64 new GraphPhase(toolcontext
, doc
),
65 new ReadmePhase(toolcontext
, doc
),
66 new RenderHTMLPhase(toolcontext
, doc
),
67 new DocTestPhase(toolcontext
, doc
): DocPhase]
69 for phase
in phases
do
70 toolcontext
.info
("# {phase.class_name}", 1)
77 var toolcontext
= new ToolContext
78 var tpl
= new Template
79 tpl
.add
"Usage: nitdoc [OPTION]... <file.nit>...\n"
80 tpl
.add
"Generates HTML pages of API documentation from Nit source files."
81 toolcontext
.tooldescription
= tpl
.write_to_string
84 toolcontext
.process_options
(args
)
85 var arguments
= toolcontext
.option_context
.rest
89 var mbuilder
= new ModelBuilder(model
, toolcontext
)
90 var mmodules
= mbuilder
.parse_full
(arguments
)
93 if mmodules
.is_empty
then return
95 toolcontext
.run_global_phases
(mmodules
)