Journal(2005) | Blog(2006) | RandomLink | WhoAmI | LiveBookmark | HomePage

<<Previous: 一个简易的用 Catalyst 编写的 RSS 聚合器  >>Next: Javascript Code Syntax Highlighter / Perl

Template Toolkit && random

Category: Catalyst   Keywords: Tempalte random

在我的 journal Index 页上往下数四行,会出现 Larry Wall 的一些语言。本来就一句
Call me bored, but don't call me boring. -- Larry Wall
后来想想应该多增加一点,且变成随机出现。一想到随机,我第一个想到的就是 List::Util , 那里面有个 shuffle 函数用以打乱 list 的次序。
当然这不是唯一选择,或许也不是最好的选择。不过或许也算凑巧, CPAN 上还是有它的 Template Plugin: Template::Plugin::ListUtil

放到里面的代码很简单,大致就是:

[% USE ListUtil %]

<style>
.quotes {
   white-space: -moz-pre-wrap; /* Mozilla, supported since 1999 */
   white-space: -pre-wrap; /* Opera 4 - 6 */
   white-space: -o-pre-wrap; /* Opera 7 */
   white-space: pre-wrap; /* CSS3 - Text module (Candidate Recommendation)
http://www.w3.org/TR/css3-text/#white-space */
   word-wrap: break-word; /* IE 5.5+ */
}
</style>

[% quote_words = [
"Call me bored, but don't call me boring. -- Larry Wall",
"I don't know if it's what you want, but it's what you get. :-)
-- Larry Wall in <10502@jpl-devvax.JPL.NASA.GOV>",
"I think it's a new feature. Don't tell anyone it was an accident. :-)
-- Larry Wall on s/foo/bar/eieio in <10911@jpl-devvax.JPL.NASA.GOV>",
"Obviously I was either onto something, or on something. -- Larry Wall",
"The following two statements are usually both true:
There's not enough documentation.
There's too much documentation. -- Larry Wall",
"If someone stinks, view it as a reason to help them, not a reason to avoid them. -- Larry Wall",
"In general, if you think something isn't in Perl, try it out, because it usually is. :-)
--Larry Wall in <1991Jul31.174523.9447@netlabs.com>"
] %]

<div class='quotes'>[% ListUtil.random(quote_words) %]</div>

后来又把右边浮动框的颜色也随机化了一下。

大致也就这样。看了一点 Perl Template Toolkit 的 Chapter 5. Filters

<<Previous: 一个简易的用 Catalyst 编写的 RSS 聚合器  >>Next: Javascript Code Syntax Highlighter / Perl

Options: +Del.icio.us

Related items Created on 2005-11-07 16:16:46, Last modified on 2005-11-25 11:46:56
Copyright 2004-2005 All Rights Reserved. Powered by Eplanet && Catalyst 5.62.