Module: Buildable
- Defined in:
- lib/more/facets/buildable.rb
Overview
Buildable
Buildable is mixin variation of BuildingBlock.
require 'facets/buildable'
require 'xmlmarkup' # hypothetical library
module XMLMarkup
include Buildable
alias :build :element
end
doc = XMLMarkup.build do
html do
head do
title "Test"
end
body do
i "Hello"
br
text "Test"
text "Hey"
end
end
end
produces
<html><head><title>Test</title><body><i>Hello</i><br />TestHey</body></html>
This is based on BuildingBlock. Refer to it for more information.
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/more/facets/buildable.rb', line 66 def self.included(base) singleton = (class << base; self; end) singleton.send(:define_method, :builder) do @builder ||= BuildingBlock.new(base, :build) end base.module_eval %{ def self.build(&block) builder.instance_eval(&block) end } end |