Class: Crafty::Builder

Inherits:
Object show all
Defined in:
lib/crafty/builder.rb

Overview

Builder provides a builder-like class to construct HTML output. You can use builders if you don’t want to include the helper modules in your own builder class. You can also subclass from the Builder class to easily create your own builders.

Direct Known Subclasses

HTML4::Builder, HTML5::Builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target = "") ⇒ Builder

Returns a new instance of Builder.



17
18
19
# File 'lib/crafty/builder.rb', line 17

def initialize(target = "")
  @target = target
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



15
16
17
# File 'lib/crafty/builder.rb', line 15

def target
  @target
end

Class Method Details

.build {|builder| ... } ⇒ Object

Yields:

  • (builder)


8
9
10
11
12
# File 'lib/crafty/builder.rb', line 8

def build
  builder = new
  yield builder
  builder.to_s
end

Instance Method Details

#<<(output) ⇒ Object



25
26
27
# File 'lib/crafty/builder.rb', line 25

def <<(output)
  @target << output
end

#to_sObject



21
22
23
# File 'lib/crafty/builder.rb', line 21

def to_s
  @target.to_s
end