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.
18 import modelize_property
21 redef class ModelBuilder
22 fun test_markdown
(page
: HTMLTag, mmodule
: MModule)
24 page
.add_raw_html
"<h3 id='{mmodule}'>module {mmodule}</h1>"
25 var mdoc
= mmodule
.mdoc
27 page
.add mdoc
.full_markdown
29 for mclassdef
in mmodule
.mclassdefs
do
32 page
.add_raw_html
"<h4 id='{mclassdef}'>class {mclassdef}</h2>"
33 page
.add mdoc
.full_markdown
35 for mpropdef
in mclassdef
.mpropdefs
do
38 page
.add_raw_html
"<h5 id='{mpropdef}'>prop {mpropdef}</h3>"
39 page
.add mdoc
.full_markdown
47 redef fun href
do return "#{to_s}"
50 redef fun href
do return "#{to_s}"
53 redef fun href
do return "#{to_s}"
56 var toolcontext
= new ToolContext
58 var opt_full
= new OptionBool("Process also imported modules", "--full")
59 toolcontext
.option_context
.add_option
(opt_full
)
60 toolcontext
.tooldescription
= "Usage: test_markdown [OPTION]... <file.nit>...\nGenerates HTML of comments of documentation from Nit source files."
62 toolcontext
.process_options
(args
)
63 var args
= toolcontext
.option_context
.rest
66 var modelbuilder
= new ModelBuilder(model
, toolcontext
)
68 var mmodules
= modelbuilder
.parse
(args
)
69 modelbuilder
.run_phases
71 var hv
= new HighlightVisitor
73 var page
= new HTMLTag("html")
76 <meta charset="utf-8">
78 page
.add_raw_html hv
.head_content
80 <style type="text/css">
83 border: 1px solid #ddd;
84 background-color: #f8f8f8;
87 background-color: #f8f8f8;
88 border: 1px solid #ddd;
98 h5 {font-weight:bold;}
103 if opt_full
.value
then
104 for p
in model
.mprojects
do
105 page
.add_raw_html
"<h1 id='P{p.name}'>project {p.name}</h2>"
108 page
.add mdoc
.full_markdown
110 for g
in p
.mgroups
do
113 page
.add_raw_html
"<h2 id='G{g.full_name}'>group {g.full_name}</h2>"
114 page
.add mdoc
.full_markdown
116 for m
in g
.mmodules
do
117 modelbuilder
.test_markdown
(page
, m
)
123 modelbuilder
.test_markdown
(page
, m
)
127 page
.add_raw_html hv
.foot_content
128 page
.add_raw_html
"</body>"
129 page
.write_to
(stdout
)