1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2012 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Dump of Nit model into hypertext human-readable format.
23 # Genetate a HTML file for the model.
24 # The generated file contains the description of each entity of the model
25 fun generate_model_hyperdoc
(toolcontext
: ToolContext, model
: Model)
28 buf
.append
("<html>\n<body>\n")
29 buf
.append
("<h1>Model</h1>\n")
31 buf
.append
("<h2>Modules</h2>\n")
32 for mmodule
in model
.mmodules
do
33 buf
.append
("<h3 id='module-{mmodule}'>{mmodule}</h3>\n")
35 buf
.append
("<dt>direct owner</dt>\n")
36 var own
= mmodule
.direct_owner
37 if own
!= null then buf
.append
("<dd>{linkto(own)}</dd>\n")
38 buf
.append
("<dt>nested</dt>\n")
39 for x
in mmodule
.in_nesting
.direct_greaters
do
40 buf
.append
("<dd>{linkto(x)}</dd>\n")
42 buf
.append
("<dt>direct import</dt>\n")
43 for x
in mmodule
.in_importation
.direct_greaters
do
44 buf
.append
("<dd>{linkto(x)}</dd>\n")
46 buf
.append
("<dt>direct clients</dt>\n")
47 for x
in mmodule
.in_importation
.direct_smallers
do
48 buf
.append
("<dd>{linkto(x)}</dd>\n")
50 buf
.append
("<dt>introduced classes</dt>\n")
51 for x
in mmodule
.mclassdefs
do
52 if not x
.is_intro
then continue
53 buf
.append
("<dd>{linkto(x.mclass)} by {linkto(x)}</dd>\n")
55 buf
.append
("<dt>refined classes</dt>\n")
56 for x
in mmodule
.mclassdefs
do
57 if x
.is_intro
then continue
58 buf
.append
("<dd>{linkto(x.mclass)} by {linkto(x)}</dd>\n")
62 buf
.append
("<h2>Classes</h2>\n")
63 for mclass
in model
.mclasses
do
64 buf
.append
("<h3 id='class-{mclass}'>{mclass}</h3>\n")
66 buf
.append
("<dt>module of introduction</dt>\n")
67 buf
.append
("<dd>{linkto(mclass.intro_mmodule)}</dd>\n")
68 buf
.append
("<dt>class definitions</dt>\n")
69 for x
in mclass
.mclassdefs
do
70 buf
.append
("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
74 buf
.append
("<h2>Class Definitions</h2>\n")
75 for mclass
in model
.mclasses
do
76 for mclassdef
in mclass
.mclassdefs
do
77 buf
.append
("<h3 id='classdef-{mclassdef}'>{mclassdef}</h3>\n")
79 buf
.append
("<dt>module</dt>\n")
80 buf
.append
("<dd>{linkto(mclassdef.mmodule)}</dd>\n")
81 buf
.append
("<dt>class</dt>\n")
82 buf
.append
("<dd>{linkto(mclassdef.mclass)}</dd>\n")
83 buf
.append
("<dt>direct refinements</dt>\n")
84 for x
in mclassdef
.in_hierarchy
.direct_greaters
do
85 if x
.mclass
!= mclass
then continue
86 buf
.append
("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
88 buf
.append
("<dt>direct refinemees</dt>\n")
89 for x
in mclassdef
.in_hierarchy
.direct_smallers
do
90 if x
.mclass
!= mclass
then continue
91 buf
.append
("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
93 buf
.append
("<dt>direct superclasses</dt>\n")
94 for x
in mclassdef
.supertypes
do
95 buf
.append
("<dd>{linkto(x.mclass)} by {x}</dd>\n")
97 buf
.append
("<dt>introduced properties</dt>\n")
98 for x
in mclassdef
.mpropdefs
do
99 if not x
.is_intro
then continue
100 buf
.append
("<dd>{linkto(x.mproperty)} by {linkto(x)}</dd>\n")
102 buf
.append
("<dt>redefined properties</dt>\n")
103 for x
in mclassdef
.mpropdefs
do
104 if x
.is_intro
then continue
105 buf
.append
("<dd>{linkto(x.mproperty)} by {linkto(x)}</dd>\n")
107 buf
.append
("</dl>\n")
110 buf
.append
("<h2>Properties</h2>\n")
111 for mprop
in model
.mproperties
do
112 buf
.append
("<h3 id='property-{mprop}'>{mprop}</h3>\n")
114 buf
.append
("<dt>module of introdcution</dt>\n")
115 buf
.append
("<dd>{linkto(mprop.intro_mclassdef.mmodule)}</dd>\n")
116 buf
.append
("<dt>class of introduction</dt>\n")
117 buf
.append
("<dd>{linkto(mprop.intro_mclassdef.mclass)}</dd>\n")
118 buf
.append
("<dt>class definition of introduction</dt>\n")
119 buf
.append
("<dd>{linkto(mprop.intro_mclassdef)}</dd>\n")
120 buf
.append
("<dt>property definitions</dt>\n")
121 for x
in mprop
.mpropdefs
do
122 buf
.append
("<dd>{linkto(x)} in {linkto(x.mclassdef)}</dd>\n")
124 buf
.append
("</dl>\n")
126 buf
.append
("<h2>Property Definitions</h2>\n")
127 for mprop
in model
.mproperties
do
128 for mpropdef
in mprop
.mpropdefs
do
129 buf
.append
("<h3 id='propdef-{mpropdef}'>{mpropdef}</h3>\n")
131 buf
.append
("<dt>module</dt>\n")
132 buf
.append
("<dd>{linkto(mpropdef.mclassdef.mmodule)}</dd>\n")
133 buf
.append
("<dt>class</dt>\n")
134 buf
.append
("<dd>{linkto(mpropdef.mclassdef.mclass)}</dd>\n")
135 buf
.append
("<dt>class definition</dt>\n")
136 buf
.append
("<dd>{linkto(mpropdef.mclassdef)}</dd>\n")
137 buf
.append
("<dt>super definitions</dt>\n")
138 for x
in mpropdef
.mproperty
.lookup_super_definitions
(mpropdef
.mclassdef
.mmodule
, mpropdef
.mclassdef
.bound_mtype
) do
139 buf
.append
("<dd>{linkto(x)} in {linkto(x.mclassdef)}</dd>\n")
143 buf
.append
("</body></html>\n")
144 var f
= new OFStream.open
(toolcontext
.output_dir
.join_path
("model.html"))
149 private fun linkto
(o
: Object): String
151 if o
isa MModule then
152 return "<a href='#module-{o}'>{o}</a>"
153 else if o
isa MClass then
154 return "<a href='#class-{o}'>{o}</a>"
155 else if o
isa MClassDef then
156 return "<a href='#classdef-{o}'>{o}</a>"
157 else if o
isa MProperty then
158 return "<a href='#property-{o}'>{o}</a>"
159 else if o
isa MPropDef then
160 return "<a href='#propdef-{o}'>{o}</a>"
162 print
"cannot linkto {o.class_name}"