-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Neatly add row_attributes to DefaultTable.
Move most logic into ::Base via include ::Extensions::RowAttributes. Update Presenters::Default to add attributes to trs. Add simple 'feature' spec in Presenters::Default spec.
- Loading branch information
Showing
6 changed files
with
54 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module TableCloth | ||
module Extensions | ||
module RowAttributes | ||
|
||
extend ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
|
||
def row_attributes(*args, &block) | ||
@tr_options ||= {} | ||
options = args.extract_options! || {} | ||
options[:proc] = block if block_given? | ||
@tr_options = options | ||
end | ||
|
||
def tr_options | ||
@tr_options ||= {} | ||
if superclass.respond_to? :tr_options | ||
@tr_options = superclass.tr_options.merge(@tr_options) | ||
end | ||
@tr_options | ||
end | ||
|
||
def tr_options_for(object) | ||
options = tr_options | ||
if options.include?(:proc) | ||
result = options[:proc].call(object) || {} | ||
options.except(:proc).merge(result) | ||
else | ||
options | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters