Sha256: 759145647fe640e36927b117da80e16ee9a1d2ba305964397094bfdf1b120075
Contents?: true
Size: 1018 Bytes
Versions: 22
Compression:
Stored size: 1018 Bytes
Contents
module InterfaceBuilder class HamlBuilder < BlankSlate def initialize template @template = template @hash, @array = OpenObject.new, [] end def method_missing m, value = nil, &block @hash[m] = get_input value, &block nil end def add value = nil, &block @array << get_input(value, &block) nil end # def add_item content, opt = {}, &block # opt[:content] = content # opt[:content] ||= @template.capture &block if block # add opt # end def get_value !@array.empty? ? @array : @hash end protected def get_input value, &block if block if block.arity <= 0 @template.should_not! :be_nil @template.capture &block else b = HamlBuilder.new @template block.call b b.get_value end else value.is_a?(Hash) ? value.to_openobject : value end end end end
Version data entries
22 entries across 22 versions & 1 rubygems