Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

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: 5)

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

9. Class Skeletons

]]></ac:plain-text-body></ac:macro>

]]></ac:plain-text-body></ac:macro>

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Nov 23, 2009

    <p>+1</p>

    <p>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.</p>

    <p>What would 'both' do, truncate at either end, e.g '...is a long sentence...', or in the middle, e.g 'This is ... sentence'?</p>

    <p>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?</p>

    1. Nov 24, 2009

      <p>My original proposal had all options included.<br />
      I was said that I have to split it into 3-4 different proposals, where this one is one of it.<br />
      You can find all other also within this section.</p>

      <p>Looking at the proposal you can see that it includes an view helper.</p>

      1. Nov 25, 2009

        <p>Sorry, I didn't think to check the proposal it was based on (Zend_Filter_StringLength).</p>

        <p>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:</p>
        <ol>
        <li>How would you go about not duplicating code between StringTruncate and the WordTruncate filter, as they perform such similar functions?</li>
        <li>Is it not too verbose having two filters which perform similar jobs? (A question for Matthew?)</li>
        </ol>

        <p>With the view helper, do you think a generic Zend_View_Helper_Filter helper would be a good idea?</p>

        1. Nov 26, 2009

          <p>Code duplication is normally prevented by extending classes.</p>

          <p>I am not sure if a generic filter helper would make sense.<br />
          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 ?</p>

  2. Aug 03, 2010

    <ac:macro ac:name="note"><ac:rich-text-body><p><strong>Community Review Team Recommendation</strong></p>

    <p>The CR Team advises against accepting this proposal. However: we do advise on implementing this functionality in the StringTruncate component</p></ac:rich-text-body></ac:macro>