-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test case triggering issue described in #379
- Loading branch information
Showing
8 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Rear Cover Page | ||
=============== | ||
|
||
Hello! |
12 changes: 12 additions & 0 deletions
12
tests_regression/sphinx/test-customtemplate/mystylesheet.rts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../images/title.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../images/biohazard.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../images/title.png |