Skip to content

Commit c308884

Browse files
committed
Added integer node to ViewEngine
1 parent 5795785 commit c308884

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

examples/Basic/Program.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
open System
2-
open System.ComponentModel.DataAnnotations
32
open System.Text.Json.Serialization
43
open System.Threading.Tasks
54
open Microsoft.AspNetCore.Authorization

src/Oxpecker.ViewEngine/Builder.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ module Builder =
100100
interface HtmlElement with
101101
member this.Render sb = this.Render sb
102102

103+
/// Integer node that will NOT be HTML-escaped
104+
type IntNode(value: int) =
105+
member this.Render(sb: StringBuilder) = value |> sb.Append |> ignore
106+
interface HtmlElement with
107+
member this.Render sb = this.Render sb
108+
103109
/// Create text node that will NOT be HTML-escaped
104110
let inline raw text = RawTextNode text
105111

@@ -132,6 +138,8 @@ module Builder =
132138

133139
member inline _.Yield(text: string | null) : HtmlContainerFun = _.AddChild(RegularTextNode text)
134140

141+
member inline _.Yield(value: int) : HtmlContainerFun = _.AddChild(IntNode value)
142+
135143
type HtmlContainerExtensions =
136144
[<Extension>]
137145
static member inline Run(this: #HtmlContainer, [<InlineIfLambda>] runExpr: HtmlContainerFun) =

tests/Oxpecker.ViewEngine.Tests/Render.Tests.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ open FsUnit.Light
1212
let ``Basic test`` () =
1313
let result =
1414
html() {
15-
div(id = "1")
15+
div(id = "1") { 1 }
1616
div(id = "2") {
1717
let x = 2
1818
div(id = "3", class' = "test")
@@ -24,13 +24,13 @@ let ``Basic test`` () =
2424
result
2525
|> Render.toString
2626
|> shouldEqual
27-
"""<html><div id="1"></div><div id="2"><div id="3" class="test"></div><br><br><div id="4"></div></div></html>"""
27+
"""<html><div id="1">1</div><div id="2"><div id="3" class="test"></div><br><br><div id="4"></div></div></html>"""
2828

2929
[<Fact>]
3030
let ``Basic test to bytes`` () =
3131
let result =
3232
html() {
33-
div(id = "1")
33+
div(id = "1") { 1 }
3434
div(id = "2") {
3535
let x = 2
3636
div(id = "3", class' = "test")
@@ -43,7 +43,7 @@ let ``Basic test to bytes`` () =
4343
|> Render.toBytes
4444
|> Encoding.UTF8.GetString
4545
|> shouldEqual
46-
"""<html><div id="1"></div><div id="2"><div id="3" class="test"></div><br><br><div id="4"></div></div></html>"""
46+
"""<html><div id="1">1</div><div id="2"><div id="3" class="test"></div><br><br><div id="4"></div></div></html>"""
4747

4848

4949
[<Fact>]

0 commit comments

Comments
 (0)