Skip to content

Make jinja default slot rendering opt-in and customizable - #115

Merged
volfpeter merged 3 commits into
mainfrom
jinja-defaultslots-optin
Jul 16, 2026
Merged

Make jinja default slot rendering opt-in and customizable#115
volfpeter merged 3 commits into
mainfrom
jinja-defaultslots-optin

Conversation

@volfpeter

@volfpeter volfpeter commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Closes #114

Summary by CodeRabbit

  • New Features
    • Added a use_default_slots option to control whether default slots are rendered in Jinja templates.
    • Default slot selection is now overridable/customizable, while explicitly provided slots still take precedence.
  • Tests
    • Expanded the Jinja template rendering test matrix to validate behavior with default slots both enabled and disabled, including recursive templates.
  • Chores
    • Bumped the package version to 0.13.0.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0d590e52-9d7b-4532-b0ec-929ae0ea4249

📥 Commits

Reviewing files that changed from the base of the PR and between 5ca8573 and cf1f192.

📒 Files selected for processing (1)
  • htmy/__init__.py

📝 Walkthrough

Walkthrough

JinjaTemplate now makes default-slot rendering opt-in through use_default_slots, delegates slot selection to _get_default_slots(), preserves explicit-slot precedence, and updates tests and the package version.

Changes

Jinja default-slot rendering

Layer / File(s) Summary
Default-slot configuration and rendering
htmy/jinja.py, htmy/__init__.py
Adds the opt-in flag and overridable slot lookup hook, conditionally renders default slots, preserves explicit-slot precedence, and bumps the package version.
Default-slot behavior coverage
tests/test_jinja.py
Updates parametrized tests and validates opt-in, opt-out, merging, overriding, and recursion behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant JinjaTemplate
  participant RenderingContext
  participant JinjaEngine
  JinjaTemplate->>RenderingContext: Look up default slots
  RenderingContext-->>JinjaTemplate: Return slot components
  JinjaTemplate->>JinjaTemplate: Render enabled slots and merge explicit slots
  JinjaTemplate->>JinjaEngine: Render template with slots context
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The version bump in htmy/init.py is unrelated to issue #114 and appears outside the requested scope. Remove the version-only change or include it only if the release bump is intentionally part of this PR.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main change: making Jinja default slot rendering opt-in and customizable.
Linked Issues check ✅ Passed The changes add an opt-in flag and a customizable hook, matching issue #114's requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jinja-defaultslots-optin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@htmy/jinja.py`:
- Around line 173-175: Update the default-slot loop in the rendering method to
skip any name already present in self._slots before calling renderer.render.
Preserve rendering for non-overridden default slots and the existing assignment
behavior for those slots.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5cd49b5c-afc1-40b1-8199-ef6e1fcd0c59

📥 Commits

Reviewing files that changed from the base of the PR and between 08d6ca7 and b5e7b79.

📒 Files selected for processing (2)
  • htmy/jinja.py
  • tests/test_jinja.py

Comment thread htmy/jinja.py Outdated
@volfpeter
volfpeter merged commit 3dfa111 into main Jul 16, 2026
3 checks passed
@volfpeter
volfpeter deleted the jinja-defaultslots-optin branch July 16, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JinjaTemplate unconditionally renders default slots

1 participant