From 30219d837fc7e97ff3f776e1cc9fe6e63dcff76f Mon Sep 17 00:00:00 2001 From: Shaun McCance Date: Wed, 24 Aug 2011 11:32:18 -0400 Subject: 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(-) delete mode 100644 giscanner/mallard-C-method.tmpl delete mode 100644 giscanner/mallard-Python-method.tmpl 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"> Methods + + Functions + Properties 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 @@ - - ${node.namespace.name}${node.name} -${formatter.format(node.doc)} + ${namespace.name}.${node.name} +${formatter.format(node.doc)} + 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 @@ - + - +% if node.parent is not None: + +% else: + +% endif + + ${formatter.format_type(node.retval.type) | x} + ${node.symbol} +% if node.is_method: + + ${node.parent.ctype} * + self + +% endif +% for arg in node.parameters: +% if arg.type.ctype == '': + +% else: + + ${formatter.format_type(arg.type) | x} + ${arg.argname} + +% endif +% endfor ${node.symbol} - -${formatter.format_type(node.retval.type)} ${node.symbol} (\ + +${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 == '': ...\ % 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 @@ - - - - - - - ${formatter.format_type(node.retval.type)} - - ${node.symbol} - - ${node.parent.ctype} * - self - -% for arg in node.parameters: -% if arg.type.ctype == '': - -% else: - - ${formatter.format_type(arg.type)} - ${arg.argname} - -% endif -% endfor - - - ${node.symbol} - -${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 == '': -...\ -% else: -${formatter.format_type(arg.type)} ${arg.argname}\ -% endif -% if ix == len(node.parameters) - 1: -); -% else: -, -%endif -% endfor - -${formatter.format(node.doc)} 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 @@ ${node.name} Documentation - + Classes - + Functions - + Other 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/"> - ${node.namespace.name}.${node.name} + ${namespace.name}.${node.name} ${formatter.format(node.doc)} Hierarchy @@ -17,12 +18,21 @@ ${formatter.format(node.doc)} - + Constructors - + Methods + + Functions + Properties 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 @@ - - ${node.namespace.name}.${node.name} + ${namespace.name}.${node.name} ${formatter.format(node.doc)} 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 @@ - + + xmlns:api="http://projectmallard.org/experimental/api/" + xmlns:ui="http://projectmallard.org/experimental/ui/"> - - ${node.symbol} +% if node.parent is not None: + +% else: + +% endif + + + ${formatter.format_type(node.retval.type) | x} + + ${node.symbol} +% if node.is_method: + + ${node.parent.ctype} * + self + +% endif +% for arg in node.parameters: +% if arg.type.ctype == '': + +% else: + + ${formatter.format_type(arg.type) | x} + ${arg.argname} + +% endif +% endfor + - ${node.symbol} + ${node.name} + +% 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 +) + ${formatter.format(node.doc)} 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 @@ - - - - - - ${node.symbol} -${formatter.format(node.doc)} - 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), -- cgit v1.2.1