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   content_for   head   html   img   method_missing   new   p   tag!   text   to_s   xhtml_strict   xhtml_transitional  

Attributes

output_helpers  [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

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

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

Builds a image tag. Assumes :border => ‘0’, :alt => ’’.

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:

  • If sym is a recognized HTML tag, the tag is output or a CssProxy is returned if no arguments are given.
  • If sym appears to be a self-closing tag, its block is ignored, thus outputting a valid self-closing tag.
  • If sym is also the name of an instance variable, the value of the instance variable is returned.
  • If sym is a helper method, the helper method is called and output to the stream.
  • Otherwise, sym and its arguments are passed to tag!

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.

xhtml_transitional(*args, &block)

Alias for html

[Validate]