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

Methods

<<   capture   concat   get   helper=   locals=   new   restore_defaults!   set   tag!   tagset=   text   to_s  

Included Modules

Markaby::BuilderTags

Constants

GENERIC_OPTIONS = { :indent => 0, :auto_validation => true, }
HTML5_OPTIONS = HTML5.default_options.dup
DEFAULT_OPTIONS = GENERIC_OPTIONS.merge(HTML5_OPTIONS)

Attributes

tagset  [R] 

Public Class methods

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
  }

Public Instance methods

<<(string)

Alias for text

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>"
concat(string)

Alias for text

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.

Write a string to the HTML stream without escaping it.

Returns a string containing the HTML stream. Internally, the stream is stored as an Array.

[Validate]