Class: SimpleDataPresentation::SimpleTable::Row

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_data_presentation/simple_table/row.rb

Instance Method Summary collapse

Methods inherited from Base

#item, #title

Constructor Details

#initialize(context, resource, options = {}, &content_block) ⇒ Row

Returns a new instance of Row.



2
3
4
5
6
7
# File 'lib/simple_data_presentation/simple_table/row.rb', line 2

def initialize(context, resource, options = {}, &content_block)
	@context = context
	@resource = resource
	@options = options
	@content_block = content_block
end

Instance Method Details

#render!Object



31
32
33
34
# File 'lib/simple_data_presentation/simple_table/row.rb', line 31

def render!
	content = @context.capture self, &@content_block
	@context.raw @context. :tr, content.html_safe, @options[:html]
end

#value(*args, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simple_data_presentation/simple_table/row.rb', line 9

def value(*args, &block)
	options = args.extract_options!
	if block.present?
		content = @context.capture @resource, &block
	else
		if (value_option = options[:value]).present?
			content = value_option.respond_to?(:call) ? value_option.call(@resource) : value_option
		else
			content = value_for_method_chain *args
		end
		as_formatter = options[:as]
		if as_formatter.present?
			as_formatter = @context.method(as_formatter).to_proc if as_formatter.is_a?(Symbol)
			content = case as_formatter.arity
			when 1; as_formatter.call content
			when 2; as_formatter.call @resource, content
			end
		end
	end
	@context. :td, content, (SimpleDataPresentation::HtmlOptions.new(options[:html] || {}).merge options[:row_html] || {})
end