-
-
Notifications
You must be signed in to change notification settings - Fork 178
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
Implement paginate tag #389
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
builder.AppendFormat( | ||
"<span class=\"prev\"><a href=\"{0}\">{1}</a></span>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any piece of text that will be rendered and could be customized should go in options. There could be a sub-object called PaginateSettings
with many things to change.
Then it's accessible here from context.Options.PaginateSettings
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can create a delegate to implement this function. This requires the PaginateValue and PartValue to be exposed.
builder.AppendFormat( | ||
"<span class=\"next\"><a href=\"{0}\">{1}</a></span>", | ||
HttpUtility.HtmlAttributeEncode(paginate.Previous.Url), | ||
HttpUtility.HtmlEncode(title) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The encoder should also be part of the options if not already available somewhere else.
public override async ValueTask<Completion> WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context) | ||
{ | ||
var value = await _expression.EvaluateAsync(context); | ||
if (value == null || value is not PaginateableValue paginateableValue) return Completion.Normal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should work with standard collection values (Array, Dictionary, even strings) but it should handle a custom IPaginate
if necessary to customize the results (somehow like you did here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IPaginate needs to return the current page, but the standard collection does not provide this value (unless we agree on a value in the context). It also requires a method to generate a URL to populate the paginate object.
I couldn't find the code where the |
We don't need to replace it because PaginateableValue is an array by default and can be used for the for tag. |
#247
I implemented paginate tag and added PaginateStatement to realize this function.
Some unit tests have been added, but they may not be comprehensive enough.
The user should create a derived class for PaginateableValue and implement its abstract methods.
I wanted to make the PaginateableValue.Paginate method asynchronous, but I didn't find a good solution (I need to introduce a third-party component: Nito.AsyncEx.Context).
Maybe we can add an interface and implement a converter from this interface to PaginateableValue.