18.8 Examples

I recently developed a site with a different quotation in every page. Every source file simply defines two variables storing quotation and content and includes a template:

type (page.quote):
Animals are my friends... and I don't eat my friends. 
-- George Bernard Shaw
endtype;

type (page.content):
<p>Page content goes here.</p>
endtype;

include ("lib/template.cws");

Script lib/template.cws creates the whole page, inserting qutation and content. The problem is that line breaks inserted by the browser according to font size, screen resolution etc. often split author's name:

Animals are my friends... and I don't eat my friends. -- George 
Bernard Shaw

or:

Animals are my friends... and I don't eat my friends. -- 
George Bernard Shaw

Of course we could simply use &nbsp; when typing quotations:

type (page.quote):
Animals are my friends... and I don't eat my friends. 
--&nbsp;George&nbsp;Bernard&nbsp;Shaw
endtype;

A better approach consists in replacing whitespaces with   entities inside lib/template.cws:

// First, we need the index of the double dash right before author name
begin_author = find (page.quote, "--");

// Then, we concatenate the first part of the string (quotation) and the 
// second one (author); the latter after replacing whitespaces with &nbsp; 
// entities.
page.quote = substring (page.quote, 0, begin_author)
  + replaceall (substring (page.quote, begin_author), " ", "&nbsp;");

This manual can be downloaded from http://www.g-cows.org/.