Skip to content

Commit 22fb6c1

Browse files
committed
readme
1 parent 05b85ba commit 22fb6c1

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: build
33
on:
44
push:
55
branches: [master]
6+
# exclude commits
7+
paths-ignore:
8+
- 'README.md'
9+
610
pull_request:
711

812
jobs:
@@ -26,4 +30,4 @@ jobs:
2630
run: dotnet build src/Falco.Markup -c Release
2731

2832
- name: Test
29-
run: dotnet test test/Falco.Markup.Tests -c Release
33+
run: dotnet test test/Falco.Markup.Tests -c Release

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,22 @@ let xmlDoc =
337337
let xml = renderXml xmlDoc
338338
```
339339

340-
## HTML Fragments
340+
## Template Fragments
341341

342-
Sometimes you may want to create a fragment of HTML, without the surrounding `<html>`, `<head>` and `<body>` tags. Or, any wrapper element for that matter.
342+
There are circumstances where you may want to render only a portion of your view. Especially common in [hypermedia driven](https://htmx.org/essays/hypermedia-driven-applications/) applications. Supporting [template fragments](https://htmx.org/essays/template-fragments/) is helpful in maintaining locality of behaviour, because it allows you to decompose a particular view for partial updates internally without pulling fragments of the template out to separate files for rendering, creating a large number of individual templates.
343343

344+
Falco.Markup supports this pattern by way of the `renderFragment` function, which will traverse the provided `XmlNode` tree and render only the child node matching the provided `id`. Otherwise, gracefully returning an empty string if no match is found.
345+
346+
```fsharp
347+
open Falco.Markup
348+
349+
let view =
350+
_div [ _id_ "my-div"; _class_ "my-class" ] [
351+
_h1 [ _id_ "my-heading" ] [ _text "hello" ] ]
352+
353+
let render = renderFragment doc "my-heading"
354+
// produces: <h1 id="my-heading">hello</h1>
355+
```
344356

345357
## SVG
346358

test/Falco.Markup.Tests/ElemTests.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ let ``Should produce valid html doc`` () =
6262
renderHtml doc |> should equal """<!DOCTYPE html><html><body><div class="my-class"><h1>hello</h1></div></body></html>"""
6363

6464
[<Fact>]
65-
let ``Should produce valid template fragment from XmlNode and id``()
66-
=
65+
let ``Should produce valid template fragment from XmlNode and id``() =
6766
let doc =
6867
_div [ _id_ "my-div"; _class_ "my-class" ] [
6968
_h1 [ _id_ "my-heading" ] [ _text "hello" ] ]

0 commit comments

Comments
 (0)