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
"<a id='{mmodule.full_name}'></a>"
25 page
.add_raw_html
"<h1>module {mmodule}</h1>"
26 if mmodule2nmodule
.has_key
(mmodule
) then
28 var mdoc
= mmodule
.mdoc
29 if mdoc
== null then break label x
30 page
.add mdoc
.full_markdown
32 for mclassdef
in mmodule
.mclassdefs
do
34 var mdoc
= mclassdef
.mdoc
36 if mclassdef
.mclass
.intro
== mclassdef
then page
.add_raw_html
"<a id='{mclassdef.mclass.full_name}'></a>"
37 page
.add_raw_html
"<h2>class {mclassdef}</h2>"
38 page
.add mdoc
.full_markdown
41 for mpropdef
in mclassdef
.mpropdefs
do
42 var mdoc
= mpropdef
.mdoc
44 if mpropdef
.mproperty
.intro
== mpropdef
then page
.add_raw_html
"<a id='{mpropdef.mproperty.full_name}'></a>"
46 page
.add_raw_html
"<h3>prop {mpropdef}</h3>"
47 page
.add mdoc
.full_markdown
55 var toolcontext
= new ToolContext
57 var opt_full
= new OptionBool("Process also imported modules", "--full")
58 toolcontext
.option_context
.add_option
(opt_full
)
59 toolcontext
.tooldescription
= "Usage: test_markdown [OPTION]... <file.nit>...\nGenerates HTML of comments of documentation from Nit source files."
61 toolcontext
.process_options
(args
)
62 var args
= toolcontext
.option_context
.rest
65 var modelbuilder
= new ModelBuilder(model
, toolcontext
)
67 var mmodules
= modelbuilder
.parse
(args
)
68 modelbuilder
.run_phases
70 var hv
= new HighlightVisitor
72 var page
= new HTMLTag("html")
75 <meta charset="utf-8">
76 <style type="text/css">
79 border: 1px solid #ddd;
80 background-color: #f8f8f8;
83 background-color: #f8f8f8;
84 border: 1px solid #ddd;
99 if opt_full
.value
then
100 for m
in model
.mmodules
do
101 modelbuilder
.test_markdown
(page
, m
)
105 modelbuilder
.test_markdown
(page
, m
)
109 page
.add_raw_html
"</body>"
110 page
.write_to
(stdout
)