"""Individual content builder functions for sx docs pages.""" from __future__ import annotations from .renders import _code, _example_code, _placeholder, _oob_code, _clear_components_btn from .utils import _attr_table_sx, _primitives_section_sx, _headers_table_sx def _docs_introduction_sx() -> str: return ( '(~doc-page :title "Introduction"' ' (~doc-section :title "What is sx?" :id "what"' ' (p :class "text-stone-600"' ' "sx is an s-expression language for building web UIs. ' 'It combines htmx\'s server-first hypermedia approach with React\'s component model. ' 'The server sends s-expression source code over the wire. The client parses, evaluates, and renders it to DOM.")' ' (p :class "text-stone-600"' ' "The same evaluator runs on both server (Python) and client (JavaScript). ' 'Components defined once render identically in both environments."))' ' (~doc-section :title "Design decisions" :id "design"' ' (p :class "text-stone-600"' ' "HTML elements are first-class: (div :class \\"card\\" (p \\"hello\\")) renders exactly what you\'d expect. ' 'Components use defcomp with keyword parameters and optional children. ' 'The evaluator supports let bindings, conditionals, lambda, map/filter/reduce, and ~80 primitives.")' ' (p :class "text-stone-600"' ' "sx replaces the pattern of ' 'shipping a JS framework + build step + client-side router + state management library ' 'just to render some server data. For most applications, sx eliminates the need for ' 'JavaScript entirely — htmx attributes handle interactivity, hyperscript handles small behaviours, ' 'and the server handles everything else."))' ' (~doc-section :title "What sx is not" :id "not"' ' (ul :class "space-y-2 text-stone-600"' ' (li "Not a general-purpose programming language — it\'s a UI rendering language")' ' (li "Not a full Lisp — it has macros and TCO, but no continuations or call/cc")' ' (li "Not production-hardened at scale — it runs one website"))))' ) def _docs_getting_started_sx() -> str: c1 = _code('(div :class "p-4 bg-white rounded"\n (h1 :class "text-2xl font-bold" "Hello, world!")\n (p "This is rendered from an s-expression."))') c2 = _code('(button\n :sx-get "/api/data"\n :sx-target "#result"\n :sx-swap "innerHTML"\n "Load data")') return ( f'(~doc-page :title "Getting Started"' f' (~doc-section :title "Minimal example" :id "minimal"' f' (p :class "text-stone-600"' f' "An sx response is s-expression source code with content type text/sx:")' f' {c1}' f' (p :class "text-stone-600"' f' "Add sx-get to any element to make it fetch and render sx:"))' f' (~doc-section :title "Hypermedia attributes" :id "attrs"' f' (p :class "text-stone-600"' f' "Like htmx, sx adds attributes to HTML elements to trigger HTTP requests:")' f' {c2}' f' (p :class "text-stone-600"' f' "sx-get, sx-post, sx-put, sx-delete, sx-patch — all work the same way. ' f'The response is parsed as sx and rendered into the target element.")))' ) def _docs_components_sx() -> str: c1 = _code('(defcomp ~card (&key title subtitle &rest children)\n' ' (div :class "border rounded p-4"\n' ' (h2 :class "font-bold" title)\n' ' (when subtitle (p :class "text-stone-500" subtitle))\n' ' (div :class "mt-3" children)))') c2 = _code('(~card :title "My Card" :subtitle "A description"\n' ' (p "First child")\n' ' (p "Second child"))') return ( f'(~doc-page :title "Components"' f' (~doc-section :title "defcomp" :id "defcomp"' f' (p :class "text-stone-600"' f' "Components are defined with defcomp. They take keyword parameters and optional children:")' f' {c1}' f' (p :class "text-stone-600"' f' "Use components with the ~ prefix:")' f' {c2})' f' (~doc-section :title "Component caching" :id "caching"' f' (p :class "text-stone-600"' f' "Component definitions are sent in a