Merge branch 'master' into ofop
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 2 Mar 2012 13:00:12 +0000 (14:00 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 2 Mar 2012 13:00:12 +0000 (14:00 +0100)
librarian/cover.py
librarian/html.py
librarian/packagers.py
librarian/res/cover.png [new file with mode: 0644]
librarian/res/webtreatsetc-5647576127-ccby.png [new file with mode: 0644]
librarian/xslt/book2html.xslt
scripts/book2cover
scripts/book2partner

index e7a8e1b..c345a50 100644 (file)
@@ -232,6 +232,8 @@ class WLCover(Cover):
     bar_width = 35
     background_color = '#444'
     author_color = '#444'
+    default_background = get_resource('res/cover.png')
+    format = 'JPEG'
 
     epochs = {
         u'Starożytność': 0,
@@ -257,6 +259,8 @@ class WLCover(Cover):
             bg_src = urlopen(book_info.cover_url)
             self.background_img = StringIO(bg_src.read())
             bg_src.close()
+        else:
+            self.background_img = self.default_background
 
     def pretty_author(self):
         return self.author.upper()
index 39e5a01..e04790f 100644 (file)
@@ -163,7 +163,8 @@ def extract_fragments(input_filename):
         # Process all elements except begin and end
         else:
             # Omit annotation tags
-            if len(element.get('name', '')) or element.get('class', '') == 'annotation':
+            if (len(element.get('name', '')) or 
+                    element.get('class', '') in ('annotation', 'anchor')):
                 if event == 'end' and element.tail:
                     for fragment_id in open_fragments:
                         open_fragments[fragment_id].append('text', element.tail)
@@ -220,6 +221,14 @@ def add_anchors(root):
             counter += 1
 
 
+def raw_printable_text(element):
+    working = copy.deepcopy(element)
+    for e in working.findall('a'):
+        if e.get('class') == 'annotation':
+            e.text = ''
+    return etree.tostring(working, method='text', encoding=unicode).strip()
+
+
 def add_table_of_contents(root):
     sections = []
     counter = 1
@@ -228,8 +237,7 @@ def add_table_of_contents(root):
             if any_ancestor(element, lambda e: e.get('id') in ('footnotes',) or e.get('class') in ('person-list',)):
                 continue
 
-            element_text = etree.tostring(element, method='text',
-                    encoding=unicode).strip()
+            element_text = raw_printable_text(element)
             if element.tag == 'h3' and len(sections) and sections[-1][1] == 'h2':
                 sections[-1][3].append((counter, element.tag, element_text, []))
             else:
index 9a93e56..cc9902b 100644 (file)
@@ -81,7 +81,7 @@ class PrestigioPdfPackager(PdfPackager):
     flags = ('less-advertising',)
 
 
-class VirtualoEpubPackager(Packager):
+class VirtualoPackager(Packager):
     @staticmethod
     def utf_trunc(text, limit):
         """ truncates text to at most `limit' bytes in utf-8 """
@@ -139,9 +139,16 @@ class VirtualoEpubPackager(Packager):
                 cover.VirtualoCover(info).save(os.path.join(outfile_dir, slug+'.jpg'))
                 outfile = os.path.join(outfile_dir, '1.epub')
                 outfile_sample = os.path.join(outfile_dir, '1.sample.epub')
-                doc.save_output_file(epub.transform(doc),
+                doc.save_output_file(doc.as_epub(),
                         output_path=outfile)
-                doc.save_output_file(epub.transform(doc, sample=25), 
+                doc.save_output_file(doc.as_epub(doc, sample=25), 
+                        output_path=outfile_sample)
+                outfile = os.path.join(outfile_dir, '1.mobi')
+                outfile_sample = os.path.join(outfile_dir, '1.sample.mobi')
+                doc.save_output_file(doc.as_mobi(cover=cover.VirtualoCover),
+                        output_path=outfile)
+                doc.save_output_file(
+                        doc.as_mobi(doc, cover=cover.VirtualoCover, sample=25), 
                         output_path=outfile_sample)
         except ParseError, e:
             print '%(file)s:%(name)s:%(message)s' % {
diff --git a/librarian/res/cover.png b/librarian/res/cover.png
new file mode 100644 (file)
index 0000000..e02acaa
Binary files /dev/null and b/librarian/res/cover.png differ
diff --git a/librarian/res/webtreatsetc-5647576127-ccby.png b/librarian/res/webtreatsetc-5647576127-ccby.png
new file mode 100644 (file)
index 0000000..6919e93
Binary files /dev/null and b/librarian/res/webtreatsetc-5647576127-ccby.png differ
index 441f641..f81f981 100755 (executable)
@@ -10,6 +10,7 @@
     xmlns:dc="http://purl.org/dc/elements/1.1/" >
 
 <xsl:output encoding="utf-8" indent="yes" omit-xml-declaration = "yes" version="2.0" />
+<xsl:strip-space  elements="opowiadanie powiesc dramat_wierszowany_l dramat_wierszowany_lp dramat_wspolczesny liryka_l liryka_lp wywiad"/>
 <xsl:template match="utwor">
     <xsl:choose>
         <xsl:when test="@full-page">
 
 <!-- Section headers (included in index)-->
 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
+  <xsl:call-template name="section-anchor"/>
     <h2><xsl:apply-templates mode="inline" /></h2>
 </xsl:template>
 
 <xsl:template match="naglowek_scena|naglowek_rozdzial">
+    <xsl:call-template name="section-anchor"/>
     <h3><xsl:apply-templates mode="inline" /></h3>
 </xsl:template>
 
 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
+      <xsl:call-template name="section-anchor"/>
     <h4><xsl:apply-templates mode="inline" /></h4>
 </xsl:template>
 
 <!-- Other paragraph tags -->
 <xsl:template match="miejsce_czas">
+      <xsl:call-template name="section-anchor"/>
     <p class="place-and-time"><xsl:apply-templates mode="inline" /></p>
 </xsl:template>
 
 <xsl:template match="didaskalia">
+      <xsl:call-template name="section-anchor"/>
     <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
 </xsl:template>
 
 </xsl:template>
 
 <xsl:template match="akap|akap_dialog|akap_cd">
-    <p class="paragraph"><xsl:apply-templates mode="inline" /></p>
+    <p class="paragraph">
+      <xsl:call-template name="section-anchor"/>
+       <xsl:apply-templates mode="inline" />
+    </p>
 </xsl:template>
 
 <xsl:template match="strofa">
     <div class="stanza">
+      <xsl:call-template name="section-anchor"/>
         <xsl:choose>
             <xsl:when test="count(br) > 0">
                 <xsl:call-template name="verse">
     <xsl:value-of select="wl:substitute_entities(.)" />
 </xsl:template>
 
+<!-- ========= -->
+<!-- = utils = -->
+<!-- ========= -->
+<xsl:template name="section-anchor">
+  <!-- 
+       this formula works as follows:
+       - get all ancestors including self
+       - choose the header (third one from root): utwor/book-type/header
+       - get all preceding siblings
+       - count them
+       - create an <a name="sec123"/> tag.
+  -->
+        <a name="{concat('sec', count(ancestor-or-self::*[last()-2]/preceding-sibling::*) + 1)}" />
+</xsl:template>
 
-</xsl:stylesheet>
\ No newline at end of file
+</xsl:stylesheet>
index d2befc3..49cd539 100755 (executable)
@@ -33,7 +33,7 @@ if __name__ == '__main__':
         if options.verbose:
             print input_filename
 
-        output_filename = os.path.splitext(input_filename)[0] + '.png'
+        output_filename = os.path.splitext(input_filename)[0] + '.jpg'
 
         doc = WLDocument.from_file(input_filename)
         WLCover(doc.book_info).save(output_filename)
index dcc8919..338b263 100755 (executable)
@@ -54,7 +54,7 @@ if __name__ == '__main__':
     if options.artatech_pdf:
         packagers.ArtaTechPdfPackager.prepare(input_filenames, options.output_dir, options.verbose)
     if options.virtualo:
-        packagers.VirtualoEpubPackager.prepare(input_filenames, options.output_dir, options.verbose)
+        packagers.VirtualoPackager.prepare(input_filenames, options.output_dir, options.verbose)
     if options.prestigio:
         packagers.PrestigioEpubPackager.prepare(input_filenames, options.output_dir, options.verbose)
     if options.prestigio_pdf: