Add virtual namespaces and abstract templates into extended bases

This commit is contained in:
Eric Holscher 2015-04-09 16:40:02 -07:00
parent a73a3fca55
commit a4a1a8604f
17 changed files with 185 additions and 280 deletions

View File

@ -9,6 +9,7 @@ class AutoAPIBase(object):
def __init__(self, obj): def __init__(self, obj):
self.obj = obj self.obj = obj
def render(self, ctx=None): def render(self, ctx=None):
if not ctx: if not ctx:
ctx = {} ctx = {}
@ -18,6 +19,12 @@ class AutoAPIBase(object):
ctx.update(**self.__dict__) ctx.update(**self.__dict__)
return template.render(**ctx) return template.render(**ctx)
def get_absolute_path(self):
return "/autoapi/{type}/{name}".format(
type=self.type,
name=self.name,
)
class UnknownType(AutoAPIBase): class UnknownType(AutoAPIBase):

View File

@ -32,6 +32,13 @@ class DotNetBase(AutoAPIBase):
self.item_map = defaultdict(list) self.item_map = defaultdict(list)
self.sort() self.sort()
@property
def ref_type(self):
return self.type.lower().replace('class', 'cls').replace('interface', 'iface').replace('delegate', 'del')
def to_ref_type(self, _type):
return _type.lower().replace('class', 'cls').replace('interface', 'iface').replace('delegate', 'del')
def sort(self): def sort(self):
from .utils import classify from .utils import classify
for item in self.children: for item in self.children:
@ -81,5 +88,18 @@ class DotNetClass(DotNetBase):
class DotNetField(DotNetBase): class DotNetField(DotNetBase):
type = 'field' type = 'field'
class DotNetEvent(DotNetBase): class DotNetEvent(DotNetBase):
type = 'event' type = 'event'
class VirtualNamespace(AutoAPIBase):
language = 'dotnet'
type = 'namespace'
def __init__(self, name, objs):
self.name = self.short_name = name
self.children = []
self.type = 'namespace'
for obj in objs:
self.children.append(obj.obj)

View File

@ -8,12 +8,13 @@ import yaml
import fnmatch import fnmatch
import shutil import shutil
from collections import defaultdict from collections import defaultdict
import traceback
from sphinx.util.osutil import ensuredir from sphinx.util.osutil import ensuredir
from sphinx.util.console import bold, darkgreen from sphinx.util.console import bold, darkgreen
from .utils import classify from .utils import classify
# from .dotnet import DotNetNamespace from .dotnet import VirtualNamespace
from epyparse import parsed from epyparse import parsed
@ -42,14 +43,22 @@ def load_yaml(app):
# print "Loading Yaml from %s" % _file # print "Loading Yaml from %s" % _file
to_open = os.path.join(app.config.autoapi_dir, _file) to_open = os.path.join(app.config.autoapi_dir, _file)
yaml_obj = yaml.safe_load(open(to_open, 'r')) yaml_obj = yaml.safe_load(open(to_open, 'r'))
app.env.autoapi_data.append(classify(yaml_obj, 'dotnet')) obj = classify(yaml_obj, 'dotnet')
app.env.autoapi_data.append(obj)
# Add to namespace dict
if yaml_obj.get('type') != 'Namespace':
try:
top, mid, last = obj.name.split('.')[0:3]
namespaces[top].append(obj)
namespaces[top+'.'+mid].append(obj)
namespaces[top+'.'+mid+'.'+last].append(obj)
except:
traceback.print_exc()
pass
# print "Sorting objects" # print "Sorting objects"
# Sort objects # Sort objects
# for obj in app.env.autoapi_data: # for obj in app.env.autoapi_data:
# obj_name = obj['qualifiedName']['CSharp']
# namespace = obj_name.split('.')[0]
# namespaces[namespace].append(classify(obj, 'dotnet'))
# rst = parse(obj, 'dotnet') # rst = parse(obj, 'dotnet')
# if rst: # if rst:
# path = os.path.join(app.config.autoapi_root, '%s%s' % (obj['name']['CSharp'], app.config.source_suffix[0])) # path = os.path.join(app.config.autoapi_root, '%s%s' % (obj['name']['CSharp'], app.config.source_suffix[0]))
@ -78,6 +87,17 @@ def load_yaml(app):
with open(path, 'w+') as detail_file: with open(path, 'w+') as detail_file:
detail_file.write(rst) detail_file.write(rst)
for namespace, objs in namespaces.items():
namespace_obj = VirtualNamespace(namespace, objs)
ensuredir(app.config.autoapi_root)
virtual_dir = os.path.join(app.config.autoapi_root, 'Virtual')
ensuredir(virtual_dir)
virtual_path = os.path.join(virtual_dir, '%s%s' % (namespace, app.config.source_suffix[0]))
with open(virtual_path, 'w+') as index_file:
namespace_rst = namespace_obj.render()
if namespace_rst:
index_file.write(namespace_rst)
elif app.config.autoapi_type == 'python': elif app.config.autoapi_type == 'python':
for root, dirnames, filenames in os.walk(app.config.autoapi_dir): for root, dirnames, filenames in os.walk(app.config.autoapi_dir):
for filename in fnmatch.filter(filenames, u'*.py'): for filename in fnmatch.filter(filenames, u'*.py'):

