Zend Framework: Zend_Filter_WordTruncate Component Proposal
| Proposed Component Name | Zend_Filter_WordTruncate |
|---|---|
| Developer Notes | http://framework.zend.com/wiki/display/ZFDEV/Zend_Filter_WordTruncate |
| Proposers | Thomas Weidner |
| Zend Liaison | TBD |
| Revision | 1.0 - 8 August 2009: Initial Draft. (wiki revision: 4) |
Table of Contents
1. Overview
Zend_Filter_StringTruncate is a filter which truncates strings, regardless of their content. But differently to Zend_Filter_StringTruncate it does not truncate words in the middle.
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
- This component will truncate strings at a given length
- This component will keep words complete when there are more than one words
- This component will also handle multibyte strings
4. Dependencies on Other Framework Components
- Zend_Filter_Interface
- Zend_View_Helper_Abstract
5. Theory of Operation
This filter truncates strings to a given length. It's the reverse filter for the StringPad Filter. Additionally it keeps words complete when there is more than one word in the given string.
For simplicity this filter also adds a view helper which makes use of this filter.
6. Milestones / Tasks
- Milestone 1: [DONE] Proposal finished
- Milestone 2: Proposal accepted
- Milestone 3: Working implementation
- Milestone 4: Unit tests
- Milestone 5: Documentation
- Milestone 6: Moved to core
7. Class Index
- Zend_Filter_WordTruncate
- Zend_View_Helper_WordTruncate
8. Use Cases
| UC-01 |
|---|
Truncate words with default settings
| UC-02 |
|---|
Truncate words using ending chars
| UC-03 |
|---|
Truncate words using ending chars and additionally get the truncated content
| UC-04 |
|---|
Truncate words but from left
5 Comments
comments.show.hideNov 23, 2009
Darren Lucas
+1
Would it make sense to offer an extra option in StringTruncate to only truncate after whole words only? That would negate the need to WordTruncate or allow it just to be a wrapper function for StringTruncate with that option set as default.
What would 'both' do, truncate at either end, e.g '...is a long sentence...', or in the middle, e.g 'This is ... sentence'?
Also this would be great as a view helper, or a generic filter view helper might be better, there isn't a $this->filter('StringTruncate',array('length'=>50)) helper at the moment is there?
Nov 24, 2009
Thomas Weidner
My original proposal had all options included.
I was said that I have to split it into 3-4 different proposals, where this one is one of it.
You can find all other also within this section.
Looking at the proposal you can see that it includes an view helper.
Nov 25, 2009
Darren Lucas
Sorry, I didn't think to check the proposal it was based on (Zend_Filter_StringLength).
I can see it would make sense splitting StringPad and StringTruncate. The questions I have with splitting it down further into StringTruncate and WordTruncate are:
With the view helper, do you think a generic Zend_View_Helper_Filter helper would be a good idea?
Nov 26, 2009
Thomas Weidner
Code duplication is normally prevented by extending classes.
I am not sure if a generic filter helper would make sense.
It would have to work with all filters, even own ones. And the usage is not identical for all filters... also several filters would be useless... why would someone call a compress-filter from within the view ?
Aug 03, 2010
Dolf Schimmel (Freeaqingme)
The CR Team advises against accepting this proposal. However: we do advise on implementing this functionality in the StringTruncate component