Skip to content

Commit

Permalink
Refactor HtmlHelper, update PagedListRenderOptions, _PostList
Browse files Browse the repository at this point in the history
Refactored HtmlHelper to use a local function named `Format` for
generating page URLs, improving readability and maintainability.

Removed the `FunctionToDisplayEachPageNumber` property from
PagedListRenderOptions, simplifying the class by eliminating an
unused feature.

Updated `_PostList.cshtml` to use a more modern and concise
syntax for initializing the `UlElementClasses` array in the
`PagedListPager` method.
  • Loading branch information
EdiWang committed Oct 31, 2024
1 parent 4989837 commit d544d4f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/Moonglade.Web/PagedList/HtmlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ private TagBuilder Previous(IPagedList list, Func<int, string> generatePageUrl,

private TagBuilder Page(int i, IPagedList list, Func<int, string> generatePageUrl, PagedListRenderOptions options)
{
var format = options.FunctionToDisplayEachPageNumber
?? (pageNumber => string.Format(options.LinkToIndividualPageFormat, pageNumber));
string Format(int pageNumber) => string.Format(options.LinkToIndividualPageFormat, pageNumber);
var targetPageNumber = i;
var page = i == list.PageNumber
? new TagBuilder("span")
: new TagBuilder("a");

SetInnerText(page, format(targetPageNumber));
SetInnerText(page, Format(targetPageNumber));

foreach (var c in options.PageClasses ?? [])
{
Expand Down
6 changes: 0 additions & 6 deletions src/Moonglade.Web/PagedList/PagedListRenderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public PagedListRenderOptions()
LinkToLastPageFormat = ">>";
PageCountAndCurrentLocationFormat = "Page {0} of {1}.";
ItemSliceAndTotalFormat = "Showing items {0} through {1} of {2}.";
FunctionToDisplayEachPageNumber = null;
UlElementClasses = ["pagination"];
PageClasses = ["page-link"];
PreviousElementClass = "PagedList-skip-to-previous";
Expand Down Expand Up @@ -111,9 +110,4 @@ public PagedListRenderOptions()
/// "Showing items {0} through {1} of {2}."
///</example>
public string ItemSliceAndTotalFormat { get; set; }

/// <summary>
/// A function that will render each page number when specified (and DisplayLinkToIndividualPages is true). If no function is specified, the LinkToIndividualPageFormat value will be used instead.
/// </summary>
public Func<int, string> FunctionToDisplayEachPageNumber { get; set; }
}
3 changes: 2 additions & 1 deletion src/Moonglade.Web/Pages/Shared/_PostList.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<partial name="_PostListEntry" model="item" />
}


@Html.PagedListPager(Model, page => $"?p={page}", new()
{
UlElementClasses = new[] { "pagination justify-content-end" },
UlElementClasses = ["pagination justify-content-end"],
MaximumPageNumbersToDisplay = 5
})

0 comments on commit d544d4f

Please sign in to comment.