Rename REAMDE to README.md
[nit.git] / src / test_docdown.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_docdown
17
18 import modelize
19 import highlight
20 import docdown
21
22 redef class ModelBuilder
23 fun do_test_markdown(page: HTMLTag, mmodule: MModule)
24 do
25 page.add_raw_html "<h3 id='{mmodule}'>module {mmodule}</h1>"
26 var mdoc = mmodule.mdoc
27 if mdoc != null then
28 page.add mdoc.full_markdown
29 end
30 for mclassdef in mmodule.mclassdefs do
31 mdoc = mclassdef.mdoc
32 if mdoc != null then
33 page.add_raw_html "<h4 id='{mclassdef}'>class {mclassdef}</h2>"
34 page.add mdoc.full_markdown
35 end
36 for mpropdef in mclassdef.mpropdefs do
37 mdoc = mpropdef.mdoc
38 if mdoc != null then
39 page.add_raw_html "<h5 id='{mpropdef}'>prop {mpropdef}</h3>"
40 page.add mdoc.full_markdown
41 end
42 end
43 end
44 end
45 end
46
47 redef class MModule
48 redef fun href do return "#{to_s}"
49 end
50 redef class MClassDef
51 redef fun href do return "#{to_s}"
52 end
53 redef class MPropDef
54 redef fun href do return "#{to_s}"
55 end
56
57 var toolcontext = new ToolContext
58
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."
62
63 toolcontext.process_options(args)
64 var args = toolcontext.option_context.rest
65
66 var model = new Model
67 var modelbuilder = new ModelBuilder(model, toolcontext)
68
69 var mmodules = modelbuilder.parse(args)
70 modelbuilder.run_phases
71
72 var hv = new HighlightVisitor
73
74 var page = new HTMLTag("html")
75 page.add_raw_html """
76 <head>
77 <meta charset="utf-8">
78 """
79 page.add_raw_html hv.head_content
80 page.add_raw_html """
81 <style type="text/css">
82 code {margin: 0 2px;
83 padding: 0px 5px;
84 border: 1px solid #ddd;
85 background-color: #f8f8f8;
86 border-radius: 3px;}
87 pre {
88 background-color: #f8f8f8;
89 border: 1px solid #ddd;
90 font-size: 13px;
91 line-height: 19px;
92 overflow: auto;
93 padding: 6px 6px;
94 border-radius: 3px;
95 }
96 .rawcode[title] {
97 border-color: red;
98 }
99 h5 {font-weight:bold;}
100 {{{hv.css_content}}}
101 </style>
102 </head><body>"""
103
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>"
107 var mdoc = p.mdoc
108 if mdoc != null then
109 page.add mdoc.full_markdown
110 end
111 for g in p.mgroups do
112 mdoc = g.mdoc
113 if mdoc != null then
114 page.add_raw_html "<h2 id='G{g.full_name}'>group {g.full_name}</h2>"
115 page.add mdoc.full_markdown
116 end
117 for m in g.mmodules do
118 modelbuilder.do_test_markdown(page, m)
119 end
120 end
121 end
122 else
123 for m in mmodules do
124 modelbuilder.do_test_markdown(page, m)
125 end
126 end
127
128 page.add_raw_html hv.foot_content
129 page.add_raw_html "</body>"
130 page.write_to(stdout)