Looking for something similar to summarize extension for truncating content


#1

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

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


#2

You could create a custom Radius tag to wrap around the Rails
truncate1
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


#3

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.


#4

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.


#5

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.


#6

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 :wink:

What do you think?

+1

+256


#7

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


#8

On Mon, Jan 12, 2009 at 9:25 PM, Mohit S. 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