class LazyForm::Tag
Constants
- BOOLEAN_ATTRIBUTES
Attributes
attributes[R]
block[R]
name[R]
Public Class Methods
new(name, attributes = {}, &block)
click to toggle source
# File lib/lazy_form.rb, line 29 def initialize(name, attributes = {}, &block) @name = name @attributes = attributes @block = block end
Public Instance Methods
to_s()
click to toggle source
# File lib/lazy_form.rb, line 35 def to_s attrs = build_attributes attributes.reject { |k, v| v.nil? } attrs.unshift name if block.nil? "<#{attrs.reject(&:empty?).join ' '}/>" else "<#{attrs.reject(&:empty?).join ' '}>#{block.call}</#{name}>" end end
Private Instance Methods
build_attributes(attributes = {})
click to toggle source
# File lib/lazy_form.rb, line 48 def build_attributes(attributes = {}) attributes.collect do |k, v| if v.is_a? Hash build_attributes Hash[v.collect { |ik, iv| [:"#{k}-#{ik}", iv] }] elsif BOOLEAN_ATTRIBUTES.include? k v ? k : '' else "#{k}=\"#{v}\"" end end.flatten end