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.
25 redef class ToolContext
26 var model_hyperdoc_phase
= new ModelHyperdocPhase(self, null)
29 private class ModelHyperdocPhase
31 redef fun process_mainmodule
(mainmodule
)
33 if not toolcontext
.opt_generate_hyperdoc
.value
and not toolcontext
.opt_all
.value
then return
34 generate_model_hyperdoc
(toolcontext
, toolcontext
.modelbuilder
.model
)
38 # Genetate a HTML file for the model.
39 # The generated file contains the description of each entity of the model
40 fun generate_model_hyperdoc
(toolcontext
: ToolContext, model
: Model)
43 buf
.append
("<html>\n<body>\n")
44 buf
.append
("<h1>Model</h1>\n")
46 buf
.append
("<h2>Projects</h2>\n")
47 for mproject
in model
.mprojects
do
48 buf
.append
("<h3 id='project-{mproject}'>Project {mproject}</h3>\n")
50 buf
.append
("<dt>groups</dt>\n")
51 for x
in mproject
.mgroups
do
52 buf
.append
("<dd>{linkto(x)}</dd>\n")
57 buf
.append
("<h2>Groups</h2>\n")
58 for mproject
in model
.mprojects
do
59 for mgroup
in mproject
.mgroups
do
60 buf
.append
("<h3 id='group-{mgroup}'>Group {mgroup}</h3>\n")
62 buf
.append
("<dt>project</dt>\n")
63 buf
.append
("<dd>{linkto(mproject)}</dd>\n")
64 buf
.append
("<dt>filepath</dt>\n")
65 buf
.append
("<dd>{mgroup.filepath}</dd>\n")
68 buf
.append
("<dt>parent group</dt>\n")
69 buf
.append
("<dd>{linkto(p)}</dd>\n")
71 buf
.append
("<dt>nested groups</dt>\n")
72 for x
in mgroup
.in_nesting
.direct_smallers
do
73 buf
.append
("<dd>{linkto(x)}</dd>\n")
75 buf
.append
("<dt>modules</dt>\n")
76 for x
in mgroup
.mmodules
do
77 buf
.append
("<dd>{linkto(x)}</dd>\n")
83 buf
.append
("<h2>Modules</h2>\n")
84 for mmodule
in model
.mmodules
do
85 buf
.append
("<h3 id='module-{mmodule}'>{mmodule}</h3>\n")
87 buf
.append
("<dt>group</dt>\n")
88 var grp
= mmodule
.mgroup
89 if grp
!= null then buf
.append
("<dd>{linkto(grp)}</dd>\n")
90 buf
.append
("<dt>direct import</dt>\n")
91 for x
in mmodule
.in_importation
.direct_greaters
do
92 buf
.append
("<dd>{linkto(x)}</dd>\n")
94 buf
.append
("<dt>direct clients</dt>\n")
95 for x
in mmodule
.in_importation
.direct_smallers
do
96 buf
.append
("<dd>{linkto(x)}</dd>\n")
98 buf
.append
("<dt>introduced classes</dt>\n")
99 for x
in mmodule
.mclassdefs
do
100 if not x
.is_intro
then continue
101 buf
.append
("<dd>{linkto(x.mclass)} by {linkto(x)}</dd>\n")
103 buf
.append
("<dt>refined classes</dt>\n")
104 for x
in mmodule
.mclassdefs
do
105 if x
.is_intro
then continue
106 buf
.append
("<dd>{linkto(x.mclass)} by {linkto(x)}</dd>\n")
108 buf
.append
("</dl>\n")
110 buf
.append
("<h2>Classes</h2>\n")
111 for mclass
in model
.mclasses
do
112 buf
.append
("<h3 id='class-{mclass}'>{mclass}</h3>\n")
114 buf
.append
("<dt>module of introduction</dt>\n")
115 buf
.append
("<dd>{linkto(mclass.intro_mmodule)}</dd>\n")
116 buf
.append
("<dt>class definitions</dt>\n")
117 for x
in mclass
.mclassdefs
do
118 buf
.append
("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
120 buf
.append
("</dl>\n")
122 buf
.append
("<h2>Class Definitions</h2>\n")
123 for mclass
in model
.mclasses
do
124 for mclassdef
in mclass
.mclassdefs
do
125 buf
.append
("<h3 id='classdef-{mclassdef}'>{mclassdef}</h3>\n")
127 buf
.append
("<dt>module</dt>\n")
128 buf
.append
("<dd>{linkto(mclassdef.mmodule)}</dd>\n")
129 buf
.append
("<dt>class</dt>\n")
130 buf
.append
("<dd>{linkto(mclassdef.mclass)}</dd>\n")
131 buf
.append
("<dt>direct refinements</dt>\n")
132 for x
in mclassdef
.in_hierarchy
.direct_greaters
do
133 if x
.mclass
!= mclass
then continue
134 buf
.append
("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
136 buf
.append
("<dt>direct refinemees</dt>\n")
137 for x
in mclassdef
.in_hierarchy
.direct_smallers
do
138 if x
.mclass
!= mclass
then continue
139 buf
.append
("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
141 buf
.append
("<dt>direct superclasses</dt>\n")
142 for x
in mclassdef
.supertypes
do
143 buf
.append
("<dd>{linkto(x.mclass)} by {x}</dd>\n")
145 buf
.append
("<dt>introduced properties</dt>\n")
146 for x
in mclassdef
.mpropdefs
do
147 if not x
.is_intro
then continue
148 buf
.append
("<dd>{linkto(x.mproperty)} by {linkto(x)}</dd>\n")
150 buf
.append
("<dt>redefined properties</dt>\n")
151 for x
in mclassdef
.mpropdefs
do
152 if x
.is_intro
then continue
153 buf
.append
("<dd>{linkto(x.mproperty)} by {linkto(x)}</dd>\n")
155 buf
.append
("</dl>\n")
158 buf
.append
("<h2>Properties</h2>\n")
159 for mprop
in model
.mproperties
do
160 buf
.append
("<h3 id='property-{mprop}'>{mprop}</h3>\n")
162 buf
.append
("<dt>module of introdcution</dt>\n")
163 buf
.append
("<dd>{linkto(mprop.intro_mclassdef.mmodule)}</dd>\n")
164 buf
.append
("<dt>class of introduction</dt>\n")
165 buf
.append
("<dd>{linkto(mprop.intro_mclassdef.mclass)}</dd>\n")
166 buf
.append
("<dt>class definition of introduction</dt>\n")
167 buf
.append
("<dd>{linkto(mprop.intro_mclassdef)}</dd>\n")
168 buf
.append
("<dt>property definitions</dt>\n")
169 for x
in mprop
.mpropdefs
do
170 buf
.append
("<dd>{linkto(x)} in {linkto(x.mclassdef)}</dd>\n")
172 buf
.append
("</dl>\n")
174 buf
.append
("<h2>Property Definitions</h2>\n")
175 for mprop
in model
.mproperties
do
176 for mpropdef
in mprop
.mpropdefs
do
177 buf
.append
("<h3 id='propdef-{mpropdef}'>{mpropdef}</h3>\n")
179 buf
.append
("<dt>module</dt>\n")
180 buf
.append
("<dd>{linkto(mpropdef.mclassdef.mmodule)}</dd>\n")
181 buf
.append
("<dt>class</dt>\n")
182 buf
.append
("<dd>{linkto(mpropdef.mclassdef.mclass)}</dd>\n")
183 buf
.append
("<dt>class definition</dt>\n")
184 buf
.append
("<dd>{linkto(mpropdef.mclassdef)}</dd>\n")
185 buf
.append
("<dt>super definitions</dt>\n")
186 for x
in mpropdef
.mproperty
.lookup_super_definitions
(mpropdef
.mclassdef
.mmodule
, mpropdef
.mclassdef
.bound_mtype
) do
187 buf
.append
("<dd>{linkto(x)} in {linkto(x.mclassdef)}</dd>\n")
191 buf
.append
("</body></html>\n")
192 var f
= new OFStream.open
(toolcontext
.output_dir
.join_path
("model.html"))
197 private fun linkto
(o
: Object): String
199 if o
isa MProject then
200 return "<a href='#project-{o}'>{o}</a>"
201 else if o
isa MGroup then
202 return "<a href='#group-{o}'>{o}</a>"
203 else if o
isa MModule then
204 return "<a href='#module-{o}'>{o}</a>"
205 else if o
isa MClass then
206 return "<a href='#class-{o}'>{o}</a>"
207 else if o
isa MClassDef then
208 return "<a href='#classdef-{o}'>{o}</a>"
209 else if o
isa MProperty then
210 return "<a href='#property-{o}'>{o}</a>"
211 else if o
isa MPropDef then
212 return "<a href='#propdef-{o}'>{o}</a>"
214 print
"cannot linkto {o.class_name}"