Ask permission for reproduction.

17-Aug-2004

Website generation - the easy way
I'm a software professional and when speaking with 'normal' people they take for granted that I enjoy nothing more than making websites. For them, software is websites, and HTML is programming. So..
I
hate making websites. Not that I hadn't done any, but the tools are either primitive, over-priced or whatever. There's simply no perfect solution that I've met so far - please send a note if you know one!
So I created my own tool -that for the least proves that I'm a real software professional, right- but it's unlike the others. It's not a fancy graphical editor or a set of JavaScript/PHP/ASP macros that require a server. No, it's a little filtering tool that stands between my brains and the HTML -imho- clumsiness. Personally, I don't like many of HTML's nuances, but a filter of this kind can keep them away from oneself.
This filter, named
Lumikki (SnowWhite in Finnish) is implemented as pure 100% Lua script. Lua, in its turn, is a simple but powerful scripting language that I've come to value and enjoy during the last couple of years. If you're not totally thinking in Python, Perl or Ruby yet, I hope you give it a try. You just might love it. :)
Back to websites..
So now when I do a website, what's changed? Nothing much. I still code the pages in a text editor (
SubEthaEdit), using HTML formatting. The files are named either .html or .lhtml (L for Lumikki). The .lhtml files get automatically converted to .html once I 'publish' the site (I made a simple Makefile for automating this). The Lumikki system will eventually also cover broken link detection and other such stuff, including automatic upload to the web server, but that's in the future.
Time for an example:

Lumikki manual



This file is both a manual of Lumikki and a sample on its use. For more feedback
and support, visit the development site at <@LINK popup>luaforge.net/projects/lumikki</@LINK>.
If you're familiar with HTML there's some aspects in here that seem to be missing. Where's the header? Where's the body? Where's the

paragraph starter? I've found that such must-have formatting things -while being good for the computer- are annoying and distracting for the person typing the text.
Lumikki takes care of these things. And yes, you can still set header options manually by using a <@DOCUMENT> tag or just by placing the etc. in there if you insist. If you forget, Lumikki will do it for you, no questions asked. Likewise, if you forget the

tag, it will see two subsequent linefeeds as a paragraph changer.
But that's not why I made Lumikki. The macros are.
In the example above, you see the <@LINK> tag. Any Lumikki tags start with a '<@' and may or may not have a terminating tag (</@>). What happens at filtering time is a Lua function named -surprise, surprise- 'LINK' gets called with the tag parameters (here, just "popup") being given to it in a nice, tabled manner. Whatever this 'LINK' function then returns will be placed instead of the code above, up to the terminating tag.
Here the LINK macro expands into:
luaforge.net/projects/lumikki
As you can see, using 'LINK' avoided us from typing the URL twice, knowing about the "_blank" target (opens in a new popup window) and having to type the "http://" prefix to the actual URL.
There's a set of premade filter functions available out-of-the-box:
   DOCUMENT [title=str] [author=str] [keywords=str] [stylesheet=str] [background=str]   EVAL   FUNC   GRA src=url [align=left/center/right] [border[=N]] [x=width] [y=width] [link[=url] [popup]]   INCLUDE url=str [expand]   LINK [popup] [url=str]   LUA   SMILEY   TAG xxx
These alone get us around some edgy corners of HTML coding. I won't go into them in detail, since that is covered in the online
Lumikki manual.
One important tag to be mentioned is the LUA tag, though. It allows you to embed Lua code within the LHTML doc itself. Like this:

function MYHEADER( tbl, text )
return "

"..text.."

"
end
</@LUA>
Now, whenever you say '<@MYHEADER>' it will be transformed into using '

' tags instead.
Limitations?
The ideology of the Lua core team (clever and nice people at the PUC-Rio University, Brazil :) has been to minimalize everything, time and again. And to have nothing fixed. Period.
This same approach has been adopted by many Lua-using projects, and Lumikki makes no exception. The premade filter functions above can easily be redefined or extended by you. Or you can declare your own, as shown above. Lumikki is intended to be a general toolkit, growing with
your projects and websites, as needed.
Licensing
Lumikki is Open Source, meaning you can use it free of charge, but no complaints are accepted unless I feel like it. I've made the tool mainly for myself, but it should be useful for others, as well. You can download and try the product off
LuaForge's website, which hosts also other valuable Lua projects.
The license selected for Lumikki is
GPL. Don't be frightened, I personally don't have anything against commercial use, and in fact, neither does GPL in this regard. Remember, you're passing on the products of Lumikki (the filtered web pages) not the code itself. So, GPL in tools like this should be no reason to avoid them. Think gcc.
Finally..
I'd be delighted to hear your feedback on this article, on Lumikki itself and/or generally nicer ways of doing websites. The next time a friend of mine asks "how should I start doing my own webpages" I hope I'd be able to help him or her a little bit more. And I hope my own pages are up by then!
Have fun,
- Asko Kauppi



This article is Copyright © 2004, Asko Kauppi
Linking to it is allowed, but for reproduction in part or in whole, ask for permission.