[gobject-introspection/wip/docs: 6/6] xxx



commit 00f332d4f7406812d13bc4db9d55f3e57fb8c371
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Dec 17 01:09:31 2013 -0500

    xxx

 giscanner/docmain.py                         |    2 +-
 giscanner/doctemplates/Gjs/namespace.tmpl    |    1 -
 giscanner/doctemplates/Python/namespace.tmpl |    1 -
 giscanner/doctemplates/namespace.tmpl        |   39 +++-----
 giscanner/docwriter.py                       |  132 ++------------------------
 5 files changed, 22 insertions(+), 153 deletions(-)
---
diff --git a/giscanner/docmain.py b/giscanner/docmain.py
index e65b57a..0ba5579 100644
--- a/giscanner/docmain.py
+++ b/giscanner/docmain.py
@@ -31,7 +31,7 @@ def doc_main(args):
 
     parser.add_option("-o", "--output",
                       action="store", dest="output",
-                      help="Directory to write output to")
+                      help="File to write output to")
     parser.add_option("-l", "--language",
                       action="store", dest="language",
                       default="c",
diff --git a/giscanner/doctemplates/Gjs/namespace.tmpl b/giscanner/doctemplates/Gjs/namespace.tmpl
index 4d80c2a..cb8195d 100644
--- a/giscanner/doctemplates/Gjs/namespace.tmpl
+++ b/giscanner/doctemplates/Gjs/namespace.tmpl
@@ -1,2 +1 @@
-<%! page_type="guide" %>\
 <%inherit file="/namespace.tmpl"/>
diff --git a/giscanner/doctemplates/Python/namespace.tmpl b/giscanner/doctemplates/Python/namespace.tmpl
index 4d80c2a..cb8195d 100644
--- a/giscanner/doctemplates/Python/namespace.tmpl
+++ b/giscanner/doctemplates/Python/namespace.tmpl
@@ -1,2 +1 @@
-<%! page_type="guide" %>\
 <%inherit file="/namespace.tmpl"/>
diff --git a/giscanner/doctemplates/namespace.tmpl b/giscanner/doctemplates/namespace.tmpl
index 2c27ee4..9798c79 100644
--- a/giscanner/doctemplates/namespace.tmpl
+++ b/giscanner/doctemplates/namespace.tmpl
@@ -1,27 +1,14 @@
-<%! page_type="guide" %>\
-<%inherit file="/base.tmpl"/>
-<%block name="doc">
-</%block>
-<%block name="info">
-</%block>
-<%block name="links">
-  <links type="topic" ui:expanded="true" groups="class" style="linklist">
-    <title>Classes</title>
-  </links>
-  <links type="topic" ui:expanded="true" groups="function" style="linklist">
-    <title>Functions</title>
-  </links>
-  <links type="topic" ui:expanded="true" groups="#first #default #last" style="linklist">
-    <title>Other</title>
-  </links>
-</%block>
-<%block name="details">
-<terms>
-% for constant in formatter.collect('constant'):
-<%include file="${language}/constant.tmpl" args="constant=constant"/>
-% endfor
-</terms>
-</%block>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+          "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"; [
+    <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
+    <!ENTITY version SYSTEM "version.xml">
+]>
+<book xml:id="${node.name}" xmlns="http://docbook.org/ns/docbook"; version="5.0">
+  <title>%{node.name} Documentation</title>
 
-<%block name="since_version">
-</%block>
+  % for node in formatter.get_children(node):
+    % if formatter.should_render_node(node):
+      ${writer.render_child(child)}
+    % endif
+  % endfor
+</book>
diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py
index 702a469..2c9f5a2 100644
--- a/giscanner/docwriter.py
+++ b/giscanner/docwriter.py
@@ -33,56 +33,6 @@ from mako.lookup import TemplateLookup
 from . import ast, xmlwriter
 from .utils import to_underscores
 
-
-def make_page_id(node, recursive=False):
-    if isinstance(node, ast.Namespace):
-        if recursive:
-            return node.name
-        else:
-            return 'index'
-
-    if hasattr(node, '_chain') and node._chain:
-        parent = node._chain[-1]
-    else:
-        parent = None
-
-    if parent is None:
-        return '%s.%s' % (node.namespace.name, node.name)
-
-    if isinstance(node, (ast.Property, ast.Signal, ast.VFunction)):
-        return '%s-%s' % (make_page_id(parent, recursive=True), node.name)
-    else:
-        return '%s.%s' % (make_page_id(parent, recursive=True), node.name)
-
-
-def get_node_kind(node):
-    if isinstance(node, ast.Namespace):
-        node_kind = 'namespace'
-    elif isinstance(node, (ast.Class, ast.Interface)):
-        node_kind = 'class'
-    elif isinstance(node, ast.Record):
-        node_kind = 'record'
-    elif isinstance(node, ast.Function):
-        if node.is_method:
-            node_kind = 'method'
-        elif node.is_constructor:
-            node_kind = 'constructor'
-        else:
-            node_kind = 'function'
-    elif isinstance(node, ast.Enum):
-        node_kind = 'enum'
-    elif isinstance(node, ast.Property) and node.parent is not None:
-        node_kind = 'property'
-    elif isinstance(node, ast.Signal) and node.parent is not None:
-        node_kind = 'signal'
-    elif isinstance(node, ast.VFunction) and node.parent is not None:
-        node_kind = 'vfunc'
-    else:
-        node_kind = 'default'
-
-    return node_kind
-
-
 class TemplatedScanner(object):
     def __init__(self, specs):
         self.specs = self.unmangle_specs(specs)
@@ -172,21 +122,11 @@ class DocFormatter(object):
         return saxutils.escape(text)
 
     def should_render_node(self, node):
-        if isinstance(node, ast.Constant):
-            return False
-
         if getattr(node, "private", False):
             return False
 
         return True
 
-    def collect(self, type_name):
-        namespace = self._transformer.namespace
-        type_ = {'constant': ast.Constant}[type_name]
-        for item in namespace.itervalues():
-            if isinstance(item, type_):
-                yield item
-
     def format(self, node, doc):
         if doc is None:
             return ''
@@ -327,31 +267,6 @@ class DocFormatter(object):
     def format_type(self, type_):
         raise NotImplementedError
 
-    def format_page_name(self, node):
-        if isinstance(node, ast.Namespace):
-            return 'Index'
-        elif isinstance(node, ast.Function):
-            return self.format_function_name(node)
-        elif isinstance(node, ast.Property) and node.parent is not None:
-            return '%s:%s' % (self.format_page_name(node.parent), node.name)
-        elif isinstance(node, ast.Signal) and node.parent is not None:
-            return '%s::%s' % (self.format_page_name(node.parent), node.name)
-        elif isinstance(node, ast.VFunction) and node.parent is not None:
-            return '%s::%s' % (self.format_page_name(node.parent), node.name)
-        else:
-            return make_page_id(node)
-
-    def format_xref(self, node, **attrdict):
-        if node is None:
-            attrs = [('xref', 'index')] + attrdict.items()
-            return xmlwriter.build_xml_tag('link', attrs)
-        elif isinstance(node, ast.Member):
-            # Enum/BitField members are linked to the main enum page.
-            return self.format_xref(node.parent, **attrdict) + '.' + node.name
-        else:
-            attrs = [('xref', make_page_id(node))] + attrdict.items()
-            return xmlwriter.build_xml_tag('link', attrs)
-
     def format_property_flags(self, property_, construct_only=False):
         flags = []
         if property_.readable and not construct_only:
@@ -661,47 +576,16 @@ class DocWriter(object):
                               output_encoding='utf-8')
 
     def write(self, output):
