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.
24 redef class ToolContext
25 # Nitdoc generation phase.
26 var docphase
: Phase = new Nitdoc(self, null)
28 # File pattern used to link documentation to source code.
29 var opt_test
= new OptionBool("do not render anything, only print test data", "--test")
33 option_context
.add_option
(opt_test
)
37 # Nitdoc phase explores the model and generate pages for each mentities found
40 redef fun process_mainmodule
(mainmodule
, mmodules
)
42 var doc
= new DocModel(mainmodule
.model
, mainmodule
)
45 new ExtractionPhase(toolcontext
, doc
),
46 new IndexingPhase(toolcontext
, doc
),
47 new MakePagePhase(toolcontext
, doc
),
48 new POSetPhase(toolcontext
, doc
),
49 new ConcernsPhase(toolcontext
, doc
),
50 new StructurePhase(toolcontext
, doc
),
51 new InheritanceListsPhase(toolcontext
, doc
),
52 new IntroRedefListPhase(toolcontext
, doc
),
53 new LinListPhase(toolcontext
, doc
),
54 new GraphPhase(toolcontext
, doc
): DocPhase]
56 if not toolcontext
.opt_test
.value
then
57 phases
.add
new RenderHTMLPhase(toolcontext
, doc
)
60 for phase
in phases
do
61 toolcontext
.info
("# {phase.class_name}", 1)
65 if toolcontext
.opt_test
.value
then
67 var page_counter
= new Counter[String]
68 var pages
= doc
.pages
.keys
.to_a
69 default_comparator
.sort
(pages
)
71 var page
= doc
.pages
[title
]
72 page_counter
.inc page
.class_name
73 print page
.pretty_print
.write_to_string
75 print
"Generated {doc.pages.length} pages"
76 page_counter
.print_elements
(100)
78 var model_counter
= new Counter[String]
79 for mentity
in doc
.mentities
do
80 model_counter
.inc mentity
.class_name
82 print
"Found {doc.mentities.length} mentities"
83 model_counter
.print_elements
(100)
89 var toolcontext
= new ToolContext
90 var tpl
= new Template
91 tpl
.add
"Usage: nitdoc [OPTION]... <file.nit>...\n"
92 tpl
.add
"Generates HTML pages of API documentation from Nit source files."
93 toolcontext
.tooldescription
= tpl
.write_to_string
96 toolcontext
.process_options
(args
)
97 var arguments
= toolcontext
.option_context
.rest
100 var model
= new Model
101 var mbuilder
= new ModelBuilder(model
, toolcontext
)
102 var mmodules
= mbuilder
.parse_full
(arguments
)
105 if mmodules
.is_empty
then return
107 toolcontext
.run_global_phases
(mmodules
)