Forum: Radiant CMS Looking for something similar to summarize extension for truncating content

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F66e643dd58d04c9945ccb92165e7125?d=identicon&s=25 Roman Marszalek (Guest)
on 2009-01-11 13:04
(Received via mailing list)
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: support@drlogic.co.uk

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

* Dr Logic Backup *
Backup for Britain
http://drlogicbackup.co.uk

* Dr Logic Training *
In partnership with Academy Class
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
514784888f1bbfb08a189684bf14abc2?d=identicon&s=25 Andrew Neil (Guest)
on 2009-01-12 14:24
(Received via mailing list)
You could create a custom Radius tag to wrap around the Rails
truncate[1]
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

[1]: http://apidock.com/rails/ActionView/Helpers/TextHe...
Ec797ac7978ab39f04b0a5844c234528?d=identicon&s=25 Mohit Sindhwani (mohits)
on 2009-01-12 14:29
(Received via mailing list)
Andrew Neil 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.
2219b363feb10ee316dbb7ad9741114f?d=identicon&s=25 Ben Morrow (benmorrow)
on 2009-01-12 16:51
Mohit Sindhwani 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.
Ec797ac7978ab39f04b0a5844c234528?d=identicon&s=25 Mohit Sindhwani (mohits)
on 2009-01-13 04:26
(Received via mailing list)
Ben Morrow 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.
514784888f1bbfb08a189684bf14abc2?d=identicon&s=25 Andrew Neil (Guest)
on 2009-01-13 14:26
(Received via mailing list)
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
3c415075c9e778e2d38ebf4588a68464?d=identicon&s=25 Nate Turnage (Guest)
on 2009-01-13 16:02
(Received via mailing list)
On Mon, Jan 12, 2009 at 9:25 PM, Mohit Sindhwani <tech@onghu.com> 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
D7e12e3bb05a31ebdff3b3f775468ecd?d=identicon&s=25 Anton Aylward (Guest)
on 2009-01-13 16:12
(Received via mailing list)
Nate Turnage 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
This topic is locked and can not be replied to.