[Checkins] SVN: z3c.rml/trunk/src/z3c/rml/ Added ability to mark test files to provide reference examples.

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Apr 14 20:05:03 EDT 2007


Log message for revision 74140:
  Added ability to mark test files to provide reference examples.
  

Changed:
  U   z3c.rml/trunk/src/z3c/rml/rml-reference.pt
  U   z3c.rml/trunk/src/z3c/rml/rml-reference.py
  U   z3c.rml/trunk/src/z3c/rml/tests/input/tag-circle.rml

-=-
Modified: z3c.rml/trunk/src/z3c/rml/rml-reference.pt
===================================================================
--- z3c.rml/trunk/src/z3c/rml/rml-reference.pt	2007-04-14 23:19:24 UTC (rev 74139)
+++ z3c.rml/trunk/src/z3c/rml/rml-reference.pt	2007-04-15 00:05:02 UTC (rev 74140)
@@ -67,6 +67,12 @@
         fontSize="10"
         leftIndent="0.3cm"
         />
+    <paraStyle
+        name="code"
+        fontName="Courier"
+        fontSize="10"
+        leftIndent="0.5cm"
+        />
   </stylesheet>
 
   <template
@@ -208,6 +214,17 @@
         </para>
       </tal:block>
 
+      <tal:block condition="directive/examples">
+        <para style="element-subtitle">
+          <i>Examples</i>
+        </para>
+        <tal:block repeat="example directive/examples">
+          <pre style="code" tal:content="structure example">
+            Example Code
+          </pre>
+        </tal:block>
+      </tal:block>
+
     </tal:block>
 
   </story>

Modified: z3c.rml/trunk/src/z3c/rml/rml-reference.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/rml-reference.py	2007-04-14 23:19:24 UTC (rev 74139)
+++ z3c.rml/trunk/src/z3c/rml/rml-reference.py	2007-04-15 00:05:02 UTC (rev 74140)
@@ -106,14 +106,22 @@
 
 
 def extractExamples(directory):
+    EXAMPLE_NS = 'http://namespaces.zope.org/rml/doc'
+    EXAMPLE_ATTR_NAME = '{%s}elementExample' %EXAMPLE_NS
     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()
-        if fileName == 'tag-circle.rml':
-            import pdb; pdb.set_trace()
+        elements = root.xpath('//@doc:elementExample/parent::*',
+                              {'doc': EXAMPLE_NS})
+        for elem in elements:
+            demoTag = elem.get(EXAMPLE_ATTR_NAME)
+            del elem.attrib[EXAMPLE_ATTR_NAME]
+            xml = etree.tounicode(elem, pretty_print=True).strip()
+            elemExamples = examples.setdefault(demoTag, [])
+            elemExamples.append(xml)
 
     return examples
 

Modified: z3c.rml/trunk/src/z3c/rml/tests/input/tag-circle.rml
===================================================================
--- z3c.rml/trunk/src/z3c/rml/tests/input/tag-circle.rml	2007-04-14 23:19:24 UTC (rev 74139)
+++ z3c.rml/trunk/src/z3c/rml/tests/input/tag-circle.rml	2007-04-15 00:05:02 UTC (rev 74140)
@@ -14,10 +14,10 @@
             fill="true" stroke="false" />
 
     <circle x="10cm" y="15cm" radius="2cm"
-            fill="false" stroke="true" />
+            fill="false" stroke="true" doc:elementExample="bulkData"/>
 
     <circle x="10cm" y="10cm" radius="2cm"
-            fill="true" stroke="true" />
+            fill="true" stroke="true" doc:elementExample="circle"/>
 
   </pageDrawing>
 </document>



More information about the Checkins mailing list