Skip to content

Commit f8bfa4b

Browse files
committed
add warp
1 parent 096505c commit f8bfa4b

1 file changed

Lines changed: 115 additions & 0 deletions

File tree

WARP.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# WARP.md
2+
3+
This file provides guidance to WARP (warp.dev) when working with code in this repository.
4+
5+
## Project Overview
6+
FSharp.ViewEngine is a view engine for F# web applications, inspired by Giraffe.ViewEngine and Feliz.ViewEngine. It provides a functional approach to generating HTML with type-safe F# code, including integrated support for HTMX, Alpine.js, Tailwind CSS, and SVG elements.
7+
8+
## Core Architecture
9+
10+
### Element System
11+
The view engine is built around a discriminated union system:
12+
- **Element**: The core type representing DOM elements (Text, Tag, Void, Fragment, Raw, Noop)
13+
- **Attribute**: Represents HTML attributes (KeyValue, Boolean, Children, Noop)
14+
- All HTML is generated through composition of these types
15+
16+
### Module Structure
17+
- `Core.fs`: Defines the core Element and Attribute types, plus the rendering engine
18+
- `Html.fs`: Standard HTML elements and attributes (div, p, h1, _class, _id, etc.)
19+
- `Htmx.fs`: HTMX-specific attributes (_hxGet, _hxPost, _hxTarget, etc.)
20+
- `Alpine.fs`: Alpine.js directives (_xData, _xShow, _xModel, etc.)
21+
- `Tailwind.fs`: Tailwind UI custom elements (el-select, el-dialog, etc.)
22+
- `Svg.fs`: SVG elements and attributes
23+
24+
## Common Development Commands
25+
26+
### Build and Test
27+
```bash
28+
# Restore tools and packages
29+
dotnet tool restore
30+
dotnet paket install
31+
32+
# Run tests (cross-platform)
33+
./fake.sh Test # Linux/macOS
34+
./fake.cmd Test # Windows
35+
36+
# Alternative direct test command
37+
dotnet test src/Tests/Tests.fsproj
38+
```
39+
40+
### Package Management
41+
```bash
42+
# Add NuGet package dependencies
43+
# Edit paket.dependencies file, then:
44+
dotnet paket install
45+
46+
# Update packages
47+
dotnet paket update
48+
```
49+
50+
### Building and Packaging
51+
```bash
52+
# Clean build artifacts
53+
./fake.sh Clean # Linux/macOS
54+
./fake.cmd Clean # Windows
55+
56+
# Create NuGet package (requires GITHUB_REF_NAME environment variable)
57+
./fake.sh Pack # Linux/macOS
58+
./fake.cmd Pack # Windows
59+
```
60+
61+
### Single Test Execution
62+
To run a specific test, use xunit's filtering:
63+
```bash
64+
# Run specific test by name pattern
65+
dotnet test src/Tests/Tests.fsproj --filter "Should render html document"
66+
```
67+
68+
## Development Patterns
69+
70+
### Creating New HTML Elements
71+
When adding HTML elements to `Html.fs`, follow the established patterns:
72+
- Standard elements: `static member elementName (attrs:Attribute seq) = Tag ("elementname", attrs)`
73+
- Void elements (self-closing): Use `Void` instead of `Tag`
74+
- Convenience overloads for common cases (e.g., `p (text:string)` for simple text paragraphs)
75+
76+
### Adding Framework-Specific Attributes
77+
- HTMX attributes go in `Htmx.fs` with `_hx` prefix
78+
- Alpine.js directives go in `Alpine.fs` with `_x` prefix
79+
- Use the `_frameworkPrefix` function pattern for consistency
80+
81+
### Testing HTML Output
82+
Tests use string comparison with whitespace normalization. The `String.clean` helper removes excess whitespace for reliable comparisons. Use the `// language=HTML` comment for syntax highlighting in expected output strings.
83+
84+
## Key Dependencies
85+
- **Paket**: Package management
86+
- **FAKE**: Build automation via F# DSL
87+
- **xUnit**: Testing framework
88+
- **System.Web**: HTML encoding utilities
89+
90+
## Usage Pattern
91+
The library uses F# static type extensions with `open type` declarations:
92+
```fsharp
93+
open FSharp.ViewEngine
94+
open type Html
95+
open type Htmx
96+
open type Alpine
97+
98+
// Creates type-safe, composable HTML
99+
div [
100+
_class "container"
101+
_hxGet "/api/data"
102+
_xData "{loading: false}"
103+
_children [
104+
h1 [ _children "Hello World" ]
105+
]
106+
]
107+
|> Element.render
108+
```
109+
110+
## Build System Notes
111+
- Uses FAKE build system with F# build scripts in `src/Build/Program.fs`
112+
- Cross-platform build scripts: `fake.sh` (Unix) and `fake.cmd` (Windows)
113+
- Targets: Test, Clean, Pack, Publish
114+
- Version extraction from Git tags for packaging
115+
- CI/CD via GitHub Actions for PR validation and releases

0 commit comments

Comments
 (0)