On Sep 14, 2005, at 8:51 AM, Robert Klemme wrote:

> James Edward Gray II wrote:
>
>> Here's the entire method, defined in a Rails helper module:
>>
>>      def excerpt( textile, id )
>>          html = sanitize(textilize(textile))
>>          html.sub!(/<p>(.*?)<\/p>(.*)\Z/m) { $1.strip }
>>          if $2 =~ /\S/
>>              "#{html} #{link_to '...', :action => :show, :id => id}"
>>          else
>>              html
>>          end
>>      end
>>
>> It works as expected now.
>>
>
> This might be a bit more efficient (dunno how often you call it):
>
>      def excerpt( textile, id )
>          html = sanitize(textilize(textile))
>          html.sub!(/<p>(.*?)<\/p>(.*)\Z/m) { $1.strip }
>          html << link_to( '...', :action => :show, :id => id ) if  
> $2 =~
> /\S/
>          html
>      end

That's not equivalent.  You're missing a space between html's content  
and the ellipses.

But thanks for the ideas.

James Edward Gray II