Tutorial: A Complex News Page
![]() |
![]() The Document Assembly Tool |
Tutorial: A News PageThe RingLord Technologies News Page contains some fairly complex HTML constructs to achieve its layout. It would be a highly painful operation to maintain this page by cutting and pasting. WebLord makes it a breeze! Let's take a look at it. At the time of this writing, our news.wl file begins with the following constructs: #requires-version '2.1'; text news-content { value = 1999-03-17 1999-03-15 1999-01-05 } The news-content object defines the body of our news page. It contains just three items, the news for 1999-03-17, 199-03-15, and 1999-01-15. Yes, in case you are wondering, these are actual object names. WebLord places few restrictions on the names of objects. Its almost exclusive concern is whether a symbol is a reference or a quoted string of text. So, we have three news items on our page. If we want to remove one of them, all we need is to remove it from this list, and it's gone! That's how easy things are supposed to be! Let us take a look at what actually lies behind each of these item references: text 1999-03-17 { value = news-date( date='March 17, 1999' ) news-items; items = 1999-03-17.1 1999-03-17.2 } The value of the news for March 17, 1999 is constructed from two references: a reference to news-date with a human readable date, followed by a reference to an object named news-items. Let us assume that the first object only creates a human readable date (although it does more than that, this is essentially its function) and examine the news-items object: text news-items { value = news-item-list '</table>'; } text news-item-list { foreach = &items; do = news-item; using = &news; } Two objects are involved with building the list of daily news items: news-item refers to news-item-list and finishes the job with an HTML end-table symbol. In case you're wondering, the table was begun by the news-date object that we said we'd ignore for now. The interesting stuff happens in news-item-list: It builds a value by iterating through the list of objects described by the (inherited) items property (see the 1999-03-17 object above). Notice that the leading & (ampersand) has a very important role here! The ampersand defers evaluation of the property; rather than iterating through the words of an evaluated property, WebLord iterates through the unevaluated list of references from the named property. This construct can be a little tricky to grasp. Consider if the items property listed three symbols, A, B, and C: ... items = A B C; ... A = "How "; B = "Are "; C = "You?"; A reference the items property in the usual way, we'll produce "How Are You?" as a result. If, on the other hand we refer to &items we defer this evaluation process and will iterate over the objects (or properties) A, B, C. Let's see what the effect of this is in our News Page example: As stated, the news-item-list object iterates over each of the day's entries, invoking the news-item object using the news property (again, evaluation deferred via the use of the ampersand!) as the placeholder for the day's news item. Looking now at the news-item definition we find the following: text news-item { value = '<tr>' '<td colspan="2">' '<table border="0" cellspacing="0" cellpadding="8" bgcolor="' panel-background '">' '<tr>' '<td rowspan="2" valign="top" bgcolor=' normal_body-bgcolor '>' news-link( url=news.url; target=news.target; visual=news-icon(icon=news.icon) ) '</td>' '<td bgcolor="' newscolor-head '">' '<tt><font size="+2" color="' newscolor-text '"><b>' news.title '</b></font></tt>' '</td>' '</tr>' '<tr>' '<td>' news.text news-link( url=news.url; target=news.target; visual=news.more; spacing=' ' ) '</td>' '</tr>' '</table>' '</td>' '</tr>' } Clearly all that HTML looks messy. The good thing is that you need define this single table row only once. WebLord will repeat this pattern for each and every news item. And once all this is done, a new entry is simply defined like this: text 1999-03-17.1 { value = news-item; title = "News for Nerds. Stuff that Matters."; text = "Just like the title says, it's news for those of us who are " "heavily into technology and all issues revolving around that."; more = "Read more..."; url = "http://slashdot.org/"; target = "_new"; icon = "newsiconname"; } All that's left for you to do is create a day's entry and then list where the day is to appear. |
|
This material is Copyright © 1997,1998,1999,2000,2001 RingLord Technologies and Udo Schuermann. All rights reserved. The latest versions of the WebLord software and (this) documentation can be obtained from the WebLord Home Page (the link will only function if you are connected to the internet.) |