X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/9b253dcb10940e8c8d25a02059153d4c80469b79..ab001bc37c0f8ee0bb92b8762f5151b5b93f6ccc:/librarian/pyhtml.py
diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py
index da7e643..bb835ae 100644
--- a/librarian/pyhtml.py
+++ b/librarian/pyhtml.py
@@ -13,28 +13,6 @@ class EduModule(Xmill):
super(EduModule, self).__init__(*args)
self.activity_counter = 0
-
-# def handle_utwor(self, element):
-# v = {}
-# # from pdb import *; set_trace()
-# v['title'] = element.xpath('//dc:title/text()', namespaces={'dc':DCNS.uri})[0]
-# return u"""
-#
-#
-#
-#
@@ -113,7 +91,10 @@ class EduModule(Xmill):
def handle_cwiczenie(self, element):
excercise_handlers = {
'wybor': Wybor,
- 'uporzadkuj': Uporzadkuj
+ 'uporzadkuj': Uporzadkuj,
+ 'luki': Luki,
+ 'zastap': Zastap,
+ 'przyporzadkuj': Przyporzadkuj
}
typ = element.attrib['typ']
@@ -121,7 +102,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}
@@ -132,7 +113,13 @@ class EduModule(Xmill):
'alfa': 'ul',
'czytelnia': 'ul'}[ltype]
- return '<%s class="lista %s">' % (listtag, ltype), '%s>' % 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), '%s>' % listtag
def handle_punkt(self, element):
if self.options['slowniczek']:
@@ -150,16 +137,19 @@ class Excercise(EduModule):
self.question_counter = 0
super(Excercise, self).__init__(*args, **kw)
+ def handle_rozw_kom(self, element):
+ return None
+
def handle_cwiczenie(self, element):
self.options = {'excercise': element.attrib['typ']}
self.question_counter = 0
self.piece_counter = 0
- return u"""
+ pre = u"""
"
class Wybor(Excercise):
@@ -187,31 +185,77 @@ class Wybor(Excercise):
qc = self.question_counter
self.piece_counter += 1
no = self.piece_counter
-
+ eid = "q%(qc)d_%(no)d" % locals()
return u"""
-
-""" % locals(), u""
+
+
+
+""" % locals(), u" "
else:
- return super(Wybor, self).handle_punkt(self, element)
+ return super(Wybor, self).handle_punkt(element)
class Uporzadkuj(Excercise):
- def handle_cwiczenie(self, element):
- pre, post = super(Uporzadkuj, self).handle_cwiczenie(element)
+ def handle_pytanie(self, element):
+ """
+Overrides the returned content default handle_pytanie
+ """
+ # we ignore the result, returning our own
+ super(Uporzadkuj, self).handle_pytanie(element)
order_items = element.xpath(".//punkt/@rozw")
- import pdb
- if order_items == []: pdb.set_trace()
- return pre + u"""
""" % \
- ','.join(order_items), \
- u"""
""" + post
-
+ return u"""
""" % \
+ (','.join(order_items), self.question_counter), \
+ u"""
"""
+
def handle_punkt(self, element):
- return """
""" % element.attrib,\
+ return """
""" \
+ % element.attrib,\
""
+class Luki(Excercise):
+ def handle_luka(self, element):
+ return '
' % element.text
+
+
+class Zastap(Excercise):
+ def handle_zastap(self, element):
+ return '
' % element.attrib, ' '
+
+
+class Przyporzadkuj(Excercise):
+ def handle_lista(self, lista):
+ print "in lista %s %s" % (lista.attrib, self.options)
+ if 'nazwa' in lista.attrib:
+ attrs = {
+ 'data-name': lista.attrib['nazwa'],
+ 'class': 'predicate'
+ }
+ self.options = {'predicate': True}
+ elif 'cel' in lista.attrib:
+ attrs = {
+ 'data-target': lista.attrib['cel'],
+ 'class': 'subject'
+ }
+ self.options = {'subject': True}
+ else:
+ attrs = {}
+ pre, post = super(Przyporzadkuj, self).handle_lista(lista, attrs)
+ return pre, post + '
'
+
+ def handle_punkt(self, element):
+ print "in punkt %s %s" % (element.attrib, self.options)
+
+ if self.options['subject']:
+ return '
' % element.attrib, ' '
+ elif self.options['predicate']:
+ return '
' % element.attrib, ' '
+ else:
+ return super(Przyporzadkuj, self).handle_punkt(element)
+
+
def transform(wldoc, stylesheet='edumed', options=None, flags=None):
"""Transforms the WL document to XHTML.
@@ -219,7 +263,6 @@ def transform(wldoc, stylesheet='edumed', options=None, flags=None):
otherwise returns True if file has been written,False if it hasn't.
File won't be written if it has no content.
"""
-
edumod = EduModule(options)
# from pdb import set_trace; set_trace()
html = edumod.generate(wldoc.edoc.getroot())