|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Feliz.ViewEngine is an F# library that renders the Feliz DSL to plain HTML or XML strings. It's designed for server-side rendering (SSR) scenarios like Giraffe web handlers, HTML email generation, or any case where HTML output is needed. The library has no dependencies and is Fable-compatible. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Restore dependencies (uses Paket) |
| 13 | +dotnet restore |
| 14 | + |
| 15 | +# Build all projects |
| 16 | +dotnet build |
| 17 | + |
| 18 | +# Run tests |
| 19 | +dotnet test test/Tests.Feliz.ViewEngine.fsproj |
| 20 | + |
| 21 | +# Build specific project |
| 22 | +dotnet build src/Feliz.ViewEngine.fsproj |
| 23 | +``` |
| 24 | + |
| 25 | +## Architecture |
| 26 | + |
| 27 | +### Core Types (src/ViewEngine.fs) |
| 28 | + |
| 29 | +The library defines its own `ReactElement` discriminated union (not Fable.React): |
| 30 | + |
| 31 | +```fsharp |
| 32 | +type IReactProperty = |
| 33 | + | KeyValue of string * obj |
| 34 | + | Children of ReactElement list |
| 35 | + | Text of string |
| 36 | +
|
| 37 | +type ReactElement = |
| 38 | + | Element of string * IReactProperty list |
| 39 | + | VoidElement of string * IReactProperty list // self-closing like <br>, <img> |
| 40 | + | TextElement of string |
| 41 | + | Elements of ReactElement seq |
| 42 | +``` |
| 43 | + |
| 44 | +The `Render` module converts these to strings via `htmlView`, `xmlView`, `htmlDocument`, or `xmlDocument`. |
| 45 | + |
| 46 | +### Interop Module (src/Interop.fs) |
| 47 | + |
| 48 | +Provides the API bridge between Feliz DSL and the ViewEngine types. Key functions: |
| 49 | + |
| 50 | +- `createElement` / `createVoidElement` - create elements with properties |
| 51 | +- `mkAttr` / `mkStyle` - create attributes and style properties |
| 52 | +- `createTextElement` / `createRawTextElement` - create text (escaped vs raw) |
| 53 | + |
| 54 | +### DSL Modules |
| 55 | + |
| 56 | +- `Html` (src/Html.fs) - HTML element functions (`Html.div`, `Html.p`, etc.) |
| 57 | +- `prop` (src/Properties.fs) - HTML properties (`prop.className`, `prop.style`, etc.) |
| 58 | +- `style` (src/Styles.fs) - CSS style properties |
| 59 | +- `React` (src/React.fs) - React-compatible utilities like `fragment` |
| 60 | + |
| 61 | +### Feliz.Bulma.ViewEngine Extension |
| 62 | + |
| 63 | +A port of Feliz.Bulma for server-side rendering, located in `Feliz.Bulma.ViewEngine/`. |
| 64 | + |
| 65 | +## Client/Server Code Sharing |
| 66 | + |
| 67 | +Use compiler directives to share views between client (Feliz) and server (Feliz.ViewEngine): |
| 68 | + |
| 69 | +```fsharp |
| 70 | +#if FABLE_COMPILER |
| 71 | +open Feliz |
| 72 | +#else |
| 73 | +open Feliz.ViewEngine |
| 74 | +#endif |
| 75 | +``` |
| 76 | + |
| 77 | +## Key Differences from Feliz |
| 78 | + |
| 79 | +- Event handlers are stored in the DOM tree but ignored during rendering |
| 80 | +- `Html.none` returns an empty `TextElement` (not `unbox null`) |
| 81 | +- `Html.text` uses `createTextElement` (not unboxing) |
| 82 | +- HTML is escaped by default; use `Html.rawText` for unescaped content |
0 commit comments