= Markaby (Markup as Ruby) Markaby is a very short bit of code for writing HTML pages in pure Ruby. It is an alternative to ERb which weaves the two languages together. Also a replacement for templating languages which use primitive languages that blend with HTML. == Using Markaby as a Rails plugin Write Rails templates in pure Ruby. Example layout: html do head do title 'Products: ' + action_name stylesheet_link_tag 'scaffold' end body do p flash[:notice], :style => "color: green" self << content_for_layout end end == Using Markaby as a Ruby class Markaby is flaming easy to call from your Ruby classes. require 'markaby' mab = Markaby::Builder.new mab.html do head { title "Boats.com" } body do h1 "Boats.com has great deals" ul do li "$49 for a canoe" li "$39 for a raft" li "$29 for a huge boot that floats and can fit 5 people" end end end puts mab.to_s Markaby::Builder.new does take two arguments for passing in variables and a helper object. You can also affix the block right on to the class. See Markaby::Builder for all of that. = A Note About instance_eval The Markaby::Builder class is different from the normal Builder class, since it uses instance_eval when running blocks. This cleans up the appearance of the Markaby code you write. If instance_eval was not used, the code would look like this: mab = Markaby::Builder.new mab.html do mab.head { mab.title "Boats.com" } mab.body do mab.h1 "Boats.com has great deals" end end puts mab.to_s So, the advantage is the cleanliness of your code. The disadvantage is that the block will run inside the Markaby::Builder object's scope. This means that inside these blocks, self will be your Markaby::Builder object. When you use instance variables in these blocks, they will be instance variables of the Markaby::Builder object. This doesn't affect Rails users, but when used in regular Ruby code, it can be a bit disorienting. You are recommended to put your Markaby code in a module where it won't mix with anything. = The Six Steps of Markaby If you dive right into Markaby, it'll probably make good sense, but you're likely to run into a few kinks. Why not review these six steps and commit them memory so you can really *know* what you're doing? == 1. Element Classes Element classes may be added by hooking methods onto container elements: div.entry do h2.entryTitle 'Son of WebPage' div.entrySection %{by Anthony} div.entryContent 'Okay, once again, the idea here is ...' end Which results in: