]> git.parisson.com Git - telemeta.git/commitdiff
epub: add cover, fix various style and (french) text
authorGuillaume Pellerin <yomguy@parisson.com>
Tue, 9 Jun 2015 15:03:47 +0000 (17:03 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Tue, 9 Jun 2015 15:03:47 +0000 (17:03 +0200)
telemeta/static/telemeta/css/telemeta_epub.css
telemeta/static/telemeta/images/cul-de-lampe_fin-page.jpg [new file with mode: 0644]
telemeta/templates/telemeta/inc/epub_collection.html
telemeta/templates/telemeta/inc/epub_cover.html [new file with mode: 0644]
telemeta/templates/telemeta/inc/epub_preamble.html
telemeta/views/epub.py

index 8c7886564108a75f52a9bef62a0c6efce29c8cf1..e2a9a78839c6350d36901ba66c7cc95d59b02b4d 100644 (file)
@@ -16,6 +16,7 @@ h3 {
     font-size: 1.25em;
     margin-top: 0px;
     font-weight: normal;
+    color: #2B90AB;
 }
 
 p {
diff --git a/telemeta/static/telemeta/images/cul-de-lampe_fin-page.jpg b/telemeta/static/telemeta/images/cul-de-lampe_fin-page.jpg
new file mode 100644 (file)
index 0000000..b4910f7
Binary files /dev/null and b/telemeta/static/telemeta/images/cul-de-lampe_fin-page.jpg differ
index d2accf60f9b2b54a629116a628638394d21fc1e8..19719e0abdd8b415eaf4c18c52607feb4124a2ea 100644 (file)
@@ -28,7 +28,5 @@
         <img src="{{ default_image }}"/>
    </div>
   {% endif %}
-
-
 </div>
 {% endfor %}
diff --git a/telemeta/templates/telemeta/inc/epub_cover.html b/telemeta/templates/telemeta/inc/epub_cover.html
new file mode 100644 (file)
index 0000000..3755556
--- /dev/null
@@ -0,0 +1,11 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="en" xml:lang="en">
+ <head>
+  <style>
+    body { margin: 0em; padding: 0em; }
+    img { max-width: 100%; max-height: 100%; }
+  </style>
+ </head>
+ <body>
+   <img src="{{ image }}" alt="cover" />
+ </body>
+</html>
\ No newline at end of file
index 172c91dbd5fd80475dbe631981ea6a7786bba23a..91f7b865935e7799aa4487a0e542963ebed03571 100644 (file)
@@ -3,18 +3,18 @@
 
 <link rel="stylesheet" type="text/css" href="style/epub.css" />
 
-<h2>{% trans 'Preambule' %}</h2>
+<!-- <h2>{% trans 'Copyright' %}</h2> #} -->
 
-<p>Ce livre contient les sons présentés dans le livre "Écoute musicale et acoustique" de Michèle Castellengo édité aux éditions Eyrolles.</p>
+<p>Vous trouverez dans ce « livret sons » au format ePub la collection complète des exemples sonores{% if mode_single %} du {{ title }}{% endif %} de l’ouvrage <i>Écoute musicale et acoustique</i> de Michèle Castellengo, paru aux Éditions Eyrolles.</p>
 
 <p>
-Copyright (c) 2015 Michèle Castellengo<br/>
-Édition (e) 2015 Eyrolles<br/>
-Publication (p) 2015 Parisson<br/>
+Conception : Michèle Castellengo<br/>
+Réalisation : Parisson<br/>
 </p>
 
 <p>
-Conception et réalisation : Eyrolles / Parisson
+(c) Groupe Eyrolles, 2015<br/>
+Reproduction interdite sans autorisation de l’éditeur.
 </p>
 
 <!--
index 8215256c8c91e041b7682de0bda2b83289feb84f..39bb95498878659b60ecc11a56bc976796f0d79e 100644 (file)
@@ -48,6 +48,7 @@ class BaseEpubMixin(TelemetaBaseMixin):
     default_image = os.sep.join([local_path, '..', 'static', 'telemeta', 'images', 'cul_de_lampe.jpg'])
     template = os.sep.join([local_path, '..', 'templates', 'telemeta', 'inc', 'epub_collection.html'])
     template_preamble = os.sep.join([local_path, '..', 'templates', 'telemeta', 'inc', 'epub_preamble.html'])
+    template_cover = os.sep.join([local_path, '..', 'templates', 'telemeta', 'inc', 'epub_cover.html'])
 
     def write_book(self, corpus, collection=None, path=None):
         self.book = epub.EpubBook()
@@ -61,7 +62,12 @@ class BaseEpubMixin(TelemetaBaseMixin):
             self.book.set_title(corpus.title)
         else:
             self.filename = collection.code
-            self.book.set_title(corpus.title + ' - ' + collection.title)
+            short_title = collection.title.split(' ')
+            if not ' 0' in collection.title:
+                short_title = short_title[0][:4] + ' ' + short_title[1]
+            else:
+                short_title = 'Intro'
+            self.book.set_title(corpus.title[:15] + '... ' + short_title)
 
         self.path = self.cache_data.dir + os.sep + self.filename + '.epub'
 
@@ -79,21 +85,31 @@ class BaseEpubMixin(TelemetaBaseMixin):
             self.collections = [collection]
             mode_single = True
             instance = collection
+            if ' 0' in collection.title:
+                chap_num = "d'introduction"
+            else:
+                chap_num = collection.code.split('_')[-1]
+            context = {'title': 'chapitre ' + chap_num,
+                        'mode_single': mode_single}
         else:
             self.collections = self.corpus.children.all()
             mode_single = False
             instance = self.corpus
+            context = {'title': '', 'mode_single': mode_single}
 
         # add cover image
         for media in instance.related.all():
             filename = os.path.split(media.file.path)[-1]
-            self.book.set_cover(filename, open(media.file.path, 'r').read())
+            self.book.set_cover(filename, open(media.file.path, 'rb').read())
+            cover = epub.EpubHtml(title='cover-bis', file_name='cover-bis' + '.xhtml', lang='fr')
+            cover.content = render_to_string(self.template_cover, {'image': filename})
+            self.book.add_item(cover)
             break
 
-        context = {}
-        preamble = epub.EpubHtml(title='Preamble', file_name='preamble' + '.xhtml', lang='fr')
+
+        preamble = epub.EpubHtml(title='Copyright', file_name='copyright' + '.xhtml', lang='fr')
         preamble.content = render_to_string(self.template_preamble, context)
-        preamble.is_chapter = False
+        preamble.is_chapter = True
         default_image_added = False
         default_image_relative_path = ''
         self.book.add_item(preamble)
@@ -134,22 +150,24 @@ class BaseEpubMixin(TelemetaBaseMixin):
                     self.book.add_item(epub_item)
                     default_image_added = True
 
-
             title_split = collection.title.split(' - ')
             if len(title_split) > 1:
-                if '0' in title_split[0]:
-                    title = title_split[1]
-                    subtitle = ''
+                if ' 0' in title_split[0]:
+                    title = ''
+                    subtitle = title_split[1]
+                    chapter_title = subtitle
                 else:
                     title = title_split[0]
                     subtitle = title_split[1]
+                    chapter_title = ' - '.join([title, subtitle])
             else:
                 title = collection.title
                 subtitle = ''
+                chapter_title = title
 
             context = {'collection': collection, 'title': title, 'subtitle': subtitle, 'mode_single': mode_single,
                         'site': site, 'items': items, 'default_image': default_image_relative_path}
-            c = epub.EpubHtml(title=' - '.join([title, subtitle]), file_name=collection.code + '.xhtml', lang='fr')
+            c = epub.EpubHtml(title=chapter_title, file_name=collection.code + '.xhtml', lang='fr')
             c.content = render_to_string(self.template, context)
             self.chapters.append(c)
             # add self.chapters to the self.book
@@ -168,7 +186,7 @@ class BaseEpubMixin(TelemetaBaseMixin):
             self.chapters.insert(0,'nav')
 
         # create spin, add cover page as first page
-        self.chapters.insert(0,'cover')
+        self.chapters.insert(0, cover)
         self.book.spine = self.chapters
 
         # write epub file
@@ -195,7 +213,6 @@ class CorpusEpubView(BaseEpubMixin, View):
         return super(CorpusEpubView, self).dispatch(*args, **kwargs)
 
 
-
 class CollectionEpubView(BaseEpubMixin, View):
     "Download collection data embedded in an EPUB3 file"