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