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

Is there a way to map new filter to existing filter? #429

Open
mckingho opened this issue Jan 20, 2021 · 3 comments
Open

Is there a way to map new filter to existing filter? #429

mckingho opened this issue Jan 20, 2021 · 3 comments

Comments

@mckingho
Copy link

mckingho commented Jan 20, 2021

liquid-rust version: 0.21.4
rust version: 1.49.0
OS: Any

I want to add a custom filter called url_param_escape, which is exactly the same function of a standard filter url_encode in the module. Can I bind new filter name to existing filter so that both filter name are valid and function the same way?

Edit:
This is my solution. originalFilter is the struct of original filter that impl Filter trait.

#[derive(Clone, ParseFilter, FilterReflection)]
#[filter(
    name = "alias_name",
    description = "Alias of original filter.",
    parsed(originalFilter)
)]
pub struct AliasFilter;
@epage
Copy link
Member

epage commented Jan 20, 2021

All of the filters are exposed and can be added to the parser like the default set does: https://github.com/cobalt-org/liquid-rust/blob/master/src/parser.rs#L109

You'll have to use a newtype to give it a new name.

Whats the motivation for renaming?

@mckingho
Copy link
Author

url_param_escape is a filter supported in shopify. It is very similar to url_encode. Before I posted this question, I want to find a way to do some alias mapping rather than duplicate all the codes from url_encode. Because I want to support both filters, not renaming.

But I just review shopify's document, there is slight difference between two filters. So I am going to write a custom one instead.

@epage
Copy link
Member

epage commented Jan 20, 2021

Either way, if you are up for contributing it back, that'd be great! We are working on having the official liquid filters, shopify, jekyll, and custom, see https://github.com/cobalt-org/liquid-rust/tree/master/crates/lib/src

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

No branches or pull requests

2 participants