View File

@ -0,0 +1,60 @@
{% block title %}
{{ short_name }} {{ type.title()}}
{{ "=" * (short_name|length + type|length + 1) }}
.. dn:{{ type.lower().replace('struct', 'structure').replace('enum', 'enumeration') }}:: {{ name }}
{% endblock %}
{% block summary %}
Summary
-------
{{ summary }}
{% endblock %}
{% block inheritance %}
Inheritance Hierarchy
---------------------
{% for item in inheritance %}
* :ref:`{{ item.id }}`
{% endfor %}
{% endblock %}
{% block syntax %}
Syntax
------
.. code-block:: csharp
{{ syntax }}
{% endblock %}
{% block content %}
{% if item_map %}
{% for obj_type, obj_list in item_map.items() %}
{{ obj_type }}
{{ "-" * obj_type|length }}
{% for obj_item in obj_list %}
{% macro render() %}{{ obj_item.render() }}{% endmacro %}
{{ render()|indent(0) }}
{% endfor %}
{% endfor %}
{% endif %}
{% endblock %}

View File

@ -0,0 +1,12 @@
.. dn:{{ type.lower() }}:: {{ name }}
{% if summary %}
{% macro render() %}{{ summary }}{% endmacro %}
{{ render()|indent(4) }}
{% endif %}
.. code-block:: csharp
{{ syntax }}

View File

