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

adjust excerpt function to make suffix a keyword argument #105

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

Conversation

jeremybmerrill
Copy link

@jeremybmerrill jeremybmerrill commented Jul 10, 2023

This PR would extend the existing excerpt function to take an optional keyword argument suffix= that would be appended to the end of the excerpt, instead of the current ... ellipsis. If the argument is unspecified, the ... suffix will be retained, i.e. this change is backwards compatible.

For instance, if suffix is set to an empty string, the excerpt will be just the first N characters of the string. ``{{excerpt string 10 suffix=""}}returns'That can o'` and `{{excerpt string 10 suffix="asdf"}}` returns `'That can oasdf'`.

I have added tests; all pre-existing tests pass unmodified.

For context: just-handlebars-helpers is packaged with Apache Superset's handlebars charts. I need to do some string processing there and want to use excerpt without the ellipsis.

Notes:

  1. The keyword argument code is copied from the sprintf implementation.
  2. If you'd prefer an implementation where suffix is an optional positional argument, you can revert the last commit in this PR.

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.

1 participant