From: Marcin Koziej Date: Wed, 30 Oct 2013 14:36:32 +0000 (+0100) Subject: last merge of edumed-red not complete X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/a36b71e91ec260eae71f133f450fe4de80974461?hp=ea995d6aea1cc1b19502825fec5f5d0445d632c4 last merge of edumed-red not complete --- diff --git a/librarian/__init__.py b/librarian/__init__.py index 430fb7e..23244ef 100644 --- a/librarian/__init__.py +++ b/librarian/__init__.py @@ -79,8 +79,8 @@ class WLURI(object): """Represents a WL URI. Extracts slug from it.""" slug = None - example = 'http://edukacjamedialna.edu.pl/' - _re_wl_uri = re.compile(r'http://(www\.)?edukacjamedialna.edu.pl/(lekcje/)?' + example = 'http://edukacjamedialna.edu.pl/lekcje/template' + _re_wl_uri = re.compile(r'http://(www\.)?edukacjamedialna.edu.pl/lekcje/' '(?P[-a-z0-9]+)/?$') def __init__(self, uri): @@ -101,10 +101,10 @@ class WLURI(object): """Contructs an URI from slug. >>> WLURI.from_slug('a-slug').uri - u'http://wolnelektury.pl/katalog/lektura/a-slug/' + u'http://edukacjamedialna.edu.pl/lekcje/a-slug/' """ - uri = 'http://prawokultury.pl/publikacje/%s/' % slug + uri = 'http://edukacjamedialna.edu.pl/lekcje/%s/' % slug return cls(uri) def __unicode__(self): @@ -113,6 +113,9 @@ class WLURI(object): def __str__(self): return self.uri + def canonical(self): + return type(self).from_slug(self.slug) + def __eq__(self, other): return self.slug == other.slug diff --git a/librarian/book2anything.py b/librarian/book2anything.py index b8b8d27..b60cd0f 100755 --- a/librarian/book2anything.py +++ b/librarian/book2anything.py @@ -10,7 +10,6 @@ import optparse from librarian import DirDocProvider, ParseError from librarian.parser import WLDocument -from librarian.cover import WLCover class Option(object): @@ -88,7 +87,7 @@ class Book2Anything(object): for option in cls.parser_options: parser_args[option.name()] = option.value(options) # Prepare additional args for transform method. - transform_args = {} + transform_args = {"verbose": options.verbose} for option in cls.transform_options: transform_args[option.name()] = option.value(options) # Add flags to transform_args, if any. @@ -98,6 +97,7 @@ class Book2Anything(object): transform_args['flags'] = transform_flags # Add cover support, if any. if cls.uses_cover: + from librarian.styles.wolnelektury.cover import WLCover if options.image_cache: def cover_class(*args, **kwargs): return WLCover(image_cache=options.image_cache, *args, **kwargs) diff --git a/librarian/cover.py b/librarian/cover.py index 1db96cb..dc64a9c 100644 --- a/librarian/cover.py +++ b/librarian/cover.py @@ -4,7 +4,7 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # import re -import Image, ImageFont, ImageDraw, ImageFilter +from PIL import Image, ImageFont, ImageDraw, ImageFilter from StringIO import StringIO from librarian import get_resource, IOFile diff --git a/librarian/fonts/Dosis-Bold.ttf b/librarian/fonts/Dosis-Bold.ttf new file mode 100644 index 0000000..d5e938e Binary files /dev/null and b/librarian/fonts/Dosis-Bold.ttf differ diff --git a/librarian/fonts/Dosis-ExtraBold.ttf b/librarian/fonts/Dosis-ExtraBold.ttf new file mode 100644 index 0000000..2144a25 Binary files /dev/null and b/librarian/fonts/Dosis-ExtraBold.ttf differ diff --git a/librarian/fonts/Dosis-ExtraLight.ttf b/librarian/fonts/Dosis-ExtraLight.ttf new file mode 100644 index 0000000..2e3bf1b Binary files /dev/null and b/librarian/fonts/Dosis-ExtraLight.ttf differ diff --git a/librarian/fonts/Dosis-Light.ttf b/librarian/fonts/Dosis-Light.ttf new file mode 100644 index 0000000..a22e7d7 Binary files /dev/null and b/librarian/fonts/Dosis-Light.ttf differ diff --git a/librarian/fonts/Dosis-Medium.ttf b/librarian/fonts/Dosis-Medium.ttf new file mode 100644 index 0000000..3254ef5 Binary files /dev/null and b/librarian/fonts/Dosis-Medium.ttf differ diff --git a/librarian/fonts/Dosis-Regular.ttf b/librarian/fonts/Dosis-Regular.ttf new file mode 100644 index 0000000..4b20862 Binary files /dev/null and b/librarian/fonts/Dosis-Regular.ttf differ diff --git a/librarian/fonts/Dosis-SemiBold.ttf b/librarian/fonts/Dosis-SemiBold.ttf new file mode 100644 index 0000000..5f48caf Binary files /dev/null and b/librarian/fonts/Dosis-SemiBold.ttf differ diff --git a/librarian/parser.py b/librarian/parser.py index f02b64c..fb2f986 100644 --- a/librarian/parser.py +++ b/librarian/parser.py @@ -204,8 +204,8 @@ class WLDocument(object): return epub.transform(self, *args, **kwargs) def as_pdf(self, *args, **kwargs): - from librarian import pdf - return pdf.transform(self, *args, **kwargs) + from librarian import pypdf + return pypdf.EduModulePDFFormat(self).build(*args, **kwargs) def as_mobi(self, *args, **kwargs): from librarian import mobi @@ -217,7 +217,7 @@ class WLDocument(object): def as_cover(self, cover_class=None, *args, **kwargs): if cover_class is None: - from librarian.cover import WLCover + from librarian.styles.wolnelektury.cover import WLCover cover_class = WLCover return cover_class(self.book_info, *args, **kwargs).output_file() diff --git a/librarian/pdf.py b/librarian/pdf.py index 9308704..03879fe 100644 --- a/librarian/pdf.py +++ b/librarian/pdf.py @@ -175,7 +175,7 @@ def package_available(package, args='', verbose=False): def load_including_children(wldoc=None, provider=None, uri=None): """ Makes one big xml file with children inserted at end. - + Either wldoc or provider and URI must be provided. """ @@ -203,7 +203,7 @@ def load_including_children(wldoc=None, provider=None, uri=None): class PDFFormat(Format): """ Base PDF format. - + Available customization: nofootnotes: Doesn't do footnotes. nothemes: Doesn't do themes. @@ -265,6 +265,9 @@ class PDFFormat(Format): # Copy style shutil.copy(get_resource('pdf/wl.cls'), temp) shutil.copy(self.style, os.path.join(temp, 'style.sty')) + #for sfile in ['wasysym.sty', 'uwasyvar.fd', 'uwasy.fd']: + # shutil.copy(get_resource(os.path.join('res/wasysym', sfile)), temp) + # Save attachments if self.cover: self.cover.for_pdf().dump_to(os.path.join(temp, 'makecover.sty')) @@ -287,7 +290,7 @@ class PDFFormat(Format): p = call(['xelatex', '-interaction=batchmode', tex_path], stdout=PIPE, stderr=PIPE) if p: - raise ParseError("Error parsing .tex file") + raise ParseError("Error parsing .tex file: %s" % tex_path) if cwd is not None: os.chdir(cwd) @@ -303,7 +306,7 @@ class PDFFormat(Format): """ self.verbose = verbose self.save_tex = save_tex - + if morefloats is None and package_available('morefloats', 'maxfloats=19'): morefloats = 'new' self.morefloats = morefloats diff --git a/librarian/pdf/wl.cls b/librarian/pdf/wl.cls index 53da8d5..128a183 100755 --- a/librarian/pdf/wl.cls +++ b/librarian/pdf/wl.cls @@ -14,6 +14,7 @@ \RequirePackage{setspace} \RequirePackage{type1cm} +\RequirePackage{wasysym} \DeclareOption{13pt}{% \AtEndOfClass{% % font size definitions, similar to ones in /usr/share/texmf-texlive/tex/latex/base/ @@ -74,21 +75,22 @@ \usepackage[overload]{textcase} \usepackage{scalefnt} % TODO: link color is a style thing -\usepackage[colorlinks=true,linkcolor=black,setpagesize=false,urlcolor=black,xetex]{hyperref} +\usepackage[hyphens]{url} +\usepackage[colorlinks=true,linkcolor=black,setpagesize=false,urlcolor=blue,xetex]{hyperref} \ifenablewlfont \setmainfont [ %ExternalLocation, -UprightFont = JunicodeWL-Regular, -ItalicFont = JunicodeWL-Italic, -BoldFont = JunicodeWL-Regular, -BoldItalicFont = JunicodeWL-Italic, -SmallCapsFont = JunicodeWL-Regular, +UprightFont = Dosis-Regular, +ItalicFont = Dosis-SemiBold, +BoldFont = Dosis-Bold, +BoldItalicFont = Dosis-Bold, +SmallCapsFont = Dosis-Regular, SmallCapsFeatures = {Letters={SmallCaps,UppercaseSmallCaps}}, Numbers=OldStyle, Scale=1.04, LetterSpace=-1.0 -] {JunicodeWL} +] {Dosis} \newfontfamily\alien[ SmallCapsFeatures = {Letters={SmallCaps,UppercaseSmallCaps}}, @@ -148,7 +150,7 @@ Letters={SmallCaps,UppercaseSmallCaps} \fancyhf{} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt} -\lfoot{{\footnotesize \textsc{\@author} \emph{\@title}}} +\lfoot{{\footnotesize \@author{} \emph{\@title}}} \cfoot{} \rfoot{{\footnotesize \thepage}} @@ -170,7 +172,7 @@ Letters={SmallCaps,UppercaseSmallCaps} \newcommand{\typosubsubsection}[1]{% -{\textsc{#1}} +{#1} } \newcommand{\typosubsection}[1]{% @@ -209,7 +211,7 @@ Letters={Uppercase} } \newcommand{\nazwautworu}[1]{% -\section*{\typosection{#1}}% +\section*{\raggedright{\typosection{#1}}}% } \newcommand{\podtytul}[1]{% @@ -293,7 +295,7 @@ Letters={Uppercase} \subsubsection*{\typosubsubsection{#1}}% } \newcommand{\naglowekrozdzial}[1]{% -\subsubsection*{\typosubsubsection{#1}}% +{\subsubsection*{\raggedright{\typosubsubsection{#1}}}}% } \newcommand{\naglowekosoba}[1]{% @@ -404,4 +406,3 @@ Letters={Uppercase} }% \fi } - diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py index 775def1..68ae384 100644 --- a/librarian/pyhtml.py +++ b/librarian/pyhtml.py @@ -82,7 +82,10 @@ class EduModule(Xmill): } submill = EduModule(dict(self.options.items() + {'sub_gen': True}.items())) - opis = submill.generate(element.xpath('opis')[0]) if len(element.xpath('opis')) else "" + if element.xpath('opis'): + opis = submill.generate(element.xpath('opis')[0]) + else: + opis = '' n = element.xpath('wskazowki') if n: wskazowki = submill.generate(n[0]) @@ -196,7 +199,7 @@ u"""%(wskazowki)s subgen = EduModule(self.options) definiens_s = subgen.generate(definiens) else: - pass # print '!! Missing definiendum in source:', element.text + print '!! Missing definiendum in source:', element.text return u"
", u"
" + definiens_s @@ -334,7 +337,7 @@ class Wybor(Exercise): if not pytania: pytania = [element] for p in pytania: - solutions = re.split(r"[, ]+", p.attrib.get('rozw', '')) + solutions = re.split(r"[, ]+", p.attrib['rozw']) if len(solutions) != 1: is_single_choice = False break diff --git a/librarian/pypdf.py b/librarian/pypdf.py index cb082ca..9034753 100644 --- a/librarian/pypdf.py +++ b/librarian/pypdf.py @@ -9,26 +9,20 @@ Creates one big XML from the book and its children, converts it to LaTeX with TeXML, then runs it by XeLaTeX. """ -from __future__ import with_statement -import os +from copy import deepcopy import os.path import shutil -from StringIO import StringIO -from tempfile import mkdtemp, NamedTemporaryFile import re -from copy import deepcopy -from subprocess import call, PIPE +import random +from urllib2 import urlopen -from Texml.processor import process from lxml import etree -from lxml.etree import XMLSyntaxError, XSLTApplyError -from xmlutils import Xmill, tag, tagged, ifoption +from xmlutils import Xmill, tag, tagged, ifoption, tag_open_close from librarian.dcparser import Person -from librarian.parser import WLDocument -from librarian import ParseError, DCNS, get_resource, IOFile, Format +from librarian import DCNS, get_resource, IOFile from librarian import functions -from pdf import PDFFormat +from pdf import PDFFormat, substitute_hyphens, fix_hanging def escape(really): @@ -48,15 +42,21 @@ def escape(really): return deco -def cmd(name, pass_text=False): - def wrap(self, element): - pre = u'' % name +def cmd(name, parms=None): + def wrap(self, element=None): + pre, post = tag_open_close('cmd', name=name) - if pass_text: - pre += "%s" % element.text - return pre + '' + if parms: + for parm in parms: + e = etree.Element("parm") + e.text = parm + pre += etree.tostring(e) + if element is not None: + pre += "" + post = "" + post + return pre, post else: - return pre, '' + return pre + post return wrap @@ -66,9 +66,17 @@ def mark_alien_characters(text): class EduModule(Xmill): - def __init__(self, options=None): - super(EduModule, self).__init__(options) + def __init__(self, options=None, state=None): + super(EduModule, self).__init__(options, state) self.activity_counter = 0 + self.activity_last = None + self.exercise_counter = 0 + + def swap_endlines(txt): + if self.options['strofa']: + txt = txt.replace("/\n", '') + return txt + self.register_text_filter(swap_endlines) self.register_text_filter(functions.substitute_entities) self.register_text_filter(mark_alien_characters) @@ -91,11 +99,15 @@ class EduModule(Xmill): u'' @escape(True) - def get_authors(self, element): - authors = self.get_dc(element, 'creator.expert') + \ - self.get_dc(element, 'creator.scenario') + \ - self.get_dc(element, 'creator.textbook') - return u', '.join(authors) + def get_authors(self, element, which=None): + dc = self.options['wldoc'].book_info + if which is None: + authors = dc.authors_textbook + \ + dc.authors_scenario + \ + dc.authors_expert + else: + authors = getattr(dc, "authors_%s" % which) + return u', '.join(author.readable() for author in authors) @escape(1) def get_title(self, element): @@ -116,32 +128,99 @@ class EduModule(Xmill): \\usepackage{morefloats} }{}'''), u'''\\def\\authors{%s}''' % self.get_authors(element), + u'''\\def\\authorsexpert{%s}''' % self.get_authors(element, 'expert'), + u'''\\def\\authorsscenario{%s}''' % self.get_authors(element, 'scenario'), + u'''\\def\\authorstextbook{%s}''' % self.get_authors(element, 'textbook'), + u'''\\author{\\authors}''', u'''\\title{%s}''' % self.get_title(element), - u'''\\def\\bookurl{%s}''' % self.get_dc(element, 'identifier.url', True), + u'''\\def\\bookurl{%s}''' % self.options['wldoc'].book_info.url.canonical(), u'''\\def\\rightsinfo{%s}''' % self.get_rightsinfo(element), u''] return u"".join(filter(None, lines)), u'' - handle_naglowek_rozdzial = escape(True)(cmd("naglowekrozdzial", True)) - handle_naglowek_podrozdzial = escape(True)(cmd("naglowekpodrozdzial", True)) - @escape(1) def handle_powiesc(self, element): return u""" - """, """""" + """, """""" + + @escape(1) + def handle_texcommand(self, element): + cmd = functions.texcommand(element.tag) + return u'' % cmd, u'' + + handle_akap = \ + handle_akap = \ + handle_akap_cd = \ + handle_akap_cd = \ + handle_akap_dialog = \ + handle_akap_dialog = \ + handle_autor_utworu = \ + handle_dedykacja = \ + handle_didaskalia = \ + handle_didask_tekst = \ + handle_dlugi_cytat = \ + handle_dzielo_nadrzedne = \ + handle_lista_osoba = \ + handle_mat = \ + handle_miejsce_czas = \ + handle_motto = \ + handle_motto_podpis = \ + handle_naglowek_akt = \ + handle_naglowek_czesc = \ + handle_naglowek_listy = \ + handle_naglowek_osoba = \ + handle_naglowek_scena = \ + handle_nazwa_utworu = \ + handle_nota = \ + handle_osoba = \ + handle_pa = \ + handle_pe = \ + handle_podtytul = \ + handle_poezja_cyt = \ + handle_pr = \ + handle_pt = \ + handle_sekcja_asterysk = \ + handle_sekcja_swiatlo = \ + handle_separator_linia = \ + handle_slowo_obce = \ + handle_srodtytul = \ + handle_tytul_dziela = \ + handle_wyroznienie = \ + handle_dywiz = \ + handle_texcommand + + def handle_naglowek_rozdzial(self, element): + if not self.options['teacher']: + if element.text.startswith((u'Wiedza', u'Zadania', u'Słowniczek')): + self.state['mute'] = False + else: + self.state['mute'] = True + return None + return self.handle_texcommand(element) + handle_naglowek_rozdzial.unmuter = True + + def handle_naglowek_podrozdzial(self, element): + self.activity_counter = 0 + return self.handle_texcommand(element) + + def handle_uwaga(self, _e): + return None + def handle_extra(self, _e): + return None + + def handle_nbsp(self, _e): + return '' - handle_autor_utworu = cmd('autorutworu', True) - handle_nazwa_utworu = cmd('nazwautworu', True) - handle_dzielo_nadrzedne = cmd('dzielonadrzedne', True) - handle_podtytul = cmd('podtytul', True) + _handle_strofa = cmd("strofa") - handle_akap = handle_akap_dialog = handle_akap_cd = lambda s, e: ("\n", "\n") - handle_strofa = lambda s, e: ("\n","\n") + def handle_strofa(self, element): + self.options = {'strofa': True} + return self._handle_strofa(element) def handle_aktywnosc(self, element): self.activity_counter += 1 @@ -150,9 +229,12 @@ class EduModule(Xmill): 'activity_counter': self.activity_counter, 'sub_gen': True, } - submill = EduModule(self.options) + submill = EduModule(self.options, self.state) - opis = submill.generate(element.xpath('opis')[0]) + if element.xpath('opis'): + opis = submill.generate(element.xpath('opis')[0]) + else: + opis = '' n = element.xpath('wskazowki') if n: wskazowki = submill.generate(n[0]) @@ -169,12 +251,24 @@ class EduModule(Xmill): counter = self.activity_counter + if element.getnext().tag == 'aktywnosc' or self.activity_last.getnext() == element: + counter_tex = """%(counter)d.""" % locals() + else: + counter_tex = '' + + self.activity_last = element + return u""" -Czas: %(czas)s min -Forma: %(forma)s -%(pomoce)s + +%(counter_tex)s + + %(czas)s + %(forma)s + %(pomoce)s + + -%(counter)d. %(opis)s +%(opis)s %(wskazowki)s """ % locals() @@ -192,162 +286,358 @@ Forma: %(forma)s def handle_forma(self, *_): return -# def handle_cwiczenie(self, element): -# exercise_handlers = { -# 'wybor': Wybor, -# 'uporzadkuj': Uporzadkuj, -# 'luki': Luki, -# 'zastap': Zastap, -# 'przyporzadkuj': Przyporzadkuj, -# 'prawdafalsz': PrawdaFalsz -# } - -# typ = element.attrib['typ'] -# handler = exercise_handlers[typ](self.options) -# return handler.generate(element) - -# # Lists -# def handle_lista(self, element, attrs={}): -# ltype = element.attrib.get('typ', 'punkt') -# if ltype == 'slowniczek': -# surl = element.attrib.get('href', None) -# sxml = None -# if surl: -# sxml = etree.fromstring(self.options['provider'].by_uri(surl).get_string()) -# self.options = {'slowniczek': True, 'slowniczek_xml': sxml } -# return '
', '
' - -# listtag = {'num': 'ol', -# 'punkt': 'ul', -# 'alfa': 'ul', -# 'czytelnia': 'ul'}[ltype] - -# 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']: -# return '
', '
' -# else: -# return '
  • ', '
  • ' - -# def handle_definiendum(self, element): -# nxt = element.getnext() -# definiens_s = '' - -# # let's pull definiens from another document -# if self.options['slowniczek_xml'] and (not nxt or nxt.tag != 'definiens'): -# sxml = self.options['slowniczek_xml'] -# assert element.text != '' -# defloc = sxml.xpath("//definiendum[text()='%s']" % element.text) -# if defloc: -# definiens = defloc[0].getnext() -# if definiens.tag == 'definiens': -# subgen = EduModule(self.options) -# definiens_s = subgen.generate(definiens) - -# return u"
    ", u"
    " + definiens_s - -# def handle_definiens(self, element): -# return u"
    ", u"
    " - - -# def handle_podpis(self, element): -# return u"""
    """, u"
    " - -# def handle_tabela(self, element): -# has_frames = int(element.attrib.get("ramki", "0")) -# if has_frames: frames_c = "framed" -# else: frames_c = "" -# return u"""""" % frames_c, u"
    " - -# def handle_wiersz(self, element): -# return u"", u"" - -# def handle_kol(self, element): -# return u"", u"" - -# def handle_rdf__RDF(self, _): -# # ustal w opcjach rzeczy :D -# return - -# def handle_link(self, element): -# if 'material' in element.attrib: -# formats = re.split(r"[, ]+", element.attrib['format']) -# fmt_links = [] -# for f in formats: -# fmt_links.append(u'%s' % (self.options['urlmapper'].url_for_material(element.attrib['material'], f), f.upper())) - -# return u"", u' (%s)' % u' '.join(fmt_links) - - -# class Exercise(EduModule): -# def __init__(self, *args, **kw): -# self.question_counter = 0 -# super(Exercise, self).__init__(*args, **kw) - -# def handle_rozw_kom(self, element): -# return u"""""" - -# def handle_cwiczenie(self, element): -# self.options = {'exercise': element.attrib['typ']} -# self.question_counter = 0 -# self.piece_counter = 0 - -# pre = u""" -#
    -#
    -# """ % element.attrib -# post = u""" -#
    -# -# -# -# -# -#
    -#
    -#
    -# """ -# # Add a single tag if it's not there -# if not element.xpath(".//pytanie"): -# qpre, qpost = self.handle_pytanie(element) -# pre = pre + qpre -# post = qpost + post -# return pre, post - -# def handle_pytanie(self, element): -# """This will handle element, when there is no -# """ -# add_class = "" -# self.question_counter += 1 -# self.piece_counter = 0 -# solution = element.attrib.get('rozw', None) -# if solution: solution_s = ' data-solution="%s"' % solution -# else: solution_s = '' - -# handles = element.attrib.get('uchwyty', None) -# if handles: -# add_class += ' handles handles-%s' % handles -# self.options = {'handles': handles} - -# minimum = element.attrib.get('min', None) -# if minimum: minimum_s = ' data-minimum="%d"' % int(minimum) -# else: minimum_s = '' - -# return '
    ' %\ -# (add_class, self.question_counter, solution_s + minimum_s), \ -# "
    " + def handle_lista(self, element, attrs={}): + ltype = element.attrib.get('typ', 'punkt') + if not element.findall("punkt"): + if ltype == 'czytelnia': + return 'W przygotowaniu.' + else: + return None + if ltype == 'slowniczek': + surl = element.attrib.get('src', None) + if surl is None: + # print '** missing src on , setting default' + surl = 'http://edukacjamedialna.edu.pl/lekcje/slowniczek/' + sxml = None + if surl: + sxml = etree.fromstring(self.options['wldoc'].provider.by_uri(surl).get_string()) + self.options = {'slowniczek': True, 'slowniczek_xml': sxml } + + listcmd = {'num': 'enumerate', + 'punkt': 'itemize', + 'alfa': 'itemize', + 'slowniczek': 'itemize', + 'czytelnia': 'itemize'}[ltype] + + return u'' % listcmd, u'' + + def handle_punkt(self, element): + return '', '' + + def handle_cwiczenie(self, element): + exercise_handlers = { + 'wybor': Wybor, + 'uporzadkuj': Uporzadkuj, + 'luki': Luki, + 'zastap': Zastap, + 'przyporzadkuj': Przyporzadkuj, + 'prawdafalsz': PrawdaFalsz + } + + typ = element.attrib['typ'] + self.exercise_counter += 1 + if not typ in exercise_handlers: + return '(no handler)' + self.options = {'exercise_counter': self.exercise_counter} + handler = exercise_handlers[typ](self.options, self.state) + return handler.generate(element) + + # XXX this is copied from pyhtml.py, except for return and + # should be refactored for no code duplication + def handle_definiendum(self, element): + nxt = element.getnext() + definiens_s = '' + + # let's pull definiens from another document + if self.options['slowniczek_xml'] is not None and (nxt is None or nxt.tag != 'definiens'): + sxml = self.options['slowniczek_xml'] + assert element.text != '' + defloc = sxml.xpath("//definiendum[text()='%s']" % element.text) + if defloc: + definiens = defloc[0].getnext() + if definiens.tag == 'definiens': + subgen = EduModule(self.options, self.state) + definiens_s = subgen.generate(definiens) + + return u'', u": " + definiens_s + + def handle_definiens(self, element): + return u"", u"" + + def handle_podpis(self, element): + return u"""""", u"" + + def handle_tabela(self, element): + max_col = 0 + for w in element.xpath("wiersz"): + ks = w.xpath("kol") + if max_col < len(ks): + max_col = len(ks) + self.options = {'columnts': max_col} + # styling: + # has_frames = int(element.attrib.get("ramki", "0")) + # if has_frames: frames_c = "framed" + # else: frames_c = "" + # return u"""""" % frames_c, u"
    " + return u''' +tabular%s + ''' % ('l' * max_col), \ + u'''tabular''' + + @escape(1) + def handle_wiersz(self, element): + return u"", u'' + + @escape(1) + def handle_kol(self, element): + if element.getnext() is not None: + return u"", u'' + return u"", u"" + + def handle_link(self, element): + if element.attrib.get('url'): + url = element.attrib.get('url') + if url == element.text: + return cmd('url')(self, element) + else: + return cmd('href', parms=[element.attrib['url']])(self, element) + else: + return cmd('emph')(self, element) + + def handle_obraz(self, element): + frmt = self.options['format'] + name = element.attrib.get('nazwa', '').strip() + image = frmt.get_image(name.strip()) + img_path = "obraz/%s" % name.replace("_", "") + frmt.attachments[img_path] = image + return cmd("obraz", parms=[img_path])(self) + + def handle_video(self, element): + url = element.attrib.get('url') + if not url: + print '!!