[Checkins] SVN: z3c.rml/trunk/ Attempt to get scripts for the dtd
and reference generator.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Jun 19 15:34:28 EDT 2007
Log message for revision 76808:
Attempt to get scripts for the dtd and reference generator.
Changed:
_U z3c.rml/trunk/
U z3c.rml/trunk/setup.py
_U z3c.rml/trunk/src/
A z3c.rml/trunk/src/z3c/rml/reference.pt
A z3c.rml/trunk/src/z3c/rml/reference.py
D z3c.rml/trunk/src/z3c/rml/rml-reference.pt
D z3c.rml/trunk/src/z3c/rml/rml-reference.py
-=-
Property changes on: z3c.rml/trunk
___________________________________________________________________
Name: svn:ignore
+ develop-eggs
eggs
parts
.installed.cfg
build
dist
bin
Modified: z3c.rml/trunk/setup.py
===================================================================
--- z3c.rml/trunk/setup.py 2007-06-19 19:26:28 UTC (rev 76807)
+++ z3c.rml/trunk/setup.py 2007-06-19 19:34:27 UTC (rev 76808)
@@ -29,7 +29,7 @@
entry_points = """
[console_scripts]
dtd = z3c.rml.dtd:generate
- reference = z3c.rml.rml-reference:main
+ reference = z3c.rml.reference:main
""",
dependency_links = ['http://download.zope.org/distribution']
)
Property changes on: z3c.rml/trunk/src
___________________________________________________________________
Name: svn:ignore
+ z3c.rml.egg-info
Copied: z3c.rml/trunk/src/z3c/rml/reference.pt (from rev 76787, z3c.rml/trunk/src/z3c/rml/rml-reference.pt)
===================================================================
--- z3c.rml/trunk/src/z3c/rml/reference.pt (rev 0)
+++ z3c.rml/trunk/src/z3c/rml/reference.pt 2007-06-19 19:34:27 UTC (rev 76808)
@@ -0,0 +1,294 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE document SYSTEM "rml.dtd">
+
+<document
+ filename="rml-reference.pdf"
+ xmlns:tal="http://xml.zope.org/namespaces/tal"
+ >
+
+ <docinit>
+ <registerFont name="ZapfDingbats" faceName="ZapfDingbats"
+ encName="StandardEncoding"/>
+ </docinit>
+
+ <stylesheet>
+ <paraStyle
+ name="section-header"
+ fontName="Helvetica-Bold"
+ fontSize="36"
+ leading="42"
+ spaceAfter="30"
+ />
+ <paraStyle
+ name="content"
+ fontName="Times-Roman"
+ fontSize="12"
+ spaceAfter="5"
+ />
+ <paraStyle
+ name="deprecation"
+ fontName="Times-Roman"
+ fontSize="12"
+ textColor="red"
+ />
+ <paraStyle
+ name="attribute-type-name"
+ fontName="Times-Bold"
+ fontSize="14"
+ spaceBefore="10"
+ spaceAfter="5"
+ keepWithNext="true"
+ />
+ <paraStyle
+ name="element-name"
+ fontName="Times-Bold"
+ fontSize="14"
+ spaceBefore="10"
+ spaceAfter="5"
+ keepWithNext="true"
+ />
+ <paraStyle
+ name="element-subtitle"
+ fontName="Times-Bold"
+ fontSize="12"
+ spaceBefore="10"
+ spaceAfter="5"
+ />
+ <paraStyle
+ name="attribute-name"
+ fontName="Times-Roman"
+ fontSize="11"
+ leftIndent="0.5cm"
+ spaceBefore="5"
+ />
+ <paraStyle
+ name="field-deprecation"
+ fontName="Times-Roman"
+ fontSize="10"
+ leftIndent="0.9cm"
+ textColor="red"
+ />
+ <paraStyle
+ name="field-description"
+ fontName="Times-Roman"
+ fontSize="10"
+ leftIndent="0.9cm"
+ />
+ <paraStyle
+ name="sub-directive"
+ fontName="Times-Roman"
+ fontSize="10"
+ leftIndent="0.5cm"
+ />
+ <paraStyle
+ name="example-info"
+ fontName="Times-Roman"
+ fontSize="10"
+ leftIndent="0.5cm"
+ spaceAfter="5"
+ />
+ <paraStyle
+ name="code"
+ fontName="Courier"
+ fontSize="10"
+ leftIndent="0.5cm"
+ />
+ <blockTableStyle id="plain">
+ <blockLeftPadding length="0" />
+ </blockTableStyle>
+ </stylesheet>
+
+ <template
+ pageSize="A4"
+ allowSplitting="true"
+ title="z3c.RML Reference"
+ author="Zope Community">
+
+ <pageTemplate id="first-page">
+ <pageGraphics>
+ <setFont name="Helvetica" size="48" />
+ <drawCenteredString x="10.5cm" y="20cm">
+ z3c.RML Reference
+ </drawCenteredString>
+ <setFont name="Helvetica" size="24" />
+ <drawCenteredString x="10.5cm" y="18.5cm">
+ Version 0.5
+ </drawCenteredString>
+ </pageGraphics>
+ <frame id="main" x1="3cm" y1="2cm" width="17cm" height="25.7cm" />
+ </pageTemplate>
+
+ <pageTemplate id="main">
+ <frame id="main" x1="2cm" y1="2cm" width="17cm" height="25.7cm" />
+ </pageTemplate>
+
+ </template>
+
+ <story firstPageTemplate="first-page">
+ <setNextTemplate name="main" />
+ <nextPage />
+ <para style="section-header">
+ Introduction
+ </para>
+ <para style="content">
+ RML is a XML dialect for generating PDF files. Like HTML produces a page
+ within the browser, RML produces a PDF file. The RML processor uses the
+ ReportLab library to convert the RML text into a full PDF template.
+ </para>
+ <para style="content">
+ The original version of RML was developed by ReportLab, Inc. as a
+ commercial extension to the free ReportLab library. This original
+ version of RML is still available and supported by ReportLab, Inc. This
+ version of RML, z3c.RML, is a free implementation of the XML dialect
+ based on the available documentation. While it tries to keep some level
+ of compatibility with the original version of RML, it is intended to
+ provde a as clean and feature-rich API as possible.
+ </para>
+ <para style="content">
+ The contents of this document is auto-generated from the code itself and
+ should thus be very accurate and complete.
+ </para>
+
+ <nextPage />
+ <para style="section-header">
+ Attribute Types
+ </para>
+ <outlineAdd>Attribute Types</outlineAdd>
+ <para style="content">
+ This section list the types of attributes used for the attributes within
+ the RML elements.
+ </para>
+ <spacer length="0.5cm" />
+ <tal:block repeat="type context/types">
+ <para style="attribute-type-name" tal:content="type/name">
+ Attribute Name
+ </para>
+ <outlineAdd level="1" tal:content="type/name">Attribute Name</outlineAdd>
+ <para style="content" tal:content="type/description">
+ Attribute purpose and data description.
+ </para>
+ </tal:block>
+
+ <nextPage />
+ <para style="section-header">
+ Directives
+ </para>
+ <outlineAdd>Directives</outlineAdd>
+ <tal:block repeat="directive context/directives">
+ <para style="element-name" tal:content="directive/name">
+ Element Name
+ </para>
+ <outlineAdd level="1" tal:content="directive/name">
+ Element Name
+ </outlineAdd>
+ <bookmark tal:attributes="name directive/id"/>
+ <para style="deprecation"
+ tal:condition="directive/deprecated">
+ <b>Deprecated:</b>
+ <tal:block tal:content="directive/reason">Reason</tal:block>
+ </para>
+ <para style="content" tal:content="directive/description">
+ What is this element doing?
+ </para>
+
+ <tal:block condition="directive/attributes">
+ <para style="element-subtitle">
+ <i>Attributes</i>
+ </para>
+ <tal:block repeat="attr directive/attributes">
+ <para style="attribute-name">
+ <b tal:content="attr/name">para</b>
+ <tal:block condition="attr/required">
+ <i>(required)</i>
+ </tal:block>
+ -
+ <tal:block content="attr/type">Type</tal:block>
+ </para>
+ <para style="field-deprecation"
+ tal:condition="attr/deprecated">
+ <b>Deprecated:</b>
+ <tal:block tal:content="attr/reason">Reason</tal:block>
+ </para>
+ <para style="field-description"
+ tal:condition="attr/title">
+ <i tal:content="attr/title">Title</i>:
+ <tal:block tal:content="attr/description">Description</tal:block>
+ </para>
+ </tal:block>
+ </tal:block>
+
+ <tal:block define="attr directive/content"
+ condition="directive/content">
+ <para style="element-subtitle">
+ <i>Content</i>
+ </para>
+ <para style="attribute-name">
+ <tal:block content="attr/type">Type</tal:block>
+ <tal:block condition="attr/required">
+ <i>(required)</i>
+ </tal:block>
+ </para>
+ <para style="field-description"
+ tal:condition="attr/title">
+ <i tal:content="attr/title">Title</i>:
+ <tal:block tal:content="attr/description">Description</tal:block>
+ </para>
+ </tal:block>
+
+ <tal:block condition="directive/sub-directives">
+ <para style="element-subtitle">
+ <i>Sub-Directives</i>
+ </para>
+ <link destination=""
+ tal:repeat="directive directive/sub-directives"
+ tal:attributes="destination directive/id">
+ <para style="sub-directive">
+ <font color="blue">
+ <b tal:content="directive/name">para</b>
+ </font>
+ <i>
+ (<tal:block replace="directive/occurence">ZeroOrMore</tal:block>)
+ </i>
+ <font color="red" tal:condition="directive/deprecated">
+ <i>(Deprecated)</i>
+ </font>
+ </para>
+ </link>
+ </tal:block>
+
+ <tal:block condition="directive/examples">
+ <para style="element-subtitle">
+ <i>Examples</i>
+ </para>
+ <tal:block repeat="example directive/examples">
+ <xpre style="code" tal:content="structure example/code">
+ Example Code
+ </xpre>
+ <blockTable style="plain">
+ <tr>
+ <td>
+ <para style="example-info">
+ (Extracted from file
+ <link href="" tal:attributes="href example/rmlurl">
+ <i tal:content="example/filename">File</i>,
+ </link>
+ line <tal:block replace="example/line" />)
+ </para>
+ </td>
+ <td>
+ <para>
+ <link href="" tal:attributes="href example/pdfurl">
+ <font color="blue">[PDF]</font>
+ </link>
+ </para>
+ </td>
+ </tr>
+ </blockTable>
+ </tal:block>
+ </tal:block>
+
+ </tal:block>
+
+ </story>
+
+</document>
Copied: z3c.rml/trunk/src/z3c/rml/reference.py (from rev 76807, z3c.rml/trunk/src/z3c/rml/rml-reference.py)
===================================================================
--- z3c.rml/trunk/src/z3c/rml/reference.py (rev 0)
+++ z3c.rml/trunk/src/z3c/rml/reference.py 2007-06-19 19:34:27 UTC (rev 76808)
@@ -0,0 +1,253 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""RML Reference Generator
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+import copy
+import re
+import os
+import zope.schema
+import zope.schema.interfaces
+from lxml import etree
+from xml.sax import saxutils
+from z3c.rml import attr, document, interfaces, pagetemplate
+
+try:
+ import SilverCity
+except ImportError:
+ SilverCity = None
+
+
+INPUT_URL = ('http://svn.zope.org/*checkout*/z3c.rml/trunk/src/z3c/'
+ 'rml/tests/input/%s')
+EXPECTED_URL = ('http://svn.zope.org/z3c.rml/trunk/src/z3c/'
+ 'rml/tests/expected/%s?view=auto')
+EXAMPLES_DIRECTORY = os.path.join(os.path.dirname(__file__), 'tests', 'input')
+IGNORE_ATTRIBUTES = ('RMLAttribute', 'BaseChoice')
+CONTENT_FIELD_TYPES = (
+ attr.TextNode, attr.TextNodeSequence, attr.TextNodeGrid,
+ attr.RawXMLContent, attr.XMLContent)
+STYLES_FORMATTING = {
+ 1 : ('<font textColor="red">', '</font>'),
+ #3 : ('<font textColor="blue">', '</font>'),
+ 6 : ('<font textColor="blue">', '</font>'),
+ 11 : ('<font textColor="red">', '</font>'),
+ }
+EXAMPLE_NS = 'http://namespaces.zope.org/rml/doc'
+EXAMPLE_ATTR_NAME = '{%s}example' %EXAMPLE_NS
+
+
+def dedent(rml):
+ spaces = re.findall('\n( *)<', rml)
+ if not spaces:
+ return rml
+ least = min([len(s) for s in spaces if s != ''])
+ return rml.replace('\n'+' '*least, '\n')
+
+
+def enforceColumns(rml, columns=80):
+ result = []
+ for line in rml.split('\n'):
+ if len(line) <= columns:
+ result.append(line)
+ continue
+ # Determine the indentation for all other lines
+ lineStart = re.findall('^( *<[a-zA-Z0-9]+ )', line)
+ lineIndent = 0
+ if lineStart:
+ lineIndent = len(lineStart[0])
+ # Create lines having at most the specified number of columns
+ while len(line) > columns:
+ end = line[:columns].rfind(' ')
+ result.append(line[:end])
+ line = ' '*lineIndent + line[end+1:]
+ result.append(line)
+
+ return '\n'.join(result)
+
+def highlightRML(rml):
+ if SilverCity is None:
+ return rml
+ lexer = SilverCity.XML.XMLLexer()
+ styledRml = ''
+ for piece in lexer.tokenize_by_style(rml):
+ start, end = STYLES_FORMATTING.get(piece['style'], ('', ''))
+ styledRml += start + saxutils.escape(piece['text']) + end
+ return styledRml
+
+
+def removeDocAttributes(elem):
+ for name in elem.attrib.keys():
+ if name.startswith('{'+EXAMPLE_NS+'}'):
+ del elem.attrib[name]
+ for child in elem.getchildren():
+ removeDocAttributes(child)
+
+
+def getAttributeTypes():
+ types = []
+ candidates = sorted(attr.__dict__.items(), key=lambda e: e[0])
+ for name, candidate in candidates:
+ if not (isinstance(candidate, type) and
+ zope.schema.interfaces.IField.implementedBy(candidate) and
+ name not in IGNORE_ATTRIBUTES):
+ continue
+ types.append({
+ 'name': name,
+ 'description': candidate.__doc__
+ })
+ return types
+
+
+def formatField(field):
+ return field.__class__.__name__
+
+def formatChoice(field):
+ choices = ', '.join([repr(choice) for choice in field.choices.keys()])
+ return '%s of (%s)' %(field.__class__.__name__, choices)
+
+def formatSequence(field):
+ vtFormatter = typeFormatters.get(field.value_type.__class__, formatField)
+ return '%s of %s' %(field.__class__.__name__, vtFormatter(field.value_type))
+
+def formatGrid(field):
+ vtFormatter = typeFormatters.get(field.value_type.__class__, formatField)
+ return '%s with %i cols of %s' %(
+ field.__class__.__name__, field.columns, vtFormatter(field.value_type))
+
+def formatCombination(field):
+ vts = [typeFormatters.get(vt.__class__, formatField)(vt)
+ for vt in field.value_types]
+ return '%s of %s' %(field.__class__.__name__, ', '.join(vts))
+
+typeFormatters = {
+ attr.Choice: formatChoice,
+ attr.Sequence: formatSequence,
+ attr.Combination: formatCombination,
+ attr.TextNodeSequence: formatSequence,
+ attr.TextNodeGrid: formatGrid}
+
+def processSignature(name, signature, examples, directives=None):
+ if directives is None:
+ directives = {}
+ # Process this directive
+ if signature not in directives:
+ info = {'name': name, 'description': signature.getDoc(),
+ 'id': str(hash(signature)), 'deprecated': False}
+ # If directive is deprecated, then add some info
+ if interfaces.IDeprecatedDirective.providedBy(signature):
+ info['deprecated'] = True
+ info['reason'] = signature.getTaggedValue('deprecatedReason')
+ attrs = []
+ content = None
+ for fname, field in zope.schema.getFieldsInOrder(signature):
+ # Handle the case, where the field describes the content
+ typeFormatter = typeFormatters.get(field.__class__, formatField)
+ fieldInfo = {
+ 'name': fname,
+ 'type': typeFormatter(field),
+ 'title': field.title,
+ 'description': field.description,
+ 'required': field.required,
+ 'deprecated': False,
+ }
+ if field.__class__ in CONTENT_FIELD_TYPES:
+ content = fieldInfo
+ else:
+ attrs.append(fieldInfo)
+
+ # Add a separate entry for the deprecated field
+ if interfaces.IDeprecated.providedBy(field):
+ deprFieldInfo = fieldInfo.copy()
+ deprFieldInfo['deprecated'] = True
+ deprFieldInfo['name'] = field.deprecatedName
+ deprFieldInfo['reason'] = field.deprecatedReason
+ attrs.append(deprFieldInfo)
+
+ info['attributes'] = attrs
+ info['content'] = content
+ # Examples can be either gotten by interface path or tag name
+ ifacePath = signature.__module__ + '.' + signature.__name__
+ if ifacePath in examples:
+ info['examples'] = examples[ifacePath]
+ else:
+ info['examples'] = examples.get(name, None)
+
+ subs = []
+ for occurence in signature.queryTaggedValue('directives', ()):
+ subs.append({
+ 'name': occurence.tag,
+ 'occurence': occurence.__class__.__name__,
+ 'deprecated': interfaces.IDeprecatedDirective.providedBy(
+ occurence.signature),
+ 'id': str(hash(occurence.signature))
+ })
+ info['sub-directives'] = subs
+ directives[signature] = info
+ # Process Children
+ for occurence in signature.queryTaggedValue('directives', ()):
+ processSignature(occurence.tag, occurence.signature,
+ examples, directives)
+
+
+def extractExamples(directory):
+ examples = {}
+ for filename in os.listdir(directory):
+ if not filename.endswith('.rml'):
+ continue
+ rmlFile = open(os.path.join(directory, filename), 'r')
+ root = etree.parse(rmlFile).getroot()
+ elements = root.xpath('//@doc:example/parent::*',
+ {'doc': EXAMPLE_NS})
+ # Phase 1: Collect all elements
+ for elem in elements:
+ demoTag = elem.get(EXAMPLE_ATTR_NAME) or elem.tag
+ elemExamples = examples.setdefault(demoTag, [])
+ elemExamples.append({
+ 'filename': filename,
+ 'line': elem.sourceline,
+ 'element': elem,
+ 'rmlurl': INPUT_URL %filename,
+ 'pdfurl': EXPECTED_URL %(filename[:-4]+'.pdf')
+ })
+ # Phase 2: Render all elements
+ removeDocAttributes(root)
+ for dirExamples in examples.values():
+ for example in dirExamples:
+ xml = etree.tounicode(example['element']).strip()
+ xml = dedent(xml)
+ xml = enforceColumns(xml, 80)
+ xml = highlightRML(xml)
+ example['code'] = xml
+
+ return examples
+
+
+def main():
+ examples = extractExamples(EXAMPLES_DIRECTORY)
+
+ template = pagetemplate.RMLPageTemplateFile('reference.pt')
+
+ directives = {}
+ processSignature('document', document.IDocument, examples, directives)
+ directives = sorted(directives.values(), key=lambda d: d['name'])
+
+ pdf = template(types=getAttributeTypes(), directives=directives)
+ open('rml-reference.pdf', 'wb').write(pdf)
+
+
+if __name__ == '__main__':
+ main()
Deleted: z3c.rml/trunk/src/z3c/rml/rml-reference.pt
===================================================================
--- z3c.rml/trunk/src/z3c/rml/rml-reference.pt 2007-06-19 19:26:28 UTC (rev 76807)
+++ z3c.rml/trunk/src/z3c/rml/rml-reference.pt 2007-06-19 19:34:27 UTC (rev 76808)
@@ -1,294 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE document SYSTEM "rml.dtd">
-
-<document
- filename="rml-reference.pdf"
- xmlns:tal="http://xml.zope.org/namespaces/tal"
- >
-
- <docinit>
- <registerFont name="ZapfDingbats" faceName="ZapfDingbats"
- encName="StandardEncoding"/>
- </docinit>
-
- <stylesheet>
- <paraStyle
- name="section-header"
- fontName="Helvetica-Bold"
- fontSize="36"
- leading="42"
- spaceAfter="30"
- />
- <paraStyle
- name="content"
- fontName="Times-Roman"
- fontSize="12"
- spaceAfter="5"
- />
- <paraStyle
- name="deprecation"
- fontName="Times-Roman"
- fontSize="12"
- textColor="red"
- />
- <paraStyle
- name="attribute-type-name"
- fontName="Times-Bold"
- fontSize="14"
- spaceBefore="10"
- spaceAfter="5"
- keepWithNext="true"
- />
- <paraStyle
- name="element-name"
- fontName="Times-Bold"
- fontSize="14"
- spaceBefore="10"
- spaceAfter="5"
- keepWithNext="true"
- />
- <paraStyle
- name="element-subtitle"
- fontName="Times-Bold"
- fontSize="12"
- spaceBefore="10"
- spaceAfter="5"
- />
- <paraStyle
- name="attribute-name"
- fontName="Times-Roman"
- fontSize="11"
- leftIndent="0.5cm"
- spaceBefore="5"
- />
- <paraStyle
- name="field-deprecation"
- fontName="Times-Roman"
- fontSize="10"
- leftIndent="0.9cm"
- textColor="red"
- />
- <paraStyle
- name="field-description"
- fontName="Times-Roman"
- fontSize="10"
- leftIndent="0.9cm"
- />
- <paraStyle
- name="sub-directive"
- fontName="Times-Roman"
- fontSize="10"
- leftIndent="0.5cm"
- />
- <paraStyle
- name="example-info"
- fontName="Times-Roman"
- fontSize="10"
- leftIndent="0.5cm"
- spaceAfter="5"
- />
- <paraStyle
- name="code"
- fontName="Courier"
- fontSize="10"
- leftIndent="0.5cm"
- />
- <blockTableStyle id="plain">
- <blockLeftPadding length="0" />
- </blockTableStyle>
- </stylesheet>
-
- <template
- pageSize="A4"
- allowSplitting="true"
- title="z3c.RML Reference"
- author="Zope Community">
-
- <pageTemplate id="first-page">
- <pageGraphics>
- <setFont name="Helvetica" size="48" />
- <drawCenteredString x="10.5cm" y="20cm">
- z3c.RML Reference
- </drawCenteredString>
- <setFont name="Helvetica" size="24" />
- <drawCenteredString x="10.5cm" y="18.5cm">
- Version 0.5
- </drawCenteredString>
- </pageGraphics>
- <frame id="main" x1="3cm" y1="2cm" width="17cm" height="25.7cm" />
- </pageTemplate>
-
- <pageTemplate id="main">
- <frame id="main" x1="2cm" y1="2cm" width="17cm" height="25.7cm" />
- </pageTemplate>
-
- </template>
-
- <story firstPageTemplate="first-page">
- <setNextTemplate name="main" />
- <nextPage />
- <para style="section-header">
- Introduction
- </para>
- <para style="content">
- RML is a XML dialect for generating PDF files. Like HTML produces a page
- within the browser, RML produces a PDF file. The RML processor uses the
- ReportLab library to convert the RML text into a full PDF template.
- </para>
- <para style="content">
- The original version of RML was developed by ReportLab, Inc. as a
- commercial extension to the free ReportLab library. This original
- version of RML is still available and supported by ReportLab, Inc. This
- version of RML, z3c.RML, is a free implementation of the XML dialect
- based on the available documentation. While it tries to keep some level
- of compatibility with the original version of RML, it is intended to
- provde a as clean and feature-rich API as possible.
- </para>
- <para style="content">
- The contents of this document is auto-generated from the code itself and
- should thus be very accurate and complete.
- </para>
-
- <nextPage />
- <para style="section-header">
- Attribute Types
- </para>
- <outlineAdd>Attribute Types</outlineAdd>
- <para style="content">
- This section list the types of attributes used for the attributes within
- the RML elements.
- </para>
- <spacer length="0.5cm" />
- <tal:block repeat="type context/types">
- <para style="attribute-type-name" tal:content="type/name">
- Attribute Name
- </para>
- <outlineAdd level="1" tal:content="type/name">Attribute Name</outlineAdd>
- <para style="content" tal:content="type/description">
- Attribute purpose and data description.
- </para>
- </tal:block>
-
- <nextPage />
- <para style="section-header">
- Directives
- </para>
- <outlineAdd>Directives</outlineAdd>
- <tal:block repeat="directive context/directives">
- <para style="element-name" tal:content="directive/name">
- Element Name
- </para>
- <outlineAdd level="1" tal:content="directive/name">
- Element Name
- </outlineAdd>
- <bookmark tal:attributes="name directive/id"/>
- <para style="deprecation"
- tal:condition="directive/deprecated">
- <b>Deprecated:</b>
- <tal:block tal:content="directive/reason">Reason</tal:block>
- </para>
- <para style="content" tal:content="directive/description">
- What is this element doing?
- </para>
-
- <tal:block condition="directive/attributes">
- <para style="element-subtitle">
- <i>Attributes</i>
- </para>
- <tal:block repeat="attr directive/attributes">
- <para style="attribute-name">
- <b tal:content="attr/name">para</b>
- <tal:block condition="attr/required">
- <i>(required)</i>
- </tal:block>
- -
- <tal:block content="attr/type">Type</tal:block>
- </para>
- <para style="field-deprecation"
- tal:condition="attr/deprecated">
- <b>Deprecated:</b>
- <tal:block tal:content="attr/reason">Reason</tal:block>
- </para>
- <para style="field-description"
- tal:condition="attr/title">
- <i tal:content="attr/title">Title</i>:
- <tal:block tal:content="attr/description">Description</tal:block>
- </para>
- </tal:block>
- </tal:block>
-
- <tal:block define="attr directive/content"
- condition="directive/content">
- <para style="element-subtitle">
- <i>Content</i>
- </para>
- <para style="attribute-name">
- <tal:block content="attr/type">Type</tal:block>
- <tal:block condition="attr/required">
- <i>(required)</i>
- </tal:block>
- </para>
- <para style="field-description"
- tal:condition="attr/title">
- <i tal:content="attr/title">Title</i>:
- <tal:block tal:content="attr/description">Description</tal:block>
- </para>
- </tal:block>
-
- <tal:block condition="directive/sub-directives">
- <para style="element-subtitle">
- <i>Sub-Directives</i>
- </para>
- <link destination=""
- tal:repeat="directive directive/sub-directives"
- tal:attributes="destination directive/id">
- <para style="sub-directive">
- <font color="blue">
- <b tal:content="directive/name">para</b>
- </font>
- <i>
- (<tal:block replace="directive/occurence">ZeroOrMore</tal:block>)
- </i>
- <font color="red" tal:condition="directive/deprecated">
- <i>(Deprecated)</i>
- </font>
- </para>
- </link>
- </tal:block>
-
- <tal:block condition="directive/examples">
- <para style="element-subtitle">
- <i>Examples</i>
- </para>
- <tal:block repeat="example directive/examples">
- <xpre style="code" tal:content="structure example/code">
- Example Code
- </xpre>
- <blockTable style="plain">
- <tr>
- <td>
- <para style="example-info">
- (Extracted from file
- <link href="" tal:attributes="href example/rmlurl">
- <i tal:content="example/filename">File</i>,
- </link>
- line <tal:block replace="example/line" />)
- </para>
- </td>
- <td>
- <para>
- <link href="" tal:attributes="href example/pdfurl">
- <font color="blue">[PDF]</font>
- </link>
- </para>
- </td>
- </tr>
- </blockTable>
- </tal:block>
- </tal:block>
-
- </tal:block>
-
- </story>
-
-</document>
Deleted: z3c.rml/trunk/src/z3c/rml/rml-reference.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/rml-reference.py 2007-06-19 19:26:28 UTC (rev 76807)
+++ z3c.rml/trunk/src/z3c/rml/rml-reference.py 2007-06-19 19:34:27 UTC (rev 76808)
@@ -1,253 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""RML Reference Generator
-
-$Id$
-"""
-__docformat__ = "reStructuredText"
-import copy
-import re
-import os
-import zope.schema
-import zope.schema.interfaces
-from lxml import etree
-from xml.sax import saxutils
-from z3c.rml import attr, document, interfaces, pagetemplate
-
-try:
- import SilverCity
-except ImportError:
- SilverCity = None
-
-
-INPUT_URL = ('http://svn.zope.org/*checkout*/z3c.rml/trunk/src/z3c/'
- 'rml/tests/input/%s')
-EXPECTED_URL = ('http://svn.zope.org/z3c.rml/trunk/src/z3c/'
- 'rml/tests/expected/%s?view=auto')
-EXAMPLES_DIRECTORY = os.path.join(os.path.dirname(__file__), 'tests', 'input')
-IGNORE_ATTRIBUTES = ('RMLAttribute', 'BaseChoice')
-CONTENT_FIELD_TYPES = (
- attr.TextNode, attr.TextNodeSequence, attr.TextNodeGrid,
- attr.RawXMLContent, attr.XMLContent)
-STYLES_FORMATTING = {
- 1 : ('<font textColor="red">', '</font>'),
- #3 : ('<font textColor="blue">', '</font>'),
- 6 : ('<font textColor="blue">', '</font>'),
- 11 : ('<font textColor="red">', '</font>'),
- }
-EXAMPLE_NS = 'http://namespaces.zope.org/rml/doc'
-EXAMPLE_ATTR_NAME = '{%s}example' %EXAMPLE_NS
-
-
-def dedent(rml):
- spaces = re.findall('\n( *)<', rml)
- if not spaces:
- return rml
- least = min([len(s) for s in spaces if s != ''])
- return rml.replace('\n'+' '*least, '\n')
-
-
-def enforceColumns(rml, columns=80):
- result = []
- for line in rml.split('\n'):
- if len(line) <= columns:
- result.append(line)
- continue
- # Determine the indentation for all other lines
- lineStart = re.findall('^( *<[a-zA-Z0-9]+ )', line)
- lineIndent = 0
- if lineStart:
- lineIndent = len(lineStart[0])
- # Create lines having at most the specified number of columns
- while len(line) > columns:
- end = line[:columns].rfind(' ')
- result.append(line[:end])
- line = ' '*lineIndent + line[end+1:]
- result.append(line)
-
- return '\n'.join(result)
-
-def highlightRML(rml):
- if SilverCity is None:
- return rml
- lexer = SilverCity.XML.XMLLexer()
- styledRml = ''
- for piece in lexer.tokenize_by_style(rml):
- start, end = STYLES_FORMATTING.get(piece['style'], ('', ''))
- styledRml += start + saxutils.escape(piece['text']) + end
- return styledRml
-
-
-def removeDocAttributes(elem):
- for name in elem.attrib.keys():
- if name.startswith('{'+EXAMPLE_NS+'}'):
- del elem.attrib[name]
- for child in elem.getchildren():
- removeDocAttributes(child)
-
-
-def getAttributeTypes():
- types = []
- candidates = sorted(attr.__dict__.items(), key=lambda e: e[0])
- for name, candidate in candidates:
- if not (isinstance(candidate, type) and
- zope.schema.interfaces.IField.implementedBy(candidate) and
- name not in IGNORE_ATTRIBUTES):
- continue
- types.append({
- 'name': name,
- 'description': candidate.__doc__
- })
- return types
-
-
-def formatField(field):
- return field.__class__.__name__
-
-def formatChoice(field):
- choices = ', '.join([repr(choice) for choice in field.choices.keys()])
- return '%s of (%s)' %(field.__class__.__name__, choices)
-
-def formatSequence(field):
- vtFormatter = typeFormatters.get(field.value_type.__class__, formatField)
- return '%s of %s' %(field.__class__.__name__, vtFormatter(field.value_type))
-
-def formatGrid(field):
- vtFormatter = typeFormatters.get(field.value_type.__class__, formatField)
- return '%s with %i cols of %s' %(
- field.__class__.__name__, field.columns, vtFormatter(field.value_type))
-
-def formatCombination(field):
- vts = [typeFormatters.get(vt.__class__, formatField)(vt)
- for vt in field.value_types]
- return '%s of %s' %(field.__class__.__name__, ', '.join(vts))
-
-typeFormatters = {
- attr.Choice: formatChoice,
- attr.Sequence: formatSequence,
- attr.Combination: formatCombination,
- attr.TextNodeSequence: formatSequence,
- attr.TextNodeGrid: formatGrid}
-
-def processSignature(name, signature, examples, directives=None):
- if directives is None:
- directives = {}
- # Process this directive
- if signature not in directives:
- info = {'name': name, 'description': signature.getDoc(),
- 'id': str(hash(signature)), 'deprecated': False}
- # If directive is deprecated, then add some info
- if interfaces.IDeprecatedDirective.providedBy(signature):
- info['deprecated'] = True
- info['reason'] = signature.getTaggedValue('deprecatedReason')
- attrs = []
- content = None
- for fname, field in zope.schema.getFieldsInOrder(signature):
- # Handle the case, where the field describes the content
- typeFormatter = typeFormatters.get(field.__class__, formatField)
- fieldInfo = {
- 'name': fname,
- 'type': typeFormatter(field),
- 'title': field.title,
- 'description': field.description,
- 'required': field.required,
- 'deprecated': False,
- }
- if field.__class__ in CONTENT_FIELD_TYPES:
- content = fieldInfo
- else:
- attrs.append(fieldInfo)
-
- # Add a separate entry for the deprecated field
- if interfaces.IDeprecated.providedBy(field):
- deprFieldInfo = fieldInfo.copy()
- deprFieldInfo['deprecated'] = True
- deprFieldInfo['name'] = field.deprecatedName
- deprFieldInfo['reason'] = field.deprecatedReason
- attrs.append(deprFieldInfo)
-
- info['attributes'] = attrs
- info['content'] = content
- # Examples can be either gotten by interface path or tag name
- ifacePath = signature.__module__ + '.' + signature.__name__
- if ifacePath in examples:
- info['examples'] = examples[ifacePath]
- else:
- info['examples'] = examples.get(name, None)
-
- subs = []
- for occurence in signature.queryTaggedValue('directives', ()):
- subs.append({
- 'name': occurence.tag,
- 'occurence': occurence.__class__.__name__,
- 'deprecated': interfaces.IDeprecatedDirective.providedBy(
- occurence.signature),
- 'id': str(hash(occurence.signature))
- })
- info['sub-directives'] = subs
- directives[signature] = info
- # Process Children
- for occurence in signature.queryTaggedValue('directives', ()):
- processSignature(occurence.tag, occurence.signature,
- examples, directives)
-
-
-def extractExamples(directory):
- examples = {}
- for filename in os.listdir(directory):
- if not filename.endswith('.rml'):
- continue
- rmlFile = open(os.path.join(directory, filename), 'r')
- root = etree.parse(rmlFile).getroot()
- elements = root.xpath('//@doc:example/parent::*',
- {'doc': EXAMPLE_NS})
- # Phase 1: Collect all elements
- for elem in elements:
- demoTag = elem.get(EXAMPLE_ATTR_NAME) or elem.tag
- elemExamples = examples.setdefault(demoTag, [])
- elemExamples.append({
- 'filename': filename,
- 'line': elem.sourceline,
- 'element': elem,
- 'rmlurl': INPUT_URL %filename,
- 'pdfurl': EXPECTED_URL %(filename[:-4]+'.pdf')
- })
- # Phase 2: Render all elements
- removeDocAttributes(root)
- for dirExamples in examples.values():
- for example in dirExamples:
- xml = etree.tounicode(example['element']).strip()
- xml = dedent(xml)
- xml = enforceColumns(xml, 80)
- xml = highlightRML(xml)
- example['code'] = xml
-
- return examples
-
-
-def main():
- examples = extractExamples(EXAMPLES_DIRECTORY)
-
- template = pagetemplate.RMLPageTemplateFile('rml-reference.pt')
-
- directives = {}
- processSignature('document', document.IDocument, examples, directives)
- directives = sorted(directives.values(), key=lambda d: d['name'])
-
- pdf = template(types=getAttributeTypes(), directives=directives)
- open('rml-reference.pdf', 'wb').write(pdf)
-
-
-if __name__ == '__main__':
- main()
More information about the Checkins
mailing list