Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Parkaby: Faster HTML Generation with Ruby

By Ric Roberts / July 7, 2009

Why's Markaby is a really convenient bit of Ruby for generating HTML in your applications, rather than having to fiddle about with string interpolation or ERb, tangling together HTML and Ruby.

However, Markaby can be slow compared with other options like Erubis or HAML. Magnus Holm has been working on an alternative solution called Parkaby, which uses ParseTree for improved performance (coming out up to 20 times faster than Markaby in Magnus's tests).  Parkaby uses near-identical syntax to Markaby, so you still get to write beautiful ruby code for building your HTML.

Parkaby {
    html {
      head {
        title "happy title"
      body {
        h1 "happy heading"
        a "a link", "href" => "url"

Magnus admits that Parkaby is currently only experimental, and that there's room for more optimization, but I think he might be onto something. Parkaby is available on Github.


  1. Stephen Stillwater says:

    Why not just fork and improve Markaby?

    Why's everyone out to get _why?




  2. lanaer says:

    What about erector ( ) ?

  3. Magnus Holn says:

    Because Parkaby isn't a modified Markaby, it's something completely different. However, I might learn some tricks I can apply to Markaby later :-)

    Expect a few Sexp-related libraries coming from here (with the help from Adam Sanderson) in the near future...

  4. Peter Cooper says:

    Stephen: I think he has bigger fish to fry, so any libraries that compete with his are really just natural evolutions in their respective areas. I mean, gem installed Markaby didn't even work with Ruby 1.9 as of a month ago (perhaps it does now, I don't know).

  5. Andrew Chalkley says:

    ERB! ERB! ERB! :D

  6. Brandon says:

    Trying to improve on _why's work isn't the same as being "out to get him" I would guess that your question was at least partially tongue-in-cheek, but nonetheless I feel it's worth pointing out that even those who create competing technology generally give him a lot of credit for his contributions. Aaron Patterson ("Tenderlove") has said complimentary things about Hpricot's API, but set out to write something much faster.

    Filling a need that is felt by many many Rubyists is not the same as making a personal attack against the creator of a similar piece of software.

  7. Stephen Stillwater says:

    Yeesh, you guys - I was being totally facetious. :)

    I was trying to poke gentle fun at The Great XML Parser Battles of Yesteryear and _why's writeup about the (allegedly) biased shootouts.

    More libraries to fill a common need is a great thing, and Parkaby looks very cool.

    So, just joking around is all.

  8. joem says:

    Stephen: You forgot to say "Why's everyone out to get Stephen?"

  9. Brandon says:

    Yes, I thought so, but it wasn't clear to me just where the facetiousness began in your comment: at the 3rd line, at the 2nd line, or at the 1st line?

  10. ben says:

    'kay but still at the end it ends up with a dozen of similar libraries that pretty much do the same thing.
    "it's faster than the almost exactly previous same one [wich sucked] and look, I've done better".

    Ruby/rails is really more about creativity I think than any other language, wich is cool, but sometimes I kind of feel bored to have the impression that everybody's trying to make it's thing on it's own, alone; and then give it to all saying it's more cool than the one it's totally been inspired by.

    We're here with another html renderer…
    Can we talk about the html/xml/whatever parser ? hoW MANY ARE THEY ?

    I sure don't get fully the point right here; but also sure that it creates a wonderful mess that weaken the whole stuff.

  11. lolcatz says:

    Just curious on how to use Parkaby on 1.9? ParseTree doesn't work on 1.9 so i don't see a reason to use Parkaby.

    And we all want to use 1.9 asap, right?

  12. Dr Nic says:

    Why is everyone out to get everyone who are out to get everyone? C'mon.

  13. Stephen Stillwater says:

    @DrNic : Metapersecution FTW!

  14. roger says:

    Is this faster parsing time or execution time?


  15. roger says:

    to answer my own question: it's execution time.

Other Posts to Enjoy

Twitter Mentions