Add true/false to auto-htmx converter (#59)
- This will allow backups to be restored, converting the value as part of the restoration
This commit is contained in:
@@ -15,7 +15,10 @@ module Json =
|
||||
override _.WriteJson(writer: JsonWriter, value: AutoHtmxType, _: JsonSerializer) =
|
||||
writer.WriteValue(string value)
|
||||
override _.ReadJson(reader: JsonReader, _: Type, _: AutoHtmxType, _: bool, _: JsonSerializer) =
|
||||
(string >> AutoHtmxType.Parse) reader.Value
|
||||
// Backups prior to v3 will still have true/false for this field
|
||||
match reader.TokenType with
|
||||
| JsonToken.Boolean -> if reader.Value :?> bool then AutoHtmx else NoAutoHtmx
|
||||
| _ -> (string >> AutoHtmxType.Parse) reader.Value
|
||||
|
||||
/// <summary>Converter for the <see cref="CategoryId" /> type</summary>
|
||||
type CategoryIdConverter() =
|
||||
|
||||
@@ -14,9 +14,13 @@ let autoHtmxTypeConverterTests = testList "AutoHtmxTypeConverter" [
|
||||
let after = JsonConvert.SerializeObject(AutoHtmax, opts)
|
||||
Expect.equal after "\"Max\"" "Auto htmx type serialized incorrectly"
|
||||
}
|
||||
test "succeeds when deserializing" {
|
||||
test "succeeds when deserializing a string" {
|
||||
let after = JsonConvert.DeserializeObject<AutoHtmxType>("\"Yes\"", opts)
|
||||
Expect.equal after AutoHtmx "Auto htmx type not serialized incorrectly"
|
||||
Expect.equal after AutoHtmx "Auto htmx type deserialized incorrectly"
|
||||
}
|
||||
test "succeeds when deserializing a boolean value" {
|
||||
let after = JsonConvert.DeserializeObject<AutoHtmxType>("false", opts)
|
||||
Expect.equal after NoAutoHtmx "Auto htmx type deserialized incorrectly"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -30,7 +34,7 @@ let categoryIdConverterTests = testList "CategoryIdConverter" [
|
||||
}
|
||||
test "succeeds when deserializing" {
|
||||
let after = JsonConvert.DeserializeObject<CategoryId>("\"test-cat-id\"", opts)
|
||||
Expect.equal after (CategoryId "test-cat-id") "Category ID not serialized incorrectly"
|
||||
Expect.equal after (CategoryId "test-cat-id") "Category ID deserialized incorrectly"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -68,10 +68,6 @@ open Giraffe
|
||||
open Giraffe.Htmx
|
||||
open Giraffe.ViewEngine
|
||||
|
||||
/// htmx script tag
|
||||
let private htmxScript (webLog: WebLog) =
|
||||
$"""<script src="{webLog.RelativeUrl(Permalink "htmx.min.js")}"></script>"""
|
||||
|
||||
/// Get the current user messages, and commit the session so that they are preserved
|
||||
let private getCurrentMessages ctx = task {
|
||||
let! messages = messages ctx
|
||||
|
||||
Reference in New Issue
Block a user