Class: K3Testing::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/k3_testing/presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, parent) ⇒ Presenter

Returns a new instance of Presenter.



97
98
99
100
# File 'lib/k3_testing/presenter.rb', line 97

def initialize(obj, parent)
  @object = obj
  @parent = parent
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



95
96
97
# File 'lib/k3_testing/presenter.rb', line 95

def object
  @object
end

Instance Method Details

#attr(name, options = {}, &block) ⇒ Object



102
103
104
105
106
107
# File 'lib/k3_testing/presenter.rb', line 102

def attr(name, options={}, &block)
  tag = options[:as] || :span
  output = block.nil? ? object.send(name).to_s : @parent.capture(&block)
  html_opts = (options[:html_options] || {}).merge('data-role' => "#{object.class.name.underscore}.#{object.id}.#{name.to_s}")
  @parent. tag, output, html_opts
end