summaryrefslogtreecommitdiff
path: root/panfry/document.py
diff options
context:
space:
mode:
Diffstat (limited to 'panfry/document.py')
-rwxr-xr-xpanfry/document.py64
1 files changed, 45 insertions, 19 deletions
diff --git a/panfry/document.py b/panfry/document.py
index 01f8f83..eec8aea 100755
--- a/panfry/document.py
+++ b/panfry/document.py
@@ -10,38 +10,54 @@ from panfry.page import TextFile, Page
from panfry.toc import TOCItem
-class Document:
+class Document(object):
+ 'A panfry documment'
+
+ valid_toc_types = ('simple',
+ 'full',
+ 'json',
+ )
+
+ standalone_toc_types = ('full')
def __init__(self, path, subdoc=''):
self.src_path = os.path.join(path, 'src', subdoc)
self.meta = self.get_meta(self.src_path)
self.pages = self.get_pages(self.src_path)
- self.full_toc = True
+ self._toc_type = 'full'
self.standalone = True
- self.json_toc = False
+ self.template_path = os.path.join(path, 'templates')
self.css_file = 'css/style.css'
- self.assets_dir = 'assets'
+ self.assets_dir = os.path.join('assets', subdoc)
self.pandoc_options = []
- @property
- def set_simple_toc(self):
- self.full_toc = False
@property
- def set_json_toc(self):
- self.json_toc = True
- self.standalone = False
+ def no_pdf(self):
+ if 'NOPDF' in os.listdir(self.src_path):
+ return True
+ return False
- def set_pandoc_options(self, options):
- self.pandoc_options = options
+ @property
+ def no_epub(self):
+ if 'NOEPUB' in os.listdir(self.src_path):
+ return True
+ return False
@property
- def set_full_toc(self):
- self.full_toc = True
+ def toc_type(self):
+ return self._toc_type
+
+ @toc_type.setter
+ def toc_type(self, toc_type):
+ if toc_type in self.valid_toc_types:
+ self._toc_type = toc_type
+ self.standalone = toc_type in self.standalone_toc_types
+ else:
+ return ''
- def set_templater(self, templater):
- self.templater = templater
+ return toc_type
def expand_int_links(self, source):
'''
@@ -146,7 +162,7 @@ class Document:
'''
links = []
for page in self.pages:
- if self.full_toc:
+ if self.toc_type == 'full':
toc = page.toc
else:
toc = [page.toc[0]]
@@ -212,6 +228,8 @@ class Document:
return self.filename_base + '.epub'
def publish_pdf(self, pub_path):
+ if self.no_pdf:
+ return ''
pdf_path = os.path.join(pub_path, self.pdf_filename)
src = self.title_block.source
for page in self.pages:
@@ -221,7 +239,11 @@ class Document:
doc.markdown = src
pandoc.set_cwd(os.path.abspath(self.src_path))
- doc.add_argument('latex-engine=xelatex')
+ template = os.path.abspath(os.path.join(self.template_path, 'tex.template'))
+ if os.path.isfile(template):
+ print(template)
+ doc.add_argument('template=%s' % template)
+ doc.add_argument('latex-engine=lualatex')
for option in self.pandoc_options:
doc.add_argument(option)
doc.to_file(pdf_path)
@@ -230,6 +252,8 @@ class Document:
return self.pdf_filename
def publish_epub(self, pub_path):
+ if self.no_epub:
+ return ''
epub_path = os.path.join(pub_path, self.epub_filename)
src = self.title_block.source
for page in self.pages:
@@ -255,6 +279,8 @@ class Document:
dst = os.path.join(pub_path, asset)
if os.path.isdir(src):
copy(src, dst)
+ else:
+ copy(src, dst)
def publish_html(self, pub_path):
pandoc.set_cwd(None)
@@ -299,7 +325,7 @@ class Document:
os.remove(ref)
os.symlink(src, ref)
- if self.json_toc:
+ if self.toc_type == 'json':
write_file(os.path.join(pub_path, 'toc.json'),
unicode(self.toc_json, 'utf-8'))