Fix spec-explorer-data: pass metadata from SX routing instead of env lookup
The helper was trying to look up all-spec-items from get_component_env(), but that only contains defcomp/defmacro — not regular defines. Now the SX routing layer calls find-spec and passes filename/title/desc directly. Also adds boundary declaration for spec-explorer-data. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -109,3 +109,8 @@
|
|||||||
:params ()
|
:params ()
|
||||||
:returns "dict"
|
:returns "dict"
|
||||||
:service "sx")
|
:service "sx")
|
||||||
|
|
||||||
|
(define-page-helper "spec-explorer-data"
|
||||||
|
:params (filename title desc)
|
||||||
|
:returns "dict"
|
||||||
|
:service "sx")
|
||||||
|
|||||||
@@ -352,9 +352,15 @@
|
|||||||
:else (cond
|
:else (cond
|
||||||
(starts-with? slug "explore/")
|
(starts-with? slug "explore/")
|
||||||
(let ((spec-slug (slice slug 8 (string-length slug)))
|
(let ((spec-slug (slice slug 8 (string-length slug)))
|
||||||
(data (spec-explorer-data spec-slug)))
|
(spec (find-spec spec-slug)))
|
||||||
(if data
|
(if spec
|
||||||
(~spec-explorer-content :data data)
|
(let ((data (spec-explorer-data
|
||||||
|
(get spec "filename")
|
||||||
|
(get spec "title")
|
||||||
|
(get spec "desc"))))
|
||||||
|
(if data
|
||||||
|
(~spec-explorer-content :data data)
|
||||||
|
(~spec-not-found :slug spec-slug)))
|
||||||
(~spec-not-found :slug spec-slug)))
|
(~spec-not-found :slug spec-slug)))
|
||||||
:else (let ((spec (find-spec slug)))
|
:else (let ((spec (find-spec slug)))
|
||||||
(if spec
|
(if spec
|
||||||
|
|||||||
@@ -142,9 +142,10 @@ def _read_spec_file(filename: str) -> str:
|
|||||||
return ";; spec file not found"
|
return ";; spec file not found"
|
||||||
|
|
||||||
|
|
||||||
def _spec_explorer_data(slug: str) -> dict | None:
|
def _spec_explorer_data(filename: str, title: str = "", desc: str = "") -> dict | None:
|
||||||
"""Parse a spec file into structured metadata for the spec explorer.
|
"""Parse a spec file into structured metadata for the spec explorer.
|
||||||
|
|
||||||
|
Receives filename/title/desc from the SX routing layer (via find-spec).
|
||||||
Returns sections with defines, effects, params, source, and translations.
|
Returns sections with defines, effects, params, source, and translations.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
@@ -152,22 +153,9 @@ def _spec_explorer_data(slug: str) -> dict | None:
|
|||||||
from shared.sx.parser import parse_all
|
from shared.sx.parser import parse_all
|
||||||
from shared.sx.types import Symbol, Keyword
|
from shared.sx.types import Symbol, Keyword
|
||||||
|
|
||||||
# Look up spec metadata from nav-data (via find-spec helper)
|
if not filename:
|
||||||
from shared.sx.jinja_bridge import get_component_env
|
|
||||||
env = get_component_env()
|
|
||||||
all_specs = env.get("all-spec-items", [])
|
|
||||||
spec_meta = None
|
|
||||||
for item in all_specs:
|
|
||||||
if isinstance(item, dict) and item.get("slug") == slug:
|
|
||||||
spec_meta = item
|
|
||||||
break
|
|
||||||
if not spec_meta:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
filename = spec_meta.get("filename", "")
|
|
||||||
title = spec_meta.get("title", slug)
|
|
||||||
desc = spec_meta.get("desc", "")
|
|
||||||
|
|
||||||
# Read the raw source
|
# Read the raw source
|
||||||
ref_dir = os.path.join(os.path.dirname(__file__), "..", "..", "shared", "sx", "ref")
|
ref_dir = os.path.join(os.path.dirname(__file__), "..", "..", "shared", "sx", "ref")
|
||||||
if not os.path.isdir(ref_dir):
|
if not os.path.isdir(ref_dir):
|
||||||
@@ -304,19 +292,6 @@ def _spec_explorer_data(slug: str) -> dict | None:
|
|||||||
i += 1
|
i += 1
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _assign_to_section(line_num: int) -> dict:
|
|
||||||
"""Find which section a line belongs to."""
|
|
||||||
best = sections[0]
|
|
||||||
for s in sections:
|
|
||||||
# Section starts at its first define or earlier
|
|
||||||
if s["defines"]:
|
|
||||||
first_line = s["defines"][0].get("line", 0)
|
|
||||||
else:
|
|
||||||
first_line = 0
|
|
||||||
# Use section order — defines after a section header belong to it
|
|
||||||
# Simple approach: find section by scanning source position
|
|
||||||
return best
|
|
||||||
|
|
||||||
# Process defines
|
# Process defines
|
||||||
all_defines: list[dict] = []
|
all_defines: list[dict] = []
|
||||||
py_emitter = None
|
py_emitter = None
|
||||||
|
|||||||
Reference in New Issue
Block a user