Module: Grapple::Helpers::TableHelper

Defined in:
lib/grapple/helpers/table_helper.rb

Constant Summary collapse

@@builder =
Grapple::DataGridBuilder

Instance Method Summary collapse

Instance Method Details

#grapple_container(*args, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/grapple/helpers/table_helper.rb', line 33

def grapple_container(*args, &block)
	options = args[0] || {}
	builder_class = options[:builder] || @@builder
	container_attr = builder_class.container_attributes(self, options)
	html = ''
	html << builder_class.before_container(self, options)
	html << tag('div', container_attr, true) + "\n"
	html << capture(&block)
	html << "</div>\n"
	html << builder_class.after_container(self, options)
	return html.html_safe
end

#grapple_request_paramsObject



25
26
27
28
29
30
31
# File 'lib/grapple/helpers/table_helper.rb', line 25

def grapple_request_params
	# params might not be defined (being called from a mailer)
	# HACK: "defined? params" is returning method but when it gets called the method is not defined
	params()
rescue
	request.params() rescue {}
end

#table_for(columns, records, *args, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/grapple/helpers/table_helper.rb', line 8

def table_for(columns, records, *args, &block)
	options = args[0] || {}
	# Don't render the container for AJAX requests by default
	render_container = (options[:container].nil? ? !request.xhr? : options[:container]) rescue false
	table_html_attributes = options[:html] || {}
	options[:builder] = options[:builder] || @@builder
	request_params = options[:params] ? options[:params] : grapple_request_params
	builder = options[:builder].new(self, columns, records, request_params, options)
	output = capture(builder, &block)
	table_html = (builder.before_table + builder.table(output, table_html_attributes) + builder.after_table)
	if render_container
		builder.container(table_html)
	else
		table_html.html_safe
	end
end