@ -0,0 +1,42 @@
{% block title %}
{{ short_name }} {{ type.title()}}
{{ "=" * (short_name|length + type|length + 1) }}
{% endblock %}
{% block toc %}
{% if children %}
.. toctree::
:hidden:
{%- for item in children %}
{# {{ item.get_absolute_path }} #}
/autoapi/{{ item.type }}/{{ item.id.split('.')[-1] }}
{%- endfor %}
{% endif %}
{% endblock %}
{% block table %}
{% if children %}
.. list-table:: Classes
:widths: 20, 80
:header-rows: 1
* - Class
- Description
{%- for item in children %}
{% macro render() %}{{ item.summary }}{% endmacro %}
* - :dn:{{ item.type.lower().replace('class', 'cls').replace('interface', 'iface').replace('delegate', 'del') }}:`{{ item.id }}`
- {{ render()|indent(7) }}
{% endfor %}
{% endif %}
{% endblock %}

View File

@ -1,41 +1 @@
{{ short_name }} {{ type.title()}} {% extends "dotnet/base_detail.rst" %}
{{ "=" * (short_name|length + type|length + 1) }}
.. dn:class:: {{ name }}
Summary
-------
{{ summary }}
Inheritance Hierarchy
---------------------
{% for item in inheritance %}
* :ref:`{{ item.id }}`
{% endfor %}
Syntax
------
.. code-block:: csharp
{{ syntax }}
{% if item_map %}
{% for obj_type, obj_list in item_map.items() %}
{{ obj_type }}
{{ "-" * obj_type|length }}
{% for obj_item in obj_list %}
{% macro render() %}{{ obj_item.render() }}{% endmacro %}
{{ render()|indent(0) }}
{% endfor %}
{% endfor %}
{% endif %}

View File

@ -1,12 +1 @@
.. dn:{{ type.lower() }}:: {{ name }} {% extends "dotnet/base_embed.rst" %}
{% if summary %}
{% macro render() %}{{ summary }}{% endmacro %}
{{ render()|indent(4) }}
{% endif %}
.. code-block:: csharp
{{ syntax }}

View File

@ -1,15 +1 @@
{{ short_name }} {% extends "dotnet/base_detail.rst" %}
{{ "=" * short_name|length }}
.. dn:delegate:: {{ name }}
{% if summary %}
{% macro render() %}{{ summary }}{% endmacro %}
{{ render()|indent(4) }}
{% endif %}
.. code-block:: csharp
{{ syntax }}

View File

@ -1,39 +1 @@
{{ short_name }} {{ type.title()}} {% extends "dotnet/base_detail.rst" %}
{{ "=" * (short_name|length + type|length + 1) }}
.. dn:enumeration:: {{ name }}
Summary
-------
{{ summary }}
Inheritance Hierarchy
---------------------
{% for item in inheritance %}
* :ref:`{{ item.id }}`
{% endfor %}
Syntax
------
.. code-block:: csharp
{{ syntax }}
{% if item_map %}
{% for obj_type, obj_list in item_map.items() %}
{{ obj_type }}
{{ "-" * obj_type|length }}
{% for obj_item in obj_list %}
{% macro render() %}{{ obj_item.render() }}{% endmacro %}
{{ render()|indent(0) }}
{% endfor %}
{% endfor %}
{% endif %}

View File

@ -1,12 +1 @@
.. dn:{{ type.lower() }}:: {{ name }} {% extends "dotnet/base_embed.rst" %}
{% if summary %}
{% macro render() %}{{ summary }}{% endmacro %}
{{ render()|indent(4) }}
{% endif %}
.. code-block:: csharp
{{ syntax }}

View File

@ -1,12 +1 @@
.. dn:{{ type.lower() }}:: {{ name }} {% extends "dotnet/base_embed.rst" %}
{% if summary %}
{% macro render() %}{{ summary }}{% endmacro %}
{{ render()|indent(4) }}
{% endif %}
.. code-block:: csharp
{{ syntax }}

View File

@ -1,40 +1 @@
{{ short_name }} {{ type.title()}} {% extends "dotnet/base_detail.rst" %}
{{ "=" * short_name|length }}{{ "=" * type|length }}=
.. dn:interface:: {{ name }}
Summary
-------
{{ summary }}
Inheritance Hierarchy
---------------------
{% for item in inheritance %}
* :ref:`{{ item.id }}`
{% endfor %}
Syntax
------
.. code-block:: csharp
{{ syntax }}
{% if item_map %}
{% for obj_type, obj_list in item_map.items() %}
{{ obj_type }}
{{ "-" * obj_type|length }}
{% for obj_item in obj_list %}
{% macro render() %}{{ obj_item.render() }}{% endmacro %}
{{ render()|indent(0) }}
{% endfor %}
{% endfor %}
{% endif %}

View File

@ -1,12 +1 @@
.. dn:{{ type.lower() }}:: {{ name }} {% extends "dotnet/base_embed.rst" %}
{% if summary %}
{% macro render() %}{{ summary }}{% endmacro %}
{{ render()|indent(4) }}
{% endif %}
.. code-block:: csharp
{{ syntax }}

View File

@ -1,33 +1 @@
{{ short_name }} {{ type.title()}} {% extends "dotnet/base_list.rst" %}
{{ "=" * short_name|length }}{{ "=" * type|length }}=
Tree:
{% if children %}
.. toctree::
:hidden:
{% for item in children %}
/autoapi/{{ item.type }}/{{ item.id.split('.')[-1] }} {% endfor %}
{% endif %}
Table:
{% if children %}
.. list-table:: Classes
:widths: 20, 80
:header-rows: 1
* - Class
- Description
{% for item in children %} {% macro render() %}{{ item.summary }}{% endmacro %}
* - :dn:{{ item.type.lower().replace('class', 'cls').replace('interface', 'iface').replace('delegate', 'del') }}:`{{ item.id }}`
- {{ render()|indent(7) }}
{% endfor %}
{% endif %}

View File

@ -1,12 +1 @@
.. dn:{{ type.lower() }}:: {{ name }} {% extends "dotnet/base_embed.rst" %}
{% if summary %}
{% macro render() %}{{ summary }}{% endmacro %}
{{ render()|indent(4) }}
{% endif %}
.. code-block:: csharp
{{ syntax }}

View File

@ -1,39 +1 @@
{{ short_name }} {{ type.title()}} {% extends "dotnet/base_detail.rst" %}
{{ "=" * short_name|length }}{{ "=" * type|length }}=
.. dn:structure:: {{ name }}
Summary
-------
{{ summary }}
Inheritance Hierarchy
---------------------
{% for item in inheritance %}
* :ref:`{{ item.id }}`
{% endfor %}
Syntax
------
.. code-block:: csharp
{{ syntax }}
{% if item_map %}
{% for obj_type, obj_list in item_map.items() %}
{{ obj_type }}
{{ "-" * obj_type|length }}
{% for obj_item in obj_list %}
{% macro render() %}{{ obj_item.render() }}{% endmacro %}
{{ render()|indent(0) }}
{% endfor %}
{% endfor %}
{% endif %}