[Checkins] SVN: z3c.rmldocument/trunk/src/z3c/rmldocument/ cleanup,
fixed field/data variable names
Christian Theune
ct at gocept.com
Mon May 5 16:44:47 EDT 2008
Log message for revision 86467:
cleanup, fixed field/data variable names
Changed:
U z3c.rmldocument/trunk/src/z3c/rmldocument/README.txt
U z3c.rmldocument/trunk/src/z3c/rmldocument/document.py
U z3c.rmldocument/trunk/src/z3c/rmldocument/examples/example1.rml
U z3c.rmldocument/trunk/src/z3c/rmldocument/interfaces.py
-=-
Modified: z3c.rmldocument/trunk/src/z3c/rmldocument/README.txt
===================================================================
--- z3c.rmldocument/trunk/src/z3c/rmldocument/README.txt 2008-05-05 20:34:11 UTC (rev 86466)
+++ z3c.rmldocument/trunk/src/z3c/rmldocument/README.txt 2008-05-05 20:44:47 UTC (rev 86467)
@@ -26,7 +26,6 @@
... salutation = zope.schema.TextLine(title=u"Salutation")
... years = zope.schema.Int(title=u"Years to go")
-
>>> class Contract(object):
... zope.interface.implements(IContractBlocks, IContractData)
... introduction = """<para>
Modified: z3c.rmldocument/trunk/src/z3c/rmldocument/document.py
===================================================================
--- z3c.rmldocument/trunk/src/z3c/rmldocument/document.py 2008-05-05 20:34:11 UTC (rev 86466)
+++ z3c.rmldocument/trunk/src/z3c/rmldocument/document.py 2008-05-05 20:44:47 UTC (rev 86467)
@@ -17,20 +17,36 @@
"""
import lxml.etree
-import zope.pagetemplate.pagetemplatefile
+import sys
+import z3c.rml.rml2pdf
import z3c.rmldocument.interfaces
-import z3c.rml.rml2pdf
import zope.interface
+import zope.pagetemplate.pagetemplatefile
class DocumentPageTemplateFile(
zope.pagetemplate.pagetemplatefile.PageTemplateFile):
+ def __init__(self, *args, **kw):
+ super(DocumentPageTemplateFile, self).__init__(*args, **kw)
+ self.content_type = 'text/xml'
+
+ def get_path_from_prefix(self, _prefix):
+ # Had to copy this because of fixed _getframe implementation in the
+ # base class.
+ if isinstance(_prefix, str):
+ path = _prefix
+ else:
+ if _prefix is None:
+ _prefix = sys._getframe(3).f_globals
+ path = zope.pagetemplate.pagetemplatefile.package_home(_prefix)
+ return path
+
def pt_getContext(self, args, kwargs):
document = args[0]
context = dict(
document=document,
- data=document.data,
+ fields=document.fields,
blocks=document.blocks)
return context
@@ -39,22 +55,24 @@
"""Preprocess a given block of para-RML to RML.
"""
+ if block is None:
+ return ''
root = lxml.etree.fromstring('<rmlblock xmlns:doc="http://xml.gocept.com/namespaces/rmldoc">'+block+'</rmlblock>')
# Process all value substitutions
- for element in root.iter():
+ for element in root.getiterator():
if element.tag != "{http://xml.gocept.com/namespaces/rmldoc}data":
continue
value = getattr(data, element.get('field'))
- text = str(value) + element.tail
+ text = str(value) + (element.tail or '')
previous = element.getprevious()
parent = element.getparent()
if previous is not None:
- previous.tail += text
+ previous.tail = (previous.tail or '') + text
else:
- parent.text += text
+ parent.text = (parent.text or '') + text
parent.remove(element)
# Remove artificial <rmlblock> tags
@@ -76,9 +94,12 @@
encoding = 'utf-8'
+ field_schema = zope.interface.Interface
+ block_schema = zope.interface.Interface
+
def __init__(self, context):
self.context = context
- self.data = self.data_schema(context)
+ self.fields = self.field_schema(context)
self._setup_blocks()
def _setup_blocks(self):
@@ -86,7 +107,7 @@
self.blocks = Bag()
for block_name in self.block_schema:
block_text = getattr(raw_blocks, block_name)
- block_text = preprocess_block(block_text, self.data)
+ block_text = preprocess_block(block_text, self.fields)
setattr(self.blocks, block_name, block_text)
def __call__(self, raw=False):
Modified: z3c.rmldocument/trunk/src/z3c/rmldocument/examples/example1.rml
===================================================================
--- z3c.rmldocument/trunk/src/z3c/rmldocument/examples/example1.rml 2008-05-05 20:34:11 UTC (rev 86466)
+++ z3c.rmldocument/trunk/src/z3c/rmldocument/examples/example1.rml 2008-05-05 20:44:47 UTC (rev 86467)
@@ -9,7 +9,7 @@
</pageTemplate>
</template>
<story>
- <heading tal:content="data/salutation"/>
+ <heading tal:content="fields/salutation"/>
<tal:block replace="structure blocks/introduction"/>
Modified: z3c.rmldocument/trunk/src/z3c/rmldocument/interfaces.py
===================================================================
--- z3c.rmldocument/trunk/src/z3c/rmldocument/interfaces.py 2008-05-05 20:34:11 UTC (rev 86466)
+++ z3c.rmldocument/trunk/src/z3c/rmldocument/interfaces.py 2008-05-05 20:44:47 UTC (rev 86467)
@@ -36,12 +36,11 @@
template = zope.interface.Attribute(
"The page template for generating the basic RML.")
- fields = zope.interface.Attribute(
+ field_schema = zope.interface.Attribute(
"A schema describing which fields are available for substitution.")
- blocks = zope.interface.Attribute(
+ block_schema = zope.interface.Attribute(
"A schema describing which blocks of RML are available")
-
def renderRML(fields=None, blocks=None):
"""Return RML ready to be rendered."""
More information about the Checkins
mailing list