# Looking for something similar to summarize extension for truncating content

**URL:** <https://www.ruby-forum.com/t/looking-for-something-similar-to-summarize-extension-for-truncating-content/157445>\
**Category:** Radiant CMS\
**Created:** [January 11, 2009, 1:04pm UTC](https://www.ruby-forum.com/t/looking-for-something-similar-to-summarize-extension-for-truncating-content/157445 "2009-01-11T13:04:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Marszalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@Roman\_Marszalek](https://www.ruby-forum.com/u/Roman_Marszalek)\
**Post date:** [January 11, 2009, 1:04pm UTC](https://www.ruby-forum.com/t/looking-for-something-similar-to-summarize-extension-for-truncating-content/157445/1 "2009-01-11T13:04:27Z")

</div>

And wondering how it can be most easily acheived.

I’d like to be able to say something like this (obviously not available)

\<r:content truncate=“30” /\>

And then it displays the fist 30 characters of the page part.

Anyone know if there’s an easy way to achieve this effect.

Thanks,

Roman

–  
Roman Marszalek  
Managing Director  
mobile: +44 7786 262 002  
email: removed\_email\_address@domain.invalid

telephone: 0800 345 7844 (+44 20 7014 3634)  
Our lines are open from 9am to 6pm Monday to Friday

Doctor Logic Limited  
Mac Support for London  
[http://drlogic.co.uk](http://drlogic.co.uk)

- Dr Logic Backup \*  
Backup for Britain  
[http://drlogicbackup.co.uk](http://drlogicbackup.co.uk)

- Dr Logic Training \*  
In partnership with Academy Class  
[http://training.drlogic.co.uk](http://training.drlogic.co.uk)

Registered in England and Wales. Company No. 04947299.  
Registered Office: 2nd Floor 145-157 St John Street, London EC1V 4PY  
VAT Reg. No. GB848448189

---

<div class="post-metadata">

**Author:** ![Roman\_Marszalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@Roman\_Marszalek](https://www.ruby-forum.com/u/Roman_Marszalek)\
**Post date:** [January 12, 2009, 2:24pm UTC](https://www.ruby-forum.com/t/looking-for-something-similar-to-summarize-extension-for-truncating-content/157445/2 "2009-01-12T14:24:20Z")

</div>

You could create a custom Radius tag to wrap around the Rails  
truncate[1](http://apidock.com/rails/ActionView/Helpers/TextHelper/truncate)  
method. Something like this might do the trick:

desc %{  
Truncates contents if the number of characters is longer than  
@length@(defaults to 30). The last characters will be replaced with  
the @omission@(defaults to “…”).  
}  
tag ‘truncate’ do |tag|  
length = tag.attr[‘length’] || 30  
omission = tag.attr[‘omission’] || “…”  
content = tag.expand  
truncate(content, :ommision =\> omission, :length =\> length)  
end

I haven’t tested this, so can’t guarantee that it would work!

You could call this as follows:

\<r:truncate length=“80” omission=“… (continued)”\>  
\<r:content part=“body”/\>  
\</r:truncate\>

I hope that helps.

Drew

---

<div class="post-metadata">

**Author:** ![Roman\_Marszalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@Roman\_Marszalek](https://www.ruby-forum.com/u/Roman_Marszalek)\
**Post date:** [January 12, 2009, 2:29pm UTC](https://www.ruby-forum.com/t/looking-for-something-similar-to-summarize-extension-for-truncating-content/157445/3 "2009-01-12T14:29:08Z")

</div>

Andrew N. wrote:

> You could create a custom Radius tag to wrap around the Rails truncate[1]  
> method. Something like this might do the trick:

Actually, this method should be written up in the Radiant 2009  
Documentation project as a good simple example of bringing in Rails  
methods into Radiant installs - it would help those “entry level” Rails  
programmers who wonder how to bridge the worlds of Rails and Radiant.

Cheers,  
Mohit.  
1/12/2009 | 9:28 PM.

---

<div class="post-metadata">

**Author:** ![Roman\_Marszalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@Roman\_Marszalek](https://www.ruby-forum.com/u/Roman_Marszalek)\
**Post date:** [January 12, 2009, 4:51pm UTC](https://www.ruby-forum.com/t/looking-for-something-similar-to-summarize-extension-for-truncating-content/157445/4 "2009-01-12T16:51:11Z")

</div>

Mohit S. wrote:

> Actually, this method should be written up in the Radiant 2009  
> Documentation project as a good simple example of bringing in Rails  
> methods into Radiant installs - it would help those “entry level” Rails  
> programmers who wonder how to bridge the worlds of Rails and Radiant.
> 
> Cheers,  
> Mohit.  
> 1/12/2009 | 9:28 PM.

I wholeheartedly agree. The method seems simple enough, but I’m not sure  
how to implement it myself.

---

<div class="post-metadata">

**Author:** ![Roman\_Marszalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@Roman\_Marszalek](https://www.ruby-forum.com/u/Roman_Marszalek)\
**Post date:** [January 13, 2009, 4:26am UTC](https://www.ruby-forum.com/t/looking-for-something-similar-to-summarize-extension-for-truncating-content/157445/5 "2009-01-13T04:26:58Z")

</div>

Ben M. wrote:

> > 
> 
> I wholeheartedly agree. The method seems simple enough, but I’m not sure  
> how to implement it myself.

Hi Everyone (especially developers),

I have a proposal that Radiant should include a default extension called  
‘my\_tags’ or ‘local’ or something.

[Rationale]  
There are quite a few suggestions on this list for doing something like  
the above ‘truncate’ tag. All it requires is to throw in some simple  
tag-related code and access it from the Admin UI. This is especially so  
for simple things that do not require complex logic in the background  
and do not need much else other than a few simple calculations.  
Examples are:

- the above truncate method
- a tag that spits out textile for a URL that is linked to itself
- a tag that uses Javascript for encoding the mail address
- something that checks if a “New” icon should be displayed next to the  
title of an article depending on its age  
…and so on.

For good reason, a lot of these are simple things and are typically  
‘local’ things that get customized for the specific installation and  
needs.

I was wondering if it would be a good idea for Radiant to include an  
empty ‘local’ extension into which such code could be dumped. This  
would have the effect of:  
a) Having a common place where people can add their own tags (or tags  
taken from this list)  
b) Less tech-savvy developers being able to modify things without  
necessarily having to “create an extension”, a task that sounds very  
demanding and daunting.

What do you think?

Cheers,  
Mohit.  
1/13/2009 | 11:25 AM.

---

<div class="post-metadata">

**Author:** ![Roman\_Marszalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@Roman\_Marszalek](https://www.ruby-forum.com/u/Roman_Marszalek)\
**Post date:** [January 13, 2009, 4:12pm UTC](https://www.ruby-forum.com/t/looking-for-something-similar-to-summarize-extension-for-truncating-content/157445/6 "2009-01-13T16:12:11Z")

</div>

Nate T. said the following on 01/13/2009 10:01 AM:

> > b) Less tech-savvy developers being able to modify things without  
> > necessarily having to “create an extension”, a task that sounds very  
> > demanding and daunting.

Sounds like me 😉

> > What do you think?

> +1

+256

---

<div class="post-metadata">

**Author:** ![Roman\_Marszalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@Roman\_Marszalek](https://www.ruby-forum.com/u/Roman_Marszalek)\
**Post date:** [January 13, 2009, 2:26pm UTC](https://www.ruby-forum.com/t/looking-for-something-similar-to-summarize-extension-for-truncating-content/157445/7 "2009-01-13T14:26:10Z")

</div>

I have a convention of my own, which is to create an extension named  
after  
each project that I am working on. So if I have Radiant sites called  
“wpbf”  
and “lilly”, each will have it’s own extension: wpbf\_extension and  
lilly\_extension. When I need to add miscellaneous tags (such as the  
‘truncate’ example I posted), I put them in the site specific extension.

I think it is an excellent suggestion that each Radiant app would  
contain a  
local\_extension. Although it is quite easy to create new extensions  
using  
the packaged generator, the process is not one that I have memorised. I  
usually have to check the wiki, or refer to one of my older extensions  
to  
remember how to do it, what goes where etc. When it comes to giving  
advice  
on the mailing list, I certainly coudn’t reel the instructions off the  
top  
of my head. If there were a local\_extension, it would be far more  
straightforward to just say, ‘try this code in this file’.

+1

Drew

---

<div class="post-metadata">

**Author:** ![Roman\_Marszalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@Roman\_Marszalek](https://www.ruby-forum.com/u/Roman_Marszalek)\
**Post date:** [January 13, 2009, 4:02pm UTC](https://www.ruby-forum.com/t/looking-for-something-similar-to-summarize-extension-for-truncating-content/157445/8 "2009-01-13T16:02:43Z")

</div>

On Mon, Jan 12, 2009 at 9:25 PM, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > Cheers,  
> > > Hi Everyone (especially developers),
> 
> - the above truncate method  
> ‘local’ extension into which such code could be dumped. This would have the  
> effect of:  
> a) Having a common place where people can add their own tags (or tags taken  
> from this list)  
> b) Less tech-savvy developers being able to modify things without  
> necessarily having to “create an extension”, a task that sounds very  
> demanding and daunting.
> 
> What do you think?

+1

~Nate
