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


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/grapple/helpers/table_helper.rb', line 43

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


35
36
37
38
39
40
41
# File 'lib/grapple/helpers/table_helper.rb', line 35

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

Render a grapple table

Parameters:

  • columns (Enumerable)
  • records (Enumerable)
  • args (Hash)

    a customizable set of options

Options Hash (*args):

  • :container (Boolean)

    If true the table will be rendered with a container div around it

  • :html (Hash)

    HTML attributes for the `<table>` element

  • :builder (Grapple::BaseTableBuilder)

    The table builder to use to render the table

  • :params (Object)

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/grapple/helpers/table_helper.rb', line 18

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