Skip to content

Commit f394a5e

Browse files
authored
revert back to double quotes (#9)
1 parent 7978ed4 commit f394a5e

2 files changed

Lines changed: 48 additions & 43 deletions

File tree

src/FSharp.ViewEngine/Library.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module private ViewBuilder =
3232
let children = ResizeArray()
3333
for attr in attributes do
3434
match attr with
35-
| KeyValue (key, value) -> sb += " " += key += "='" += value +! "'"
35+
| KeyValue (key, value) -> sb += " " += key += "=\"" += value +! "\""
3636
| Boolean key -> sb += " " +! key
3737
| Children elements -> children.AddRange(elements)
3838
| Attribute.Noop -> ()
@@ -43,7 +43,7 @@ module private ViewBuilder =
4343
sb += "<" +! tag
4444
for attr in attributes do
4545
match attr with
46-
| KeyValue (key, value) -> sb += " " += key += "='" += value +! "'"
46+
| KeyValue (key, value) -> sb += " " += key += "=\"" += value +! "\""
4747
| Boolean key -> sb += " " +! key
4848
| Children _ -> failwith "void elements cannot have children"
4949
| Attribute.Noop -> ()

src/Tests/Tests.fs

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,17 @@ open type Htmx
99
open type Alpine
1010
open type Svg
1111

12-
let clean (s:string) = Regex.Replace(s, @"\s{2,}|\r|\n|\r\n", "")
12+
module String =
13+
let replace (oldValue:string) (newValue:string) (s:string) = s.Replace(oldValue, newValue)
14+
let clean (s:string) = Regex.Replace(s, @"\s{2,}|\r|\n|\r\n", "")
1315

1416
[<Fact>]
1517
let ``Should render html document`` () =
16-
// language=HTML
17-
let expected = """
18-
<!DOCTYPE html>
19-
<html lang='en'>
20-
<head>
21-
<title>Test</title>
22-
<meta charset='utf-8'>
23-
<link href='/css/compiled.css' rel='stylesheet'>
24-
</head>
25-
<body x-data='{"showContent":false,"x":[1,2,3],"y":["a","b","c"]}' class='bg-gray-50'>
26-
<div id='page' class='flex flex-col'>
27-
<h1 hx-get='/hello' hx-target='#page'>Hello</h1>
28-
<h1 hx-get='/world' hx-target='#page'>World</h1>
29-
</div>
30-
<br>
31-
<div x-show='showContent'>
32-
<h2>Content</h2>
33-
<p>Some content</p>
34-
<p>Some more content</p>
35-
<pre class='language-html'>
36-
<code class='language-html'>
37-
&lt;p&gt;Even more content&lt;/p&gt;
38-
</code>
39-
</pre>
40-
<ul>
41-
<li>One</li>
42-
<li>Two</li>
43-
</ul>
44-
<a href='https://github.com/ameier38/FSharp.ViewEngine' class='rounded-lg text-gray-800 font-semibold flex items-center gap-3 p-1'>
45-
<svg viewBox='0 0 24 24' class='h-6 w-6 fill-current'>
46-
<path fill-rule='evenodd' clip-rule='evenodd' d='M12 2C6.477 2 2 6.463 2 11.97c0 4.404 2.865 8.14 6.839 9.458.5.092.682-.216.682-.48 0-.236-.008-.864-.013-1.695-2.782.602-3.369-1.337-3.369-1.337-.454-1.151-1.11-1.458-1.11-1.458-.908-.618.069-.606.069-.606 1.003.07 1.531 1.027 1.531 1.027.892 1.524 2.341 1.084 2.91.828.092-.643.35-1.083.636-1.332-2.22-.251-4.555-1.107-4.555-4.927 0-1.088.39-1.979 1.029-2.675-.103-.252-.446-1.266.098-2.638 0 0 .84-.268 2.75 1.022A9.607 9.607 0 0 1 12 6.82c.85.004 1.705.114 2.504.336 1.909-1.29 2.747-1.022 2.747-1.022.546 1.372.202 2.386.1 2.638.64.696 1.028 1.587 1.028 2.675 0 3.83-2.339 4.673-4.566 4.92.359.307.678.915.678 1.846 0 1.332-.012 2.407-.012 2.734 0 .267.18.577.688.48 3.97-1.32 6.833-5.054 6.833-9.458C22 6.463 17.522 2 12 2Z'></path>
47-
</svg>
48-
Documentation
49-
</a>
50-
</div>
51-
</body>
52-
</html>
53-
"""
5418
let actual =
55-
let xData = {| showContent = false; x = [ 1; 2; 3 ]; y = [ "a"; "b"; "c" ] |} |> JsonSerializer.Serialize
19+
let xData =
20+
{| showContent = false; x = [ 1; 2; 3 ]; y = [ "a"; "b"; "c" ] |}
21+
|> JsonSerializer.Serialize
22+
|> String.replace "\"" "'"
5623
html [
5724
_lang "en"
5825
_children [
@@ -122,4 +89,42 @@ let ``Should render html document`` () =
12289
]
12390
]
12491
|> Element.render
125-
Assert.Equal(clean expected, clean actual)
92+
// language=HTML
93+
let expected = """
94+
<!DOCTYPE html>
95+
<html lang="en">
96+
<head>
97+
<title>Test</title>
98+
<meta charset="utf-8">
99+
<link href="/css/compiled.css" rel="stylesheet">
100+
</head>
101+
<body x-data="{'showContent':false,'x':[1,2,3],'y':['a','b','c']}" class="bg-gray-50">
102+
<div id="page" class="flex flex-col">
103+
<h1 hx-get="/hello" hx-target="#page">Hello</h1>
104+
<h1 hx-get="/world" hx-target="#page">World</h1>
105+
</div>
106+
<br>
107+
<div x-show="showContent">
108+
<h2>Content</h2>
109+
<p>Some content</p>
110+
<p>Some more content</p>
111+
<pre class="language-html">
112+
<code class="language-html">
113+
&lt;p&gt;Even more content&lt;/p&gt;
114+
</code>
115+
</pre>
116+
<ul>
117+
<li>One</li>
118+
<li>Two</li>
119+
</ul>
120+
<a href="https://github.com/ameier38/FSharp.ViewEngine" class="rounded-lg text-gray-800 font-semibold flex items-center gap-3 p-1">
121+
<svg viewBox="0 0 24 24" class="h-6 w-6 fill-current">
122+
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 2C6.477 2 2 6.463 2 11.97c0 4.404 2.865 8.14 6.839 9.458.5.092.682-.216.682-.48 0-.236-.008-.864-.013-1.695-2.782.602-3.369-1.337-3.369-1.337-.454-1.151-1.11-1.458-1.11-1.458-.908-.618.069-.606.069-.606 1.003.07 1.531 1.027 1.531 1.027.892 1.524 2.341 1.084 2.91.828.092-.643.35-1.083.636-1.332-2.22-.251-4.555-1.107-4.555-4.927 0-1.088.39-1.979 1.029-2.675-.103-.252-.446-1.266.098-2.638 0 0 .84-.268 2.75 1.022A9.607 9.607 0 0 1 12 6.82c.85.004 1.705.114 2.504.336 1.909-1.29 2.747-1.022 2.747-1.022.546 1.372.202 2.386.1 2.638.64.696 1.028 1.587 1.028 2.675 0 3.83-2.339 4.673-4.566 4.92.359.307.678.915.678 1.846 0 1.332-.012 2.407-.012 2.734 0 .267.18.577.688.48 3.97-1.32 6.833-5.054 6.833-9.458C22 6.463 17.522 2 12 2Z"></path>
123+
</svg>
124+
Documentation
125+
</a>
126+
</div>
127+
</body>
128+
</html>
129+
"""
130+
Assert.Equal(String.clean expected, String.clean actual)

0 commit comments

Comments
 (0)