-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
140 additions
and
84 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
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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
from os import path | ||
import subprocess | ||
|
||
def compile(driver_file, cwd): | ||
def compile(driver_file, cwd, pipe=True): | ||
# compile | ||
out = subprocess.run(['xelatex', driver_file], | ||
cwd=cwd, | ||
stdout=subprocess.PIPE) | ||
|
||
print('wtf') | ||
opt = dict(stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
opt = opt if pipe else {} | ||
out = subprocess.run(['xelatex', '-halt-on-error', driver_file], | ||
cwd=cwd) | ||
# stdout=subprocess.PIPE, | ||
# stderr=subprocess.STDOUT) | ||
base = path.splitext(driver_file)[0] | ||
|
||
if out.returncode == 0: | ||
return path.join(cwd, base+'.pdf') | ||
else: | ||
raise Exception('Fail to compile: ' + out.stdout.decode('utf-8')) | ||
output = out.stdout.decode('utf-8') if pipe else 'See above' | ||
raise Exception('Fail to compilation: ' + output) |
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
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
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,29 @@ | ||
from template_base import TemplateBase | ||
from os import path | ||
import shutil | ||
__all__=['template'] | ||
|
||
def template(): | ||
return UltimateSampleTemplate() | ||
|
||
class UltimateSampleTemplate(TemplateBase): | ||
def __init__(self): | ||
super().__init__(path.dirname(__file__)) #this setup jinja loader | ||
pass | ||
|
||
def preprocess(self, data, cwd): | ||
""" | ||
should return a dictionary with all the data | ||
some additional data might be build here | ||
This is the place where we should render graph and put the output | ||
file name in the directory | ||
""" | ||
asset_dir = path.join(path.dirname(__file__), 'assets') | ||
shutil.copytree(asset_dir, path.join(cwd, 'assets')) #should we symlink instead? | ||
return data | ||
|
||
def get_template(self, data): | ||
return 'template.tex' | ||
|
||
def sample_data(self): | ||
return { "name": "ปิติ" } |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 @@ | ||
\documentclass[12pt]{article} | ||
|
||
\usepackage{fontspec} | ||
\usepackage{xltxtra} | ||
\XeTeXlinebreaklocale "th_TH" | ||
\XeTeXlinebreakskip = 0pt plus 1pt | ||
\usepackage{fonts-tlwg} | ||
|
||
\setmainfont[ | ||
Path=assets/, | ||
BoldFont={THSarabunNew Bold.ttf}, | ||
ItalicFont={THSarabunNew Italic.ttf}, | ||
BoldItalicFont={THSarabunNew BoldItalic.ttf}, | ||
]{THSarabunNew.ttf} | ||
|
||
|
||
\begin{document} | ||
|
||
International Text | ||
|
||
สวัสดี (((name))) (((thainame))) | ||
|
||
Embed Static Image | ||
|
||
\begin{center} | ||
\includegraphics[width=0.7\linewidth]{assets/birthday-cake} | ||
\end{center} | ||
|
||
Embed dynamic image เช่น graph ได้เหมือนกัน | ||
\begin{center} | ||
\includegraphics[width=0.7\linewidth]{graph} | ||
\end{center} | ||
|
||
|
||
\end{document} |
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 |
---|---|---|
@@ -1,7 +1,31 @@ | ||
from templates import sample_template | ||
from templates import sample_template, ultimate_sample_template | ||
from os import path | ||
from importlib import import_module | ||
import os | ||
import shutil | ||
import sys | ||
import argparse | ||
|
||
tmpdir = path.join(path.dirname(__file__), 'temp') | ||
|
||
t = sample_template.SampleTemplate() | ||
t.compile({"x": "abc", "y": "def"}, tmpdir) | ||
def main(module_name): | ||
# module_name = 'templates.ultimate_sample_template' | ||
|
||
module = import_module(module_name) | ||
|
||
t = module.template() | ||
tmpdir = path.join(path.dirname(__file__), 'tmp') | ||
print('Working on '+tmpdir) | ||
shutil.rmtree(tmpdir) | ||
os.makedirs(tmpdir) | ||
t.compile(t.sample_data(), tmpdir, pipe=False) | ||
|
||
print('see output at '+tmpdir+'/driver.pdf') | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description= | ||
'Test template. Ex: python test_template.py templates.sample_template') | ||
parser.add_argument('module', metavar='module', type=str, nargs=1, | ||
help='template module name(ex: templates.sample_template)') | ||
args = parser.parse_args() | ||
main(args.module[0]) |