tableficate 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. data/README.markdown +53 -48
  2. data/app/views/tableficate/{_column_header.html.erb → _header.html.erb} +0 -0
  3. data/app/views/tableficate/_table.html.erb +4 -4
  4. data/app/views/tableficate/filters/_check_box.html.erb +4 -0
  5. data/app/views/tableficate/{_input_filter.html.erb → filters/_input.html.erb} +0 -0
  6. data/app/views/tableficate/{_input_range_filter.html.erb → filters/_input_range.html.erb} +0 -0
  7. data/app/views/tableficate/filters/_radio.html.erb +4 -0
  8. data/app/views/tableficate/{_select_filter.html.erb → filters/_select.html.erb} +0 -0
  9. data/app/views/tableficate/filters/_select_range.html.erb +6 -0
  10. data/changelog.markdown +8 -0
  11. data/lib/tableficate/action_column.rb +2 -2
  12. data/lib/tableficate/base.rb +2 -2
  13. data/lib/tableficate/column.rb +6 -2
  14. data/lib/tableficate/exceptions.rb +4 -0
  15. data/lib/tableficate/filters/base.rb +21 -0
  16. data/lib/tableficate/filters/check_box.rb +6 -0
  17. data/lib/tableficate/filters/choice.rb +23 -0
  18. data/lib/tableficate/filters/collection.rb +30 -0
  19. data/lib/tableficate/filters/input.rb +12 -0
  20. data/lib/tableficate/filters/input_range.rb +57 -0
  21. data/lib/tableficate/filters/radio.rb +6 -0
  22. data/lib/tableficate/filters/select.rb +6 -0
  23. data/lib/tableficate/filters/select_range.rb +54 -0
  24. data/lib/tableficate/helper.rb +69 -4
  25. data/lib/tableficate/table.rb +56 -10
  26. data/lib/tableficate/version.rb +1 -1
  27. data/lib/tableficate.rb +9 -3
  28. data/spec/action_column_spec.rb +1 -1
  29. data/spec/column_spec.rb +8 -0
  30. data/spec/filters/base_spec.rb +30 -0
  31. data/spec/filters/choice_spec.rb +13 -0
  32. data/spec/filters/collection_spec.rb +94 -0
  33. data/spec/filters/input_range_spec.rb +91 -0
  34. data/spec/filters/input_spec.rb +24 -0
  35. data/spec/generators/tableficate_table_spec.rb +20 -0
  36. data/spec/generators/tableficate_theme_spec.rb +11 -0
  37. data/spec/helper_spec.rb +164 -0
  38. data/spec/spec_helper.rb +3 -0
  39. data/spec/table_spec.rb +38 -13
  40. data/spec/test_app/Gemfile +1 -1
  41. data/spec/test_app/app/controllers/filters_controller.rb +7 -0
  42. data/spec/test_app/app/views/filters/check_box_tags.html.erb +14 -0
  43. data/spec/test_app/app/views/filters/multi_select_from_string.html.erb +11 -0
  44. data/spec/test_app/app/views/filters/multi_select_tag.html.erb +11 -0
  45. data/spec/test_app/app/views/filters/radio_tags.html.erb +14 -0
  46. data/spec/test_app/app/views/filters/select_from_string.html.erb +11 -0
  47. data/spec/test_app/app/views/filters/select_tag.html.erb +11 -0
  48. data/spec/test_app/app/views/tableficate/custom_check_box_block/_data.html.erb +1 -0
  49. data/spec/test_app/app/views/tableficate/custom_check_box_block/_header.html.erb +8 -0
  50. data/spec/test_app/app/views/tableficate/custom_check_box_block/_row.html.erb +5 -0
  51. data/spec/test_app/app/views/tableficate/custom_check_box_block/_table.html.erb +36 -0
  52. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_check_box.html.erb +7 -0
  53. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_input.html.erb +4 -0
  54. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_input_range.html.erb +6 -0
  55. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_radio.html.erb +4 -0
  56. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_select.html.erb +4 -0
  57. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_select_range_filter.html.erb +6 -0
  58. data/spec/test_app/app/views/tableficate/custom_radio_block/_data.html.erb +1 -0
  59. data/spec/test_app/app/views/tableficate/custom_radio_block/_header.html.erb +8 -0
  60. data/spec/test_app/app/views/tableficate/custom_radio_block/_row.html.erb +5 -0
  61. data/spec/test_app/app/views/tableficate/custom_radio_block/_table.html.erb +36 -0
  62. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_check_box.html.erb +4 -0
  63. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_input.html.erb +4 -0
  64. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_input_range.html.erb +6 -0
  65. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_radio.html.erb +7 -0
  66. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_select.html.erb +4 -0
  67. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_select_range_filter.html.erb +6 -0
  68. data/spec/test_app/config/routes.rb +1 -56
  69. data/tableficate.gemspec +4 -2
  70. metadata +122 -27
  71. data/lib/tableficate/filters/filter.rb +0 -19
  72. data/lib/tableficate/filters/input_filters.rb +0 -64
  73. data/lib/tableficate/filters/select_filter.rb +0 -11
  74. data/spec/filter_spec.rb +0 -30
  75. data/spec/input_filter_spec.rb +0 -90
  76. data/spec/select_filter_spec.rb +0 -10
