return val
return [ self.validator(v) if v is not None else v for v in val ]
elif len(val) > 1:
- raise ValidationError("Mulitply values not allowed for field '%s'" % self.uri)
+ raise ValidationError("Multiple values not allowed for field '%s'" % self.uri)
elif len(val) == 0:
raise ValidationError("Field %s has no value to assign. Check your defaults." % self.uri)
else:
</xsl:otherwise>\r
</xsl:choose>\r
</div>\r
+ <p class="info"><xsl:value-of select="//dc:source" /></p>\r
<p class="info">Publikacja zrealizowana w ramach projektu WolneLektury.pl</p>\r
<p class="info">\r
<img src="logo_wolnelektury.png" alt="WolneLektury.pl" />\r
from lxml import etree
import re
+from librarian.dcparser import Person
+
def _register_function(f):
""" Register extension function with lxml """
ns = etree.FunctionNamespace('http://wolnelektury.pl/functions')
text = ''.join(text)
if not wrapping:
return text
-
+
words = re.split(r'\s', text)
-
+
line_length = 0
lines = [[]]
for word in words:
""" Converts "Name, Forename" to "Forename Name" """
if isinstance(text, list):
text = ''.join(text)
- return ' '.join([t.strip() for t in text.split(',', 1)[::-1]])
+ p = Person.from_text(text)
+ return ' '.join(p.first_names + (p.last_name,))
_register_function(person_name)
from lxml import etree
from lxml.etree import XMLSyntaxError, XSLTApplyError
+from librarian.dcparser import Person
from librarian.parser import WLDocument
-from librarian import ParseError
+from librarian import ParseError, DCNS
from librarian import functions
-
functions.reg_substitute_entities()
-functions.reg_person_name()
functions.reg_strip()
functions.reg_starts_white()
functions.reg_ends_white()
<a><b>A<d/>B<d/>C</b>X<d/>Y<d/>Z</a>
"""
- for elem in doc.iter():
- try:
- if elem.text:
- chunks = split_re.split(elem.text)
- while len(chunks) > 1:
- ins = etree.Element(tagname)
- ins.tail = chunks.pop()
- elem.insert(0, ins)
- elem.text = chunks.pop(0)
- if elem.tail:
- chunks = split_re.split(elem.tail)
- parent = elem.getparent()
- ins_index = parent.index(elem) + 1
- while len(chunks) > 1:
- ins = etree.Element(tagname)
- ins.tail = chunks.pop()
- parent.insert(ins_index, ins)
- elem.tail = chunks.pop(0)
- except TypeError, e:
- # element with no children, like comment
- pass
+ for elem in doc.iter(tag=etree.Element):
+ if elem.text:
+ chunks = split_re.split(elem.text)
+ while len(chunks) > 1:
+ ins = etree.Element(tagname)
+ ins.tail = chunks.pop()
+ elem.insert(0, ins)
+ elem.text = chunks.pop(0)
+ if elem.tail:
+ chunks = split_re.split(elem.tail)
+ parent = elem.getparent()
+ ins_index = parent.index(elem) + 1
+ while len(chunks) > 1:
+ ins = etree.Element(tagname)
+ ins.tail = chunks.pop()
+ parent.insert(ins_index, ins)
+ elem.tail = chunks.pop(0)
def substitute_hyphens(doc):
break
+def parse_creator(doc):
+ """ find all dc:creator tags and add dc:creator_parsed with forenames first """
+ for creator in doc.findall('//'+DCNS('creator')):
+ p = Person.from_text(creator.text)
+ creator_parsed = deepcopy(creator)
+ creator_parsed.tag = DCNS('creator_parsed')
+ creator_parsed.text = ' '.join(p.first_names + (p.last_name,))
+ creator.getparent().insert(0, creator_parsed)
+
+
def get_resource(path):
return os.path.join(os.path.dirname(__file__), path)
# hack the tree
move_motifs_inside(document.edoc)
hack_motifs(document.edoc)
+ parse_creator(document.edoc)
substitute_hyphens(document.edoc)
fix_hanging(document.edoc)
\clubpenalty=100000
\widowpenalty=100000
-%\interlinepenalty=8000
-
\renewcommand{\maketitle}{
{
\includegraphics[width=\textwidth]{wl-logo.png}
\end{minipage}
\begin{minipage}[t]{.65\textwidth}\vspace{0pt}
+ \sourceinfo
+
+ \vspace{.5em}
+
Wejdź na stronę http://wolnelektury.pl/ i~zobacz, jak wiele możliwości daje interaktywna wersja szkolnej biblioteki
internetowej Wolne Lektury.
\vspace{.5em}
Bibliotekę Narodową z egzemplarza pochodzącego ze zbiorów BN.
\n%(license_description)s.
+%(source)s
+
Wersja lektury w opracowaniu merytorycznym i krytycznym (przypisy i motywy) dostępna jest na stronie %(url)s.
-----
parsed_dc = dcparser.parse(input_filename)
url = parsed_dc.url
license_description = parsed_dc.license_description
- license = parsed_dc.license
+ license = parsed_dc.license
if license:
license_description = u"Ten utwór jest udostepniony na licencji %s: \n%s" % (license_description, license)
else:
- license_description = u"Ten utwór nie jest chroniony prawem autorskim i znajduje się w domenie publicznej, co oznacza, że możesz go swobodnie wykorzystywać, publikować i rozpowszechniać"
+ license_description = u"Ten utwór nie jest chroniony prawem autorskim i znajduje się w domenie publicznej, co oznacza, że możesz go swobodnie wykorzystywać, publikować i rozpowszechniać"
+ source = parsed_dc.source_name
else:
url = '*' * 10
license = ""
license_description = ""
+ source = ""
output_file.write(TEMPLATE % {
'url': url,
- 'license_description': license_description,
+ 'license_description': license_description,
'text': unicode(result),
+ 'source': source,
})
<xsl:template match="rdf:RDF" mode="titlepage">
<cmd name='title'><parm>
- <xsl:value-of select=".//dc:title/text()" />
+ <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
</parm></cmd>
<cmd name='author'><parm>
- <xsl:value-of select="wl:person_name(.//dc:creator/text())" />
+ <xsl:apply-templates select=".//dc:creator_parsed/node()" mode="inline" />
</parm></cmd>
+ <TeXML escape="0">
+ \def\sourceinfo{<TeXML escape="1"><xsl:apply-templates select=".//dc:source/node()" mode="inline" /></TeXML>}
+ </TeXML>
</xsl:template>
<xsl:template match="rdf:RDF" mode="firstdctitle">
<cmd name="subsection*"><parm>
- <xsl:value-of select="wl:person_name(.//dc:creator/text())" />
+ <xsl:apply-templates select=".//dc:creator_parsed/node()" mode="inline" />
</parm></cmd>
<cmd name="section*"><parm>
- <xsl:value-of select=".//dc:title/text()" />
+ <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
</parm></cmd>
</xsl:template>