| Class | Markaby::Builder |
| In: |
lib/markaby/builder.rb
|
| Parent: | Object |
The Markaby::Builder class is the central gear in the system. When using from Ruby code, this is the only class you need to instantiate directly.
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
| output_helpers | [RW] |
Create a Markaby builder object. Pass in a hash of variable assignments to assigns which will be available as instance variables inside tag construction blocks. If an object is passed in to helpers, its methods will be available from those same blocks.
Pass in a block to new and the block will be evaluated.
mab = Markaby::Builder.new {
html do
body do
h1 "Matching Mole"
end
end
}
Captures the HTML code built inside the block. This is done by creating a new builder object, running the block and passing back its stream as a string.
>> Markaby::Builder.new.capture { h1 "TEST"; h2 "CAPTURE ME" }
=> "<h1>TITLE</h1>\n<h2>CAPTURE ME</h2>\n"
Content_for will store the given block in an instance variable for later use in another template or in the layout.
The name of the instance variable is content_for_<name> to stay consistent with @content_for_layout which is used by ActionView’s layouts.
Example:
content_for("header") do
h1 "Half Shark and Half Lion"
end
If used several times, the variable will contain all the parts concatenated.
Builds an html tag. An XML 1.0 instruction and an XHTML 1.0 Transitional doctype are prepended. Also assumes :xmlns => "www.w3.org/1999/xhtml", "xml:lang" => "en", :lang => "en".
Create XML markup based on the name of the method sym. This method is never invoked directly, but is called for each markup method in the markup block.
This method is also used to intercept calls to helper methods and instance variables. Here is the order of interception:
Create a tag named tag. Other than the first argument which is the tag name, the arguments are the same as the tags implemented via method_missing.