data/spec/table_spec.rb CHANGED
@@ -2,7 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Tableficate::Table do
4
4
  before(:each) do
5
- @table = Tableficate::Table.new(nil, NobelPrizeWinner.limit(1), {}, {current_sort: {column: :first_name, dir: 'asc'}})
5
+ template = mock('Template')
6
+ template.stub!(:lookup_context).and_return(ActionView::LookupContext.new([]))
7
+ template.lookup_context.stub!(:exists?).and_return(true)
8
+ @table = Tableficate::Table.new(template, NobelPrizeWinner.limit(1), {}, {current_sort: {column: :first_name, dir: 'asc'}})
6
9
  end
7
10
 
8
11
  it 'should have the current sort if provided' do
@@ -65,30 +68,52 @@ describe Tableficate::Table do
65
68
  table.show_sort?.should be false
66
69
  end
67
70
 
68
- it 'should add an InputFilter' do
69
- @table.input_filter(:first_name, label: 'First')
70
- @table.input_filter(:last_name, label: 'Last')
71
+ it 'should add an Input filter' do
72
+ @table.filter(:first_name, label: 'First')
73
+ @table.filter(:last_name, label: 'Last')
71
74
 
72
75
  @table.filters.first.name.should == :first_name
73
- @table.filters.first.is_a?(Tableficate::InputFilter).should be true
76
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
74
77
  @table.filters.last.name.should == :last_name
75
78
  end
76
79
 
77
- it 'should add an InputRangeFilter' do
78
- @table.input_range_filter(:first_name, label: 'First')
79
- @table.input_range_filter(:last_name, label: 'Last')
80
+ it 'should raise an error if Input is passed an unknown type' do
81
+ lambda {@table.filter(:first_name, as: :foo)}.should raise_error(Tableficate::Filter::UnknownInputType)
82
+ end
83
+
84
+ it 'should add the Input for known types and pass through the type based on :as' do
85
+ @table.filter(:first_name, as: :search)
86
+
87
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
88
+ @table.filters.first.options[:type].should == 'search'
89
+ end
90
+
91
+ it 'should add a InputRange filter' do
92
+ @table.filter_range(:first_name, label: 'First')
93
+ @table.filter_range(:last_name, label: 'Last')
80
94
 
81
95
  @table.filters.first.name.should == :first_name
82
- @table.filters.first.is_a?(Tableficate::InputRangeFilter).should be true
96
+ @table.filters.first.is_a?(Tableficate::Filter::InputRange).should be true
83
97
  @table.filters.last.name.should == :last_name
84
98
  end
85
99
 
86
- it 'should add an SelectFilter' do
87
- @table.select_filter(:first_name, {}, label: 'First')
88
- @table.select_filter(:last_name, {}, label: 'Last')
100
+ it 'should raise an error if InputRange is passed an unknown type' do
101
+ lambda {@table.filter_range(:first_name, as: :foo)}.should raise_error(Tableficate::Filter::UnknownInputType)
102
+ end
103
+
104
+ it 'should add the InputRange for known types and pass through the type based on :as' do
105
+ @table.filter_range(:first_name, as: :search)
106
+
107
+ @table.filters.first.is_a?(Tableficate::Filter::InputRange).should be true
108
+ @table.filters.first.options[:type].should == 'search'
109
+ end
110
+
111
+ it 'should add a Select filter' do
112
+ @table.filter(:first_name, collection: {}, label: 'First')
113
+ @table.filter(:last_name, collection: {}, label: 'Last')
89
114
 
90
115
  @table.filters.first.name.should == :first_name
91
- @table.filters.first.is_a?(Tableficate::SelectFilter).should be true
116
+ @table.filters.first.is_a?(Tableficate::Filter::Select).should be true
92
117
  @table.filters.last.name.should == :last_name
93
118
  end
