Move rendered templates out of project dir

This commit is contained in:
Jake Howard 2017-05-28 11:13:36 +01:00
parent 2c7c905c42
commit 0fcd1584be
8 changed files with 35 additions and 17 deletions

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../static/style.css" />
<link rel="stylesheet" href="{{ static_dir }}/style.css" />
</head>
<body class="cover">
<h1>{{ title }}</h1>

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../static/style.css" />
<link rel="stylesheet" href="{{ static_dir }}/style.css" />
</head>
<body class="footer">
<table>
@ -17,6 +17,6 @@
</td>
</tr>
</table>
<script type="text/javascript" src="../static/context.js"></script>
<script type="text/javascript" src="{{ internal_static_dir }}/context.js"></script>
</body>
</html>

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../static/style.css" />
<link rel="stylesheet" href="{{ static_dir }}/style.css" />
</head>
<body class="header">
<table>
@ -15,6 +15,6 @@
</td>
</tr>
</table>
<script type="text/javascript" src="../static/context.js"></script>
<script type="text/javascript" src="{{ internal_static_dir }}/context.js"></script>
</body>
</html>

View file

@ -1,4 +1,4 @@
from md_pdf.consts import TEMPLATES_DIR, STATIC_DIR, DATE_FORMAT, TIME_FORMAT, DATETIME_FORMAT
from md_pdf.consts import TEMPLATES_DIR, STATIC_DIR, DATE_FORMAT, TIME_FORMAT, DATETIME_FORMAT, INTERNAL_TEMPLATES_DIR, INTERNAL_STATIC_DIR
from word_count import word_count
from md_pdf.utils import get_plain_text
from md_pdf import __version__
@ -10,6 +10,8 @@ import os
EXTRA_CONTEXT = {
'templates_dir': TEMPLATES_DIR,
'static_dir': STATIC_DIR,
'internal_templates_dir': INTERNAL_TEMPLATES_DIR,
'internal_static_dir': INTERNAL_STATIC_DIR,
'date': datetime.datetime.now().strftime(DATE_FORMAT),
'time': datetime.datetime.now().strftime(TIME_FORMAT),
'datetime': datetime.datetime.now().strftime(DATETIME_FORMAT),

View file

@ -1,10 +1,10 @@
from scss import Compiler
from md_pdf.consts import STATIC_DIR
from md_pdf.consts import INTERNAL_STATIC_DIR
from md_pdf.build.pdf import STYLE_FILE
import os
STYLE_SRC_FILE = os.path.join(STATIC_DIR, 'style.scss')
STYLE_SRC_FILE = os.path.join(INTERNAL_STATIC_DIR, 'style.scss')
def render_css():

View file

@ -1,5 +1,5 @@
from jinja2 import Template
from md_pdf.consts import TEMPLATES_DIR
from md_pdf.consts import TEMPLATES_DIR, INTERNAL_TEMPLATES_DIR
from md_pdf.build.context import get_context
import os
import logging
@ -8,7 +8,7 @@ logger = logging.getLogger(__file__)
FILE_NAME_FORMAT = os.path.join(TEMPLATES_DIR, "{}.html")
TEMPLATE_FORMAT = os.path.join(TEMPLATES_DIR, "{}-template.html")
TEMPLATE_FORMAT = os.path.join(INTERNAL_TEMPLATES_DIR, "{}-template.html")
def render_page(input_file, output_file, context):
@ -30,4 +30,4 @@ def render_templates(config, content):
]:
render_page(TEMPLATE_FORMAT.format(template), FILE_NAME_FORMAT.format(template), context)
if config.get('toc', False):
render_page(os.path.join(TEMPLATES_DIR, 'toc-template.xsl'), os.path.join(TEMPLATES_DIR, 'toc.xsl'), context)
render_page(os.path.join(INTERNAL_TEMPLATES_DIR, 'toc-template.xsl'), os.path.join(TEMPLATES_DIR, 'toc.xsl'), context)

View file

@ -1,12 +1,23 @@
import os
import shutil
PROJECT_DIR = os.path.dirname(__file__)
WORKING_DIR = os.getcwd()
ASSET_DIR = os.path.join(PROJECT_DIR, 'assets')
CSL_DIR = os.path.join(ASSET_DIR, 'csl')
TEMPLATES_DIR = os.path.join(ASSET_DIR, 'templates')
STATIC_DIR = os.path.join(ASSET_DIR, 'static')
try:
ASSETS_DIR = os.path.join(os.environ['APPDATA'], '.mdp')
except KeyError:
ASSETS_DIR = os.path.join(os.environ['HOME'], '.mdp')
CSL_DIR = os.path.join(ASSETS_DIR, 'csl')
TEMPLATES_DIR = os.path.join(ASSETS_DIR, 'templates')
STATIC_DIR = os.path.join(ASSETS_DIR, 'static')
INTERNAL_ASSETS_DIR = os.path.join(PROJECT_DIR, 'assets')
INTERNAL_STATIC_DIR = os.path.join(INTERNAL_ASSETS_DIR, 'static')
INTERNAL_TEMPLATES_DIR = os.path.join(INTERNAL_ASSETS_DIR, 'templates')
CONFIG_FILE = os.path.join(WORKING_DIR, 'mdp.yml')
@ -15,3 +26,8 @@ CSL_DOWNLOAD_LINK = "https://github.com/citation-style-language/styles/archive/m
DATE_FORMAT = "%d %B %Y"
TIME_FORMAT = "%H:%M"
DATETIME_FORMAT = "{} {}".format(DATE_FORMAT, TIME_FORMAT)
os.makedirs(ASSETS_DIR, exist_ok=True)
os.makedirs(TEMPLATES_DIR, exist_ok=True)
os.makedirs(STATIC_DIR, exist_ok=True)

View file

@ -1,4 +1,4 @@
from md_pdf.consts import CSL_DOWNLOAD_LINK, ASSET_DIR, CSL_DIR
from md_pdf.consts import CSL_DOWNLOAD_LINK, ASSETS_DIR, CSL_DIR
from md_pdf.exceptions import PrematureExit
import os
import urllib
@ -12,7 +12,7 @@ import logging
logger = logging.getLogger(__file__)
CSL_TEMP_DIR = os.path.join(ASSET_DIR, 'styles-master')
CSL_TEMP_DIR = os.path.join(ASSETS_DIR, 'styles-master')
def check_csl():