コード例 #1
0
    def _add_css_styles(self, epub_book):
        """Adds default css styles and custom css text if exists in config"""

        book_css = []

        try:
            content = render_to_string('themes/style_{}.css'.format(self.name),
                                       {'dir': self.direction})

            item = ebooklib.epub.EpubItem(uid='default.css',
                                          content=content,
                                          file_name='{}/{}'.format(
                                              STYLES_DIR, 'default.css'),
                                          media_type='text/css')

            epub_book.add_item(item)
            book_css.append('default.css')
        except:
            pass

        if self.theme_name:
            content = read_theme_style(self.theme_name, self.name)

            if self.theme_name == 'custom':
                try:
                    data = json.loads(
                        self.config['theme']['custom'].encode('utf8'))

                    tmpl = Template(content)
                    ctx = Context(data)
                    content = tmpl.render(ctx)
                except:
                    logger.exception("Fails with custom theme.")

            item = ebooklib.epub.EpubItem(uid='theme.css',
                                          content=content,
                                          file_name='{}/{}'.format(
                                              STYLES_DIR, 'theme.css'),
                                          media_type='text/css')

            epub_book.add_item(item)
            book_css.append('theme.css')

        # we need to add css from publishing settings screen
        settings_style = self.config.get('settings', {}).get('styling', None)

        if settings_style:
            item = ebooklib.epub.EpubItem(uid='custom_style.css',
                                          content=settings_style,
                                          file_name='{}/{}'.format(
                                              STYLES_DIR, 'custom_style.css'),
                                          media_type='text/css')

            epub_book.add_item(item)
            book_css.append('custom_style.css')

        return book_css
コード例 #2
0
ファイル: converter.py プロジェクト: jsaugustyn/Booktype
    def _write_style(self, book):
        """Creates style file.

        Style file will include default styling, theme styling and custom styling
        provided by the user.

        Created style file will be used by booktype2mpdf.php script
        to create final PDF file.

        :Args:
          - book: EPUB Book object
        """

        if 'settings' not in self.config:
            return

        css_style = create_default_style(self.config, self.name,
                                         self.get_extra_style(book))
        theme_style = u''

        if self.theme_name != '':
            theme_style = read_theme_style(self.theme_name, self.name)

            try:
                if self.theme_name == 'custom':
                    custom = self.config['theme'].pop('custom', '{}')
                    custom = json.loads(custom.encode('utf-8'))
                    self.config.update(custom)

                tmpl = Template(theme_style)
                ctx = Context(self.config)
                _style = tmpl.render(ctx)
                theme_style = _style
            except:
                logger.exception("Writing styles failed for `%s` theme." %
                                 self.theme_name)

        custom_style = self.config.get('settings', {}).get('styling', u'')

        # add css for fpi
        css_style += self._full_page_images_css

        f = codecs.open('{}/style.css'.format(self.sandbox_path), 'wt', 'utf8')
        f.write(css_style)
        f.write(theme_style)
        f.write(custom_style)
        f.close()
コード例 #3
0
ファイル: converter.py プロジェクト: danielhjames/Booktype
    def _write_style(self, book):
        """Creates style file.

        Style file will include default styling, theme styling and custom styling
        provided by the user.

        Created style file will be used by booktype2mpdf.php script
        to create final PDF file.

        :Args:
          - book: EPUB Book object
        """

        if 'settings' not in self.config:
            return

        css_style = create_default_style(self.config, self.name, self.get_extra_style(book))
        theme_style = u''

        if self.theme_name != '':
            theme_style = read_theme_style(self.theme_name, self.name)

            try:
                if self.theme_name == 'custom':
                    custom = self.config['theme'].pop('custom', '{}')
                    custom = json.loads(custom.encode('utf-8'))
                    self.config.update(custom)

                tmpl = Template(theme_style)
                ctx = Context(self.config)
                _style = tmpl.render(ctx)
                theme_style = _style
            except:
                logger.exception("Writing styles failed for `%s` theme." % self.theme_name)

        custom_style = self.config.get('settings', {}).get('styling', u'')

        # add css for fpi
        css_style += self._full_page_images_css

        f = codecs.open('{}/style.css'.format(self.sandbox_path), 'wt', 'utf8')
        f.write(css_style)
        f.write(theme_style)
        f.write(custom_style)
        f.close()
コード例 #4
0
ファイル: converter.py プロジェクト: danielhjames/Booktype
 def _get_theme_style(self):
     return read_theme_style(self.theme_name, self._theme_suffix)
コード例 #5
0
ファイル: converter.py プロジェクト: nikhilponnuru/Booktype
 def _get_theme_style(self):
     return read_theme_style(self.theme_name, self._theme_suffix)
コード例 #6
0
    def _add_css_styles(self, epub_book):
        """Adds default css styles and custom css text if exists in config"""

        book_css = []

        try:
            content = render_to_string(
                'themes/style_{}.css'.format(self.name),
                {'dir': self.direction}
            )

            item = ebooklib.epub.EpubItem(
                uid='default.css',
                content=content,
                file_name='{}/{}'.format(STYLES_DIR, 'default.css'),
                media_type='text/css'
            )

            epub_book.add_item(item)
            book_css.append('default.css')
        except:
            pass

        if self.theme_name:
            content = read_theme_style(self.theme_name, self.name)

            if self.theme_name == 'custom':
                try:
                    data = json.loads(self.config['theme']['custom'].encode('utf8'))

                    tmpl = Template(content)
                    ctx = Context(data)
                    content = tmpl.render(ctx)
                except:
                    logger.exception("Fails with custom theme.")

            item = ebooklib.epub.EpubItem(
                uid='theme.css',
                content=content,
                file_name='{}/{}'.format(STYLES_DIR, 'theme.css'),
                media_type='text/css'
            )

            epub_book.add_item(item)
            book_css.append('theme.css')

        # we need to add css from publishing settings screen
        settings_style = self.config.get('settings', {}).get('styling', None)

        if settings_style:
            item = ebooklib.epub.EpubItem(
                uid='custom_style.css',
                content=settings_style,
                file_name='{}/{}'.format(STYLES_DIR, 'custom_style.css'),
                media_type='text/css'
            )

            epub_book.add_item(item)
            book_css.append('custom_style.css')

        return book_css
コード例 #7
0
    def _get_theme_style(self):
        """Return selected theme style content

        Theme plugin reads theme using "epub" key, because we repeat epub convertion.
        """
        return read_theme_style(self.theme_name, 'epub')