Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Change casing on SwapStyle (and other htmx enums) for correct serialization #54

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions src/Htmxor/HtmxConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public partial record class HtmxConfig
public bool? RefreshOnHistoryMiss { get; set; }

/// <summary>
/// Defaults to <see cref="SwapStyle.InnerHTML"/> if this property is null.
/// Defaults to <see cref="SwapStyle.innerHTML"/> if this property is null.
/// </summary>
[JsonPropertyName("defaultSwapStyle")]
public SwapStyle? DefaultSwapStyle
Expand Down Expand Up @@ -160,7 +160,7 @@ public SwapStyle? DefaultSwapStyle
public TimeSpan? Timeout { get; set; }

/// <summary>
/// Defaults to <see cref="ScrollBehavior.Smooth" /> if this property is null.
/// Defaults to <see cref="ScrollBehavior.smooth" /> if this property is null.
/// The behavior for a boosted link on page transitions.
/// Smooth will smooth scroll to the top of the page while auto will behave like a vanilla link.
/// </summary>
Expand Down
8 changes: 5 additions & 3 deletions src/Htmxor/ScrollBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Htmxor;
// ReSharper disable InconsistentNaming
namespace Htmxor;

/// <summary>
/// The behavior for a boosted link on page transitions.
Expand All @@ -8,10 +9,11 @@ public enum ScrollBehavior
/// <summary>
/// Smooth will smooth-scroll to the top of the page.
/// </summary>
Smooth,
smooth,

/// <summary>
/// Auto will behave like a vanilla link.
/// </summary>
Auto,
auto,
}

7 changes: 4 additions & 3 deletions src/Htmxor/ScrollDirection.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
namespace Htmxor;
// ReSharper disable InconsistentNaming
namespace Htmxor;

