Improve cuddly #1
2 changed files with 19 additions and 12 deletions
add short options and possibility to use several --output
commit
fcc05b233c
|
|
@ -26,6 +26,12 @@ Generating a HTML file
|
|||
env/bin/cuddly --template samples/cv/cv.template.html --input samples/cv.kdl --output samples/cv.html
|
||||
```
|
||||
|
||||
Generating both at the same time, with short options:
|
||||
|
||||
```
|
||||
env/bin/cuddly -t samples/cv/cv.template.html -i samples/cv.kdl -o samples/cv.pdf -o samples/cv.html
|
||||
```
|
||||
|
||||
### Template usage
|
||||
|
||||
The template language used is [Jinja](https://jinja.palletsprojects.com/en/3.0.x/), source template need to be a single HTML template file.
|
||||
|
|
|
|||
|
|
@ -115,10 +115,10 @@ def stripscheme(url):
|
|||
return url[scheme_len:]
|
||||
|
||||
@click.command()
|
||||
@click.option('--template', help="Path to a template file")
|
||||
@click.option('--input', help="Path to a KDL file")
|
||||
@click.option('--output', help="Output file")
|
||||
def main(template, input, output):
|
||||
@click.option('-t', '--template', help="Path to a template file")
|
||||
@click.option('-i', '--input', help="Path to a KDL file")
|
||||
@click.option('-o', '--output', 'outputs', help="Output file", multiple=True)
|
||||
def main(template, input, outputs):
|
||||
"""
|
||||
Template a file using a KDL input
|
||||
"""
|
||||
|
|
@ -145,11 +145,12 @@ def main(template, input, output):
|
|||
|
||||
output_html = input_node.render(template)
|
||||
|
||||
for output in outputs:
|
||||
if output.endswith('.pdf'):
|
||||
from weasyprint import HTML, default_url_fetcher
|
||||
base_dir = pathlib.Path(template_path).absolute().parent
|
||||
HTML(string=output_html, base_url=f'file://{base_dir}/').write_pdf(output, pdf_variant='pdf/ua-1')
|
||||
|
||||
HTML(string=output_html, base_url=f'file://{base_dir}/').write_pdf(
|
||||
output, pdf_variant='pdf/ua-1'
|
||||
)
|
||||
else:
|
||||
with open(output, 'w') as output_file:
|
||||
output_file.write(output_html)
|
||||
|
|
|
|||
Loading…
Reference in a new issue