-
Notifications
You must be signed in to change notification settings - Fork 0
Closed as not planned
Closed as not planned
Copy link
Labels
enhancementNew feature or requestNew feature or request
Description
Goal
Wire up the full pipeline so that playground code blocks render both a preview (Web Component) and a <rafters-knobs> controls panel, while live blocks render preview-only (no knobs). Update the builder, template, and markdown rendering to support this.
Exact Implementation Requirements
Builder Changes (`builder.rs`)
- In `build_page()`, handle both `is_live()` and `is_playground()` code blocks
- For `live` blocks: existing behavior (preview + source code)
- For `playground` blocks: preview + knobs + source code
- Use `generate_knobs_config()` from the transformed block
- Render `` in the HTML
- Track whether any playground blocks exist on the page
- If any playground blocks exist, include `knobs.js` script in the page
Template Changes (`templates.rs`)
- Add `has_playground: bool` to the `Context` struct
- In `BASE_TEMPLATE`, conditionally include knobs JS:
{% if has_playground %}<script src="{{ base_url }}assets/knobs.js"></script>{% endif %}
Asset Changes (`assets.rs`)
- In `generate_assets()`, write `knobs.js` to the assets directory
Markdown Rendering (`builder.rs` `render_markdown`)
- For playground blocks, insert preview container + knobs element + source code:
Followed by the syntax-highlighted source code block
<div class="preview-container" id="{block_id}"> <{custom-element} ...>{content}</{custom-element}> </div> <rafters-knobs for="{block_id}" config='{knobs_config}'></rafters-knobs>
Behavior Requirements
- `live` blocks: unchanged behavior (preview + source)
- `playground` blocks: preview + knobs controls + source
- Pages with zero playground blocks: no `knobs.js` loaded
- The preview container gets an `id` attribute matching the `for` attribute on ``
Acceptance Criteria
Functional Tests Required
#[tokio::test]
async fn playground_block_includes_knobs() {
// Create a temp site with a playground code block
// Build it
// Verify output HTML contains <rafters-knobs> element
// Verify knobs.js is included
}
#[tokio::test]
async fn live_block_excludes_knobs() {
// Create a temp site with a live code block (not playground)
// Build it
// Verify output HTML does NOT contain <rafters-knobs>
// Verify knobs.js is NOT included
}What NOT to Include
- The knobs Web Component itself (feat(docs-rs): Create reusable rafters-knobs Web Component for playground controls #769)
- AST extraction (feat(docs-rs): Create ast_extract module for shared AST extraction with oxc_parser #765)
- Generator changes (refactor(docs-rs): Make Web Component generator discovery-driven with knobs config output #767)
File Locations
- `crates/rafters-static/src/builder.rs` - pipeline integration
- `crates/rafters-static/src/templates.rs` - add `has_playground` to Context
- `crates/rafters-static/src/assets.rs` - write knobs.js asset
Integration Requirements
Dependencies
- refactor(docs-rs): Make Web Component generator discovery-driven with knobs config output #767: `TransformedBlock.knobs_config` field
- refactor(docs-rs): Rename BlockMode::Editable to Playground #768: `BlockMode::Playground` and `is_playground()` method
- feat(docs-rs): Create reusable rafters-knobs Web Component for playground controls #769: `AssetPipeline::generate_knobs_js()`
Success Criteria
- Playground blocks render preview + knobs + source
- Live blocks render preview + source (no knobs)
- Source-only blocks render just source (no change)
- `knobs.js` only loaded when playground blocks exist
- `cargo test --workspace` passes
- `cargo clippy --workspace --all-targets` clean
This issue is complete when: A page with ```````tsx playground``````` renders an interactive preview with variant/size/boolean knobs, while ```````tsx live``````` renders preview-only.
Context & References
- Depends on: refactor(docs-rs): Make Web Component generator discovery-driven with knobs config output #767, refactor(docs-rs): Rename BlockMode::Editable to Playground #768, feat(docs-rs): Create reusable rafters-knobs Web Component for playground controls #769
- Current build pipeline: `builder.rs:380-456`
- Current markdown rendering: `builder.rs:534-590`
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request