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

Implement paginate tag #389

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Implement paginate tag #389

wants to merge 3 commits into from

Conversation

Soar360
Copy link
Contributor

@Soar360 Soar360 commented Nov 2, 2021

#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.

}

builder.AppendFormat(
"<span class=\"prev\"><a href=\"{0}\">{1}</a></span>",
Copy link
Owner

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.

Copy link
Contributor Author

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)
Copy link
Owner

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;
Copy link
Owner

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).

Copy link
Contributor Author

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.

@sebastienros
Copy link
Owner

I couldn't find the code where the for tag is used and shows how the current value is replaced by the page, like in this example https://github.com/Shopify/liquid/blob/eab13a07d9861a38d993d2749ae25f06ff76426b/performance/tests/vogue/blog.liquid

@Soar360
Copy link
Contributor Author

Soar360 commented Nov 3, 2021

I couldn't find the code where the for tag is used and shows how the current value is replaced by the page, like in this example https://github.com/Shopify/liquid/blob/eab13a07d9861a38d993d2749ae25f06ff76426b/performance/tests/vogue/blog.liquid

We don't need to replace it because PaginateableValue is an array by default and can be used for the for tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants