Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api-overwrites/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ example:
---

---
uid: Ramstack.HtmxToolkit.Configuration.ResponseHandlingConfig
uid: Ramstack.HtmxToolkit.Configuration.HtmxResponseHandlingOptions
example:
- |-
[!code-csharp[](../snippets/configuration/ResponseHandling.cs)]
Expand Down
4 changes: 2 additions & 2 deletions docs/articles/configuration-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
10 changes: 5 additions & 5 deletions docs/articles/migrate-to-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down Expand Up @@ -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<HttpVerb>` instead of `string[]`) |
| `methods-that-use-url-params` | `MethodsThatUseUrlParams` (`IReadOnlyList<HtmxHttpVerb>` 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Ramstack.HtmxToolkit.Configuration;
/// <summary>
/// Defines the HTTP methods that can be used in HTMX configuration.
/// </summary>
public enum HttpVerb
public enum HtmxHttpVerb
{
/// <summary>
/// The <c>GET</c> method requests a representation of the specified resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Ramstack.HtmxToolkit.Configuration;
/// Represents the response handling configuration for responses that match
/// a specific HTTP status code pattern.
/// </summary>
public sealed class ResponseHandlingConfig
public sealed class HtmxResponseHandlingOptions
{
/// <summary>
/// Gets or sets the regular expression used to match response status codes.
Expand Down
4 changes: 2 additions & 2 deletions src/Ramstack.HtmxToolkit/Configuration/HtmxV1Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ public bool? GlobalViewTransitions
/// Gets or sets the HTTP methods that use URL parameters.
/// The HTMX default is <c>["get"]</c>.
/// </summary>
[JsonConverter(typeof(HttpVerbListJsonConverter))]
public IReadOnlyList<HttpVerb>? MethodsThatUseUrlParams
[JsonConverter(typeof(HtmxHttpVerbListJsonConverter))]
public IReadOnlyList<HtmxHttpVerb>? MethodsThatUseUrlParams
{
get;
set => SetField(ref field, value);
Expand Down
6 changes: 3 additions & 3 deletions src/Ramstack.HtmxToolkit/Configuration/HtmxV2Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ public bool? GlobalViewTransitions
/// Gets or sets the HTTP methods that use URL parameters.
/// The HTMX default is <c>["get", "delete"]</c>.
/// </summary>
[JsonConverter(typeof(HttpVerbListJsonConverter))]
public IReadOnlyList<HttpVerb>? MethodsThatUseUrlParams
[JsonConverter(typeof(HtmxHttpVerbListJsonConverter))]
public IReadOnlyList<HtmxHttpVerb>? MethodsThatUseUrlParams
{
get;
set => SetField(ref field, value);
Expand Down Expand Up @@ -344,7 +344,7 @@ public bool? TriggerSpecsCacheEnabled
/// The HTMX default is <c>[{ code: "204", swap: false }, { code: "[23]..", swap: true },
/// { code: "[45]..", swap: false, error: true }]</c>.
/// </summary>
public IReadOnlyList<ResponseHandlingConfig>? ResponseHandling
public IReadOnlyList<HtmxResponseHandlingOptions>? ResponseHandling
{
get;
set => SetField(ref field, value);
Expand Down
40 changes: 20 additions & 20 deletions src/Ramstack.HtmxToolkit/Internal/EnumHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,35 @@ or HtmxSwap.Delete
}

/// <summary>
/// Converts a <see cref="HttpVerb" /> value to its corresponding lowercase HTTP method string.
/// Converts a <see cref="HtmxHttpVerb" /> value to its corresponding lowercase HTTP method string.
/// </summary>
/// <param name="value">The <see cref="HttpVerb" /> value.</param>
/// <param name="value">The <see cref="HtmxHttpVerb" /> value.</param>
/// <returns>
/// The lowercase HTTP method name, such as <c>get</c>, <c>post</c>, or <c>delete</c>.
/// </returns>
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"
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
namespace Ramstack.HtmxToolkit.Serialization;

/// <summary>
/// Represents a <see cref="JsonConverter{T}" /> for lists of <see cref="HttpVerb" /> values.
/// Represents a <see cref="JsonConverter{T}" /> for lists of <see cref="HtmxHttpVerb" /> values.
/// </summary>
internal sealed class HttpVerbListJsonConverter : JsonConverter<IReadOnlyList<HttpVerb>>
internal sealed class HtmxHttpVerbListJsonConverter : JsonConverter<IReadOnlyList<HtmxHttpVerb>>
{
/// <inheritdoc />
public override IReadOnlyList<HttpVerb> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
public override IReadOnlyList<HtmxHttpVerb> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
throw new NotSupportedException();

/// <inheritdoc />
public override void Write(Utf8JsonWriter writer, IReadOnlyList<HttpVerb> value, JsonSerializerOptions options)
public override void Write(Utf8JsonWriter writer, IReadOnlyList<HtmxHttpVerb> value, JsonSerializerOptions options)
{
// NOTE: value is never null here: null-valued properties are omitted
// by JsonIgnoreCondition.WhenWritingNull before this converter is invoked.
Expand Down
20 changes: 10 additions & 10 deletions tests/Ramstack.HtmxToolkit.Tests/Internal/EnumHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 + "\"}]"));
Expand All @@ -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\"}]"));
Expand All @@ -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("[{}]"));
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading