summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun McCance <shaunm@gnome.org>2011-08-24 11:32:18 -0400
committerTomeu Vizoso <tomeu.vizoso@collabora.com>2012-02-17 10:27:40 +0100
commit30219d837fc7e97ff3f776e1cc9fe6e63dcff76f (patch)
tree5fa171cae0a385a62330cb1fabf281458205e645
parent836259072ee674bcadb57ae0dcb23ab7db6ae211 (diff)
downloadgobject-introspection-30219d837fc7e97ff3f776e1cc9fe6e63dcff76f.tar.gz
g-ir-doc-tool: Consolidating the function templates
-rw-r--r--giscanner/mallard-C-class.tmpl5
-rw-r--r--giscanner/mallard-C-default.tmpl7
-rw-r--r--giscanner/mallard-C-function.tmpl50
-rw-r--r--giscanner/mallard-C-method.tmpl53
-rw-r--r--giscanner/mallard-C-namespace.tmpl6
-rw-r--r--giscanner/mallard-Python-class.tmpl16
-rw-r--r--giscanner/mallard-Python-default.tmpl4
-rw-r--r--giscanner/mallard-Python-function.tmpl71
-rw-r--r--giscanner/mallard-Python-method.tmpl13
-rw-r--r--giscanner/mallardwriter.py48
10 files changed, 168 insertions, 105 deletions
diff --git a/giscanner/mallard-C-class.tmpl b/giscanner/mallard-C-class.tmpl
index 9ca3fece..ad2735e0 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 a30d10e7..577fa566 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 fd87a83a..d86328d8 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-method.tmpl b/giscanner/mallard-C-method.tmpl
deleted file mode 100644
index e80931f1..00000000
--- a/giscanner/mallard-C-method.tmpl
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0"?>
-<page id="${namespace.name}.${node.parent.name}.${node.name}"
- type="topic"
- style="method"
- 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="${namespace.name}.${node.parent.name}" group="method"/>
- <api:function>
- <api:returns>
- <api:type>${formatter.format_type(node.retval.type)}</api:type>
- </api:returns>
- <api:name>${node.symbol}</api:name>
- <api:arg>
- <api:type>${node.parent.ctype} *</api:type>
- <api:name>self</api:name>
- </api:arg>
-% for arg in node.parameters:
-% if arg.type.ctype == '<varargs>':
- <api:varargs/>
-% else:
- <api:arg>
- <api:type>${formatter.format_type(arg.type)}</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} (${node.parent.ctype} *self\
-% if len(node.parameters) == 0:
-);
-% else:
-,
-% endif
-% for arg, ix in zip(node.parameters, range(len(node.parameters))):
-${' ' * (len(formatter.format_type(node.retval.type)) + len(node.symbol) + 3)}\
-% if arg.type.ctype == '<varargs>':
-...\
-% else:
-${formatter.format_type(arg.type)} ${arg.argname}\
-% endif
-% if ix == len(node.parameters) - 1:
-);
-% else:
-,
-%endif
-% endfor
-</code></synopsis>
-${formatter.format(node.doc)}</page>
diff --git a/giscanner/mallard-C-namespace.tmpl b/giscanner/mallard-C-namespace.tmpl
index 935cd440..284ba238 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 6803dfbb..b317b432 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 4a321e6b..683adf6a 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 54d4a7aa..3ae28f33 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/mallard-Python-method.tmpl b/giscanner/mallard-Python-method.tmpl
deleted file mode 100644
index feaade6b..00000000
--- a/giscanner/mallard-Python-method.tmpl
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0"?>
-<page id="${namespace.name}.${node.parent.name}.${node.name}"
- type="topic"
- style="method"
- xmlns="http://projectmallard.org/1.0/"
- xmlns:ui="http://projectmallard.org/experimental/ui/"
- xmlns:c="http://www.gtk.org/introspection/c/1.0">
- <info>
- <link type="guide" xref="${namespace.name}.${node.parent.name}" group="method"/>
- </info>
- <title>${node.symbol}</title>
-${formatter.format(node.doc)}
-</page>
diff --git a/giscanner/mallardwriter.py b/giscanner/mallardwriter.py
index 14922540..f34d6e06 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),