/// <summary>
/// Direction values for scroll and show modifier methods
/// </summary>
public enum ScrollDirection
{
Top,
Bottom
top,
bottom
}
16 changes: 8 additions & 8 deletions src/Htmxor/Serialization/SwapStyleEnumConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public override SwapStyle Read(ref Utf8JsonReader reader, Type typeToConvert, Js
{
null => SwapStyle.Default,
Constants.SwapStyles.Default => SwapStyle.Default,
Constants.SwapStyles.InnerHTML => SwapStyle.InnerHTML,
Constants.SwapStyles.OuterHTML => SwapStyle.OuterHTML,
Constants.SwapStyles.BeforeBegin => SwapStyle.BeforeBegin,
Constants.SwapStyles.AfterBegin => SwapStyle.AfterBegin,
Constants.SwapStyles.BeforeEnd => SwapStyle.BeforeEnd,
Constants.SwapStyles.AfterEnd => SwapStyle.AfterEnd,
Constants.SwapStyles.Delete => SwapStyle.Delete,
Constants.SwapStyles.None => SwapStyle.None,
Constants.SwapStyles.InnerHTML => SwapStyle.innerHTML,
Constants.SwapStyles.OuterHTML => SwapStyle.outerHTML,
Constants.SwapStyles.BeforeBegin => SwapStyle.beforebegin,
Constants.SwapStyles.AfterBegin => SwapStyle.afterbegin,
Constants.SwapStyles.BeforeEnd => SwapStyle.beforeend,
Constants.SwapStyles.AfterEnd => SwapStyle.afterend,
Constants.SwapStyles.Delete => SwapStyle.delete,
Constants.SwapStyles.None => SwapStyle.none,
_ => throw new SwitchExpressionException(value)
};

Expand Down
21 changes: 11 additions & 10 deletions src/Htmxor/SwapStyle.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Htmxor;
// ReSharper disable InconsistentNaming
namespace Htmxor;

/// <summary>
/// How to swap the response into the target element.
Expand All @@ -7,48 +8,48 @@ public enum SwapStyle
{
/// <summary>
/// Default style is what is specified in <see cref="HtmxConfig.DefaultSwapStyle"/> for the application
/// or htmx's default, which is <see cref="InnerHTML"/>.
/// or htmx's default, which is <see cref="innerHTML"/>.
/// </summary>
Default,

/// <summary>
/// Replace the inner html of the target element.
/// </summary>
InnerHTML,
innerHTML,

/// <summary>
/// Replace the entire target element with the response.
/// </summary>
OuterHTML,
outerHTML,

/// <summary>
/// Insert the response before the target element.
/// </summary>
BeforeBegin,
beforebegin,

/// <summary>
/// Insert the response before the first child of the target element.
/// </summary>
AfterBegin,
afterbegin,

/// <summary>
/// Insert the response after the last child of the target element.
/// </summary>
BeforeEnd,
beforeend,

/// <summary>
/// Insert the response after the target element.
/// </summary>
AfterEnd,
afterend,

/// <summary>
/// Deletes the target element regardless of the response.
/// </summary>
Delete,
delete,

/// <summary>
/// Does not append content from response (out of band items will still be processed).
/// </summary>
None,
none,
}

28 changes: 14 additions & 14 deletions src/Htmxor/SwapStyleBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public SwapStyleBuilder AfterSettleDelay(TimeSpan time)
/// Specifies how to set the content scrollbar position after the swap and appends the modifier <c>scroll:<paramref name="direction"/></c>.
/// </summary>
/// <remarks>
/// Sets the swapped content scrollbar position after swapping immediately (without animation). For instance, using <see cref="ScrollDirection.Top"/>
/// Sets the swapped content scrollbar position after swapping immediately (without animation). For instance, using <see cref="ScrollDirection.top"/>
/// will add the modifier <c>scroll:top</c> which sets the scrollbar position to the top of swap content after the swap.
/// If css <paramref name="cssSelector"/> is present then the page is scrolled to the <paramref name="direction"/> of the content identified by the css cssSelector.
/// </remarks>
Expand All @@ -75,10 +75,10 @@ public SwapStyleBuilder Scroll(ScrollDirection direction, string? cssSelector =
{
switch (direction)
{
case ScrollDirection.Top:
case ScrollDirection.top:
AddModifier("scroll", cssSelector is null ? "top" : $"{cssSelector}:top");
break;
case ScrollDirection.Bottom:
case ScrollDirection.bottom:
AddModifier("scroll", cssSelector is null ? "bottom" : $"{cssSelector}:bottom");
break;
}
Expand All @@ -96,7 +96,7 @@ public SwapStyleBuilder Scroll(ScrollDirection direction, string? cssSelector =
/// </remarks>
/// <param name="cssSelector">Optional CSS cssSelector of the target element.</param>
/// <returns>This <see cref="SwapStyleBuilder"/> object instance.</returns>
public SwapStyleBuilder ScrollTop(string? cssSelector = null) => Scroll(ScrollDirection.Top, cssSelector);
public SwapStyleBuilder ScrollTop(string? cssSelector = null) => Scroll(ScrollDirection.top, cssSelector);

/// <summary>
/// Sets the content scrollbar position to the bottom of the swapped content after a swap.
Expand All @@ -108,7 +108,7 @@ public SwapStyleBuilder Scroll(ScrollDirection direction, string? cssSelector =
/// </remarks>
/// <param name="cssSelector">Optional CSS cssSelector of the target element.</param>
/// <returns>This <see cref="SwapStyleBuilder"/> object instance.</returns>
public SwapStyleBuilder ScrollBottom(string? cssSelector = null) => Scroll(ScrollDirection.Bottom, cssSelector);
public SwapStyleBuilder ScrollBottom(string? cssSelector = null) => Scroll(ScrollDirection.bottom, cssSelector);

/// <summary>
/// Determines whether to ignore the document title in the swap response by appending the modifier
Expand Down Expand Up @@ -207,7 +207,7 @@ public SwapStyleBuilder ScrollFocus(bool scroll = true)
/// </summary>
/// <remarks>
/// Adds a show modifier with the specified CSS cssSelector and scroll direction. For example, if <paramref name="cssSelector"/>
/// is ".item" and <paramref name="direction"/> is <see cref="ScrollDirection.Top"/>, the modifier <c>show:.item:top</c>
/// is ".item" and <paramref name="direction"/> is <see cref="ScrollDirection.top"/>, the modifier <c>show:.item:top</c>
/// is added.
/// </remarks>
/// <param name="direction">The scroll direction after swap.</param>
Expand All @@ -217,10 +217,10 @@ public SwapStyleBuilder ShowOn(ScrollDirection direction, string? cssSelector =
{
switch (direction)
{
case ScrollDirection.Top:
case ScrollDirection.top:
AddModifier("show", cssSelector is null ? "top" : $"{cssSelector}:top");
break;
case ScrollDirection.Bottom:
case ScrollDirection.bottom:
AddModifier("show", cssSelector is null ? "bottom" : $"{cssSelector}:bottom");
break;
}
Expand All @@ -237,7 +237,7 @@ public SwapStyleBuilder ShowOn(ScrollDirection direction, string? cssSelector =
/// </remarks>
/// <param name="cssSelector">Optional CSS cssSelector of the target element.</param>
/// <returns>This <see cref="SwapStyleBuilder"/> object instance.</returns>
public SwapStyleBuilder ShowOnTop(string? cssSelector = null) => ShowOn(ScrollDirection.Top, cssSelector);
public SwapStyleBuilder ShowOnTop(string? cssSelector = null) => ShowOn(ScrollDirection.top, cssSelector);

/// <summary>
/// Specifies that the swap should show the bottom of the element matching the CSS cssSelector.
Expand All @@ -248,7 +248,7 @@ public SwapStyleBuilder ShowOn(ScrollDirection direction, string? cssSelector =
/// </remarks>
/// <param name="cssSelector">Optional CSS cssSelector of the target element.</param>
/// <returns>This <see cref="SwapStyleBuilder"/> object instance.</returns>
public SwapStyleBuilder ShowOnBottom(string? cssSelector = null) => ShowOn(ScrollDirection.Bottom, cssSelector);
public SwapStyleBuilder ShowOnBottom(string? cssSelector = null) => ShowOn(ScrollDirection.bottom, cssSelector);

/// <summary>
/// Specifies that the swap should show in the window by smoothly scrolling to either the top or bottom of the window.
Expand All @@ -263,10 +263,10 @@ public SwapStyleBuilder ShowWindow(ScrollDirection direction)
{
switch (direction)
{
case ScrollDirection.Top:
case ScrollDirection.top:
AddModifier("show", "window:top");
break;
case ScrollDirection.Bottom:
case ScrollDirection.bottom:
AddModifier("show", "window:bottom");
break;
}
Expand All @@ -284,7 +284,7 @@ public SwapStyleBuilder ShowWindow(ScrollDirection direction)
/// the user after a swap operation.
/// </remarks>
/// <returns>This <see cref="SwapStyleBuilder"/> object instance.</returns>
public SwapStyleBuilder ShowWindowTop() => ShowWindow(ScrollDirection.Top);
public SwapStyleBuilder ShowWindowTop() => ShowWindow(ScrollDirection.top);

/// <summary>
/// Specifies that the swap should smoothly scroll to the bottom of the window.
Expand All @@ -295,7 +295,7 @@ public SwapStyleBuilder ShowWindow(ScrollDirection direction)
/// can be used for infinite scrolling, footers, or information appended at the end of the page.
/// </remarks>
/// <returns>This <see cref="SwapStyleBuilder"/> object instance.</returns>
public SwapStyleBuilder ShowWindowBottom() => ShowWindow(ScrollDirection.Bottom);
public SwapStyleBuilder ShowWindowBottom() => ShowWindow(ScrollDirection.bottom);

/// <summary>
/// Turns off scrolling after swap.
Expand Down
4 changes: 2 additions & 2 deletions src/Htmxor/SwapStyleBuilderExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static class SwapStyleBuilderExtension
/// Specifies how to set the content scrollbar position after the swap and appends the modifier <c>scroll:<paramref name="direction"/></c>.
/// </summary>
/// <remarks>
/// Sets the swapped content scrollbar position after swapping immediately (without animation). For instance, using <see cref="ScrollDirection.Top"/>
/// Sets the swapped content scrollbar position after swapping immediately (without animation). For instance, using <see cref="ScrollDirection.top"/>
/// will add the modifier <c>scroll:top</c> which sets the scrollbar position to the top of swap content after the swap.
/// If css <paramref name="cssSelector"/> is present then the page is scrolled to the <paramref name="direction"/> of the content identified by the css cssSelector.
/// </remarks>
Expand Down Expand Up @@ -165,7 +165,7 @@ public static SwapStyleBuilder Scroll(this SwapStyle style, ScrollDirection dire
/// </summary>
/// <remarks>
/// Adds a show modifier with the specified CSS selector and scroll direction. For example, if <paramref name="cssSelector"/>
/// is ".item" and <paramref name="direction"/> is <see cref="ScrollDirection.Top"/>, the modifier <c>show:.item:top</c>
/// is ".item" and <paramref name="direction"/> is <see cref="ScrollDirection.top"/>, the modifier <c>show:.item:top</c>
/// is added.
/// </remarks>
/// <param name="style">The swap style.</param>
Expand Down
16 changes: 8 additions & 8 deletions src/Htmxor/SwapStyleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public static string ToHtmxString(this SwapStyle swapStyle)
{
var style = swapStyle switch
{
SwapStyle.InnerHTML => Constants.SwapStyles.InnerHTML,
SwapStyle.OuterHTML => Constants.SwapStyles.OuterHTML,
SwapStyle.BeforeBegin => Constants.SwapStyles.BeforeBegin,
SwapStyle.AfterBegin => Constants.SwapStyles.AfterBegin,
SwapStyle.BeforeEnd => Constants.SwapStyles.BeforeEnd,
SwapStyle.AfterEnd => Constants.SwapStyles.AfterEnd,
SwapStyle.Delete => Constants.SwapStyles.Delete,
SwapStyle.None => Constants.SwapStyles.None,
SwapStyle.innerHTML => Constants.SwapStyles.InnerHTML,
SwapStyle.outerHTML => Constants.SwapStyles.OuterHTML,
SwapStyle.beforebegin => Constants.SwapStyles.BeforeBegin,
SwapStyle.afterbegin => Constants.SwapStyles.AfterBegin,
SwapStyle.beforeend => Constants.SwapStyles.BeforeEnd,
SwapStyle.afterend => Constants.SwapStyles.AfterEnd,
SwapStyle.delete => Constants.SwapStyles.Delete,
SwapStyle.none => Constants.SwapStyles.None,
SwapStyle.Default => Constants.SwapStyles.Default,
_ => throw new SwitchExpressionException(swapStyle),
};
Expand Down
10 changes: 5 additions & 5 deletions src/Htmxor/TriggerModifierBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ public TriggerModifierBuilder Consume()
/// // Resulting hx-trigger: <![CDATA[<div hx-get="/process" hx-trigger="click queue:all">Queue All]]>
/// </code>
/// </example>
public TriggerModifierBuilder Queue(TriggerQueueOption option = TriggerQueueOption.Last)
public TriggerModifierBuilder Queue(TriggerQueueOption option = TriggerQueueOption.last)
{
var value = option switch
{
TriggerQueueOption.First => "first",
TriggerQueueOption.Last => "last",
TriggerQueueOption.None => "none",
TriggerQueueOption.All => "all",
TriggerQueueOption.first => "first",
TriggerQueueOption.last => "last",
TriggerQueueOption.none => "none",
TriggerQueueOption.all => "all",
_ => throw new SwitchExpressionException(option),
};

Expand Down
9 changes: 5 additions & 4 deletions src/Htmxor/TriggerQueueOption.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ReSharper disable InconsistentNaming
namespace Htmxor;

/// <summary>
Expand All @@ -8,20 +9,20 @@ public enum TriggerQueueOption
/// <summary>
/// queue the first event
/// </summary>
First,
first,

/// <summary>
/// queue the last event (default)
/// </summary>
Last,
last,

/// <summary>
/// queue all events (issue a request for each event)
/// </summary>
All,
all,

/// <summary>
/// do not queue new events
/// </summary>
None
none
}
4 changes: 2 additions & 2 deletions test/Htmxor.Tests/Configuration/HtmxHeadOutletTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void HtmxConfig_serializer()
DefaultFocusScroll = true,
DefaultSettleDelay = TimeSpan.FromHours(1),
DefaultSwapDelay = TimeSpan.FromMinutes(1),
DefaultSwapStyle = SwapStyle.BeforeBegin,
DefaultSwapStyle = SwapStyle.beforebegin,
DisableSelector = "disable-selector",
GetCacheBusterParam = true,
GlobalViewTransitions = true,
Expand All @@ -32,7 +32,7 @@ public void HtmxConfig_serializer()
MethodsThatUseUrlParams = ["GET", "POST", "DELETE"],
RefreshOnHistoryMiss = true,
RequestClass = "request-class",
ScrollBehavior = ScrollBehavior.Smooth,
ScrollBehavior = ScrollBehavior.smooth,
ScrollIntoViewOnBoost = true,
SelfRequestsOnly = true,
SettlingClass = "settling-class",
Expand Down
2 changes: 1 addition & 1 deletion test/Htmxor.Tests/Http/HtmxResponseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void Reswap_AddsReswapHeader()
var response = context.GetHtmxContext().Response;

// Act
response.Reswap(SwapStyle.InnerHTML);
response.Reswap(SwapStyle.innerHTML);

// Assert
context.Response.Headers[HtmxResponseHeaderNames.Reswap].Should().Equal(["innerHTML"]);
Expand Down
Loading
Loading