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 # Program to test the `markdown` module on real source files.
22 redef class ModelBuilder
23 fun test_markdown
(page
: HTMLTag, mmodule
: MModule)
25 page
.add_raw_html
"<h3 id='{mmodule}'>module {mmodule}</h1>"
26 var mdoc
= mmodule
.mdoc
28 page
.add mdoc
.full_markdown
30 for mclassdef
in mmodule
.mclassdefs
do
33 page
.add_raw_html
"<h4 id='{mclassdef}'>class {mclassdef}</h2>"
34 page
.add mdoc
.full_markdown
36 for mpropdef
in mclassdef
.mpropdefs
do
39 page
.add_raw_html
"<h5 id='{mpropdef}'>prop {mpropdef}</h3>"
40 page
.add mdoc
.full_markdown
48 redef fun href
do return "#{to_s}"
51 redef fun href
do return "#{to_s}"
54 redef fun href
do return "#{to_s}"
57 var toolcontext
= new ToolContext
59 var opt_full
= new OptionBool("Process also imported modules", "--full")
60 toolcontext
.option_context
.add_option
(opt_full
)
61 toolcontext
.tooldescription
= "Usage: test_markdown [OPTION]... <file.nit>...\nGenerates HTML of comments of documentation from Nit source files."
63 toolcontext
.process_options
(args
)
64 var args
= toolcontext
.option_context
.rest
67 var modelbuilder
= new ModelBuilder(model
, toolcontext
)
69 var mmodules
= modelbuilder
.parse
(args
)
70 modelbuilder
.run_phases
72 var hv
= new HighlightVisitor
74 var page
= new HTMLTag("html")
77 <meta charset="utf-8">
79 page
.add_raw_html hv
.head_content
81 <style type="text/css">
84 border: 1px solid #ddd;
85 background-color: #f8f8f8;
88 background-color: #f8f8f8;
89 border: 1px solid #ddd;
99 h5 {font-weight:bold;}
104 if opt_full
.value
then
105 for p
in model
.mprojects
do
106 page
.add_raw_html
"<h1 id='P{p.name}'>project {p.name}</h2>"
109 page
.add mdoc
.full_markdown
111 for g
in p
.mgroups
do
114 page
.add_raw_html
"<h2 id='G{g.full_name}'>group {g.full_name}</h2>"
115 page
.add mdoc
.full_markdown
117 for m
in g
.mmodules
do
118 modelbuilder
.test_markdown
(page
, m
)
124 modelbuilder
.test_markdown
(page
, m
)
128 page
.add_raw_html hv
.foot_content
129 page
.add_raw_html
"</body>"
130 page
.write_to
(stdout
)