Merge: CallSite on AFor and ARange
[nit.git] / src / test_markdown.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # Program to test the `markdown` module on real source files.
16 module test_markdown
17
18 import modelize_property
19 import markdown
20
21 redef class ModelBuilder
22 fun test_markdown(page: HTMLTag, mmodule: MModule)
23 do
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 do
28 var mdoc = mmodule.mdoc
29 if mdoc == null then break label x
30 page.add mdoc.full_markdown
31 end label x
32 for mclassdef in mmodule.mclassdefs do
33 do
34 var mdoc = mclassdef.mdoc
35 if mdoc != null then
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
39 end
40 end
41 for mpropdef in mclassdef.mpropdefs do
42 var mdoc = mpropdef.mdoc
43 if mdoc != null then
44 if mpropdef.mproperty.intro == mpropdef then page.add_raw_html "<a id='{mpropdef.mproperty.full_name}'></a>"
45
46 page.add_raw_html "<h3>prop {mpropdef}</h3>"
47 page.add mdoc.full_markdown
48 end
49 end
50 end
51 end
52 end
53 end
54
55 var toolcontext = new ToolContext
56
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."
60
61 toolcontext.process_options(args)
62 var args = toolcontext.option_context.rest
63
64 var model = new Model
65 var modelbuilder = new ModelBuilder(model, toolcontext)
66
67 var mmodules = modelbuilder.parse(args)
68 modelbuilder.run_phases
69
70 var hv = new HighlightVisitor
71
72 var page = new HTMLTag("html")
73 page.add_raw_html """
74 <head>
75 <meta charset="utf-8">
76 <style type="text/css">
77 code {margin: 0 2px;
78 padding: 0px 5px;
79 border: 1px solid #ddd;
80 background-color: #f8f8f8;
81 border-radius: 3px;}
82 pre {
83 background-color: #f8f8f8;
84 border: 1px solid #ddd;
85 font-size: 13px;
86 line-height: 19px;
87 overflow: auto;
88 padding: 6px 6px;
89 border-radius: 3px;
90 }
91 .rawcode[title] {
92 border-color: red;
93 }
94 {{{hv.css_content}}}
95 </style>
96 </head><body>
97 """
98
99 if opt_full.value then
100 for m in model.mmodules do
101 modelbuilder.test_markdown(page, m)
102 end
103 else
104 for m in mmodules do
105 modelbuilder.test_markdown(page, m)
106 end
107 end
108
109 page.add_raw_html "</body>"
110 page.write_to(stdout)