94
119
  end
@@ -1,6 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'rails', '3.1.0'
3
+ gem 'rails', '3.1.3'
4
4
 
5
5
  gem 'sqlite3'
6
6
 
@@ -0,0 +1,7 @@
1
+ class FiltersController < ApplicationController
2
+ before_filter :get_npw
3
+
4
+ def get_npw
5
+ @npw = NobelPrizeWinner.select('nobel_prize_winners.*, nobel_prizes.category, nobel_prizes.year').joins(:nobel_prizes).tableficate(params[:nobel_prize_winners])
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ <% theme = params[:theme] %>
2
+
3
+ <%= table_for @npw, theme: theme do |t|
4
+ t.column :id
5
+ t.column :first_name
6
+ t.column :last_name
7
+ t.column :category
8
+ t.column :year
9
+
10
+ t.filter :category,
11
+ as: :checkbox,
12
+ collection: ['Chemistry', 'Literature', 'Peace', 'Physics', 'Physiology or Medicine'],
13
+ include_blank: true
14
+ end %>
@@ -0,0 +1,11 @@
1
+ <%= table_for @npw do |t|
2
+ t.column :id
3
+ t.column :first_name
4
+ t.column :last_name
5
+ t.column :category
6
+ t.column :year
7
+
8
+ t.filter :category,
9
+ collection: '<option>Chemistry</option><option>Literature</option><option>Peace</option><option>Physics</option><option>Physiology or Medicine</option>',
10
+ multiple: true
11
+ end %>
@@ -0,0 +1,11 @@
1
+ <%= table_for @npw do |t|
2
+ t.column :id
3
+ t.column :first_name
4
+ t.column :last_name
5
+ t.column :category
6
+ t.column :year
7
+
8
+ t.filter :category,
9
+ collection: ['Chemistry', 'Literature', 'Peace', 'Physics', 'Physiology or Medicine'],
10
+ multiple: true
11
+ end %>
@@ -0,0 +1,14 @@
1
+ <% theme = params[:theme] %>
2
+
3
+ <%= table_for @npw, theme: theme do |t|
4
+ t.column :id
5
+ t.column :first_name
6
+ t.column :last_name
7
+ t.column :category
8
+ t.column :year
9
+
10
+ t.filter :category,
11
+ as: :radio,
12
+ collection: ['Chemistry', 'Literature', 'Peace', 'Physics', 'Physiology or Medicine'],
13
+ include_blank: true
14
+ end %>
@@ -0,0 +1,11 @@
1
+ <%= table_for @npw do |t|
2
+ t.column :id
3
+ t.column :first_name
4
+ t.column :last_name
5
+ t.column :category
6
+ t.column :year
7
+
8
+ t.filter :category,
9
+ collection: '<option>Chemistry</option><option>Literature</option><option>Peace</option><option>Physics</option><option>Physiology or Medicine</option>',
10
+ include_blank: true
11
+ end %>
@@ -0,0 +1,11 @@
1
+ <%= table_for @npw do |t|
2
+ t.column :id
3
+ t.column :first_name
4
+ t.column :last_name
5
+ t.column :category
6
+ t.column :year
7
+
8
+ t.filter :category,
9
+ collection: ['Chemistry', 'Literature', 'Peace', 'Physics', 'Physiology or Medicine'],
10
+ include_blank: true
11
+ end %>
@@ -0,0 +1 @@
1
+ <td><%= column.value(row) %></td>
@@ -0,0 +1,8 @@
1
+ <th>
2
+ <%= column.header %>
3
+ <% table_params = (params[column.table.as] || {}) %>
4
+ <% if column.show_sort? %>
5
+ <%= link_to 'A', url_for(params.merge(column.table.as => table_params.merge({sort: column.name.to_s, dir: 'asc'}))) %><% if column.is_sorted?('asc') %>*<% end %>
6
+ <%= link_to 'D', url_for(params.merge(column.table.as => table_params.merge({sort: column.name.to_s, dir: 'desc'}))) %><% if column.is_sorted?('desc') %>*<% end %>
7
+ <% end %>
8
+ </th>
@@ -0,0 +1,5 @@
1
+ <tr>
2
+ <% columns.each do |column| %>
3
+ <%= tableficate_data_tag row, column %>
4
+ <% end %>
5
+ </tr>
@@ -0,0 +1,36 @@
1
+ <% if table.filters.any? %>
2
+ <%= form_tag '', method: :get do %>
3
+ <% if params[table.as] and params[table.as][:sort] %>
4
+ <%= hidden_field_tag("#{table.as}[sort]", params[table.as][:sort]) %>
5
+ <% end %>
6
+ <% if params[table.as] and params[table.as][:dir] %>
7
+ <%= hidden_field_tag("#{table.as}[dir]", params[table.as][:dir]) %>
8
+ <% end %>
9
+ <% table.filters.each do |filter| %>
10
+ <%= tableficate_filter_tag filter %>
11
+ <% end %>
12
+
13
+ <%= submit_tag('Filter') %>
14
+ <% end %>
15
+ <% end %>
16
+
17
+ <% if defined? ::Kaminari %>
18
+ <%= paginate(table.rows, param_name: "#{table.as}_page") %>
19
+ <% elsif defined? ::WillPaginate %>
20
+ <%= will_paginate(table.rows, param_name: "#{table.as}_page") %>
21
+ <% end %>
22
+
23
+ <%= content_tag(:table, table.options[:html]) do %>
24
+ <thead>
25
+ <tr>
26
+ <% table.columns.each do |column| %>
27
+ <%= tableficate_header_tag column %>
28
+ <% end %>
29
+ </tr>
30
+ </thead>
31
+ <tbody>
32
+ <% table.rows.each do |row| %>
33
+ <%= tableficate_row_tag row, table.columns %>
34
+ <% end %>
35
+ </tbody>
36
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter) %>
3
+ <%= tableficate_check_box_tags(filter) do |choice| %>
4
+ <%= label_tag("#{filter.field_name}[#{choice.value}]", choice.name) %>
5
+ <%= check_box_tag("#{filter.field_name}[#{choice.value}]", choice.value, choice.checked?, choice.options.reverse_merge(name: "#{filter.field_name}[]")) %>
6
+ <% end %>
7
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter) %>
3
+ <%= tableficate_text_field_tag(filter) %>
4
+ </div>
@@ -0,0 +1,6 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter.start) %>
3
+ <%= tableficate_text_field_tag(filter.start) %>
4
+ <%= tableficate_label_tag(filter.stop) %>
5
+ <%= tableficate_text_field_tag(filter.stop) %>
6
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter) %>
3
+ <%= tableficate_radio_tags(filter) %>
4
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter) %>
3
+ <%= tableficate_select_tag(filter) %>
4
+ </div>
@@ -0,0 +1,6 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter.start) %>
3
+ <%= tableficate_select_tag(filter.start) %>
4
+ <%= tableficate_label_tag(filter.stop) %>
5
+ <%= tableficate_select_tag(filter.stop) %>
6
+ </div>
@@ -0,0 +1 @@
1
+ <td><%= column.value(row) %></td>
@@ -0,0 +1,8 @@
1
+ <th>
2
+ <%= column.header %>
3
+ <% table_params = (params[column.table.as] || {}) %>
4
+ <% if column.show_sort? %>
5
+ <%= link_to 'A', url_for(params.merge(column.table.as => table_params.merge({sort: column.name.to_s, dir: 'asc'}))) %><% if column.is_sorted?('asc') %>*<% end %>
6
+ <%= link_to 'D', url_for(params.merge(column.table.as => table_params.merge({sort: column.name.to_s, dir: 'desc'}))) %><% if column.is_sorted?('desc') %>*<% end %>
7
+ <% end %>
8
+ </th>
@@ -0,0 +1,5 @@
1
+ <tr>
2
+ <% columns.each do |column| %>
3
+ <%= tableficate_data_tag row, column %>
4
+ <% end %>
5
+ </tr>
@@ -0,0 +1,36 @@
1
+ <% if table.filters.any? %>
2
+ <%= form_tag '', method: :get do %>
3
+ <% if params[table.as] and params[table.as][:sort] %>
4
+ <%= hidden_field_tag("#{table.as}[sort]", params[table.as][:sort]) %>
5
+ <% end %>
6
+ <% if params[table.as] and params[table.as][:dir] %>
7
+ <%= hidden_field_tag("#{table.as}[dir]", params[table.as][:dir]) %>
8
+ <% end %>
9
+ <% table.filters.each do |filter| %>
10
+ <%= tableficate_filter_tag filter %>
11
+ <% end %>
12
+
13
+ <%= submit_tag('Filter') %>
14
+ <% end %>
15
+ <% end %>
16
+
17
+ <% if defined? ::Kaminari %>
18
+ <%= paginate(table.rows, param_name: "#{table.as}_page") %>
19
+ <% elsif defined? ::WillPaginate %>
20
+ <%= will_paginate(table.rows, param_name: "#{table.as}_page") %>
21
+ <% end %>
22
+
23
+ <%= content_tag(:table, table.options[:html]) do %>
24
+ <thead>
25
+ <tr>
26
+ <% table.columns.each do |column| %>
27
+ <%= tableficate_header_tag column %>
28
+ <% end %>
29
+ </tr>
30
+ </thead>
31
+ <tbody>
32
+ <% table.rows.each do |row| %>
33
+ <%= tableficate_row_tag row, table.columns %>
34
+ <% end %>
35
+ </tbody>
36
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter) %>
3
+ <%= tableficate_check_box_tags(filter) %>
4
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter) %>
3
+ <%= tableficate_text_field_tag(filter) %>
4
+ </div>
@@ -0,0 +1,6 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter.start) %>
3
+ <%= tableficate_text_field_tag(filter.start) %>
4
+ <%= tableficate_label_tag(filter.stop) %>
5
+ <%= tableficate_text_field_tag(filter.stop) %>
6
+ </div>
@@ -0,0 +1,7 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter) %>
3
+ <%= tableficate_radio_tags(filter) do |choice| %>
4
+ <%= label_tag("#{filter.field_name}[#{choice.value}]", choice.name) %>
5
+ <%= radio_button_tag(filter.field_name, choice.value, choice.checked?, choice.options) %>
6
+ <% end %>
7
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter) %>
3
+ <%= tableficate_select_tag(filter) %>
4
+ </div>
@@ -0,0 +1,6 @@
1
+ <div>
2
+ <%= tableficate_label_tag(filter.start) %>
3
+ <%= tableficate_select_tag(filter.start) %>
4
+ <%= tableficate_label_tag(filter.stop) %>
5
+ <%= tableficate_select_tag(filter.stop) %>
6
+ </div>
@@ -1,58 +1,3 @@
1
1
  TestApp::Application.routes.draw do
