09-Jan-2005 17:31 | Playing around with Ruby and MT Template Modules

For some time now I have been thinking about changing the way my site is built. The problem was that whenever I wanted to change some general part of the site -- the side bar for example -- I had to do it in each template that is used in MovableType. That is fairly tedious and error prone work. Now the first idea I had was to use some scripting language. MovableType would generate the script which would then call some external code to generate the side bar, the header, footer etc.

I'm making my living out of software development in Java. So JSPs and servlets are natural choices for me when it comes to web application development. Unfortunately my hoster doesn't support Java as very few web hosters do. You have to have an own server which hosts your site to be able to use Java on it.

Let's look what's available then. Hmm, PHP. Why not? So I got some book about PHP5 and read through it. Well, PHP5 does have some object-oriented aspects. It knows classes and objects - hurray. But somehow those aren't really first class citizens. It looks like the PHP developers wanted to get a part of the OO hype and just threw in classes and objects into PHP. PHP is still an imperative programming language looking very much like C and borrowing some ideas from Perl.

The next one was Ruby . Ruby is a real object-oriented language. In many aspects it resembles Smalltalk. I haven't used Smalltalk, but I have seen enough of it to recognize a language that takes a similar path. In Ruby you can write something like this

(1..10).each {|i| puts i}

This will iterate from 1 to 10 and put out the numbers on the console each on its own line. There's also a for loop for people not feeling comfortable with this very object-oriented loop variant. Ruby is nice and fun to code. It's dynamically typed which gave me some headaches, but then there's no scripting language with static typing.

So I started coding my web site in Ruby. There is no really good IDE for Ruby. There's something called Ruby Development Tools , which is a plugin for Eclipse. Compared to the Java IDE's like IntelliJ IDEA it's only little more than a text editor with syntax highlighting.

I was nearly finished with the whole framework for my site and was coding the templates, when I began having some security concerns. Think about the following Ruby code

commentbody =<< 'END'
<$MTCommentBody$>
END

That's a really good idea at the first sight, but look twice. Ruby will read all after "<< 'END'" until the next occurrence of "END" into the variable commentbody. But what happens if the comment body looks like the following

blah blah
END
`do something nasty`

Fortunately Ruby will report a syntax error on the second END. The worst thing that happens here is that the page containing this code won't show up in the browser. It won't execute "do something nasty" (backticks are used in Ruby to enclose commands that are directly executed on the shell). But a page that doesn't show up because some user wrote some hackish code into a comment isn't acceptable.

So back in MovableType I saw for the first time the section titled "Template Modules". I don't know why I didn't see it earlier. The documentation concerning template modules is very sparse. It only tells that they can be used to define blocks of HTML code that can be reused in the templates. It doesn't tell you that you can have MovableType-tags in there and that you can include template modules into other template modules. So in the end, template modules -- being a rather simple thing -- where what I really needed.

That said, I'm not leaving Ruby behind. Ruby is still a cool language. I have some ideas for things where Ruby can be pretty handy. I'm currently trying to create a new archive index. I'm trying to do it with a MovableType-plugin, but currently have no success with it. If that doesn't work, I'll probably take Ruby for this task.

01-Jan-2005 15:55 | New Applications Directly Supporting Squareness Look And Feel

I came across two other applications which directly support Squareness Look And Feel.

The Magic-Project is a computerized version of Magic The Gathering, a very famous collectible card game, that can be played in a LAN or over the internet. The Magic Project comes preinstalled with Squareness Look And Feel and other look and feels. I've never played Magic and so I don't understand the program, but it looks good - especially with Squareness switched on :)

WordRider is a text editor for a very special text format that can be read on the TI-89 calculator. It's base installation package doesn't contain Squareness, but there is a link to Squareness on the website and Squareness will be available in the "Look & Feel"-menu if you put the jar file in WordRider's lib directory.

In the meanwhile I have released an update to the look and feel, which fixes a bug reported by the author of the Magic-Project. Strangely there was a recursion that only occurred on JDialogs that used look and feel painted window decorations (border and window buttons). Fortunately finding and fixing the bug only took about 6 hours.

I think finding it was so fast because of YourKit Profiler. The bug resulted in 100% CPU time consumption. So I started the profiler, had a look at the findings and nearly immediately got the idea what was wrong. Without the profiler I would have been forced to use System.out debugging or real step-by-step-debugging, which probably would have been a bit difficult. But so, it was a breeze. Somehow I never used profilers before, partly because they nearly always look very complicated with all their graphs and partly because they are mostly very expensive. Those two statements aren't true of Yourkit Profiler. The personal license is rather cheap and the generated snapshots are very clean and readable.

Back to Squareness: I also released an updated version of the Windowblinds skin. It has been quite some time since the last release. I originally planned to make a 2.0 release that would come with some new color schemes and would be accompanied by a finished Colorizer. But that will take some more time and this new release contains some bugfixes and improvements which I just didn't want to keep from the public any longer.