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>Modules</h2>\n")
47 for mmodule
in model
.mmodules
do
48 buf
.append
("<h3 id='module-{mmodule}'>{mmodule}</h3>\n")
50 buf
.append
("<dt>direct owner</dt>\n")
51 var own
= mmodule
.direct_owner
52 if own
!= null then buf
.append
("<dd>{linkto(own)}</dd>\n")
53 buf
.append
("<dt>nested</dt>\n")
54 for x
in mmodule
.in_nesting
.direct_greaters
do
55 buf
.append
("<dd>{linkto(x)}</dd>\n")
57 buf
.append
("<dt>direct import</dt>\n")
58 for x
in mmodule
.in_importation
.direct_greaters
do
59 buf
.append
("<dd>{linkto(x)}</dd>\n")
61 buf
.append
("<dt>direct clients</dt>\n")
62 for x
in mmodule
.in_importation
.direct_smallers
do
63 buf
.append
("<dd>{linkto(x)}</dd>\n")
65 buf
.append
("<dt>introduced classes</dt>\n")
66 for x
in mmodule
.mclassdefs
do
67 if not x
.is_intro
then continue
68 buf
.append
("<dd>{linkto(x.mclass)} by {linkto(x)}</dd>\n")
70 buf
.append
("<dt>refined classes</dt>\n")
71 for x
in mmodule
.mclassdefs
do
72 if x
.is_intro
then continue
73 buf
.append
("<dd>{linkto(x.mclass)} by {linkto(x)}</dd>\n")
77 buf
.append
("<h2>Classes</h2>\n")
78 for mclass
in model
.mclasses
do
79 buf
.append
("<h3 id='class-{mclass}'>{mclass}</h3>\n")
81 buf
.append
("<dt>module of introduction</dt>\n")
82 buf
.append
("<dd>{linkto(mclass.intro_mmodule)}</dd>\n")
83 buf
.append
("<dt>class definitions</dt>\n")
84 for x
in mclass
.mclassdefs
do
85 buf
.append
("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
89 buf
.append
("<h2>Class Definitions</h2>\n")
90 for mclass
in model
.mclasses
do
91 for mclassdef
in mclass
.mclassdefs
do
92 buf
.append
("<h3 id='classdef-{mclassdef}'>{mclassdef}</h3>\n")
94 buf
.append
("<dt>module</dt>\n")
95 buf
.append
("<dd>{linkto(mclassdef.mmodule)}</dd>\n")
96 buf
.append
("<dt>class</dt>\n")
97 buf
.append
("<dd>{linkto(mclassdef.mclass)}</dd>\n")
98 buf
.append
("<dt>direct refinements</dt>\n")
99 for x
in mclassdef
.in_hierarchy
.direct_greaters
do
100 if x
.mclass
!= mclass
then continue
101 buf
.append
("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
103 buf
.append
("<dt>direct refinemees</dt>\n")
104 for x
in mclassdef
.in_hierarchy
.direct_smallers
do
105 if x
.mclass
!= mclass
then continue
106 buf
.append
("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
108 buf
.append
("<dt>direct superclasses</dt>\n")
109 for x
in mclassdef
.supertypes
do
110 buf
.append
("<dd>{linkto(x.mclass)} by {x}</dd>\n")
112 buf
.append
("<dt>introduced properties</dt>\n")
113 for x
in mclassdef
.mpropdefs
do
114 if not x
.is_intro
then continue
115 buf
.append
("<dd>{linkto(x.mproperty)} by {linkto(x)}</dd>\n")
117 buf
.append
("<dt>redefined properties</dt>\n")
118 for x
in mclassdef
.mpropdefs
do
119 if x
.is_intro
then continue
120 buf
.append
("<dd>{linkto(x.mproperty)} by {linkto(x)}</dd>\n")
122 buf
.append
("</dl>\n")
125 buf
.append
("<h2>Properties</h2>\n")
126 for mprop
in model
.mproperties
do
127 buf
.append
("<h3 id='property-{mprop}'>{mprop}</h3>\n")
129 buf
.append
("<dt>module of introdcution</dt>\n")
130 buf
.append
("<dd>{linkto(mprop.intro_mclassdef.mmodule)}</dd>\n")
131 buf
.append
("<dt>class of introduction</dt>\n")
132 buf
.append
("<dd>{linkto(mprop.intro_mclassdef.mclass)}</dd>\n")
133 buf
.append
("<dt>class definition of introduction</dt>\n")
134 buf
.append
("<dd>{linkto(mprop.intro_mclassdef)}</dd>\n")
135 buf
.append
("<dt>property definitions</dt>\n")
136 for x
in mprop
.mpropdefs
do
137 buf
.append
("<dd>{linkto(x)} in {linkto(x.mclassdef)}</dd>\n")
139 buf
.append
("</dl>\n")
141 buf
.append
("<h2>Property Definitions</h2>\n")
142 for mprop
in model
.mproperties
do
143 for mpropdef
in mprop
.mpropdefs
do
144 buf
.append
("<h3 id='propdef-{mpropdef}'>{mpropdef}</h3>\n")
146 buf
.append
("<dt>module</dt>\n")
147 buf
.append
("<dd>{linkto(mpropdef.mclassdef.mmodule)}</dd>\n")
148 buf
.append
("<dt>class</dt>\n")
149 buf
.append
("<dd>{linkto(mpropdef.mclassdef.mclass)}</dd>\n")
150 buf
.append
("<dt>class definition</dt>\n")
151 buf
.append
("<dd>{linkto(mpropdef.mclassdef)}</dd>\n")
152 buf
.append
("<dt>super definitions</dt>\n")
153 for x
in mpropdef
.mproperty
.lookup_super_definitions
(mpropdef
.mclassdef
.mmodule
, mpropdef
.mclassdef
.bound_mtype
) do
154 buf
.append
("<dd>{linkto(x)} in {linkto(x.mclassdef)}</dd>\n")
158 buf
.append
("</body></html>\n")
159 var f
= new OFStream.open
(toolcontext
.output_dir
.join_path
("model.html"))
164 private fun linkto
(o
: Object): String
166 if o
isa MModule then
167 return "<a href='#module-{o}'>{o}</a>"
168 else if o
isa MClass then
169 return "<a href='#class-{o}'>{o}</a>"
170 else if o
isa MClassDef then
171 return "<a href='#classdef-{o}'>{o}</a>"
172 else if o
isa MProperty then
173 return "<a href='#property-{o}'>{o}</a>"
174 else if o
isa MPropDef then
175 return "<a href='#propdef-{o}'>{o}</a>"
177 print
"cannot linkto {o.class_name}"