-        try:
-            os.makedirs(output)
-        except OSError:
-            # directory already made
-            pass
-
-        self._walk_node(output, self._transformer.namespace, [])
-        self._transformer.namespace.walk(lambda node, chain: self._walk_node(output, node, chain))
-
-    def _walk_node(self, output, node, chain):
-        if isinstance(node, ast.Section):
-            return False
-        if isinstance(node, ast.Function) and node.moved_to is not None:
-            return False
-        if getattr(node, 'disguised', False):
-            return False
-        if self._formatter.should_render_node(node):
-            self._render_node(node, chain, output)
-            return True
-        return False
-
-    def _render_node(self, node, chain, output):
-        namespace = self._transformer.namespace
-
-        # A bit of a hack...maybe this should be an official API
-        node._chain = list(chain)
+        result = self.render_node(self._transformer.namespace)
+        fp = open(output, 'w')
+        fp.write(result)
+        fp.close()
 
+    def render_node(self, node):
         page_kind = get_node_kind(node)
         template_name = '%s/%s.tmpl' % (self._language, page_kind)
-        page_id = make_page_id(node)
 
         template = self._lookup.get_template(template_name)
-        result = template.render(namespace=namespace,
-                                 language=self._language,
-                                 node=node,
-                                 page_id=page_id,
-                                 page_kind=page_kind,
-                                 formatter=self._formatter)
-
-        output_file_name = os.path.join(os.path.abspath(output),
-                                        page_id + '.page')
-        fp = open(output_file_name, 'w')
-        fp.write(result)
-        fp.close()
+        return template.render(node=node,
+                               formatter=self._formatter,
+                               writer=self)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]