Class Markaby::Builder
In: lib/markaby/builder.rb
lib/markaby/rails.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

Attributes

output_helpers  [RW] 
tagset  [RW] 

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 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
  }

Public Instance methods

<<(string)

Alias for text

Emulate ERB to satisfy helpers like form_for.

Emulate ERB to satisfy helpers like form_for.

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

Alias for text

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 a head tag. Adds a meta tag inside with Content-Type set to text/html; charset=utf-8.

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:

  • If sym is a helper method, the helper method is called and output to the stream.
  • If sym is a Builder::XmlMarkup method, it is passed on to the builder object.
  • If sym is also the name of an instance variable, the value of the instance variable is returned.
  • If sym has come this far and no tagset is found, sym and its arguments are passed to tag!
  • If a tagset is found, though, NoMethodError is raised.

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.

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.

Builds an html tag with XHTML 1.0 Strict doctype instead.

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".

[Validate]