Skip to content

Commit

Permalink
Test case triggering issue described in #379
Browse files Browse the repository at this point in the history
  • Loading branch information
brechtm committed Dec 3, 2022
1 parent 59e8674 commit 48dfd77
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests_regression/sphinx/test-customtemplate/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'Custom Template'
copyright = '1999, Author'
author = 'Author'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = []

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for rinohtype PDF output ----------------------------------------

import os
import sys

sys.path.insert(0, os.path.abspath('.'))

import mytemplate

rinoh_documents = [dict(
doc='index',
target='customtemplate',
template='mytemplate.rtt',
)]
4 changes: 4 additions & 0 deletions tests_regression/sphinx/test-customtemplate/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Rear Cover Page
===============

Hello!
12 changes: 12 additions & 0 deletions tests_regression/sphinx/test-customtemplate/mystylesheet.rts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[STYLESHEET]
name=Custom
base=sphinx
description=The Sphinx stylesheet, but using core PDF fonts

[VARIABLES]
mono_typeface=Courier
serif_typeface=Times
sans_typeface=Helvetica

[title page date : Paragraph('title page date')]
hide = true
59 changes: 59 additions & 0 deletions tests_regression/sphinx/test-customtemplate/mytemplate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from pathlib import Path

from rinoh import register_template
from rinoh.attribute import OverrideDefault
from rinoh.dimension import CM, PT
from rinoh.image import Image
from rinoh.layout import CONTENT, DownExpandingContainer, UpExpandingContainer
from rinoh.paragraph import Paragraph
from rinoh.template import (DocumentTemplate, DocumentPartTemplate,
PageBase, PageTemplateBase)
from rinoh.templates import Book
from rinoh.text import StyledText


class RearCoverPageTemplate(PageTemplateBase):
def page(self, document_part, page_number, chain):
return RearCoverPage(document_part, self, page_number)


REAR_COVER_PAGE_TEXT = r"""
'Some '(style 1) 'Text\n'(style 2)
'Some '(style 1) 'Text'(style 2)
""".replace('\n', '') # work around rinohtype bug


class RearCoverPage(PageBase):
configuration_class = RearCoverPageTemplate

def __init__(self, document_part, template, page_number):
super().__init__(document_part, template, page_number)
margin = 2*CM
split = 20*CM
width = self.width - 2 * margin
self.text = UpExpandingContainer('text', CONTENT, self, left=margin,
bottom=split, width=width)
self.text << Paragraph(StyledText.from_string(REAR_COVER_PAGE_TEXT),
style='rear cover page text')
self.imgs = DownExpandingContainer('images', CONTENT, self,
left=margin, top=split, width=width)
self.imgs << Image(Path(__file__).parent / 'rear_page_1.png',
width=2*CM, align='right')
self.imgs << Image(Path(__file__).parent / 'rear_page_2.png',
width=2*CM, align='right')


class RearCoverPartTemplate(DocumentPartTemplate):
drop_if_empty = OverrideDefault(False)

def _flowables(self, document):
return iter([]) # content is static, placed in RearCoverPage


class MyDocumentTemplate(Book):
parts = OverrideDefault(['title', 'front_matter', 'contents', 'back_matter',
'rear_cover'])
rear_cover = RearCoverPartTemplate()
rear_cover_page = RearCoverPageTemplate(base='page')

register_template('my_template', MyDocumentTemplate)
7 changes: 7 additions & 0 deletions tests_regression/sphinx/test-customtemplate/mytemplate.rtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[TEMPLATE_CONFIGURATION]
name=my template configuration
template=my_template
stylesheet=mystylesheet.rts

[rear_cover_page]
background = 'rear_page_bg.png', scale=fit

0 comments on commit 48dfd77

Please sign in to comment.