mirror of
https://github.com/PR0M3TH3AN/VoxVera.git
synced 2025-09-08 06:58:42 +00:00
Move flyer examples to templates and add template support
This commit is contained in:
14
docs/templates.md
Normal file
14
docs/templates.md
Normal file
@@ -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 <name>
|
||||||
|
```
|
||||||
|
|
||||||
|
This will create a new folder under `dist/` named `<name>-<YYYYMMDD>` 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.
|
0
host/blank/extract_form_fields.sh → templates/blank/extract_form_fields.sh
Executable file → Normal file
0
host/blank/extract_form_fields.sh → templates/blank/extract_form_fields.sh
Executable file → Normal file
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
@@ -5,6 +5,7 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import datetime
|
||||||
from InquirerPy import prompt, inquirer
|
from InquirerPy import prompt, inquirer
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
tmpimport = None
|
tmpimport = None
|
||||||
@@ -106,13 +107,27 @@ def update_from_pdf(config_path: str, pdf_path: str):
|
|||||||
tmpdir = tempfile.mkdtemp()
|
tmpdir = tempfile.mkdtemp()
|
||||||
os.makedirs(os.path.join(tmpdir, 'from_client'), exist_ok=True)
|
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(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'))
|
shutil.copy(config_path, os.path.join(tmpdir, 'config.json'))
|
||||||
run(['bash', 'extract_form_fields.sh'], cwd=tmpdir)
|
run(['bash', 'extract_form_fields.sh'], cwd=tmpdir)
|
||||||
shutil.copy(os.path.join(tmpdir, 'config.json'), config_path)
|
shutil.copy(os.path.join(tmpdir, 'config.json'), config_path)
|
||||||
shutil.rmtree(tmpdir)
|
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):
|
def build_assets(config_path: str, pdf_path: str | None = None):
|
||||||
# generate QR codes
|
# generate QR codes
|
||||||
run(['bash', 'generate_qr.sh', config_path], cwd='src')
|
run(['bash', 'generate_qr.sh', config_path], cwd='src')
|
||||||
@@ -198,6 +213,7 @@ def main(argv=None):
|
|||||||
sub = parser.add_subparsers(dest='command')
|
sub = parser.add_subparsers(dest='command')
|
||||||
|
|
||||||
p_init = sub.add_parser('init', help='Update configuration interactively or from PDF')
|
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('--from-pdf')
|
||||||
p_init.add_argument('--non-interactive', action='store_true')
|
p_init.add_argument('--non-interactive', action='store_true')
|
||||||
|
|
||||||
@@ -212,7 +228,10 @@ def main(argv=None):
|
|||||||
config_path = os.path.abspath(args.config)
|
config_path = os.path.abspath(args.config)
|
||||||
|
|
||||||
if args.command == 'init':
|
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'):
|
if not require_cmd('pdftotext'):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
update_from_pdf(config_path, args.from_pdf)
|
update_from_pdf(config_path, args.from_pdf)
|
||||||
|
Reference in New Issue
Block a user