[gobject-introspection/mallard-templates: 5/6] g-ir-doc-tool: Consolidating the function templates
- From: Tomeu Vizoso <tomeuv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/mallard-templates: 5/6] g-ir-doc-tool: Consolidating the function templates
- Date: Fri, 17 Feb 2012 09:55:37 +0000 (UTC)
commit 30219d837fc7e97ff3f776e1cc9fe6e63dcff76f
Author: Shaun McCance <shaunm gnome org>
Date: Wed Aug 24 11:32:18 2011 -0400
g-ir-doc-tool: Consolidating the function templates
giscanner/mallard-C-class.tmpl | 5 ++
giscanner/mallard-C-default.tmpl | 7 ++-
giscanner/mallard-C-function.tmpl | 50 ++++++++++++++++++++---
giscanner/mallard-C-method.tmpl | 53 ------------------------
giscanner/mallard-C-namespace.tmpl | 6 +-
giscanner/mallard-Python-class.tmpl | 16 ++++++-
giscanner/mallard-Python-default.tmpl | 4 +-
giscanner/mallard-Python-function.tmpl | 71 ++++++++++++++++++++++++++++---
giscanner/mallard-Python-method.tmpl | 13 ------
giscanner/mallardwriter.py | 48 +++++++++++++++-------
10 files changed, 168 insertions(+), 105 deletions(-)
---
diff --git a/giscanner/mallard-C-class.tmpl b/giscanner/mallard-C-class.tmpl
index 9ca3fec..ad2735e 100644
--- a/giscanner/mallard-C-class.tmpl
+++ b/giscanner/mallard-C-class.tmpl
@@ -28,6 +28,11 @@ ${formatter.format(node.doc)}
groups="method" style="linklist">
<title>Methods</title>
</links>
+ <links type="topic" ui:expanded="yes"
+ api:type="function" api:mime="text/x-csrc"
+ groups="function" style="linklist">
+ <title>Functions</title>
+ </links>
<links type="topic" ui:expanded="yes" groups="property" style="linklist">
<title>Properties</title>
</links>
diff --git a/giscanner/mallard-C-default.tmpl b/giscanner/mallard-C-default.tmpl
index a30d10e..577fa56 100644
--- a/giscanner/mallard-C-default.tmpl
+++ b/giscanner/mallard-C-default.tmpl
@@ -1,10 +1,11 @@
<?xml version="1.0"?>
-<page id="${node.namespace.name}.${node.name}"
+<page id="${namespace.name}.${node.name}"
type="topic"
style=""
xmlns="http://projectmallard.org/1.0/"
xmlns:ui="http://projectmallard.org/experimental/ui/">
<info>
</info>
- <title>${node.namespace.name}${node.name}</title>
-${formatter.format(node.doc)}</page>
+ <title>${namespace.name}.${node.name}</title>
+${formatter.format(node.doc)}
+</page>
diff --git a/giscanner/mallard-C-function.tmpl b/giscanner/mallard-C-function.tmpl
index fd87a83..d86328d 100644
--- a/giscanner/mallard-C-function.tmpl
+++ b/giscanner/mallard-C-function.tmpl
@@ -1,21 +1,59 @@
<?xml version="1.0"?>
-<page id="${namespace.name}.${node.name}"
+<%
+page_style = 'function'
+if node.is_constructor:
+ page_style = 'constructor'
+elif node.is_method:
+ page_style = 'method'
+%>
+<page id="${page_id}"
type="topic"
- style="function"
+ style="${page_style}"
xmlns="http://projectmallard.org/1.0/"
xmlns:api="http://projectmallard.org/experimental/api/"
xmlns:ui="http://projectmallard.org/experimental/ui/">
<info>
- <link type="guide" xref="index" group="function"/>
+% if node.parent is not None:
+ <link type="guide" xref="${namespace.name}.${node.parent.name}" group="${page_style}"/>
+% else:
+ <link type="guide" xref="index" group="${page_style}"/>
+% endif
<api:function>
+ <api:returns>
+ <api:type>${formatter.format_type(node.retval.type) | x}</api:type>
+ </api:returns>
<api:name>${node.symbol}</api:name>
+% if node.is_method:
+ <api:arg>
+ <api:type>${node.parent.ctype} *</api:type>
+ <api:name>self</api:name>
+ </api:arg>
+% endif
+% for arg in node.parameters:
+% if arg.type.ctype == '<varargs>':
+ <api:varargs/>
+% else:
+ <api:arg>
+ <api:type>${formatter.format_type(arg.type) | x}</api:type>
+ <api:name>${arg.argname}</api:name>
+ </api:arg>
+% endif
+% endfor
</api:function>
</info>
<title>${node.symbol}</title>
-<synopsis><code>
-${formatter.format_type(node.retval.type)} ${node.symbol} (\
+<synopsis><code mime="text/x-csrc">
+${formatter.format_type(node.retval.type) | x} ${node.symbol} (\
+% if node.is_method:
+${node.parent.ctype} *self\
+%endif
% if len(node.parameters) == 0:
+% if not node.is_method:
+void\
+%endif
);
+% elif node.is_method:
+,
% endif
% for arg, ix in zip(node.parameters, range(len(node.parameters))):
% if ix != 0:
@@ -24,7 +62,7 @@ ${' ' * (len(formatter.format_type(node.retval.type)) + len(node.symbol) + 3)}\
% if arg.type.ctype == '<varargs>':
...\
% else:
-${formatter.format_type(arg.type)} ${arg.argname}\
+${formatter.format_type(arg.type) | x} ${arg.argname}\
% endif
% if ix == len(node.parameters) - 1:
);
diff --git a/giscanner/mallard-C-namespace.tmpl b/giscanner/mallard-C-namespace.tmpl
index 935cd44..284ba23 100644
--- a/giscanner/mallard-C-namespace.tmpl
+++ b/giscanner/mallard-C-namespace.tmpl
@@ -7,13 +7,13 @@
<info>
</info>
<title>${node.name} Documentation</title>
- <links type="topic" ui:expanded="yes" groups="class">
+ <links type="topic" ui:expanded="yes" groups="class" style="linklist">
<title>Classes</title>
</links>
- <links type="topic" ui:expanded="yes" groups="function">
+ <links type="topic" ui:expanded="yes" groups="function" style="linklist">
<title>Functions</title>
</links>
- <links type="topic" ui:expanded="yes" groups="#first #default #last">
+ <links type="topic" ui:expanded="yes" groups="#first #default #last" style="linklist">
<title>Other</title>
</links>
</page>
diff --git a/giscanner/mallard-Python-class.tmpl b/giscanner/mallard-Python-class.tmpl
index 6803dfb..b317b43 100644
--- a/giscanner/mallard-Python-class.tmpl
+++ b/giscanner/mallard-Python-class.tmpl
@@ -3,11 +3,12 @@
type="guide"
style="class"
xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
xmlns:ui="http://projectmallard.org/experimental/ui/">
<info>
<link type="guide" xref="index" group="class"/>
</info>
- <title>${node.namespace.name}.${node.name}</title>
+ <title>${namespace.name}.${node.name}</title>
${formatter.format(node.doc)}
<synopsis ui:expanded="no">
<title>Hierarchy</title>
@@ -17,12 +18,21 @@ ${formatter.format(node.doc)}
</item>
</tree>
</synopsis>
- <links type="topic" ui:expanded="yes" groups="constructor" style="linklist">
+ <links type="topic" ui:expanded="yes"
+ api:type="function" api:mime="text/x-python"
+ groups="constructor" style="linklist">
<title>Constructors</title>
</links>
- <links type="topic" ui:expanded="yes" groups="method" style="linklist">
+ <links type="topic" ui:expanded="yes"
+ api:type="function" api:mime="text/x-python"
+ groups="method" style="linklist">
<title>Methods</title>
</links>
+ <links type="topic" ui:expanded="yes"
+ api:type="function" api:mime="text/x-python"
+ groups="function" style="linklist">
+ <title>Functions</title>
+ </links>
<links type="topic" ui:expanded="yes" groups="property" style="linklist">
<title>Properties</title>
</links>
diff --git a/giscanner/mallard-Python-default.tmpl b/giscanner/mallard-Python-default.tmpl
index 4a321e6..683adf6 100644
--- a/giscanner/mallard-Python-default.tmpl
+++ b/giscanner/mallard-Python-default.tmpl
@@ -1,11 +1,11 @@
<?xml version="1.0"?>
-<page id="${node.namespace.name}.${node.name}"
+<page id="${page_id}"
type="topic"
style=""
xmlns="http://projectmallard.org/1.0/"
xmlns:ui="http://projectmallard.org/experimental/ui/">
<info>
</info>
- <title>${node.namespace.name}.${node.name}</title>
+ <title>${namespace.name}.${node.name}</title>
${formatter.format(node.doc)}
</page>
diff --git a/giscanner/mallard-Python-function.tmpl b/giscanner/mallard-Python-function.tmpl
index 54d4a7a..3ae28f3 100644
--- a/giscanner/mallard-Python-function.tmpl
+++ b/giscanner/mallard-Python-function.tmpl
@@ -1,14 +1,71 @@
<?xml version="1.0"?>
-<page id="${namespace.name}.${node.name}"
+<%
+page_style = 'function'
+if node.is_constructor:
+ page_style = 'constructor'
+elif node.is_method:
+ page_style = 'method'
+%>
+<page id="${page_id}"
type="topic"
- style="function"
+ style="${page_style}"
xmlns="http://projectmallard.org/1.0/"
- xmlns:ui="http://projectmallard.org/experimental/ui/"
- xmlns:c="http://www.gtk.org/introspection/c/1.0">
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/experimental/ui/">
<info>
- <link type="guide" xref="index" group="function"/>
- <c:identifier>${node.symbol}</c:identifier>
+% if node.parent is not None:
+ <link type="guide" xref="${namespace.name}.${node.parent.name}" group="${page_style}"/>
+% else:
+ <link type="guide" xref="index" group="${page_style}"/>
+% endif
+ <api:function>
+ <api:returns>
+ <api:type>${formatter.format_type(node.retval.type) | x}</api:type>
+ </api:returns>
+ <api:name>${node.symbol}</api:name>
+% if node.is_method:
+ <api:arg>
+ <api:type>${node.parent.ctype} *</api:type>
+ <api:name>self</api:name>
+ </api:arg>
+% endif
+% for arg in node.parameters:
+% if arg.type.ctype == '<varargs>':
+ <api:varargs/>
+% else:
+ <api:arg>
+ <api:type>${formatter.format_type(arg.type) | x}</api:type>
+ <api:name>${arg.argname}</api:name>
+ </api:arg>
+% endif
+% endfor
+ </api:function>
</info>
- <title>${node.symbol}</title>
+ <title>${node.name}</title>
+<synopsis><code mime="text/x-python">
+% if len(node.parameters) != 0:
+ accepts(\
+% for arg, ix in zip(node.parameters, range(len(node.parameters))):
+${formatter.format_type(arg.type) | x}\
+% if ix != len(node.parameters) - 1:
+, \
+%endif
+% endfor
+)
+% endif
+ returns(${formatter.format_type(node.retval.type) | x})
+def \
+% if node.parent is not None:
+${namespace.name}.${node.parent.name}.\
+% endif
+${node.name}(\
+% for arg, ix in zip(node.parameters, range(len(node.parameters))):
+${arg.argname}\
+% if ix != len(node.parameters) - 1:
+, \
+%endif
+% endfor
+)
+</code></synopsis>
${formatter.format(node.doc)}
</page>
diff --git a/giscanner/mallardwriter.py b/giscanner/mallardwriter.py
index 1492254..f34d6e0 100644
--- a/giscanner/mallardwriter.py
+++ b/giscanner/mallardwriter.py
@@ -76,13 +76,25 @@ class MallardFormatter(object):
class MallardFormatterC(MallardFormatter):
@classmethod
def format_type(cls, type_):
- if type_.ctype is not None:
+ if isinstance(type_, ast.Array):
+ try:
+ return cls.format_type(type_.element_type) + '*'
+ except:
+ return type_.target_fundamental
+ elif type_.ctype is not None:
return type_.ctype
else:
return type_.target_fundamental
class MallardFormatterPython(MallardFormatter):
- pass
+ @classmethod
+ def format_type(cls, type_):
+ if isinstance(type_, ast.Array):
+ return '[' + cls.format_type(type_.element_type) + ']'
+ elif type_.target_giname is not None:
+ return type_.target_giname
+ else:
+ return type_.target_fundamental
class MallardWriter(object):
def __init__(self, transformer, language):
@@ -93,17 +105,22 @@ class MallardWriter(object):
self._language = language
def write(self, output):
- self._render_node(self._transformer.namespace, output)
+ nodes = [self._transformer.namespace]
for node in self._transformer.namespace.itervalues():
+ if isinstance(node, ast.Function) and node.moved_to is not None:
+ continue
+ if getattr(node, 'disguised', False):
+ continue
+ nodes.append(node)
+ if isinstance(node, (ast.Class, ast.Interface, ast.Record)):
+ nodes += getattr(node, 'methods', [])
+ nodes += getattr(node, 'constructors', [])
+ nodes += getattr(node, 'static_methods', [])
+ nodes += getattr(node, 'virtual_methods', [])
+ nodes += getattr(node, 'properties', [])
+ nodes += getattr(node, 'signals', [])
+ for node in nodes:
self._render_node(node, output)
- if isinstance(node, (ast.Class, ast.Record)):
- for method in node.methods:
- self._render_node(method, output)
- if isinstance(node, ast.Class):
- for property_ in node.properties:
- self._render_node(property_, output)
- for signal in node.signals:
- self._render_node(signal, output)
def _render_node(self, node, output):
namespace = self._transformer.namespace
@@ -116,12 +133,12 @@ class MallardWriter(object):
elif isinstance(node, ast.Record):
template_name = 'mallard-%s-record.tmpl' % self._language
page_id = '%s.%s' % (namespace.name, node.name)
- elif isinstance(node, ast.Function) and node.parent is not None:
- template_name = 'mallard-%s-method.tmpl' % self._language
- page_id = '%s.%s.%s' % (namespace.name, node.parent.name, node.name)
elif isinstance(node, ast.Function):
template_name = 'mallard-%s-function.tmpl' % self._language
- page_id = '%s.%s' % (namespace.name, node.name)
+ if node.parent is not None:
+ page_id = '%s.%s.%s' % (namespace.name, node.parent.name, node.name)
+ else:
+ page_id = '%s.%s' % (namespace.name, node.name)
elif isinstance(node, ast.Property) and node.parent is not None:
template_name = 'mallard-%s-property.tmpl' % self._language
page_id = '%s.%s-%s' % (namespace.name, node.parent.name, node.name)
@@ -148,6 +165,7 @@ class MallardWriter(object):
formatter = MallardFormatter
result = template.render(namespace=namespace,
node=node,
+ page_id=page_id,
formatter=formatter)
output_file_name = os.path.join(os.path.dirname(output),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]