import os
from .page import Page
# all objects here require a header and footer as minimum
class HF:
def __init__(self):
self.header: str = None
self.footer: str = None
# some objects require a "list-like" set of attributes
class Common(HF):
def __init__(self):
self.list_header: str = None
self.list_footer: str = None
self.list_entry: str = None
self.list_separator: str = None
# main class
class Template(HF):
def __init__(self, src: str):
self.src: str = src
self.article: HF = HF()
self.articles: Common = Common()
self.tags: Common = Common()
self.rss: str = None
self.is_read: bool = False
# writes default templates
def write(self) -> None:
# get initial working directory
iwd = os.getcwd()
os.chdir(self.src)
# create templates dir
os.mkdir('templates')
os.chdir('templates')
# common
os.mkdir('common')
os.chdir('common')
self.__write_template('header.html',
['\n',
'\n',
'
\n',
'\n',
'$$TITLE\n',
'\n',
'\n'])
self.__write_template('footer.html',
['\n',
'\n'])
# go back to templates
os.chdir('..')
# article entry
os.mkdir('article')
os.chdir('article')
self.__write_template('header.html',
['
$$TITLE
\n',
'
$$AUTHOR
\n',
'
Created: $$CTIME, modified: $$MTIME
\n'])
self.__write_template('footer.html',
[''])
# go back to templates
os.chdir('..')
# article index (articles)
os.mkdir('articles')
os.chdir('articles')
self.__write_template('header.html',
[''])
self.__write_template('list_header.html',
['
\n'])
self.__write_template('footer.html',
[''])
# go back to templates
os.chdir('..')
# tag
os.mkdir('tag')
os.chdir('tag')
self.__write_template('header.html',
[''])
self.__write_template('list_header.html',
['