From 0e9c8429bb1d32074d9b4134ae08c771b7276da1 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Thu, 19 Jun 2025 11:47:48 -0400 Subject: [PATCH] Move flyer examples to templates and add template support --- docs/templates.md | 14 +++++++++++ .../blank/extract_form_fields.sh | 0 {host => templates}/voxvera/config.json | 0 {host => templates}/voxvera/example.pdf | Bin {host => templates}/voxvera/index.html | 0 {host => templates}/voxvera/nostr.html | 0 .../voxvera/qrcode-content.png | Bin .../voxvera/qrcode-tear-offs.png | Bin .../voxvera/submission_form.pdf | Bin voxvera/cli.py | 23 ++++++++++++++++-- 10 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 docs/templates.md rename {host => templates}/blank/extract_form_fields.sh (100%) mode change 100755 => 100644 rename {host => templates}/voxvera/config.json (100%) rename {host => templates}/voxvera/example.pdf (100%) rename {host => templates}/voxvera/index.html (100%) rename {host => templates}/voxvera/nostr.html (100%) rename {host => templates}/voxvera/qrcode-content.png (100%) rename {host => templates}/voxvera/qrcode-tear-offs.png (100%) rename {host => templates}/voxvera/submission_form.pdf (100%) diff --git a/docs/templates.md b/docs/templates.md new file mode 100644 index 0000000..f299c24 --- /dev/null +++ b/docs/templates.md @@ -0,0 +1,14 @@ +# Flyer Templates + +Pre-built flyer templates live in the `templates/` directory. Use the CLI to copy one with: + +```bash +voxvera init --template +``` + +This will create a new folder under `dist/` named `-` containing the template files. + +Available templates: + +- **blank** – minimal placeholder files, also used when extracting fields from a PDF. +- **voxvera** – example flyer showcasing the VoxVera project. diff --git a/host/blank/extract_form_fields.sh b/templates/blank/extract_form_fields.sh old mode 100755 new mode 100644 similarity index 100% rename from host/blank/extract_form_fields.sh rename to templates/blank/extract_form_fields.sh diff --git a/host/voxvera/config.json b/templates/voxvera/config.json similarity index 100% rename from host/voxvera/config.json rename to templates/voxvera/config.json diff --git a/host/voxvera/example.pdf b/templates/voxvera/example.pdf similarity index 100% rename from host/voxvera/example.pdf rename to templates/voxvera/example.pdf diff --git a/host/voxvera/index.html b/templates/voxvera/index.html similarity index 100% rename from host/voxvera/index.html rename to templates/voxvera/index.html diff --git a/host/voxvera/nostr.html b/templates/voxvera/nostr.html similarity index 100% rename from host/voxvera/nostr.html rename to templates/voxvera/nostr.html diff --git a/host/voxvera/qrcode-content.png b/templates/voxvera/qrcode-content.png similarity index 100% rename from host/voxvera/qrcode-content.png rename to templates/voxvera/qrcode-content.png diff --git a/host/voxvera/qrcode-tear-offs.png b/templates/voxvera/qrcode-tear-offs.png similarity index 100% rename from host/voxvera/qrcode-tear-offs.png rename to templates/voxvera/qrcode-tear-offs.png diff --git a/host/voxvera/submission_form.pdf b/templates/voxvera/submission_form.pdf similarity index 100% rename from host/voxvera/submission_form.pdf rename to templates/voxvera/submission_form.pdf diff --git a/voxvera/cli.py b/voxvera/cli.py index 8de3e44..f854569 100644 --- a/voxvera/cli.py +++ b/voxvera/cli.py @@ -5,6 +5,7 @@ import re import shutil import subprocess import sys +import datetime from InquirerPy import prompt, inquirer from rich.console import Console tmpimport = None @@ -106,13 +107,27 @@ def update_from_pdf(config_path: str, pdf_path: str): tmpdir = tempfile.mkdtemp() os.makedirs(os.path.join(tmpdir, 'from_client'), exist_ok=True) shutil.copy(pdf_path, os.path.join(tmpdir, 'from_client', 'submission_form.pdf')) - shutil.copy('host/blank/extract_form_fields.sh', tmpdir) + shutil.copy('templates/blank/extract_form_fields.sh', tmpdir) shutil.copy(config_path, os.path.join(tmpdir, 'config.json')) run(['bash', 'extract_form_fields.sh'], cwd=tmpdir) shutil.copy(os.path.join(tmpdir, 'config.json'), config_path) shutil.rmtree(tmpdir) +def copy_template(name: str) -> str: + """Copy a template directory into dist/ with a datestamped folder.""" + date = datetime.date.today().strftime('%Y%m%d') + src = os.path.join('templates', name) + if not os.path.isdir(src): + print(f"Template {name} not found", file=sys.stderr) + sys.exit(1) + dest = os.path.join('dist', f"{name}-{date}") + os.makedirs('dist', exist_ok=True) + shutil.copytree(src, dest, dirs_exist_ok=True) + print(f"Template copied to {dest}") + return dest + + def build_assets(config_path: str, pdf_path: str | None = None): # generate QR codes run(['bash', 'generate_qr.sh', config_path], cwd='src') @@ -198,6 +213,7 @@ def main(argv=None): sub = parser.add_subparsers(dest='command') p_init = sub.add_parser('init', help='Update configuration interactively or from PDF') + p_init.add_argument('--template', help='Copy a template into dist/') p_init.add_argument('--from-pdf') p_init.add_argument('--non-interactive', action='store_true') @@ -212,7 +228,10 @@ def main(argv=None): config_path = os.path.abspath(args.config) if args.command == 'init': - if args.from_pdf: + if args.template: + copy_template(args.template) + return + elif args.from_pdf: if not require_cmd('pdftotext'): sys.exit(1) update_from_pdf(config_path, args.from_pdf)