Perl Programming Page 4 - Site Layout with Perl Templating Tools |
Now we need to make some decisions about our site's layout. As we've mentioned, we're going to put our feeds in the filesystem, categorized by directory. Well actually have each individual feed be a Mason component, drawing on a library component we'll call RSSBox. Our Directories component is a box containing a list of categories; clicking on a category displays all the feeds in that category. As each category is a directory, we can create the list, as in Example 3-12. Example 3-12. Directories <& /BoxTop, title=> "Resources" &> <ul> <%ONCE> What's happening here is that when the server starts up, it looks at all the subdirectories of our portal directory and strips them of their root (in this instance, /var/portal/)to turn them into a link for the purposes of our application. For instance, a directory called /var/portal/News would turn into a link Let's think about how that pane is implemented. We know that we open a directory and find it full of Mason component files. We want to then dynamically include each of those component files in turn, to build up our directory of feeds. The trick to dynamically calling a component is the comp method on the Mason request object $m; this is the Perl-side version of the <& comp &> component include tag. Hence, our directory pane ends up looking like Example 3-13. Example 3-13 . DirectoryPane <%ARGS> % for (grep {-f $_} glob( "/var/portal/$open/*") ) { <% $m->comp($_) %> We first receive the name of the directory we're trying to open. Next we look at each file in that directory, strip off the name of the root directory (ideally this would all be provided by a configuration file), and then call the component with that name. This means that if we have a directory called Technology containing the following files: 01-Register then calling <& /DirectoryPane, open => "Technology" &> would have the effect of saying: <& /Technology/01-Register &> The standard pane, shown in Example 3-14, appears when no directory is open. It consists of whatever feeds we choose to make default. Example 3-14. StandardPane <& /BoxTop, title=> "Hello!", color => "dd2222"&> <& /Weather/01-Oxford &> So what's in the individual files? As we've mentioned, they make use of an RSSBox component, and they simply pass in the URL for the feed and optionally a color, a maximum number of items, and a name for the feed. They also pass in a parameter to say whether we want to display just the titles and links for each RSS item, or the description as well. For instance, /News/01-BBC looks like this: <& /RSSBox, URL =>"http://www.newsisfree.com/HPE/xml/feeds/ whereas Rael Dornfest's blog looks like this: <& /RSSBox, URL => http://www.oreillynet.com/~rael/index.rss, As we'll see in a moment, the beauty of this modular system is that we can have components that do things other than fire off RSS feeds if we want. Please check back next week for the conclusion to this article.
blog comments powered by Disqus |
|
|
|
|
|
|
|