Skip to content

Commit

Permalink
Merge pull request #288 from clearsightstudio/fix-indexable
Browse files Browse the repository at this point in the history
Fix indexable
  • Loading branch information
jamonholmgren committed Sep 4, 2013
2 parents 36b8ff8 + 9925cfe commit dde7938
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
8 changes: 6 additions & 2 deletions lib/ProMotion/table/extensions/indexable.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
module ProMotion
module Table
module Indexable
def index_from_section_titles
@promotion_table_data.filtered ? nil : @promotion_table_data.sections.collect{ |section| section[:title][0] }
def table_data_index
return nil if @promotion_table_data.filtered || !self.class.get_indexable

index = @promotion_table_data.sections.collect{ |section| section[:title][0] }
index.unshift("{search}") if self.class.get_searchable
index
end
end
end
Expand Down
14 changes: 5 additions & 9 deletions lib/ProMotion/table/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,12 @@ def tableView(table_view, titleForHeaderInSection:section)

# Set table_data_index if you want the right hand index column (jumplist)
def sectionIndexTitlesForTableView(table_view)
if @promotion_table_data.filtered
nil
return nil if @promotion_table_data.filtered

if self.respond_to?(:table_data_index)
self.table_data_index
else
if self.respond_to?(:table_data_index)
self.table_data_index
elsif self.class.respond_to?(:get_indexable) && self.class.get_indexable
self.index_from_section_titles
else
nil
end
nil
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/helpers/table_screen_indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ def table_data
end

end

class TableScreenIndexableSearchable < TableScreenIndexable
indexable
searchable
end
19 changes: 16 additions & 3 deletions spec/unit/tables/table_indexable_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
describe "PM::Table module" do
describe "PM::Table module indexable" do

before do
@screen = TableScreenIndexable.new
end

it "should automatically return the first letter of each section" do
result = %w{ A G M O S U }
@screen.sectionIndexTitlesForTableView(@screen.table_view).should == result
end

end

describe "PM::Table module indexable/searchable" do

before do
@screen = TableScreenIndexableSearchable.new
end

it "should automatically return the first letter of each section" do
result = %w{ {search} A G M O S U }
@screen.sectionIndexTitlesForTableView(@screen.table_view).should == result
end

end

0 comments on commit dde7938

Please sign in to comment.