diff --git a/lib/ProMotion/table/extensions/indexable.rb b/lib/ProMotion/table/extensions/indexable.rb index d24b210..3adac5e 100644 --- a/lib/ProMotion/table/extensions/indexable.rb +++ b/lib/ProMotion/table/extensions/indexable.rb @@ -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 diff --git a/lib/ProMotion/table/table.rb b/lib/ProMotion/table/table.rb index 43463d1..f8d341b 100644 --- a/lib/ProMotion/table/table.rb +++ b/lib/ProMotion/table/table.rb @@ -180,16 +180,12 @@ module ProMotion # 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 diff --git a/spec/helpers/table_screen_indexable.rb b/spec/helpers/table_screen_indexable.rb index 08c8551..57746fc 100644 --- a/spec/helpers/table_screen_indexable.rb +++ b/spec/helpers/table_screen_indexable.rb @@ -11,3 +11,8 @@ class TableScreenIndexable < PM::TableScreen end end + +class TableScreenIndexableSearchable < TableScreenIndexable + indexable + searchable +end diff --git a/spec/unit/tables/table_indexable_spec.rb b/spec/unit/tables/table_indexable_spec.rb index 9020a1b..0f6027c 100644 --- a/spec/unit/tables/table_indexable_spec.rb +++ b/spec/unit/tables/table_indexable_spec.rb @@ -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