From e0e7693096469f5952eef1c5847dabc9cf797f70 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 4 Jan 2013 15:32:22 +0100 Subject: [PATCH] excercises: uporzadkuj, zastap, luki --- librarian/pyhtml.py | 44 +++++++++++++++++++++++++++++++++++-------- librarian/xmlutils.py | 7 ++----- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py index 64629d7..fcfb3a6 100644 --- a/librarian/pyhtml.py +++ b/librarian/pyhtml.py @@ -114,7 +114,9 @@ class EduModule(Xmill): def handle_cwiczenie(self, element): excercise_handlers = { 'wybor': Wybor, - 'uporzadkuj': Uporzadkuj + 'uporzadkuj': Uporzadkuj, + 'luki': Luki, + 'zastap': Zastap, } typ = element.attrib['typ'] @@ -122,7 +124,7 @@ class EduModule(Xmill): return handler.generate(element) # Lists - def handle_lista(self, element): + def handle_lista(self, element, attrs={}): ltype = element.attrib.get('typ', 'punkt') if ltype == 'slowniczek': self.options = {'slowniczek': True} @@ -133,7 +135,13 @@ class EduModule(Xmill): 'alfa': 'ul', 'czytelnia': 'ul'}[ltype] - return '<%s class="lista %s">' % (listtag, ltype), '' % listtag + classes = attrs.get('class', '') + if classes: del attrs['class'] + + attrs_s = ' '.join(['%s="%s"' % kv for kv in attrs.items()]) + if attrs_s: attrs_s = ' ' + attrs_s + + return '<%s class="lista %s %s"%s>' % (listtag, ltype, classes, attrs_s), '' % listtag def handle_punkt(self, element): if self.options['slowniczek']: @@ -190,7 +198,9 @@ class Wybor(Excercise): no = self.piece_counter eid = "q%(qc)d_%(no)d" % locals() return u""" -
  • + +
  • " else: @@ -209,19 +219,37 @@ class Uporzadkuj(Excercise): u"""""" + post def handle_punkt(self, element): - return """
  • """ % element.attrib,\ + return """
  • """ \ + % element.attrib,\ "
  • " class Luki(Excercise): def handle_luka(self, element): - return '' % element.text, \ - '' + return '' % element.text + class Zastap(Excercise): def handle_zastap(self, element): - return '' % element.attrib, '' + return '' % element.attrib, '' + + +class Przyporzadkuj(Excercise): + def handle_lista(self, element): + if 'nazwa' in lista.attrib: + attrs = { + 'data-name': lista.attrib['nazwa'], + 'class': 'category' + } + elif 'cel' in lista.attrib: + attrs = { + 'data-target': lista.attrib['cel'], + 'class': 'object' + } + else: + attrs = {} + return super(Przyporzadkuj, self).handle_lista(element, attrs) diff --git a/librarian/xmlutils.py b/librarian/xmlutils.py index 839ae89..a3f9df9 100644 --- a/librarian/xmlutils.py +++ b/librarian/xmlutils.py @@ -94,13 +94,10 @@ class Xmill(object): return [] else: if not isinstance(vals, tuple): - return [vals] + return [vals, element.tail] else: pre = [vals[0], element.text] - post = [vals[1]] - - if element.tail: - post.append(element.tail) + post = [vals[1], element.tail] out = pre + [self._handle_element(child) for child in element] + post finally: -- 2.20.1