Add better reference and obj id handling for generics

This commit is contained in:
Anthony Johnson 2015-04-24 18:32:16 -07:00
parent a3cea299dc
commit 9612dae694
4 changed files with 38 additions and 14 deletions

View File

@ -90,7 +90,7 @@ class DotNetDomain(AutoAPIDomain):
self.top_level_objects[obj.name] = obj self.top_level_objects[obj.name] = obj
if type(obj) == DotNetNamespace: if type(obj) == DotNetNamespace:
self.namespaces[obj.name] = obj self.namespaces[obj.name] = obj
self.objects[obj.name] = obj self.objects[obj.id] = obj
def organize_objects(self): def organize_objects(self):
'''Organize objects and namespaces''' '''Organize objects and namespaces'''
@ -242,6 +242,11 @@ class DotNetBase(AutoAPIBase):
except KeyError: except KeyError:
return self.id return self.id
@property
def short_name(self):
'''Shorten name property'''
return self.name.split('.')[-1]
@property @property
def edit_link(self): def edit_link(self):
try: try:
@ -255,7 +260,6 @@ class DotNetBase(AutoAPIBase):
import traceback; traceback.print_exc(); import traceback; traceback.print_exc();
return '' return ''
@property @property
def source(self): def source(self):
return self.obj.get('source') return self.obj.get('source')
@ -264,11 +268,6 @@ class DotNetBase(AutoAPIBase):
def path(self): def path(self):
return self.source['path'] return self.source['path']
@property
def short_name(self):
'''Shorten name property'''
return self.name.split('.')[-1]
@property @property
def namespace(self): def namespace(self):
pieces = self.id.split('.')[:-1] pieces = self.id.split('.')[:-1]
@ -289,6 +288,29 @@ class DotNetBase(AutoAPIBase):
def ref_directive(self): def ref_directive(self):
return self.type return self.type
@property
def ref_name(self):
'''Return object name suitable for use in references
Escapes several known strings that cause problems, including the
following reference syntax::
:dotnet:cls:`Foo.Bar<T>`
As the `<T>` notation is also special syntax in references, indicating
the reference to Foo.Bar should be named T.
See: http://sphinx-doc.org/domains.html#role-cpp:any
'''
return (self.name
.replace('<', '\<')
.replace('`', '\`'))
@property
def ref_short_name(self):
'''Same as above, return the truncated name instead'''
return self.ref_name.split('.')[-1]
class DotNetNamespace(DotNetBase): class DotNetNamespace(DotNetBase):
type = 'namespace' type = 'namespace'

View File

@ -27,9 +27,9 @@ Inheritance Hierarchy
--------------------- ---------------------
{%- for item in obj.inheritance %} {%- for item in obj.inheritance %}
* :dn:{{ item.ref_directive }}:`{{ item.id }}` * :dn:{{ item.ref_directive }}:`{{ item.ref_name }}`
{%- endfor %} {%- endfor %}
* :dn:{{ obj.ref_directive }}:`{{ obj.id}}` * :dn:{{ obj.ref_directive }}:`{{ obj.ref_name }}`
{%- endif %} {%- endif %}
{% endblock %} {% endblock %}

View File

@ -17,6 +17,8 @@
:rtype: {{ obj.returns.id }} :rtype: {{ obj.returns.id }}
{%- endif %} {%- endif %}
{%- if obj.example %}
.. code-block:: csharp .. code-block:: csharp
{{ obj.example }} {{ obj.example }}
{%- endif %}

View File

@ -1,7 +1,7 @@
{% block title %} {% block title %}
{{ obj.id }} {{ obj.type.title() }} {{ obj.name }} {{ obj.type.title() }}
{{ "=" * (obj.id|length + obj.type|length + 1) }} {{ "=" * (obj.name|length + obj.type|length + 1) }}
{% endblock %} {% endblock %}
@ -15,7 +15,7 @@
{% for item in obj.children|sort %} {% for item in obj.children|sort %}
{% if item.type != 'namespace' %} {% if item.type != 'namespace' %}
/autoapi/{{ item.id.split('.')|join('/') }}/index /autoapi/{{ item.name.split('.')|join('/') }}/index
{% endif %} {% endif %}
{%- endfor %} {%- endfor %}
@ -34,7 +34,7 @@
{%- for obj_item in obj.item_map.get(item_type, []) %} {%- for obj_item in obj.item_map.get(item_type, []) %}
{% macro render() %}{{ obj_item.summary }}{% endmacro %} {% macro render() %}{{ obj_item.summary }}{% endmacro %}
{{ obj_item.type }} :dn:{{ obj_item.ref_directive }}:`{{ obj_item.short_name }}` {{ obj_item.type }} :dn:{{ obj_item.ref_directive }}:`{{ obj_item.ref_short_name }}`
{{ render()|indent(8) }} {{ render()|indent(8) }}
{%- endfor %} {%- endfor %}