# HG changeset patch
# User paulb@localhost.localdomain
# Date 1181601323 -7200
# Node ID 81617214c43aebac8f8377a3714eb7394a385a7d
# Parent 18df9fb80d62d5393eb356eb81a04db4347c69fd
Introduced links to summaries for classes, along with a more tabular summary
format.
diff -r 18df9fb80d62 -r 81617214c43a simplify/viewer.py
--- a/simplify/viewer.py Tue Jun 12 00:34:38 2007 +0200
+++ b/simplify/viewer.py Tue Jun 12 00:35:23 2007 +0200
@@ -120,6 +120,10 @@
display: block;
}
+ .summary-class {
+ background-color: #004400;
+ }
+
.summary-instance {
background-color: #0000FF;
}
@@ -143,6 +147,8 @@
"A utility class providing useful HTML output methods."
+ # Methods which return strings.
+
def _text(self, text):
return text.replace("&", "&").replace("<", "<").replace(">", ">")
@@ -152,6 +158,11 @@
def _url(self, url):
return self._attr(url).replace("#", "%23").replace("-", "%2d")
+ def _summary_link(self, module_name, name):
+ return "%s" % (module_name, os.path.extsep, self._attr(name), self._text(name))
+
+ # Methods which write to the stream.
+
def _comment(self, comment):
self.stream.write("\n" % comment)
@@ -178,48 +189,100 @@
self.stream = stream
def process(self, module):
+ self.module = module
+ self._init_details()
self.stream.write(html_header)
self._write_classes(module)
self.stream.write(html_footer)
def _write_classes(self, module):
- for structure in module.simplifier.structures:
+ self.stream.write("
\n")
+ for structure in self.structures:
self._write_class(structure)
+ self.stream.write("
\n")
def _write_class(self, structure):
- self.stream.write("\n" % structure.full_name())
+
+ # Write the class...
+
+ self.stream.write("
\n")
+ self.stream.write("\n")
+ self.stream.write("\n" % structure.full_name())
self._keyword("class")
self.stream.write(structure.name)
- names = set()
- instances = {}
- for instance in structure.instances.values():
- for name, values in instance.namespace.items():
- if not name in names:
- names.add(name)
- instances[instance.full_name()] = instance
+ self.stream.write(" | \n")
+
+ # ...and all known attribute names.
- sorted_names = list(names)
- sorted_names.sort()
- sorted_instances = instances.keys()
- sorted_instances.sort()
+ structure_attributes = self.structure_attributes[structure]
+ for name in self.attribute_names:
+ if name in structure_attributes:
+ self.stream.write("%s | \n" % self._text(name))
+ else:
+ self.stream.write(" | \n")
+ self.stream.write("
\n")
- self.stream.write("\n")
- self.stream.write("\n")
- self.stream.write(" | \n")
- for name in sorted_names:
- self.stream.write("%s | \n" % self._text(name))
- self.stream.write("
\n")
- for instance in sorted_instances:
+ # Write instances for the class, along with type details for each attribute.
+
+ for instance in self.structures_to_instances[structure]:
self.stream.write("\n")
- self.stream.write("%s | \n" % self._text(instance))
- for name in sorted_names:
+ self.stream.write("%s | \n" % self._text(instance.full_name()))
+ for name in self.attribute_names:
self.stream.write("\n")
- for value in instances[instance].namespace.get(name):
- self.stream.write("%s\n" % value.type.full_name())
+ values = instance.namespace.get(name, [])
+ type_names = [value.type.full_name() for value in values]
+ type_names.sort()
+ for type_name in type_names:
+ self.stream.write("%s\n" % type_name)
self.stream.write(" | \n")
self.stream.write("
\n")
- self.stream.write("
\n")
- self.stream.write("\n")
+ self.stream.write("\n")
+
+ def _init_details(self):
+ names = set()
+ self.structures_to_instances = {}
+ self.structure_attributes = {}
+ names_to_structures = {}
+
+ # Visit all structures.
+
+ for structure in self.module.simplifier.structures:
+
+ # Map all instance names to instances.
+
+ names_to_instances = {}
+ attribute_names = set()
+
+ for instance in structure.instances.values():
+ for name, values in instance.namespace.items():
+ if not name in attribute_names:
+ attribute_names.add(name)
+ if not name in names:
+ names.add(name)
+ names_to_instances[instance.full_name()] = instance
+
+ # Record the instances in name order for the structure.
+
+ instance_names = names_to_instances.keys()
+ instance_names.sort()
+ sorted_instances = [names_to_instances[name] for name in instance_names]
+ self.structures_to_instances[structure] = sorted_instances
+
+ # Record the attributes used in all instances of the structure.
+
+ self.structure_attributes[structure] = attribute_names
+
+ # Record the name to structure mapping.
+
+ names_to_structures[structure.full_name()] = structure
+
+ self.attribute_names = list(names)
+ self.attribute_names.sort()
+
+ structure_names = names_to_structures.keys()
+ structure_names.sort()
+
+ self.structures = [names_to_structures[name] for name in structure_names]
# Browser classes.
@@ -246,6 +309,7 @@
self.stream = stream
def process(self, module):
+ self.module = module
self.stream.write(html_header)
self.dispatch(module)
self.stream.write(html_footer)
@@ -326,7 +390,7 @@
self.stream.write(")")
self.stream.write(":\n")
- self._comment(self._text(structure.full_name()))
+ self._comment(self._summary_link(self.module._node.name, structure.full_name()))
self.stream.write("
\n")
self.stream.write("\n")