6.8 Configuring WML with .wmlrc


6.8 Configuring WML with . wmlrc

Like many other things Unix, WML has an rc file, another of those invisible configuration files such as .bashrc and .tcshrc that can be seen with ls -a . Unsurprisingly enough, it's called .wmlrc . [6]

[6] The name rc comes from runcom.

If this file is placed into a directory, the commands and preferences within are applied to that directory and all its subdirectories. This file is a useful way to declare WML variables , specify include directories, etc.

6.8.1 Defining Variables

Variables can be defined in .wmlrc in one of two ways. First:

 -DVARIABLE=value 

The value can then be used by the syntax $(VARIABLE) .

As an example, parts of the www.opensourcewebbook.com web site were developed with WML. As we wrote this book, the title was in flux. This title is used on many of the HTML pages, so instead of hard-coding a title that would probably have to be changed in a great many places, we created a variable that holds the title's value. In the .wmlrc file in the root directory of the HTML tree, we put:

 -DBOOK_TITLE="Open Source Web Development with LAMP" 

So, one of the web pages may say this:

 Go buy <b>$(BOOK_TITLE)</b>! 

That gets expanded into:

 Go buy <b>Open Source Web Development with LAMP</b>! 

Then, when we changed the name (which we did frequently, for WML testing only, you understand), we simply changed the definition in .wmlrc and ran wmk recursively, and the entire web site got the same book title. Sweet! At least for the WML portions of the site.

We also defined another helpful variable, the URL for the book's web site:

 -DOSWB="http://www.opensourcewebbook.com/" 

This is the other way to define variables:

 -DVARIABLE~value 

This creates the variable named $(VARIABLE) , and its value changes depending on the directory in which the .wml resides. For instance, let's say we add the following variable assignment to the .wmlrc file in the HTML document tree root:

 -DIMG~images 

This defines $(IMG) as the images subdirectory of the HTML root directory. If this WML code is added to a .wml file in the same directory:

 <img src="$(IMG)/pic.png"> 

when the WML file is made with wmk , this is the resulting HTML:

 <img src="images/pic.png" alt=""> 

This means "Grab the file pic.png in the images subdirectory of this directory (the HTML document root)." Now, let's say there is a subdirectory of the HTML root. Within a .wml file within that directory we add this:

 <img src="$(IMG)/pic.png"> 

This generates:

 <img src="../images/pic.png" alt=""> 

This means "Grab the file pic.png in the images directory that is a subdirectory of our parent directory (our parent is the HTML root)." Notice that the relative link is created automagically ”hence the beauty of this type of variable.

Now, if we had a subdirectory of a subdirectory of the HTML root, the same WML code produces this:

 <img src="../../images/pic.png" alt=""> 

The great thing about this magic is that the link that is generated is relative to the directory in which the .wml file is found. So, if the file is moved to another directory, simply rerun wmk , and the links will work.

In the book's web site, we added the following to the .wmlrc file in the HTML root directory:

 -DROOT~. 

This means that $(ROOT) has the value of " . ", or the current directory (the HTML root). Therefore, whenever $(ROOT) is used throughout our web site, the magic relative links are created.

6.8.2 Include Directories

When we were designing and developing the web site for this book, we wanted to maintain a consistent look and feel, an image in the graphic design business. Most of the pages of the web site would follow this layout. The layout consists of a heading at the top, a list of links on the left rail, and content in the middle. To top it off, some pages have content along the right rail (usually links to examples), and some do not.

To implement this look and feel, we created a WML template, oswb.wml . That template is in a directory named /var/www/wml-lib/ not within the Apache HTML root so that a would-be cracker would not find the template in a directory served up by Apache. All the WML files find this file by simply saying:

 #use wml::oswb 

WML knows to look for oswb.wml in the proper directory because we put -I /var/www/wml-lib/ in the .wmlrc file. The .wmlrc has:

 -I.  -I/var/www/wml-lib 

This means "For the files I use, first look in the current directory, then look in /var/www/wml-lib , then look in the default WML library location." For this example, that is /usr/local/lib/wml/include/ .

We've talked about several different things to put in the .wmlrc file. Here are the complete contents of the .wmlrc file found in the directory /var/www/html/ :

 -DOSWB="http://www.opensourcewebbook.com/"  -DROOT~.  -DBOOK_TITLE="Open Source Web Development with LAMP"  -I.  -I/var/www/wml-lib 


Open Source Development with Lamp
Open Source Development with LAMP: Using Linux, Apache, MySQL, Perl, and PHP
ISBN: 020177061X
EAN: 2147483647
Year: 2002
Pages: 136

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net