Skip to content

feat(compose): cortex compose command stacks widgets into single SVG#12

Merged
AbdullahBakir97 merged 1 commit intomainfrom
feature/cortex-compose
Apr 27, 2026
Merged

feat(compose): cortex compose command stacks widgets into single SVG#12
AbdullahBakir97 merged 1 commit intomainfrom
feature/cortex-compose

Conversation

@AbdullahBakir97
Copy link
Copy Markdown
Owner

Summary

Tier C #8. New CLI command cortex compose produces a single composite SVG from any subset of the 22 widgets — for users who want one image to drop in their README rather than 17 separate references.

cortex compose -c examples/extreme.yml   -w synthwave-banner -w brain-anatomical -w badges   -w yearly-highlights -w footer-banner   -o assets/composite.svg

Test plan

  • 164/164 pytest passes (156 prior + 8 new compose tests)
  • Smoke-tested with 5 widgets: 1200×2374 viewBox, 158.7KB output
  • Unknown slug raises ValueError with available-list message
  • ruff + format clean

Tier C #8. New CLI command + supporting cortex.compose module.

## Use case
Profile READMEs often want ONE image to drop in (a hero stack of
header-banner + brain + badges + footer-banner) rather than 17 separate
references. compose() builds each listed widget in-memory and nests them
vertically inside one outer <svg>.

## CLI
    cortex compose -c examples/extreme.yml \
      -w synthwave-banner -w brain-anatomical -w badges \
      -w yearly-highlights -w footer-banner \
      -o assets/composite.svg [--gap 12] [--list]

--list prints the available widget slugs and exits.

## Implementation
- _WIDGET_REGISTRY maps slug -> (builder_module, builder_func, filename),
  mirroring the order in cortex.__init__.build_all but accessible by name.
- _build_widget_svg() invokes the matching builder, reads back the SVG
  text, parses the viewBox to extract intrinsic height. Falls back to the
  height= attribute or 200px on parse failure.
- _nest_svg() rewrites the outer <svg> opening tag with x/y/width/height
  while preserving the child's viewBox, xmlns, and other attributes.
  Renderers handle the coordinate-system mapping automatically.
- Composite outer viewBox = 1200 × sum(child_heights) + gap*(n-1).

## Tests
8 new tests in test_compose.py:
  • list_available() returns all 22 known widget slugs
  • _strip_xml_decl removes <?xml ...?> declaration safely
  • compose() with valid widgets produces well-formed XML
  • Unknown slug raises ValueError with helpful message
  • Stacked widgets have monotonically-increasing y positions
  • Composite total height = sum(child heights) + gaps
  • Size budget for 3-widget compose under 60KB

Total tests: 164/164 passing.

## Smoke-test
  $ cortex compose -c examples/extreme.yml \
      -w synthwave-banner -w brain-anatomical -w badges \
      -w yearly-highlights -w footer-banner -o /tmp/composite.svg
  [OK] Composite SVG -> /tmp/composite.svg  (158.7 KB)
  → 1200×2374 viewBox, all 5 widgets stacked correctly.
@AbdullahBakir97 AbdullahBakir97 merged commit e913f5e into main Apr 27, 2026
13 checks passed
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.

1 participant