rta: store real types in live_cast_type
[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 var nmodule = mmodule2nmodule[mmodule]
28 do
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
34 end label x
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
39 if ndoc != null then
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
43 end
44 end
45 for npropdef in nclassdef.n_propdefs do
46 var mpropdef = npropdef.mpropdef.as(not null)
47 var ndoc = npropdef.n_doc
48 if ndoc != null then
49 if mpropdef.mproperty.intro == mpropdef then page.add_raw_html "<a id='{mpropdef.mproperty.full_name}'></a>"
50
51 page.add_raw_html "<h3>prop {mpropdef}</h3>"
52 page.add ndoc.full_markdown
53 end
54 end
55 end
56 end
57 end
58 end
59
60 var toolcontext = new ToolContext
61
62 var opt_full = new OptionBool("Process also imported modules", "--full")
63 toolcontext.option_context.add_option(opt_full)
64
65 toolcontext.process_options
66 var args = toolcontext.option_context.rest
67 if args.is_empty then
68 print "usage: test_markdown [options] file.nit..."
69 toolcontext.option_context.usage
70 return
71 end
72
73 var model = new Model
74 var modelbuilder = new ModelBuilder(model, toolcontext)
75
76 var mmodules = modelbuilder.parse(args)
77 modelbuilder.run_phases
78
79 var hv = new HighlightVisitor
80
81 var page = new HTMLTag("html")
82 page.add_raw_html """
83 <head>
84 <meta charset="utf-8">
85 <style type="text/css">
86 code {margin: 0 2px;
87 padding: 0px 5px;
88 border: 1px solid #ddd;
89 background-color: #f8f8f8;
90 border-radius: 3px;}
91 pre {
92 background-color: #f8f8f8;
93 border: 1px solid #ddd;
94 font-size: 13px;
95 line-height: 19px;
96 overflow: auto;
97 padding: 6px 6px;
98 border-radius: 3px;
99 }
100 .rawcode[title] {
101 border-color: red;
102 }
103 {{{hv.css_content}}}
104 </style>
105 </head><body>
106 """
107
108 if opt_full.value then
109 for m in model.mmodules do
110 modelbuilder.test_markdown(page, m)
111 end
112 else
113 for m in mmodules do
114 modelbuilder.test_markdown(page, m)
115 end
116 end
117
118 page.add_raw_html "</body>"
119 print page.html