Truncate Formatter
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- ruby
- Domain
- documentation
Research direction
Review README.md and the existing documentation around Grape::Entity and format_with. Confirm whether the example belongs in README.md or a wiki, then document the truncate formatter example and its rendered output. Done means the guidance is easy to find and accurately explains truncating long fields with an ellipsis.
Written by the indexing model from the issue text.
Description
Do we have a wiki to stick this content into? Or maybe we can add it to the README.md?
I thought identifying how to truncate long fields may be useful for others as well.
For large character length fields that you wish to truncate and append ellipse (...), you can utilize the format_with function.
Code example:
class MyEntity < Grape::Entity
format_with(:truncate) { |str| str.truncate(50) }
with_options(format_with: :truncate) do
expose :summary
expose :raw_content
end
end
This will render your content as following when the field is over 50 characters long:
{
"summary": "adfasdf sdafjlksdaf kslafj lksdaf jlkdsfafdkasl...",
"raw_content": "adfasdf sdafjlksdaf kslafj lksdaf jlkdsfafdkasl..."
}
- Dominant language
- Ruby
- Stars
- 729
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby-grape/grape-entity
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
ruby-grape/grape-entity#386 · 7 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-grape/grape-entity#382 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-grape/grape-entity#380 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
ruby-grape/grape-entity#373 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
ruby-grape/grape-entity#370 ·
All issues in ruby-grape/grape-entity
Similar issues
-
user-reported
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kong/developer.konghq.com#7316 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TheOdinProject/curriculum#31408 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
notch8/utk_knapsack#148 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Homebrew/homebrew-cask#288729 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100