tableficate 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +53 -48
- data/app/views/tableficate/{_column_header.html.erb → _header.html.erb} +0 -0
- data/app/views/tableficate/_table.html.erb +4 -4
- data/app/views/tableficate/filters/_check_box.html.erb +4 -0
- data/app/views/tableficate/{_input_filter.html.erb → filters/_input.html.erb} +0 -0
- data/app/views/tableficate/{_input_range_filter.html.erb → filters/_input_range.html.erb} +0 -0
- data/app/views/tableficate/filters/_radio.html.erb +4 -0
- data/app/views/tableficate/{_select_filter.html.erb → filters/_select.html.erb} +0 -0
- data/app/views/tableficate/filters/_select_range.html.erb +6 -0
- data/changelog.markdown +8 -0
- data/lib/tableficate/action_column.rb +2 -2
- data/lib/tableficate/base.rb +2 -2
- data/lib/tableficate/column.rb +6 -2
- data/lib/tableficate/exceptions.rb +4 -0
- data/lib/tableficate/filters/base.rb +21 -0
- data/lib/tableficate/filters/check_box.rb +6 -0
- data/lib/tableficate/filters/choice.rb +23 -0
- data/lib/tableficate/filters/collection.rb +30 -0
- data/lib/tableficate/filters/input.rb +12 -0
- data/lib/tableficate/filters/input_range.rb +57 -0
- data/lib/tableficate/filters/radio.rb +6 -0
- data/lib/tableficate/filters/select.rb +6 -0
- data/lib/tableficate/filters/select_range.rb +54 -0
- data/lib/tableficate/helper.rb +69 -4
- data/lib/tableficate/table.rb +56 -10
- data/lib/tableficate/version.rb +1 -1
- data/lib/tableficate.rb +9 -3
- data/spec/action_column_spec.rb +1 -1
- data/spec/column_spec.rb +8 -0
- data/spec/filters/base_spec.rb +30 -0
- data/spec/filters/choice_spec.rb +13 -0
- data/spec/filters/collection_spec.rb +94 -0
- data/spec/filters/input_range_spec.rb +91 -0
- data/spec/filters/input_spec.rb +24 -0
- data/spec/generators/tableficate_table_spec.rb +20 -0
- data/spec/generators/tableficate_theme_spec.rb +11 -0
- data/spec/helper_spec.rb +164 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/table_spec.rb +38 -13
- data/spec/test_app/Gemfile +1 -1
- data/spec/test_app/app/controllers/filters_controller.rb +7 -0
- data/spec/test_app/app/views/filters/check_box_tags.html.erb +14 -0
- data/spec/test_app/app/views/filters/multi_select_from_string.html.erb +11 -0
- data/spec/test_app/app/views/filters/multi_select_tag.html.erb +11 -0
- data/spec/test_app/app/views/filters/radio_tags.html.erb +14 -0
- data/spec/test_app/app/views/filters/select_from_string.html.erb +11 -0
- data/spec/test_app/app/views/filters/select_tag.html.erb +11 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_data.html.erb +1 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_header.html.erb +8 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_row.html.erb +5 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_table.html.erb +36 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_check_box.html.erb +7 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_input.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_input_range.html.erb +6 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_radio.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_select.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_select_range_filter.html.erb +6 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/_data.html.erb +1 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/_header.html.erb +8 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/_row.html.erb +5 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/_table.html.erb +36 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_check_box.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_input.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_input_range.html.erb +6 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_radio.html.erb +7 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_select.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_select_range_filter.html.erb +6 -0
- data/spec/test_app/config/routes.rb +1 -56
- data/tableficate.gemspec +4 -2
- metadata +122 -27
- data/lib/tableficate/filters/filter.rb +0 -19
- data/lib/tableficate/filters/input_filters.rb +0 -64
- data/lib/tableficate/filters/select_filter.rb +0 -11
- data/spec/filter_spec.rb +0 -30
- data/spec/input_filter_spec.rb +0 -90
- 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
|
-
|
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
|
69
|
-
@table.
|
70
|
-
@table.
|
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::
|
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
|
78
|
-
@table.
|
79
|
-
|
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::
|
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
|
87
|
-
@table.
|
88
|
-
|
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::
|
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
|
data/spec/test_app/Gemfile
CHANGED
@@ -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,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 @@
|
|
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,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_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>
|
@@ -1,58 +1,3 @@
|
|
1
1
|
TestApp::Application.routes.draw do
|
2
|
-
|
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{
|
12
|
-
s.description = %q{
|
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
|