# -*- coding: iso-8859-15 -*-
import wrpylib.wrmwmarkup
import formencode
+import textwrap
def test_rodelbahnbox_to_sledrun():
}
wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
- assert wikitext == u'''
+ assert wikitext == textwrap.dedent(u'''\
<wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
<gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
<parkplatz>47.245789 11.238971</parkplatz>
47.244951 11.230868
47.245470 11.237853
</rodelbahn>
- </wrmap>'''
+ </wrmap>''')
def create_wrmap(geojson):
"""Creates a <wrmap> wikitext from geojson (as python types)."""
wrmap_xml = xml.etree.ElementTree.Element('wrmap')
+ wrmap_xml.text = '\n\n'
for k, v in geojson['properties'].iteritems():
wrmap_xml.attrib[k] = str(v)
assert geojson['type'] == 'FeatureCollection'
json_features = geojson['features']
+ last_json_feature = None
for json_feature in json_features:
feature_xml = xml.etree.ElementTree.SubElement(wrmap_xml, json_feature['properties']['type'])
geo = json_feature['geometry']
if geo['type'] == 'Point':
feature_xml.text = create_wrmap_coordinates([geo['coordinates']])
+ if last_json_feature is not None:
+ last_json_feature.tail = '\n'
else:
- feature_xml.text = create_wrmap_coordinates(geo['coordinates'])
+ if last_json_feature is not None:
+ last_json_feature.tail = '\n\n'
+ feature_xml.text = '\n' + create_wrmap_coordinates(geo['coordinates']) + '\n'
+ last_json_feature = feature_xml
feature_xml.attrib = json_feature['properties']
+ print last_json_feature.tag
+ if last_json_feature is not None:
+ last_json_feature.tail = '\n\n'
return xml.etree.ElementTree.tostring(wrmap_xml)