Sorting on list and detail pages, plus type and ref type fixes to classes

go-templates
Anthony Johnson 10 years ago
parent 5a5ae1cf15
commit e7be3b1804

@ -33,6 +33,12 @@ class AutoAPIBase(object):
context['object'] = self
return context
def __lt__(self, other):
'''Object sorting comparison'''
if isinstance(other, AutoAPIBase):
return self.id < other.id
return super(AutoAPIBase, self).__lt__(other)
class UnknownType(AutoAPIBase):

@ -135,6 +135,8 @@ class DotNetDomain(AutoAPIDomain):
# TODO not here!
for child in obj.children:
obj.item_map[child.type].append(child)
for key in obj.item_map.keys():
obj.item_map[key].sort()
rst = obj.render()
# Detail
@ -226,60 +228,68 @@ class DotNetBase(AutoAPIBase):
if pieces:
return '.'.join(pieces)
@property
def ref_type(self):
return self.type
@property
def ref_directive(self):
return self.type
class DotNetNamespace(DotNetBase):
type = 'namespace'
ref_type = 'ns'
ref_directive = 'ns'
class DotNetMethod(DotNetBase):
type = 'method'
ref_type = 'meth'
ref_directive = 'meth'
class DotNetProperty(DotNetBase):
type = 'property'
ref_type = 'prop'
ref_directive = 'prop'
class DotNetEnum(DotNetBase):
type = 'enum'
ref_type = 'enum'
ref_type = 'enumeration'
ref_directive = 'enum'
class DotNetStruct(DotNetBase):
type = 'struct'
ref_type = 'struct'
ref_type = 'structure'
ref_directive = 'struct'
class DotNetConstructor(DotNetBase):
type = 'constructor'
ref_type = 'ctor'
ref_directive = 'ctor'
class DotNetInterface(DotNetBase):
type = 'interface'
ref_type = 'iface'
ref_directive = 'iface'
class DotNetDelegate(DotNetBase):
type = 'delegate'
ref_type = 'del'
ref_directive = 'del'
class DotNetClass(DotNetBase):
type = 'class'
ref_type = 'cls'
ref_directive = 'cls'
class DotNetField(DotNetBase):
type = 'field'
ref_type = 'field'
class DotNetEvent(DotNetBase):
type = 'event'
ref_type = 'event'
class DotNetVirtualNamespace(AutoAPIBase):

@ -3,7 +3,7 @@
{{ object.short_name }} {{ object.type.title()}}
{{ "=" * (object.short_name|length + object.type|length + 1) }}
.. dn:{{ object.type }}:: {{ object.name }}
.. dn:{{ object.ref_type }}:: {{ object.name }}
{% endblock %}

@ -1,4 +1,4 @@
.. dn:{{ object.type }}:: {{ object.name }}
.. dn:{{ object.ref_type }}:: {{ object.name }}
{% if summary %}

@ -1,9 +1,9 @@
{% block title %}
{{ object.short_name }} {{ object.type.title()}}
{{ object.short_name }} {{ object.type.title() }}
{{ "=" * (object.short_name|length + object.type|length + 1) }}
.. dn:{{ object.type }}:: {{ object.name }}
.. dn:{{ object.ref_type }}:: {{ object.name }}
{% endblock %}
@ -24,17 +24,17 @@
{% block table %}
{% if children %}
{% if object.children %}
.. list-table:: Classes
.. list-table:: Members
:widths: 20, 80
:header-rows: 1
* - Class
- Description
{%- for item in children %}
{%- for item in object.children|sort %}
{% macro render() %}{{ item.summary }}{% endmacro %}
* - :dn:{{ item.ref_type }}:`{{ item.id }}`
* - :dn:{{ item.ref_directive }}:`{{ item.id }}`
- {{ render()|indent(7) }}
{% endfor %}

@ -12,15 +12,59 @@ class NamespaceTests(unittest.TestCase):
'''Test types of some of the objects'''
obj = dotnet.DotNetNamespace({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'namespace')
self.assertEqual(obj.ref_type, 'ns')
self.assertEqual(obj.ref_type, 'namespace')
self.assertEqual(obj.ref_directive, 'ns')
obj = dotnet.DotNetMethod({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'method')
self.assertEqual(obj.ref_type, 'meth')
self.assertEqual(obj.ref_type, 'method')
self.assertEqual(obj.ref_directive, 'meth')
obj = dotnet.DotNetProperty({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'property')
self.assertEqual(obj.ref_type, 'property')
self.assertEqual(obj.ref_directive, 'prop')
obj = dotnet.DotNetEnum({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'enum')
self.assertEqual(obj.ref_type, 'enumeration')
self.assertEqual(obj.ref_directive, 'enum')
obj = dotnet.DotNetStruct({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'struct')
self.assertEqual(obj.ref_type, 'structure')
self.assertEqual(obj.ref_directive, 'struct')
obj = dotnet.DotNetConstructor({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'constructor')
self.assertEqual(obj.ref_type, 'constructor')
self.assertEqual(obj.ref_directive, 'ctor')
obj = dotnet.DotNetInterface({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'interface')
self.assertEqual(obj.ref_type, 'interface')
self.assertEqual(obj.ref_directive, 'iface')
obj = dotnet.DotNetDelegate({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'delegate')
self.assertEqual(obj.ref_type, 'delegate')
self.assertEqual(obj.ref_directive, 'del')
obj = dotnet.DotNetClass({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'class')
self.assertEqual(obj.ref_type, 'cls')
self.assertEqual(obj.ref_type, 'class')
self.assertEqual(obj.ref_directive, 'cls')
obj = dotnet.DotNetField({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'field')
self.assertEqual(obj.ref_type, 'field')
self.assertEqual(obj.ref_directive, 'field')
obj = dotnet.DotNetEvent({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'event')
self.assertEqual(obj.ref_type, 'event')
self.assertEqual(obj.ref_directive, 'event')
def test_names(self):
'''Test names of objects'''

Loading…
Cancel
Save