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
27 var nmodule
= mmodule2nmodule
[mmodule
]
29 var nmoduledecl
= nmodule
.n_moduledecl
30 if nmoduledecl
== null then break label x
31 var ndoc
= nmoduledecl
.n_doc
32 if ndoc
== null then break label x
33 page
.add ndoc
.full_markdown
35 for nclassdef
in nmodule
.n_classdefs
do
36 var mclassdef
= nclassdef
.mclassdef
.as(not null)
37 if nclassdef
isa AStdClassdef then
38 var ndoc
= nclassdef
.n_doc
40 if mclassdef
.mclass
.intro
== mclassdef
then page
.add_raw_html
"<a id='{mclassdef.mclass.full_name}'></a>"
41 page
.add_raw_html
"<h2>class {mclassdef}</h2>"
42 page
.add ndoc
.full_markdown
45 for npropdef
in nclassdef
.n_propdefs
do
46 var mpropdef
= npropdef
.mpropdef
.as(not null)
47 var ndoc
= npropdef
.n_doc
49 if mpropdef
.mproperty
.intro
== mpropdef
then page
.add_raw_html
"<a id='{mpropdef.mproperty.full_name}'></a>"
51 page
.add_raw_html
"<h3>prop {mpropdef}</h3>"
52 page
.add ndoc
.full_markdown
60 var toolcontext
= new ToolContext
62 var opt_full
= new OptionBool("Process also imported modules", "--full")
63 toolcontext
.option_context
.add_option
(opt_full
)
65 toolcontext
.process_options
66 var args
= toolcontext
.option_context
.rest
68 print
"usage: test_markdown [options] file.nit..."
69 toolcontext
.option_context
.usage
74 var modelbuilder
= new ModelBuilder(model
, toolcontext
)
76 var mmodules
= modelbuilder
.parse
(args
)
77 modelbuilder
.run_phases
79 var hv
= new HighlightVisitor
81 var page
= new HTMLTag("html")
84 <meta charset="utf-8">
85 <style type="text/css">
88 border: 1px solid #ddd;
89 background-color: #f8f8f8;
92 background-color: #f8f8f8;
93 border: 1px solid #ddd;
108 if opt_full
.value
then
109 for m
in model
.mmodules
do
110 modelbuilder
.test_markdown
(page
, m
)
114 modelbuilder
.test_markdown
(page
, m
)
118 page
.add_raw_html
"</body>"