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
GENERIC_OPTIONS | = | { :indent => 0, :auto_validation => true, } |
HTML5_OPTIONS | = | HTML5.default_options.dup |
DEFAULT_OPTIONS | = | GENERIC_OPTIONS.merge(HTML5_OPTIONS) |
tagset | [R] |
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 helper, 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>TEST</h1><h2>CAPTURE ME</h2>"