Class | Markaby::Builder |
In: |
lib/markaby/rails.rb
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] | |
tagset | [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 stream for the 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.
Every HTML tag method goes through an html_tag call. So, calling div is equivalent to calling html_tag(:div). All HTML tags in Markaby‘s list are given generated wrappers for this method.
If the @auto_validation setting is on, this method will check for many common mistakes which could lead to invalid XHTML.
This method is used to intercept calls to helper methods and instance variables. Here is the order of interception:
method_missing used to be the lynchpin in Markaby, but it‘s no longer used to handle HTML tags. See html_tag for that.
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.
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", :lang => "en".