Introduction
I’ve been following the Weblocks web framework for about a year now, and it’s my opinion that Weblocks is the best Common Lisp web framework available. One of the difficulties with Weblocks right now is a lack of documentation and example code. This will be a contribution to that need. I have created a simple blog application based on Weblocks. I started with the blog that Evan Monroig put together as a simple tutorial, but wanted to go a little further with it. This will be a multi-part screencast tutorial, but rather than spreading it across multiple posts, I”ll just update this one as I have new material to post. I apologize in advance if there are very dry moments in these videos; I’m new to screencasting and am using free tools. You get what you pay for
So let’s start…
Setup
I use the Linux-Emacs-Slime-SBCL stack for the screencasts. Â Slime, Emacs, and SBCL are functional on Windows, but I don’t know that Weblocks (or, more importantly, it’s dependencies) will. Â I haven’t tried. Â I prefer Franz’ Allegro Common Lisp, but Weblocks is targeted specifically at the Hunchentoot webserver. There is a very good Lisp environment screencast by Marco Berringer, and an accompanying reference by Peter Christensen. Â I highly recommend them for learning more about how to get your Lisp environment set up. There are many other references on the web that will help you with getting Lisp set up on your machine. Â I use the Gentoo distribution of Linux. Â Gentoo has a very good package management system called “Portage”, which works something like the FreeBSD/OpenBSD ports system, but better (there are also drop-in replacement systems that improve on Portage in different ways, but I haven’t had a need for them; Portage works just fine for me). Â One of the more recently developed features of Portage is the concept of “overlays”, which provide the ability to more easily customize the set of packages available at a particular location or over a particular subset of categories. Â There is a Common Lisp overlay that provides fairly up-to-date releases of most of the useful Common Lisp libraries available (the overlay contains 200+ ebuilds), and I’ve found that to be adequate for my needs. Â Thus I avoid all the teeth-gnashing over Lisp library management and installation. For me, I just needed to install Emacs, Slime, paredit, SBCL and finally Weblocks (which pulls in a lot of other libraries as dependencies) through the portage system. Â The only thing I needed to do to make things work was to edit my .emacs and .swank.lisp files. Â My .emacs file needed this:
(load "/usr/share/emacs/site-lisp/site-gentoo" nil t)
and my .swank.lisp (the user lisp initialization file for swank, the Slime backend).
(defun project-setup () (mapcar #'(lambda (path) (push path asdf:*central-registry*)) '( #p"/home/bc/proj/weblocks-dev-aggieben/" #p"/home/bc/proj/simple-blog/" ))) (project-setup)
As you can tell (hopefully), the PROJECT-SETUP function merely adds my local project directories to the ASDF path so I can simply use (require :simple-blog) to load my application (SBCL’s REQUIRE function uses ASDF to find packages). The two directories I’m adding to the ASDF path are key to this tutorial: Â I am a Weblocks contributor (barely), so I run a local development version of Weblocks in my project directory. Â Most users can just install Weblocks however is best supported by their Linux distribution, through ASDF-INSTALL, or manually. Â This tutorial was created and tested on the latest development version. Â It may or may not work on the last stable (0.8, I think). Â Also, I added the ‘simple-blog’ directory to the list because that’s where we will create our application.
Creating a Weblocks Application
After making sure my Lisp environment is set up, I can start everything up:
At this point, we have the skeleton of a Weblocks application. It only writes a little text on the site, but all the plumbing is in place. Since we’re building a blog, we need to design a simple object model to represent it:
Now we have our object model in place and have shown how to use gridedits and default views for viewing and data entry, as well as the limits of the default views. In order to successfully input data, we need to customize the form views:
Now that we have data entry working, we need to build more interesting pieces of our blog. Firstly, how do we display a post to a user? We can write a custom widget to do that:
We’d like to be able to show more than one post to a user. We’ll construct a custom widget to represent the blog itself:
Check back for updates….when I get time, I’ll post screencasts to demonstrate further improvements to the blog, including graphical styling, navigation, author login, and tags.
Looks nice Ben. Thanks.
Thanks so much for posting this! I tried to work through the blog tutorial before, but had some trouble understanding what was going on. This is very helpful.
I’m very gratified to hear that it helped you. Be sure and post any feedback you have, so I can improve my screencasting skills
Hi, while this is awesome work, it is unreadable in the current sized player. When I set this to fullscreen I can read the text, but the switching between the screencast and emacs closes the fullscreen mode. This really blows – so do you have this available for download? I'd really appreciate this.
Bartosz, I’ll look into a solution for the problem you pose. It’s very tricky – If you post videos that are sized too large, then it screws up the blog formatting, but as you say, at smaller sizes it’s unreadable. Perhaps I’ll figure out a way to post a separate page.
I usually don’t post in Blogs but your blog forced me to, amazing work.. beautiful …
What theme is this?
Charles, this is the “Japanese Fleur theme design by Lorelei and Web Hosting Geeks for Debt & Free Encyclopedia”. Links in the footer.
Stupid question, the auto completion you where using in the vids, like where a slot’s code just appears out of nothing. What do you need to get that working in emacs?
This an Fantastic post, I will bookmark this in my Digg account. Have a awesome evening.