1.1 --- a/simplify/viewer.py Tue Jun 12 00:34:38 2007 +0200
1.2 +++ b/simplify/viewer.py Tue Jun 12 00:35:23 2007 +0200
1.3 @@ -120,6 +120,10 @@
1.4 display: block;
1.5 }
1.6
1.7 + .summary-class {
1.8 + background-color: #004400;
1.9 + }
1.10 +
1.11 .summary-instance {
1.12 background-color: #0000FF;
1.13 }
1.14 @@ -143,6 +147,8 @@
1.15
1.16 "A utility class providing useful HTML output methods."
1.17
1.18 + # Methods which return strings.
1.19 +
1.20 def _text(self, text):
1.21 return text.replace("&", "&").replace("<", "<").replace(">", ">")
1.22
1.23 @@ -152,6 +158,11 @@
1.24 def _url(self, url):
1.25 return self._attr(url).replace("#", "%23").replace("-", "%2d")
1.26
1.27 + def _summary_link(self, module_name, name):
1.28 + return "<a href='%s-summary%sxhtml#%s'>%s</a>" % (module_name, os.path.extsep, self._attr(name), self._text(name))
1.29 +
1.30 + # Methods which write to the stream.
1.31 +
1.32 def _comment(self, comment):
1.33 self.stream.write("<span class='comment'># %s</span>\n" % comment)
1.34
1.35 @@ -178,48 +189,100 @@
1.36 self.stream = stream
1.37
1.38 def process(self, module):
1.39 + self.module = module
1.40 + self._init_details()
1.41 self.stream.write(html_header)
1.42 self._write_classes(module)
1.43 self.stream.write(html_footer)
1.44
1.45 def _write_classes(self, module):
1.46 - for structure in module.simplifier.structures:
1.47 + self.stream.write("<table cellspacing='5' cellpadding='5'>\n")
1.48 + for structure in self.structures:
1.49 self._write_class(structure)
1.50 + self.stream.write("</table>\n")
1.51
1.52 def _write_class(self, structure):
1.53 - self.stream.write("<div class='class' id='%s'>\n" % structure.full_name())
1.54 +
1.55 + # Write the class...
1.56 +
1.57 + self.stream.write("<tbody class='class'>\n")
1.58 + self.stream.write("<tr>\n")
1.59 + self.stream.write("<th class='summary-class' id='%s'>\n" % structure.full_name())
1.60 self._keyword("class")
1.61 self.stream.write(structure.name)
1.62 - names = set()
1.63 - instances = {}
1.64 - for instance in structure.instances.values():
1.65 - for name, values in instance.namespace.items():
1.66 - if not name in names:
1.67 - names.add(name)
1.68 - instances[instance.full_name()] = instance
1.69 + self.stream.write("</th>\n")
1.70 +
1.71 + # ...and all known attribute names.
1.72
1.73 - sorted_names = list(names)
1.74 - sorted_names.sort()
1.75 - sorted_instances = instances.keys()
1.76 - sorted_instances.sort()
1.77 + structure_attributes = self.structure_attributes[structure]
1.78 + for name in self.attribute_names:
1.79 + if name in structure_attributes:
1.80 + self.stream.write("<th class='summary-attr'>%s</th>\n" % self._text(name))
1.81 + else:
1.82 + self.stream.write("<th></th>\n")
1.83 + self.stream.write("</tr>\n")
1.84
1.85 - self.stream.write("<table cellspacing='5' cellpadding='5'>\n")
1.86 - self.stream.write("<tr>\n")
1.87 - self.stream.write("<th></th>\n")
1.88 - for name in sorted_names:
1.89 - self.stream.write("<th class='summary-attr'>%s</th>\n" % self._text(name))
1.90 - self.stream.write("</tr>\n")
1.91 - for instance in sorted_instances:
1.92 + # Write instances for the class, along with type details for each attribute.
1.93 +
1.94 + for instance in self.structures_to_instances[structure]:
1.95 self.stream.write("<tr>\n")
1.96 - self.stream.write("<th class='summary-instance'>%s</th>\n" % self._text(instance))
1.97 - for name in sorted_names:
1.98 + self.stream.write("<th class='summary-instance'>%s</th>\n" % self._text(instance.full_name()))
1.99 + for name in self.attribute_names:
1.100 self.stream.write("<td>\n")
1.101 - for value in instances[instance].namespace.get(name):
1.102 - self.stream.write("<span>%s</span>\n" % value.type.full_name())
1.103 + values = instance.namespace.get(name, [])
1.104 + type_names = [value.type.full_name() for value in values]
1.105 + type_names.sort()
1.106 + for type_name in type_names:
1.107 + self.stream.write("<span>%s</span>\n" % type_name)
1.108 self.stream.write("</td>\n")
1.109 self.stream.write("</tr>\n")
1.110 - self.stream.write("</table>\n")
1.111 - self.stream.write("</div>\n")
1.112 + self.stream.write("</tbody>\n")
1.113 +
1.114 + def _init_details(self):
1.115 + names = set()
1.116 + self.structures_to_instances = {}
1.117 + self.structure_attributes = {}
1.118 + names_to_structures = {}
1.119 +
1.120 + # Visit all structures.
1.121 +
1.122 + for structure in self.module.simplifier.structures:
1.123 +
1.124 + # Map all instance names to instances.
1.125 +
1.126 + names_to_instances = {}
1.127 + attribute_names = set()
1.128 +
1.129 + for instance in structure.instances.values():
1.130 + for name, values in instance.namespace.items():
1.131 + if not name in attribute_names:
1.132 + attribute_names.add(name)
1.133 + if not name in names:
1.134 + names.add(name)
1.135 + names_to_instances[instance.full_name()] = instance
1.136 +
1.137 + # Record the instances in name order for the structure.
1.138 +
1.139 + instance_names = names_to_instances.keys()
1.140 + instance_names.sort()
1.141 + sorted_instances = [names_to_instances[name] for name in instance_names]
1.142 + self.structures_to_instances[structure] = sorted_instances
1.143 +
1.144 + # Record the attributes used in all instances of the structure.
1.145 +
1.146 + self.structure_attributes[structure] = attribute_names
1.147 +
1.148 + # Record the name to structure mapping.
1.149 +
1.150 + names_to_structures[structure.full_name()] = structure
1.151 +
1.152 + self.attribute_names = list(names)
1.153 + self.attribute_names.sort()
1.154 +
1.155 + structure_names = names_to_structures.keys()
1.156 + structure_names.sort()
1.157 +
1.158 + self.structures = [names_to_structures[name] for name in structure_names]
1.159
1.160 # Browser classes.
1.161
1.162 @@ -246,6 +309,7 @@
1.163 self.stream = stream
1.164
1.165 def process(self, module):
1.166 + self.module = module
1.167 self.stream.write(html_header)
1.168 self.dispatch(module)
1.169 self.stream.write(html_footer)
1.170 @@ -326,7 +390,7 @@
1.171 self.stream.write(")")
1.172
1.173 self.stream.write(":\n")
1.174 - self._comment(self._text(structure.full_name()))
1.175 + self._comment(self._summary_link(self.module._node.name, structure.full_name()))
1.176 self.stream.write("</div>\n")
1.177
1.178 self.stream.write("<div class='body'>\n")