Skip to content

Slice 3: Template zones + Renderer #4

Description

@qwerkilo

Parent

#1 — context2html Framework

What to build

Add data-zone attributes to both templates (starter.html, report-starter.html) to replace comment-based insertion points, then build context2html/renderer.py that assembles components into templates.

Template changes:

<style data-zone="component-css"></style>
<div data-zone="component-html"></div>
<script data-zone="component-js"></script>

Keep existing <!-- INSERT: ... --> comments as fallback for backward compatibility. Update scripts/sync-template-styles.py to preserve data-zone attributes when syncing CSS from base-styles.css.

Renderer API:

  • TemplateRenderer.assemble(template_name, components, theme_name) → complete HTML string
    • template_name: "report-starter" or "starter" (resolved via known path)
    • components: list of component IDs (strings) — passed to registry for lookup
    • theme_name: theme name for <html data-theme="xxx">

What assemble() does:

  1. Load the template HTML file
  2. Set <html data-theme="xxx"> on the root element
  3. For each component ID, get Component from Registry, append HTML at data-zone="component-html"
  4. Merge all component CSS into data-zone="component-css" (dedup via selector prefix)
  5. Append all component JS at data-zone="component-js"
  6. Return the assembled HTML

Acceptance criteria

  • Both templates have data-zone attributes for css, html, and js zones
  • sync-template-styles.py preserves data-zone attributes during sync
  • render("starter", ["26"], "warm") returns valid HTML with component #26 embedded
  • Component CSS is merged (not duplicated) in the output
  • Component JS is appended after the last script
  • Tests use small inline HTML templates, not full template files
  • All 376 existing tests still pass

Blocked by

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions