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

Added a handlebars helper to truncate a string #106

Merged
merged 3 commits into from
Feb 16, 2017

Conversation

elephantengine
Copy link
Contributor

FUNCTION
truncate(str, length)

DESCRIPTION (WHAT)
Returns the first X characters in a string (unless it reaches the end
of the string first, in which case it will return fewer). Returns a
new string that is truncated to the given length.

USE CASE (WHY)
As a merchant, I want to display a card, at the bottom of
my home page that highlights the most recent blog post. In the card,
I want to display the blog thumbnail, title and the first 40 characters
of the post's body. In order to extract the first 40 characters, I need
a Handlebars helper that works like the javascript substring() function.

USAGE
{{lang (truncate 'blog.post.body.' 40) }}

@mcampa , @junedkazi , @mjschock

@mcampa
Copy link
Contributor

mcampa commented Feb 15, 2017

Looks good to me. Do you mind writing a simple test case in /tests/helpers?
take a look at this example https://github.com/bigcommerce/paper/blob/master/test/helpers/concat.js

@bc-mkatz can you add this new helper to the docs?

@mQkatz
Copy link

mQkatz commented Feb 15, 2017

@mcampa: Looks straightforward, will add this to the docs later today. Thanks.

@mcampa
Copy link
Contributor

mcampa commented Feb 16, 2017

Awesome, thanks for writing the test. Just one more thing, can you fix the lint errors?

/home/travis/build/bigcommerce/paper/test/helpers/truncate.js
  16:7  error  Expected indentation of 8 space characters but found 6  indent
  17:7  error  Expected indentation of 8 space characters but found 6  indent

@mcampa
Copy link
Contributor

mcampa commented Feb 16, 2017

👍

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

Successfully merging this pull request may close these issues.

4 participants