Class: Borges::HtmlBuilder

# Borges::HtmlBuilder (Class)

In: | lib/Borges/HTML/HtmlBuilder.rb
Parent: | Object

Borges::HTMLBuilder is a generic class for outputting HTML.

## Methods

break close css_class div_named div_with_class element_id encode encode_text fieldset head_tag head_tag_with heading heading_level horizontal_rule image image_url_anchor input list list_do new open_tag render set_attribute space style_link table table_headings table_row table_row_labeled table_row_span table_row_with table_spacer_row tag tag_do text title url_anchor

## Constants

SIMPLE_ELEMENTS | = | { :bold => :b, :code => :code, :div => :div, :emphasis => :em, :italic => :i, :paragraph => :p, :preformatted => :pre, :strong => :strong, :small => :small, :span => :span, :sub => :sub, :sup => :sup, :table_data => :td, :table_heading => :th, :underline => :u, }
HTML_CHARACTERS | = | {}

## Attributes

attributes | [R] |
document | [RW] |

## Public Class methods

new(document)

Creates a new HtmlBuilder.

`document` must have the following interface:

      #head
      #add_element
      #pop_element
      #push_element

## Public Instance methods

break()

Creates a line break.

close()

Close the last open element.

css_class(classes)

Adds a class attribute that contains `classes`

div_named(name, obj = nil, &block)

Creates a <div> that has an id attribute containing `name`.

div_with_class(classes, obj = nil, &block)

Creates a <div> that has an class attribute containing `classes`.

element_id(e_id)

Adds an id attribute containing `e_id`

encode(obj)

Turns an `obj` into an HTML encoded string

encode "foo > bar" # => "foo &gt; bar"

encode_text(obj)

Adds `obj` as an HTML encoded string.

fieldset(legend, &block)

Creates a <fieldset> labeled `legend`

head_tag(name)

Creates a tag that goes in the <head> of the document with `name`.

head_tag_with(name, child)

Creates a tag that goes in the <head> of the document with `name`, that contains `child` in its contents.

heading(str)

Creates a level 1 heading

heading("My Heading")

<h1>My Heading</h1>

heading_level(obj, level)

Creates a heading with level

heading_level("My Heading", 2)

<h2>My Heading</h2>

horizontal_rule()

Adds an <hr> to the document.

image(src, alt = "")

Adds an <img> with `src` as its src attribute. If `alt` is specified, it is used as the image’s alternate text, otherwise the alt attribute is left empty.

image_url_anchor(url, src, alt='')

Add an anchor on an <img> with `src` as its src attribute. If `alt` is specified, it is used as the image’s alternate text, otherwise the alt attribute is left empty.

input(input_type, name = nil, value = nil)

Creates an <input> of type `input_type` with an optional `name` and `value`.

list(items)

Builds an unordered list of items from an Enumerable. text will be called on each item.

list ["x", 5, { :x => :y }]

<ul><li>x</li><li>5</li><li>xy</li></ul>

list_do(items, &block)

Builds an unordered list of items from an Enumerable. The given block will be called on each item.

See also list

open_tag(name)

Adds a new element `name` to the document with all the attributes specified for it.

render(obj)

Renders `obj`.

set_attribute(attr, val)
space()

Adds a non-breakin space (&nbsp;).

style_link(url)

Adds a link to an external stylesheet with `url`.

table(&block)

Creates a <table> element.

table_headings(*headings)

Creates a row of table headings from `headings`

table_row(&block)

Creates a table row.

table_row_labeled(label, obj = nil, &block)

Creates a table row with `label` in the first cell.

table_row_span(span, &block)

Creates a table row with a table cell that spans `span` columns.

table_row_with(obj = nil, &block)

Creates a table row containing a single data cell.

table_spacer_row()

Creates an empty table row.

tag(name)

Creates an empty element with `name`

tag_do(name, obj)

Creates a `name` element containing `obj`

text(obj)

Turn an object into a string. It is not recommened to use this method to dump raw HTML.

text("hello world")

hello world

title(str)

Sets the <title> of the document to `str`

url_anchor(url, obj = nil, &block)

Creates an anchor that links to `url`.

[Validate]