Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass view_context along to row_attributes proc #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/table_cloth/extensions/row_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def tr_options
@tr_options
end

def tr_options_for(object)
def tr_options_for(object, view_context)
options = tr_options
if options.include?(:proc)
result = options[:proc].call(object) || {}
result = options[:proc].call(object, view_context) || {}
options.except(:proc).merge(result)
else
options
Expand Down
6 changes: 3 additions & 3 deletions lib/table_cloth/presenters/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def thead

def tbody
@tbody ||= ElementFactory::Element.new(:tbody, tag_options(:tbody)).tap do |tbody|
objects.each {|object| tbody << row_for_object(object) }
objects.each {|object| tbody << row_for_object(object, view_context) }
end
end

Expand All @@ -32,8 +32,8 @@ def thead_row
end
end

def row_for_object(object)
tr_options = table.class.tr_options_for(object)
def row_for_object(object, view_context)
tr_options = table.class.tr_options_for(object, view_context)

ElementFactory::Element.new(:tr, tag_options(:tr).merge(tr_options)).tap do |row|
columns.each do |column|
Expand Down