Toto, when it all comes together
February 12th 2011 byFor the past few weeks I've been toying with this website, trying to decide what I wanted and which tools were the right ones for the task. I had been suggested to use WordPress, bu long story short, it's in PHP and you can't use HAML.
Research and expectations
I obviously had a strong preference for anything made with Ruby. There are many CMS and blog engines built on Ruby, such as Typo, Refinery and Toto. These are the three I tried.
What I wanted was a solution allowing Chris and me to
- Create pages for our projects
- Blog
- Use HAML
- Customize easily
- Host a local copy
Typo
Typo 6.0.3 was the first engine I tried. I tried following the instructions, and there may be a problem in the latest release, but I couldn't run the migrations, so I had to use a previous version and upgrade afterwards. My experience didn't go as smoothly as I had expected, and I really didn't feel like repeating it for a local copy.
No HAML.
Refinery
I tried Refinery second. It's mainely a CMS, but it has a nice Blog plugin. Comments and management are built-in, the admin section is friendly and it has been relatively easy to setup. Using it on my machine was nice and smooth.
However, Refinery isn't exacly lightweight on RAM. The server we use to host this site is an RPS by OVH. We host more than just a few applications and we're short on memory, so a lot of paging occurs. The server has an iSCSI disk with a guarenteed 1MB/s, so the paging is fairely slow.
And again, no HAML.
Toto
Toto is a lightweight CMS/blog engine build directly on Rack. It uses flat files with custom metadata for the pages and arcles. It uses markdown for the articles and erb for the layout. No HAML by default. However, the thing is about 300 sloc (source lines of code) so finding what code to insert wasn't hard. As an added benefit, Toto is my development shortword.
Adding HAML
The first part, for the layouts and pages, Toto gives you direction to do this here.
set :to_html, lambda {|path, page, ctx|
::Haml::Engine.new(File.read("#{path}/#{page}.haml"),
:format => :html5, :ugly => true).render(ctx)
}
set :error do |code|
::Haml::Engine.new(File.read("templates/pages/#{code}.haml"),
:format => :html5, :ugly => true).render(@context)
end
But this doesn't cover the articles. And I'd much rather use HAML than markdown. Looking at the code I noticed that all I had to change is Toto::Article#body and Toto::Article#summary
module Toto
class Article
def render_part str
::Haml::Engine.new(str.force_encoding("ASCII-8BIT"),
:format => :html5, :ugly => true).render
end
end
end
def body
render_part self[:body]
end
def summary length = nil
sum = self[:body].split(config[:delim]).first
render_part(sum.length == self[:body].length ? sum :
sum.strip.sub(/\.\Z/, '…'))
end
The right tool for the job
I believe that you shouldn't reinvent the wheel and use the tools available to you. And so I used the following tools:
- Nginx, HTTP server
- Unicorn, Application server
- Railsify, management tool
- Toto, CMS and blog engine
- Git, source control and deployment
- Disqus, comments
Now that all the pieces have come together, the ThirdSide website is running under Toto and things should move from now.