2
- # The priority is based upon order of creation:
3
- # first created -> highest priority.
4
-
5
- # Sample of regular route:
6
- # match 'products/:id' => 'catalog#view'
7
- # Keep in mind you can assign values other than :controller and :action
8
-
9
- # Sample of named route:
10
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
- # This route can be invoked with purchase_url(:id => product.id)
12
-
13
- # Sample resource route (maps HTTP verbs to controller actions automatically):
14
- # resources :products
15
-
16
- # Sample resource route with options:
17
- # resources :products do
18
- # member do
19
- # get 'short'
20
- # post 'toggle'
21
- # end
22
- #
23
- # collection do
24
- # get 'sold'
25
- # end
26
- # end
27
-
28
- # Sample resource route with sub-resources:
29
- # resources :products do
30
- # resources :comments, :sales
31
- # resource :seller
32
- # end
33
-
34
- # Sample resource route with more complex sub-resources
35
- # resources :products do
36
- # resources :comments
37
- # resources :sales do
38
- # get 'recent', :on => :collection
39
- # end
40
- # end
41
-
42
- # Sample resource route within a namespace:
43
- # namespace :admin do
44
- # # Directs /admin/products/* to Admin::ProductsController
45
- # # (app/controllers/admin/products_controller.rb)
46
- # resources :products
47
- # end
48
-
49
- # You can have the root of your site routed with "root"
50
- # just remember to delete public/index.html.
51
- # root :to => 'welcome#index'
52
-
53
- # See how all your routes lay out with "rake routes"
54
-
55
- # This is a legacy wild controller route that's not recommended for RESTful applications.
56
- # Note: This route will make all actions in every controller accessible via GET requests.
57
- # match ':controller(/:action(/:id(.:format)))'
2
+ match ':controller(/:action(/:id(.:format)))'
58
3
  end
data/tableficate.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Aaron Lasseigne"]
9
9
  s.email = ["alasseigne@sei-mi.com"]
10
10
  s.homepage = "https://github.com/sei-mi/tableficate"
11
- s.summary = %q{Simple tables for Rails.}
12
- s.description = %q{Simple tables for Rails.}
11
+ s.summary = %q{A DSL for Rails that provides easy table creation with sorting and filtering.}
12
+ s.description = %q{A DSL for Rails that provides easy table creation with sorting and filtering.}
13
13
 
14
14
  s.rubyforge_project = "tableficate"
15
15
 
@@ -22,5 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_development_dependency 'rake'
24
24
  s.add_development_dependency 'rspec'
25
+ s.add_development_dependency 'genspec'
25
26
  s.add_development_dependency 'sqlite3'
27
+ s.add_development_dependency 'capybara'
26
28
  end