Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

[PATCH] ActionView::TextHelper Graceful Truncate

#2582

Use :graceful option to truncate given text to the end of the last word after the given :length.

Reported by etozzato · April 29th, 2009 @ 05:55 PM

State: stale
Milestone: 3.0.2
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: Low

Activity

  1. etozzato
    etozzato
    • Title changed from ActionView::TextHelper Graceful Truncate to [Patch] ActionView::TextHelper Graceful Truncate

    April 29th, 2009 @ 10:57 PM

  2. Michael Schuerig
    Michael Schuerig

    If you're truncating text with tags, you'd have to make sure that the space you see is not inside of a tag.

    April 30th, 2009 @ 08:26 PM

  3. Jeremy Kemper
    Jeremy Kemper

    Nice tweak, but the implementation is not multibyte compatible.

    April 30th, 2009 @ 09:05 PM

  4. etozzato
    etozzato

    Thanks for the feedback! I'll work on updating this patch.. now I see it's not ready :)

    April 30th, 2009 @ 09:30 PM

  5. Pratik
    Pratik
    • Title changed from [Patch] ActionView::TextHelper Graceful Truncate to ActionView::TextHelper Graceful Truncate

    April 30th, 2009 @ 10:54 PM

  6. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from actionpack, tested, text_helper, truncate to actionpack, bugmash, tested, text_helper, truncate

    August 6th, 2009 @ 02:20 PM

  7. Elise Huard
    Elise Huard

    +1 i've had to insert a method doing that several times on projects.

    August 8th, 2009 @ 10:06 AM

  8. Steve St. Martin
    Steve St. Martin

    -1 this functionality exists in master with options[:seperator] and probably should not be backported in a bugfix release

    August 8th, 2009 @ 10:37 PM

  9. Elad Meidar
    Elad Meidar

    -1 exists and passes tests on master (+ multibyte), tested manually too.

    August 8th, 2009 @ 11:21 PM

  10. Rebecca Frankel
  11. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to incomplete

    Ok - anyone up for a :separator backport?

    August 9th, 2009 @ 01:32 AM

  12. Steve St. Martin
    Steve St. Martin
    • Title changed from ActionView::TextHelper Graceful Truncate to [PATCH] ActionView::TextHelper Graceful Truncate

    I've attached a patch to backport options[:seperator] and its tests to 2-3-stable

    August 9th, 2009 @ 01:46 AM

  13. Steve St. Martin
  14. Elad Meidar
    Elad Meidar

    +1 Back port patch applies cleanly on 2-3-stable, tests pass.

    August 9th, 2009 @ 03:04 AM

  15. Hugo Peixoto
    Hugo Peixoto

    +1 The patch applies cleanly on 2-3-stable and the tests pass.

    August 9th, 2009 @ 03:33 AM

  16. RomKo
    RomKo

    _1 The patch applies cleanly on 2-3 stable and tests pass.

    August 9th, 2009 @ 04:32 AM

  17. RomKo
    RomKo

    +1 The patch applies cleanly on 2-3 stable and tests pass.

    August 9th, 2009 @ 04:32 AM

  18. Jeremy Kemper
    Jeremy Kemper
    • Assigned user set to Jeremy Kemper
    • Milestone changed from 2.x to 2.3.4

    How about a test with multibyte :separator?

    August 9th, 2009 @ 08:59 PM

  19. Steve St. Martin
    Steve St. Martin

    In attempting to create a test case for this identified a bug with ActiveSupport

    https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets... , once this ticket is complete the patch can be updated.

    August 10th, 2009 @ 12:06 AM

  20. Elad Meidar
  21. Elad Meidar
    Elad Meidar

    Trying to test an RTL input to truncate fails:

    def test_truncate_multibyte_with_seperator
       with_kcode 'none' do
         assert_equal "אלעד ...", truncate("אלעד אוכל גזר כתום", :seperator => ' ', :length => 12)
       end
       with_kcode 'u' do
         assert_equal "אלעד ...",
           truncate("אלעד אוכלת גזר כתום", :length => 10, :seperator => ' ')
       end
    end
     
     
      1) Failure:
    test_truncate_multibyte_with_seperator(TextHelperTest)
        [./test/template/text_helper_test.rb:77:in `test_truncate_multibyte_with_seperator'
         ./test/testing_sandbox.rb:7:in `with_kcode'
         ./test/template/text_helper_test.rb:76:in `test_truncate_multibyte_with_seperator'
         ./test/../../activesupport/lib/active_support/testing/setup_and_teardown.rb:62:in `__send__'
         ./test/../../activesupport/lib/active_support/testing/setup_and_teardown.rb:62:in `run']:
    <"אלעד ..."> expected but was
    <"אלעד או...">.
    

    stevestmartin suggests it has something to do with the fact rindex is used, and i used an RTL language as input.

    should there be any difference in RTL / LTR languages in this case ?

    August 10th, 2009 @ 04:01 AM

  22. Steve St. Martin
    Steve St. Martin

    now that rindex has been corrected, here is a patch with test case to be applied against both 2-3-stable and master as master does not have a test case for this.

    previous backport patch still works against 2-3-stable

    August 11th, 2009 @ 12:58 AM

  23. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.3.4 to 2.3.6

    [milestone:id#50064 bulk edit command]

    September 11th, 2009 @ 11:04 PM

  24. Rizwan Reza
    Rizwan Reza
    • Tag changed from actionpack, bugmash, tested, text_helper, truncate to actionpack, tested, text_helper, truncate
    • State changed from incomplete to open

    January 20th, 2010 @ 11:47 AM

  25. Rizwan Reza
    Rizwan Reza
    • State changed from open to stale
    • Milestone cleared.

    stevestmartin, any chance you can provide a unified patch that applies to master? I will get it applied. And let's patch it against master only.

    I am marking it as stale, please reopen and assign it to me when done. Thanks.

    March 27th, 2010 @ 01:13 PM

  26. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM