[Checkins] SVN: z3c.rml/trunk/src/z3c/rml/ Initial script to
generate the DTD for RML. The DTD is not complete yet,
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Mar 28 03:34:08 EDT 2007
Log message for revision 73814:
Initial script to generate the DTD for RML. The DTD is not complete yet,
since I have not completed all the signatures yet.
Changed:
U z3c.rml/trunk/src/z3c/rml/chart.py
U z3c.rml/trunk/src/z3c/rml/document.py
A z3c.rml/trunk/src/z3c/rml/dtd.py
U z3c.rml/trunk/src/z3c/rml/flowable.py
U z3c.rml/trunk/src/z3c/rml/template.py
-=-
Modified: z3c.rml/trunk/src/z3c/rml/chart.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/chart.py 2007-03-28 06:24:47 UTC (rev 73813)
+++ z3c.rml/trunk/src/z3c/rml/chart.py 2007-03-28 07:34:06 UTC (rev 73814)
@@ -779,7 +779,11 @@
factories = {'slice': Slice3D}
+class ISimpleLabels(interfaces.IRMLDirectiveSignature):
+ pass
+
class SimpleLabels(directive.RMLDirective):
+ signature = ISimpleLabels
factories = {'label': Name}
def process(self):
Modified: z3c.rml/trunk/src/z3c/rml/document.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/document.py 2007-03-28 06:24:47 UTC (rev 73813)
+++ z3c.rml/trunk/src/z3c/rml/document.py 2007-03-28 07:34:06 UTC (rev 73814)
@@ -164,6 +164,11 @@
class IDocument(interfaces.IRMLDirectiveSignature):
occurence.containing(
occurence.ZeroOrOne('docinit', IDocInit),
+ occurence.ZeroOrOne('stylesheet', stylesheet.IStylesheet),
+ occurence.ZeroOrOne('template', template.ITemplate),
+ occurence.ZeroOrOne('story', template.IStory),
+ occurence.ZeroOrOne('pageInfo', canvas.IPageInfo),
+ occurence.ZeroOrMore('pageDrawing', canvas.IPageDrawing),
)
filename = attr.String(
Added: z3c.rml/trunk/src/z3c/rml/dtd.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/dtd.py 2007-03-28 06:24:47 UTC (rev 73813)
+++ z3c.rml/trunk/src/z3c/rml/dtd.py 2007-03-28 07:34:06 UTC (rev 73814)
@@ -0,0 +1,75 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Generate a DTD from the code
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+import zope.schema
+
+from z3c.rml import attr, document, occurence
+
+occurence2Symbol = {
+ occurence.ZeroOrMore: '*',
+ occurence.ZeroOrOne: '?',
+ occurence.OneOrMore: '+',
+ }
+
+
+def generateElement(name, signature):
+ if signature is None:
+ return ''
+ # Create the list of sub-elements.
+ subElementList = []
+ for occurence in signature.queryTaggedValue('directives', ()):
+ subElementList.append(
+ occurence.tag + occurence2Symbol[occurence.__class__]
+ )
+ fields = zope.schema.getFields(signature).keys()
+ if len(fields) == 1 and isinstance(fields[0], attr.TextNode):
+ subElementList.append('#PCDATA')
+ subElementList = ','.join(subElementList)
+ if subElementList:
+ subElementList = ' (' + subElementList + ')'
+ text = '\n<!ELEMENT %s%s>' %(name, subElementList)
+ # Create a list of attributes for this element.
+ for attrName, field in zope.schema.getFieldsInOrder(signature):
+ # Create the type
+ if isinstance(field, attr.Choice):
+ type = '(' + '|'.join(field.choices.keys()) + ')'
+ else:
+ type = 'CDATA'
+ # Create required flag
+ if field.required:
+ required = '#REQUIRED'
+ else:
+ required = '#IMPLIED'
+ # Put it all together
+ text += '\n<!ATTLIST %s %s %s %s>' %(name, attrName, type, required)
+ text += '\n'
+ # Walk through all sub-elements, creating th eDTD entries for them.
+ for occurence in signature.queryTaggedValue('directives', ()):
+ text += generateElement(occurence.tag, occurence.signature)
+ return text
+
+
+def generate(useWrapper=False):
+ text = generateElement('document', document.Document.signature)
+ if useWrapper:
+ text = '<!DOCTYPE RML [\n%s]>\n' %text
+ return text
+
+
+if __name__ == '__main__':
+ print generate()
Property changes on: z3c.rml/trunk/src/z3c/rml/dtd.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: z3c.rml/trunk/src/z3c/rml/flowable.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/flowable.py 2007-03-28 06:24:47 UTC (rev 73813)
+++ z3c.rml/trunk/src/z3c/rml/flowable.py 2007-03-28 07:34:06 UTC (rev 73814)
@@ -1045,6 +1045,34 @@
class IFlow(interfaces.IRMLDirectiveSignature):
"""A list of flowables."""
+ occurence.containing(
+ occurence.ZeroOrMore('spacer', ISpacer),
+ occurence.ZeroOrMore('illustration', IIllustration),
+ occurence.ZeroOrMore('pre', IPreformatted),
+ occurence.ZeroOrMore('xpre', IXPreformatted),
+ occurence.ZeroOrMore('plugInFlowable', IPluginFlowable),
+ occurence.ZeroOrMore('barCodeFlowable', IBarCodeFlowable),
+ occurence.ZeroOrMore('outlineAdd', IOutlineAdd),
+ occurence.ZeroOrMore('title', ITitle),
+ occurence.ZeroOrMore('h1', IHeading1),
+ occurence.ZeroOrMore('h2', IHeading2),
+ occurence.ZeroOrMore('h3', IHeading3),
+ occurence.ZeroOrMore('para', IParagraph),
+ occurence.ZeroOrMore('blockTable', IBlockTable),
+ occurence.ZeroOrMore('nextFrame', INextFrame),
+ occurence.ZeroOrMore('setNextFrame', ISetNextFrame),
+ occurence.ZeroOrMore('nextPage', INextPage),
+ occurence.ZeroOrMore('setNextTemplate', ISetNextTemplate),
+ occurence.ZeroOrMore('condPageBreak', IConditionalPageBreak),
+ occurence.ZeroOrMore('keepInFrame', IKeepInFrame),
+ occurence.ZeroOrMore('imageAndFlowables', IImageAndFlowables),
+ occurence.ZeroOrMore('pto', IPTO),
+ occurence.ZeroOrMore('indent', IIndent),
+ occurence.ZeroOrMore('fixedSize', IFixedSize),
+ occurence.ZeroOrMore('bookmark', IBookmark),
+ occurence.ZeroOrMore('hr', IHorizontalRow),
+ occurence.ZeroOrMore('name', special.IName),
+ )
class Flow(directive.RMLDirective):
Modified: z3c.rml/trunk/src/z3c/rml/template.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/template.py 2007-03-28 06:24:47 UTC (rev 73813)
+++ z3c.rml/trunk/src/z3c/rml/template.py 2007-03-28 07:34:06 UTC (rev 73814)
@@ -24,6 +24,8 @@
class IStory(flowable.IFlow):
"""The story of the PDF file."""
+ occurence.containing(
+ *flowable.IFlow.getTaggedValue('directives'))
firstPageTemplate = attr.Text(
title=u'First Page Template',
@@ -197,7 +199,7 @@
class ITemplate(interfaces.IRMLDirectiveSignature):
"""Define a page template."""
occurence.containing(
- occurence.OneOrMore('pagetemplate', IPageTemplate),
+ occurence.OneOrMore('pageTemplate', IPageTemplate),
)
pagesize = attr.PageSize(
More information about the Checkins
mailing list