Level 5 / Project 09 - Template Report Renderer¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | Browser |
Quick Recall: This project uses string parsing and pattern matching to find placeholders in text. Before starting, make sure you can: split a string on a delimiter and use
str.replace()to substitute values into a template string (Level 1, Project 04 - Log Line Parser).
Estimated time: 75 minutes
Focus¶
- report generation by template blocks
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-5/09-template-report-renderer
python project.py --template data/report_template.txt --data data/report_data.json --output data/rendered_report.txt
pytest -q
Expected terminal output¶
Expected artifacts¶
data/rendered_report.txt- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add
{{IF NOT condition}}...{{END IF}}blocks for negated conditionals. - Add a
{{DATE}}placeholder that inserts the current date. - Support nested variable access like
{{config.max_retries}}. - Re-run script and tests.
Break it (required) — Core¶
- Use a template with
{{variable}}that is not in the data JSON. - Create an
{{EACH items}}block whereitemsis not a list. - Capture the first failing test or visible bad output.
Fix it (required) — Core¶
- Replace missing variables with
[MISSING: variable]instead of crashing. - Skip
EACHblocks when the data is not iterable, with a warning. - Add tests for missing variables and non-iterable EACH data.
- Re-run until output and tests are deterministic.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- How does
render_variablesfind and replace{{name}}placeholders? - Why are
EACHblocks processed beforeIFblocks? - What regex pattern matches the
{{EACH items}}...{{END EACH}}block? - Where do you see template engines in production (Jinja2, Handlebars, Mustache)?
Mastery check¶
You can move on when you can: - run baseline without docs, - explain one core function line-by-line, - break and recover in one session, - keep tests passing after your change.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|