Template text trimmer

18 views
Skip to first unread message

Etam

unread,
Jun 3, 2011, 6:10:07 AM6/3/11
to lif...@googlegroups.com
Hi,

I am trying to write something like this:

<span class="lift:trimmer.trimChars?length=3"><p>This tex will be trimmed</p></span>

class Trimmer {
def trimChars = {
val length: Int = S.param("length").dmap(3)(_.toInt)
"*" #> ((ns: NodeSeq) => {
val text = ns.text
if (text.length <= length)
Text(text)
else
Text(text.substring(0, length))
})
}
}

to trim long text in templates.

Is it possible to adjust the method to use it in another snippet, like:

<div class="article">
<span class="lift:trimmer.trimChars?length=50">
<h1 class="title">A very long title</h1>
</span>
<p class="content">Some content</p>
</div>

Thanks in advance,
Etam.

Lukasz Kuczera

unread,
Jun 3, 2011, 8:26:16 AM6/3/11
to Lift
It is but trimming something that is not text only can be dangerous to
your html if you cut your tag in a half.

On Jun 3, 12:10 pm, Etam <odwrot...@gmail.com> wrote:
> Hi,
>
> I am trying to write something like this:
>
> <span class="lift:trimmer.trimChars?length=3"><p>This tex will be
> trimmed</p></span>
>
> class Trimmer {
> def trimChars = {
> val length: Int = S.param("length").dmap(3)(_.toInt)
> "*" #> ((ns: NodeSeq) => {
> val text = ns.text
> if (text.length <= length)
> Text(text)
> else
> Text(text.substring(0, length))
>
> })
> }
> }
>
> to trim long text in templates.
>
> Is it possible to adjust the method to use it in another snippet, like:
>
> <div class="article">
> *<span class="lift:trimmer.trimChars?length=50">*
>  *<h1 class="title">A very long title</h1>*
> *</span>*

Etam

unread,
Jun 3, 2011, 9:57:48 AM6/3/11
to lif...@googlegroups.com
It is but trimming something that is not text only can be dangerous to
your html if you cut your tag in a half.
 
I'd like to write html safe trimmer. Do you have any ideas?

Thanks,
Etam.

Lukasz Kuczera

unread,
Jun 4, 2011, 6:19:11 AM6/4/11
to Lift
You would have to be shure you trim text then its safe. If you want to
present user generated data as html then there is something like
HtmlCleaner but its still not safe to use that, other than that I
would recommend using textile or other markup language.

Cheers.
Reply all
Reply to author
Forward
0 new messages