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("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
),
55 new ReadmePhase(toolcontext
, doc
),
56 new RenderHTMLPhase(toolcontext
, doc
): DocPhase]
58 for phase
in phases
do
59 toolcontext
.info
("# {phase.class_name}", 1)
63 if toolcontext
.opt_test
.value
then
65 var page_counter
= new Counter[String]
66 var pages
= doc
.pages
.keys
.to_a
67 default_comparator
.sort
(pages
)
69 var page
= doc
.pages
[title
]
70 page_counter
.inc page
.class_name
71 print page
.pretty_print
.write_to_string
73 print
"Generated {doc.pages.length} pages"
74 page_counter
.print_elements
(100)
76 var model_counter
= new Counter[String]
77 for mentity
in doc
.mentities
do
78 model_counter
.inc mentity
.class_name
80 print
"Found {doc.mentities.length} mentities"
81 model_counter
.print_elements
(100)
87 var toolcontext
= new ToolContext
88 var tpl
= new Template
89 tpl
.add
"Usage: nitdoc [OPTION]... <file.nit>...\n"
90 tpl
.add
"Generates HTML pages of API documentation from Nit source files."
91 toolcontext
.tooldescription
= tpl
.write_to_string
94 toolcontext
.process_options
(args
)
95 var arguments
= toolcontext
.option_context
.rest
99 var mbuilder
= new ModelBuilder(model
, toolcontext
)
100 var mmodules
= mbuilder
.parse_full
(arguments
)
103 if mmodules
.is_empty
then return
105 toolcontext
.run_global_phases
(mmodules
)