From f01cd884d4c4323d4cbb99706b0dec2d6dc877c3 Mon Sep 17 00:00:00 2001 From: rameel Date: Tue, 3 Nov 2026 00:35:53 +0500 Subject: [PATCH] config: prefix the remaining configuration types with Htmx HttpVerb and ResponseHandlingConfig were the only public configuration types without the prefix. Rename them, and the converter for HttpVerb: - HttpVerb to HtmxHttpVerb - ResponseHandlingConfig to HtmxResponseHandlingOptions Use Options rather than Config for the last one: it follows HtmxLocationOptions, and the type does not derive from HtmxConfig like HtmxV2Config and the others do. --- docs/api-overwrites/configuration.md | 2 +- docs/articles/configuration-v2.md | 4 +- docs/articles/migrate-to-v2.md | 10 ++--- .../{HttpVerb.cs => HtmxHttpVerb.cs} | 2 +- ...nfig.cs => HtmxResponseHandlingOptions.cs} | 2 +- .../Configuration/HtmxV1Config.cs | 4 +- .../Configuration/HtmxV2Config.cs | 6 +-- .../Internal/EnumHelper.cs | 40 +++++++++---------- ...er.cs => HtmxHttpVerbListJsonConverter.cs} | 8 ++-- .../Internal/EnumHelperTests.cs | 20 +++++----- .../TagHelpers/HtmxConfigTagHelperTests.cs | 34 ++++++++-------- 11 files changed, 66 insertions(+), 66 deletions(-) rename src/Ramstack.HtmxToolkit/Configuration/{HttpVerb.cs => HtmxHttpVerb.cs} (98%) rename src/Ramstack.HtmxToolkit/Configuration/{ResponseHandlingConfig.cs => HtmxResponseHandlingOptions.cs} (97%) rename src/Ramstack.HtmxToolkit/Serialization/{HttpVerbListJsonConverter.cs => HtmxHttpVerbListJsonConverter.cs} (70%) diff --git a/docs/api-overwrites/configuration.md b/docs/api-overwrites/configuration.md index df612a6..a675921 100644 --- a/docs/api-overwrites/configuration.md +++ b/docs/api-overwrites/configuration.md @@ -20,7 +20,7 @@ example: --- --- -uid: Ramstack.HtmxToolkit.Configuration.ResponseHandlingConfig +uid: Ramstack.HtmxToolkit.Configuration.HtmxResponseHandlingOptions example: - |- [!code-csharp[](../snippets/configuration/ResponseHandling.cs)] diff --git a/docs/articles/configuration-v2.md b/docs/articles/configuration-v2.md index 87bf030..e8f77e1 100644 --- a/docs/articles/configuration-v2.md +++ b/docs/articles/configuration-v2.md @@ -63,8 +63,8 @@ Use `SwapOverride` to select a typed swap style, or `SwapOverrideExpression` for expression with modifiers or a custom swap style: ```csharp -new ResponseHandlingConfig { Code = "422", Swap = true, SwapOverride = HtmxSwap.OuterHtml }; -new ResponseHandlingConfig { Code = "422", Swap = true, SwapOverrideExpression = "outerHTML settle:200ms" }; +new HtmxResponseHandlingOptions { Code = "422", Swap = true, SwapOverride = HtmxSwap.OuterHtml }; +new HtmxResponseHandlingOptions { Code = "422", Swap = true, SwapOverrideExpression = "outerHTML settle:200ms" }; ``` Both properties use the same underlying expression and serialize as `swapOverride`. diff --git a/docs/articles/migrate-to-v2.md b/docs/articles/migrate-to-v2.md index cdcb977..85bf40a 100644 --- a/docs/articles/migrate-to-v2.md +++ b/docs/articles/migrate-to-v2.md @@ -40,10 +40,10 @@ The package still targets .NET 6 and runs on .NET 6 or later. Add these namespaces where needed: -| Namespace | Contains | -|--------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `Ramstack.HtmxToolkit.Hosting` | `AddHtmxToolkit` | -| `Ramstack.HtmxToolkit.Configuration` | `HtmxToolkitOptions`, `HtmxV1Config`, `HtmxV2Config`, `HtmxV4Config`, and configuration enums such as `HtmxScrollBehavior`, `HtmxBinaryType`, and `HttpVerb` | +| Namespace | Contains | +|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `Ramstack.HtmxToolkit.Hosting` | `AddHtmxToolkit` | +| `Ramstack.HtmxToolkit.Configuration` | `HtmxToolkitOptions`, `HtmxV1Config`, `HtmxV2Config`, `HtmxV4Config`, and configuration enums such as `HtmxScrollBehavior`, `HtmxBinaryType`, and `HtmxHttpVerb` | `HtmxScrollBehavior` and `HtmxBinaryType` moved from `Ramstack.HtmxToolkit` to `Ramstack.HtmxToolkit.Configuration`. @@ -116,7 +116,7 @@ on `HtmxV1Config` or `HtmxV2Config`. The exceptions are: | `include-antiforgery-token` | `HtmxToolkitOptions.IncludeAntiforgeryToken`, now `true` by default; see the next section | | `use-template-fragments` | `HtmxV1Config.UseTemplateFragments` only; HTMX 2.x always parses responses with templates | | `trigger-specs-cache` | `TriggerSpecsCacheEnabled` (`bool?`) | -| `methods-that-use-url-params` | `MethodsThatUseUrlParams` (`IReadOnlyList` instead of `string[]`) | +| `methods-that-use-url-params` | `MethodsThatUseUrlParams` (`IReadOnlyList` instead of `string[]`) | | `ws-reconnect-delay` | Removed: HTMX accepts only a function or the default `"full-jitter"`, and a function cannot be passed through JSON | For every property, see [HTMX 1.9.x](configuration-v1.md), [HTMX 2.x](configuration-v2.md), diff --git a/src/Ramstack.HtmxToolkit/Configuration/HttpVerb.cs b/src/Ramstack.HtmxToolkit/Configuration/HtmxHttpVerb.cs similarity index 98% rename from src/Ramstack.HtmxToolkit/Configuration/HttpVerb.cs rename to src/Ramstack.HtmxToolkit/Configuration/HtmxHttpVerb.cs index 5bd114f..65088f2 100644 --- a/src/Ramstack.HtmxToolkit/Configuration/HttpVerb.cs +++ b/src/Ramstack.HtmxToolkit/Configuration/HtmxHttpVerb.cs @@ -3,7 +3,7 @@ namespace Ramstack.HtmxToolkit.Configuration; /// /// Defines the HTTP methods that can be used in HTMX configuration. /// -public enum HttpVerb +public enum HtmxHttpVerb { /// /// The GET method requests a representation of the specified resource. diff --git a/src/Ramstack.HtmxToolkit/Configuration/ResponseHandlingConfig.cs b/src/Ramstack.HtmxToolkit/Configuration/HtmxResponseHandlingOptions.cs similarity index 97% rename from src/Ramstack.HtmxToolkit/Configuration/ResponseHandlingConfig.cs rename to src/Ramstack.HtmxToolkit/Configuration/HtmxResponseHandlingOptions.cs index 1d74066..6fc7fb3 100644 --- a/src/Ramstack.HtmxToolkit/Configuration/ResponseHandlingConfig.cs +++ b/src/Ramstack.HtmxToolkit/Configuration/HtmxResponseHandlingOptions.cs @@ -8,7 +8,7 @@ namespace Ramstack.HtmxToolkit.Configuration; /// Represents the response handling configuration for responses that match /// a specific HTTP status code pattern. /// -public sealed class ResponseHandlingConfig +public sealed class HtmxResponseHandlingOptions { /// /// Gets or sets the regular expression used to match response status codes. diff --git a/src/Ramstack.HtmxToolkit/Configuration/HtmxV1Config.cs b/src/Ramstack.HtmxToolkit/Configuration/HtmxV1Config.cs index f856591..02cc657 100644 --- a/src/Ramstack.HtmxToolkit/Configuration/HtmxV1Config.cs +++ b/src/Ramstack.HtmxToolkit/Configuration/HtmxV1Config.cs @@ -288,8 +288,8 @@ public bool? GlobalViewTransitions /// Gets or sets the HTTP methods that use URL parameters. /// The HTMX default is ["get"]. /// - [JsonConverter(typeof(HttpVerbListJsonConverter))] - public IReadOnlyList? MethodsThatUseUrlParams + [JsonConverter(typeof(HtmxHttpVerbListJsonConverter))] + public IReadOnlyList? MethodsThatUseUrlParams { get; set => SetField(ref field, value); diff --git a/src/Ramstack.HtmxToolkit/Configuration/HtmxV2Config.cs b/src/Ramstack.HtmxToolkit/Configuration/HtmxV2Config.cs index c52308d..c8c02a8 100644 --- a/src/Ramstack.HtmxToolkit/Configuration/HtmxV2Config.cs +++ b/src/Ramstack.HtmxToolkit/Configuration/HtmxV2Config.cs @@ -300,8 +300,8 @@ public bool? GlobalViewTransitions /// Gets or sets the HTTP methods that use URL parameters. /// The HTMX default is ["get", "delete"]. /// - [JsonConverter(typeof(HttpVerbListJsonConverter))] - public IReadOnlyList? MethodsThatUseUrlParams + [JsonConverter(typeof(HtmxHttpVerbListJsonConverter))] + public IReadOnlyList? MethodsThatUseUrlParams { get; set => SetField(ref field, value); @@ -344,7 +344,7 @@ public bool? TriggerSpecsCacheEnabled /// The HTMX default is [{ code: "204", swap: false }, { code: "[23]..", swap: true }, /// { code: "[45]..", swap: false, error: true }]. /// - public IReadOnlyList? ResponseHandling + public IReadOnlyList? ResponseHandling { get; set => SetField(ref field, value); diff --git a/src/Ramstack.HtmxToolkit/Internal/EnumHelper.cs b/src/Ramstack.HtmxToolkit/Internal/EnumHelper.cs index 00ca9f2..9179602 100644 --- a/src/Ramstack.HtmxToolkit/Internal/EnumHelper.cs +++ b/src/Ramstack.HtmxToolkit/Internal/EnumHelper.cs @@ -102,35 +102,35 @@ or HtmxSwap.Delete } /// - /// Converts a value to its corresponding lowercase HTTP method string. + /// Converts a value to its corresponding lowercase HTTP method string. /// - /// The value. + /// The value. /// /// The lowercase HTTP method name, such as get, post, or delete. /// - public static string GetHttpVerbValue(this HttpVerb value) + public static string GetHttpVerbValue(this HtmxHttpVerb value) { Debug.Assert(value - is HttpVerb.Get - or HttpVerb.Head - or HttpVerb.Post - or HttpVerb.Put - or HttpVerb.Delete - or HttpVerb.Connect - or HttpVerb.Options - or HttpVerb.Trace - or HttpVerb.Patch); + is HtmxHttpVerb.Get + or HtmxHttpVerb.Head + or HtmxHttpVerb.Post + or HtmxHttpVerb.Put + or HtmxHttpVerb.Delete + or HtmxHttpVerb.Connect + or HtmxHttpVerb.Options + or HtmxHttpVerb.Trace + or HtmxHttpVerb.Patch); return value switch { - HttpVerb.Get => "get", - HttpVerb.Head => "head", - HttpVerb.Post => "post", - HttpVerb.Put => "put", - HttpVerb.Delete => "delete", - HttpVerb.Connect => "connect", - HttpVerb.Options => "options", - HttpVerb.Trace => "trace", + HtmxHttpVerb.Get => "get", + HtmxHttpVerb.Head => "head", + HtmxHttpVerb.Post => "post", + HtmxHttpVerb.Put => "put", + HtmxHttpVerb.Delete => "delete", + HtmxHttpVerb.Connect => "connect", + HtmxHttpVerb.Options => "options", + HtmxHttpVerb.Trace => "trace", _ => "patch" }; } diff --git a/src/Ramstack.HtmxToolkit/Serialization/HttpVerbListJsonConverter.cs b/src/Ramstack.HtmxToolkit/Serialization/HtmxHttpVerbListJsonConverter.cs similarity index 70% rename from src/Ramstack.HtmxToolkit/Serialization/HttpVerbListJsonConverter.cs rename to src/Ramstack.HtmxToolkit/Serialization/HtmxHttpVerbListJsonConverter.cs index a0b5535..521810d 100644 --- a/src/Ramstack.HtmxToolkit/Serialization/HttpVerbListJsonConverter.cs +++ b/src/Ramstack.HtmxToolkit/Serialization/HtmxHttpVerbListJsonConverter.cs @@ -7,16 +7,16 @@ namespace Ramstack.HtmxToolkit.Serialization; /// -/// Represents a for lists of values. +/// Represents a for lists of values. /// -internal sealed class HttpVerbListJsonConverter : JsonConverter> +internal sealed class HtmxHttpVerbListJsonConverter : JsonConverter> { /// - public override IReadOnlyList Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => + public override IReadOnlyList Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => throw new NotSupportedException(); /// - public override void Write(Utf8JsonWriter writer, IReadOnlyList value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, IReadOnlyList value, JsonSerializerOptions options) { // NOTE: value is never null here: null-valued properties are omitted // by JsonIgnoreCondition.WhenWritingNull before this converter is invoked. diff --git a/tests/Ramstack.HtmxToolkit.Tests/Internal/EnumHelperTests.cs b/tests/Ramstack.HtmxToolkit.Tests/Internal/EnumHelperTests.cs index e85d56f..e764bcb 100644 --- a/tests/Ramstack.HtmxToolkit.Tests/Internal/EnumHelperTests.cs +++ b/tests/Ramstack.HtmxToolkit.Tests/Internal/EnumHelperTests.cs @@ -78,16 +78,16 @@ public void ParseHtmxSwap_ReturnsNull_ForUnknownValue(string expression) => public void ParseHtmxSwap_ReturnsNull_WithoutStyle(string? expression) => Assert.That(EnumHelper.ParseHtmxSwap(expression), Is.Null); - [TestCase(HttpVerb.Get, "get")] - [TestCase(HttpVerb.Head, "head")] - [TestCase(HttpVerb.Post, "post")] - [TestCase(HttpVerb.Put, "put")] - [TestCase(HttpVerb.Delete, "delete")] - [TestCase(HttpVerb.Connect, "connect")] - [TestCase(HttpVerb.Options, "options")] - [TestCase(HttpVerb.Trace, "trace")] - [TestCase(HttpVerb.Patch, "patch")] - public void GetHttpVerbValue_ReturnsExpectedString(HttpVerb value, string expected) => + [TestCase(HtmxHttpVerb.Get, "get")] + [TestCase(HtmxHttpVerb.Head, "head")] + [TestCase(HtmxHttpVerb.Post, "post")] + [TestCase(HtmxHttpVerb.Put, "put")] + [TestCase(HtmxHttpVerb.Delete, "delete")] + [TestCase(HtmxHttpVerb.Connect, "connect")] + [TestCase(HtmxHttpVerb.Options, "options")] + [TestCase(HtmxHttpVerb.Trace, "trace")] + [TestCase(HtmxHttpVerb.Patch, "patch")] + public void GetHttpVerbValue_ReturnsExpectedString(HtmxHttpVerb value, string expected) => Assert.That(value.GetHttpVerbValue(), Is.EqualTo(expected)); [TestCase(HtmxBinaryType.Blob, "blob")] diff --git a/tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxConfigTagHelperTests.cs b/tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxConfigTagHelperTests.cs index 1b0f64f..69cf25d 100644 --- a/tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxConfigTagHelperTests.cs +++ b/tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxConfigTagHelperTests.cs @@ -83,7 +83,7 @@ public async Task ProcessAsync_SerializesFullResponseHandlingConfig() var options = new HtmxToolkitOptions(); options.UseHtmxV2(htmx => htmx.ResponseHandling = [ - new ResponseHandlingConfig + new HtmxResponseHandlingOptions { Code = "404", Swap = false, @@ -130,18 +130,18 @@ public async Task ProcessAsync_SerializesResponseHandlingSwapOverride(HtmxSwap s [TestCase("customSwap settle:200ms", null)] public async Task ProcessAsync_SerializesResponseHandlingSwapOverrideExpression(string expression, HtmxSwap? expectedStyle) { - var handlingConfig = new ResponseHandlingConfig + var handlingOptions = new HtmxResponseHandlingOptions { SwapOverride = HtmxSwap.InnerHtml, SwapOverrideExpression = expression }; var options = new HtmxToolkitOptions(); - options.UseHtmxV2(config => config.ResponseHandling = [handlingConfig]); + options.UseHtmxV2(config => config.ResponseHandling = [handlingOptions]); var json = await RenderJson(options); - Assert.That(handlingConfig.SwapOverride, Is.EqualTo(expectedStyle)); + Assert.That(handlingOptions.SwapOverride, Is.EqualTo(expectedStyle)); Assert.That( json["responseHandling"].GetRawText(), Is.EqualTo("[{\"swapOverride\":\"" + expression + "\"}]")); @@ -150,18 +150,18 @@ public async Task ProcessAsync_SerializesResponseHandlingSwapOverrideExpression( [Test] public async Task ProcessAsync_ResponseHandlingTypedSwapOverride_ReplacesExpression() { - var handlingConfig = new ResponseHandlingConfig + var handlingOptions = new HtmxResponseHandlingOptions { SwapOverrideExpression = "innerHTML settle:200ms", SwapOverride = HtmxSwap.OuterHtml }; var options = new HtmxToolkitOptions(); - options.UseHtmxV2(config => config.ResponseHandling = [handlingConfig]); + options.UseHtmxV2(config => config.ResponseHandling = [handlingOptions]); var json = await RenderJson(options); - Assert.That(handlingConfig.SwapOverrideExpression, Is.EqualTo("outerHTML")); + Assert.That(handlingOptions.SwapOverrideExpression, Is.EqualTo("outerHTML")); Assert.That( json["responseHandling"].GetRawText(), Is.EqualTo("[{\"swapOverride\":\"outerHTML\"}]")); @@ -171,20 +171,20 @@ public async Task ProcessAsync_ResponseHandlingTypedSwapOverride_ReplacesExpress [TestCase(true)] public async Task ProcessAsync_OmitsClearedResponseHandlingSwapOverride(bool clearExpression) { - var handlingConfig = new ResponseHandlingConfig { SwapOverrideExpression = "outerHTML settle:200ms" }; + var handlingOptions = new HtmxResponseHandlingOptions { SwapOverrideExpression = "outerHTML settle:200ms" }; if (clearExpression) - handlingConfig.SwapOverrideExpression = null; + handlingOptions.SwapOverrideExpression = null; else - handlingConfig.SwapOverride = null; + handlingOptions.SwapOverride = null; var options = new HtmxToolkitOptions(); - options.UseHtmxV2(config => config.ResponseHandling = [handlingConfig]); + options.UseHtmxV2(config => config.ResponseHandling = [handlingOptions]); var json = await RenderJson(options); - Assert.That(handlingConfig.SwapOverride, Is.Null); - Assert.That(handlingConfig.SwapOverrideExpression, Is.Null); + Assert.That(handlingOptions.SwapOverride, Is.Null); + Assert.That(handlingOptions.SwapOverrideExpression, Is.Null); Assert.That(json["responseHandling"].GetRawText(), Is.EqualTo("[{}]")); } @@ -220,7 +220,7 @@ public async Task ProcessAsync_SerializesOnlyHtmx1Options() htmx.DefaultFocusScroll = true; htmx.GetCacheBusterParam = true; htmx.GlobalViewTransitions = true; - htmx.MethodsThatUseUrlParams = [HttpVerb.Get, HttpVerb.Delete]; + htmx.MethodsThatUseUrlParams = [HtmxHttpVerb.Get, HtmxHttpVerb.Delete]; htmx.IgnoreTitle = true; htmx.ScrollIntoViewOnBoost = false; htmx.TriggerSpecsCacheEnabled = true; @@ -279,14 +279,14 @@ public async Task ProcessAsync_SerializesOnlyHtmx2Options_InResponseHandlingOrde htmx.DefaultFocusScroll = true; htmx.GetCacheBusterParam = true; htmx.GlobalViewTransitions = true; - htmx.MethodsThatUseUrlParams = [HttpVerb.Get, HttpVerb.Delete]; + htmx.MethodsThatUseUrlParams = [HtmxHttpVerb.Get, HtmxHttpVerb.Delete]; htmx.IgnoreTitle = true; htmx.ScrollIntoViewOnBoost = false; htmx.TriggerSpecsCacheEnabled = true; htmx.ResponseHandling = [ - new ResponseHandlingConfig { Code = "204", Swap = false }, - new ResponseHandlingConfig { Code = "[45]..", Swap = false, Error = true } + new HtmxResponseHandlingOptions { Code = "204", Swap = false }, + new HtmxResponseHandlingOptions { Code = "[45]..", Swap = false, Error = true } ]; htmx.AllowNestedOobSwaps = true; htmx.HistoryRestoreAsHxRequest = false;