table-for 3.1.5 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -2
- data/Gemfile +1 -1
- data/Gemfile.lock +8 -6
- data/README.rdoc +2 -2
- data/VERSION +1 -1
- data/app/views/table_for/_table_for.html.erb +4 -16
- data/lib/table_for.rb +7 -13
- data/lib/table_for/base.rb +91 -2
- data/lib/table_for/engine.rb +0 -1
- data/spec/integration/table_for_spec.rb +2 -1
- data/spec/table_for/{helper_methods_spec.rb → base_spec.rb} +72 -17
- data/spec/table_for/view_additions_spec.rb +1 -1
- data/table-for.gemspec +6 -7
- metadata +6 -7
- data/lib/table_for/helper_methods.rb +0 -101
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
3.2.0
|
2
|
+
* Changed the way configuration is done for TableFor. It is still done through TableFor.setup {|config|}, but some of the options have changed. Namely, the new configuration options are thead_tag, tbody_tag, tfoot_tag. If you do not want thead, tbody, or tfoot tags to be rendered, you can specify this in the setup block as follows: TableFor.setup {|config| config.thead_tag = nil; config.tbody_tag = nil; config.tfoot_tag = nil }. In addition, you can also globally define styles for the table as follows: TableFor.setup {|config| config.table_html = {:class => "table striped"}}. This undoes what was was released in 2.1.0
|
3
|
+
|
1
4
|
3.1.5
|
2
|
-
* Added automatic internationalization (thanks killthekitten)
|
5
|
+
* Added automatic internationalization (thanks {killthekitten}[https://github.com/killthekitten])
|
3
6
|
|
4
7
|
3.1.0
|
5
8
|
* Since templating was moved from blocks into its own gem with_template, TableFor::Base now extends WithTemplate::Base instead of Blocks::Base.
|
@@ -36,4 +39,4 @@
|
|
36
39
|
|
37
40
|
1.1.0 (February 4, 2012)
|
38
41
|
|
39
|
-
* Removed dependency on rails 3.1, switched to >= 3.0.0
|
42
|
+
* Removed dependency on rails 3.1, switched to >= 3.0.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -29,11 +29,12 @@ GEM
|
|
29
29
|
i18n (= 0.6.1)
|
30
30
|
multi_json (~> 1.0)
|
31
31
|
arel (3.0.2)
|
32
|
-
blocks (2.
|
33
|
-
call_with_params
|
32
|
+
blocks (2.6.3)
|
33
|
+
call_with_params (~> 0.0.2)
|
34
|
+
hashie
|
34
35
|
rails (>= 3.0.0)
|
35
36
|
builder (3.0.4)
|
36
|
-
call_with_params (0.0.
|
37
|
+
call_with_params (0.0.2)
|
37
38
|
activesupport (>= 3.0.0)
|
38
39
|
columnize (0.3.6)
|
39
40
|
debugger (1.6.1)
|
@@ -45,6 +46,7 @@ GEM
|
|
45
46
|
diff-lcs (1.2.1)
|
46
47
|
erubis (2.7.0)
|
47
48
|
git (1.2.5)
|
49
|
+
hashie (2.0.5)
|
48
50
|
hike (1.2.1)
|
49
51
|
i18n (0.6.1)
|
50
52
|
jeweler (1.8.4)
|
@@ -121,8 +123,8 @@ GEM
|
|
121
123
|
with_model (0.2.6)
|
122
124
|
activerecord (>= 2.3.5, < 4.0.0)
|
123
125
|
rspec (< 3)
|
124
|
-
with_template (0.0.
|
125
|
-
blocks (~> 2.
|
126
|
+
with_template (0.0.6)
|
127
|
+
blocks (~> 2.6.3)
|
126
128
|
rails (>= 3.0.0)
|
127
129
|
xml-simple (1.1.1)
|
128
130
|
|
@@ -139,5 +141,5 @@ DEPENDENCIES
|
|
139
141
|
sqlite3
|
140
142
|
supermodel (= 0.1.4)
|
141
143
|
with_model (= 0.2.6)
|
142
|
-
with_template (~> 0.0.
|
144
|
+
with_template (~> 0.0.6)
|
143
145
|
xml-simple (= 1.1.1)
|
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@ TableFor is a table builder for a collection of domain objects. It very easily a
|
|
6
6
|
|
7
7
|
In <b>Rails 3 or Rails 4</b>, add this to your Gemfile.
|
8
8
|
|
9
|
-
gem "table-for"
|
9
|
+
gem "table-for"
|
10
10
|
|
11
11
|
== Example
|
12
12
|
The following example is purposely complex (in many cases, there are easier ways to do what is shown) in order to show a wide range of features that TableFor is capable of:
|
@@ -164,4 +164,4 @@ Then, +table-for+ will automatically catch up correct translations for column he
|
|
164
164
|
|
165
165
|
<%= table_for @users do |table| %>
|
166
166
|
<% table.column :parent_name, header: "Mr. Smith" %>
|
167
|
-
<% end %>
|
167
|
+
<% end %>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.2.0
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% table.define :table do |options| %>
|
2
|
-
<%= content_tag :table,
|
2
|
+
<%= content_tag :table, options[:table_html] do %>
|
3
3
|
<%= table.render :header %>
|
4
4
|
<%= table.render :body %>
|
5
5
|
<%# Purposely no default implementation for the tfoot block given, since most tables do not have footers (provided to for easy hook to add a footer). %>
|
@@ -8,11 +8,7 @@
|
|
8
8
|
<% end %>
|
9
9
|
|
10
10
|
<% table.define :header do |options| %>
|
11
|
-
|
12
|
-
<%= content_tag :thead, options[:thead_html] do %>
|
13
|
-
<%= table.render :header_row %>
|
14
|
-
<% end %>
|
15
|
-
<% else %>
|
11
|
+
<%= table.content_tag_with_block options[:thead_tag], options[:thead_html] do %>
|
16
12
|
<%= table.render :header_row %>
|
17
13
|
<% end %>
|
18
14
|
<% end %>
|
@@ -35,11 +31,7 @@
|
|
35
31
|
<% end %>
|
36
32
|
|
37
33
|
<% table.define :body do |options| %>
|
38
|
-
|
39
|
-
<%= content_tag :tbody, options[:tbody_html] do %>
|
40
|
-
<%= table.render :data_row, :collection => records %>
|
41
|
-
<% end %>
|
42
|
-
<% else %>
|
34
|
+
<%= table.content_tag_with_block options[:tbody_tag], options[:tbody_html] do %>
|
43
35
|
<%= table.render :data_row, :collection => records %>
|
44
36
|
<% end %>
|
45
37
|
<% end %>
|
@@ -63,11 +55,7 @@
|
|
63
55
|
<% end %>
|
64
56
|
|
65
57
|
<% table.define :footer do |options| %>
|
66
|
-
|
67
|
-
<%= content_tag :tfoot, options[:tfoot_html] do %>
|
68
|
-
<%= table.render :footer_row %>
|
69
|
-
<% end %>
|
70
|
-
<% else %>
|
58
|
+
<%= table.content_tag_with_block options[:tfoot_tag], options[:tfoot_html] do %>
|
71
59
|
<%= table.render :footer_row %>
|
72
60
|
<% end %>
|
73
61
|
<% end if table.defined?(:footer_content) %>
|
data/lib/table_for.rb
CHANGED
@@ -5,23 +5,17 @@ require "table_for/engine"
|
|
5
5
|
module TableFor
|
6
6
|
autoload :Base, "table_for/base"
|
7
7
|
autoload :ViewAdditions, "table_for/view_additions"
|
8
|
-
autoload :HelperMethods, "table_for/helper_methods"
|
9
8
|
|
10
|
-
mattr_accessor :
|
11
|
-
@@
|
12
|
-
|
13
|
-
|
14
|
-
@@
|
15
|
-
|
16
|
-
mattr_accessor :render_tbody_element
|
17
|
-
@@render_tbody_element = true
|
18
|
-
|
19
|
-
mattr_accessor :render_tfoot_element
|
20
|
-
@@render_tfoot_element = true
|
9
|
+
mattr_accessor :config
|
10
|
+
@@config = Hashie::Mash.new
|
11
|
+
# set these to nil in setup block if you do not want thead, tbody, or tfoot tags rendered
|
12
|
+
@@config.thead_tag = :thead
|
13
|
+
@@config.tbody_tag = :tbody
|
14
|
+
@@config.tfoot_tag = :tfoot
|
21
15
|
|
22
16
|
# Default way to setup TableFor
|
23
17
|
def self.setup
|
24
|
-
yield
|
18
|
+
yield config
|
25
19
|
end
|
26
20
|
end
|
27
21
|
|
data/lib/table_for/base.rb
CHANGED
@@ -3,12 +3,101 @@ require 'blocks'
|
|
3
3
|
|
4
4
|
module TableFor
|
5
5
|
class Base < WithTemplate::Base
|
6
|
-
include TableFor::HelperMethods::InstanceMethods
|
7
|
-
|
8
6
|
alias columns queued_blocks
|
9
7
|
alias column queue
|
10
8
|
|
11
9
|
attr_accessor :current_record
|
12
10
|
alias_method :current_row, :current_record
|
11
|
+
|
12
|
+
def initialize(view, options={})
|
13
|
+
super(view, TableFor.config.merge(options))
|
14
|
+
end
|
15
|
+
|
16
|
+
def header(name, options={}, &block)
|
17
|
+
define("#{name.to_s}_header", options.reverse_merge(:header => true), &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def footer(options={}, &block)
|
21
|
+
define(:footer_content, options, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def header_column_html(column, options={})
|
25
|
+
header_column_html = call_each_hash_value_with_params(options[:header_column_html], column)
|
26
|
+
if options[:sortable]
|
27
|
+
order = options[:order] ? options[:order].to_s : column.name.to_s
|
28
|
+
sort_class = (view.params[:order] != order || view.params[:sort_mode] == "reset") ? "sorting" : (view.params[:sort_mode] == "desc" ? "sorting_desc" : "sorting_asc")
|
29
|
+
header_column_html[:class] = (header_column_html[:class] ? "#{header_column_html[:class]} #{sort_class}" : sort_class)
|
30
|
+
end
|
31
|
+
header_column_html
|
32
|
+
end
|
33
|
+
|
34
|
+
def header_cell_content(column, options={})
|
35
|
+
unless options[:header] == false
|
36
|
+
header_sort_link(column, options) do
|
37
|
+
if options[:header]
|
38
|
+
call_with_params options[:header], column
|
39
|
+
elsif column.anonymous
|
40
|
+
nil
|
41
|
+
else
|
42
|
+
I18n.t("#{translation_lookup_prefix}.#{column.name.to_s.underscore}", :default => column.name.to_s.titleize)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def cell_content(record, column, options={})
|
49
|
+
if options[:link_url] || options[:link_action] || options[:link_method] || options[:link_confirm] || options[:link]
|
50
|
+
url = options[:link_url] ? call_with_params(options[:link_url], record) : [options[:link_action], options[:link_namespace], record].flatten
|
51
|
+
end
|
52
|
+
|
53
|
+
if options[:formatter]
|
54
|
+
if options[:formatter].is_a?(Proc)
|
55
|
+
content = call_with_params(options[:formatter], record.send(column.name), options)
|
56
|
+
else
|
57
|
+
content = record.send(column.name).try(*options[:formatter])
|
58
|
+
end
|
59
|
+
elsif options[:data] || [:edit, :show, :delete].include?(column.name)
|
60
|
+
content = call_with_params(options[:data], record)
|
61
|
+
else
|
62
|
+
content = record.send(column.name)
|
63
|
+
end
|
64
|
+
|
65
|
+
if content.blank? || url.blank? || options[:link] == false
|
66
|
+
content
|
67
|
+
elsif url
|
68
|
+
view.link_to content, url, {:method => options[:link_method], :confirm => options[:link_confirm]}.merge(options[:link_html])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def set_current_record(record)
|
73
|
+
self.current_record = record
|
74
|
+
end
|
75
|
+
|
76
|
+
def header_sort_link(column, options={}, &block)
|
77
|
+
if options[:sortable] && (options[:header] || !column.anonymous)
|
78
|
+
order = options[:order] ? options[:order].to_s : column.name.to_s
|
79
|
+
sort_mode = (view.params[:order] != order || view.params[:sort_mode] == "reset") ? "asc" : (view.params[:sort_mode] == "desc" ? "reset" : "desc")
|
80
|
+
parameters = view.params.merge(:order => order, :sort_mode => sort_mode)
|
81
|
+
parameters.delete(:action)
|
82
|
+
parameters.delete(:controller)
|
83
|
+
url = options[:sort_url] ? options[:sort_url] : ""
|
84
|
+
view.link_to view.capture(self, &block), "#{url}?#{parameters.to_query}"
|
85
|
+
else
|
86
|
+
view.capture(self, &block)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
def translation_lookup_prefix
|
92
|
+
if global_options[:records].respond_to?(:model)
|
93
|
+
"activerecord.attributes.#{global_options[:records].model.to_s.underscore}"
|
94
|
+
elsif global_options[:records].all? {|record| record.is_a?(ActiveRecord::Base) && record.class == global_options[:records].first.class }
|
95
|
+
"activerecord.attributes.#{global_options[:records].first.class.to_s.underscore}"
|
96
|
+
elsif global_options[:records].all? {|record| record.class == global_options[:records].first.class }
|
97
|
+
"tables.columns.#{global_options[:records].first.class.to_s.underscore}"
|
98
|
+
else
|
99
|
+
"tables.columns"
|
100
|
+
end
|
101
|
+
end
|
13
102
|
end
|
14
103
|
end
|
data/lib/table_for/engine.rb
CHANGED
@@ -85,7 +85,7 @@ describe "table_for" do
|
|
85
85
|
|
86
86
|
it "should translate column names" do
|
87
87
|
rails_4_active_record_array = @users[0, 1].clone
|
88
|
-
|
88
|
+
Array.any_instance.expects(:model => User)
|
89
89
|
I18n.expects(:t).with("activerecord.attributes.user.first_name", :default => "First Name").returns("Vorname")
|
90
90
|
buffer = @view.table_for rails_4_active_record_array do |table|
|
91
91
|
table.column :first_name
|
@@ -93,6 +93,7 @@ describe "table_for" do
|
|
93
93
|
xml = XmlSimple.xml_in(%%<table><thead><tr><th>Vorname</th></tr></thead><tbody><tr><td>Andrew</td></tr></tbody></table>%)
|
94
94
|
XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
|
95
95
|
|
96
|
+
Array.any_instance.stubs(:respond_to? => false)
|
96
97
|
I18n.expects(:t).with("activerecord.attributes.user.first_name", :default => "First Name").returns("Vorname2")
|
97
98
|
buffer = @view.table_for @users[0,1] do |table|
|
98
99
|
table.column :first_name
|
@@ -1,58 +1,113 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe TableFor::
|
3
|
+
describe TableFor::Base do
|
4
4
|
before(:each) do
|
5
5
|
@view_class = Class.new
|
6
6
|
@view = @view_class.new
|
7
7
|
@view_class.send(:include, Blocks::ViewAdditions::ClassMethods)
|
8
|
-
@
|
8
|
+
@base = TableFor::Base.new(@view)
|
9
9
|
@records = [OpenStruct.new(:id => 1)]
|
10
10
|
@column = stub(:name => :my_column, :anonymous => false)
|
11
11
|
end
|
12
12
|
|
13
|
-
describe "
|
13
|
+
describe "#header" do
|
14
|
+
it "should define a block with the specified options and force header to be present" do
|
15
|
+
proc = Proc.new {}
|
16
|
+
@base.header(:first_name, :option_1 => 10, :option2 => "abcd", &proc)
|
17
|
+
block = @base.blocks[:first_name_header]
|
18
|
+
block.should be_present
|
19
|
+
block.should be_a(Blocks::Container)
|
20
|
+
block.block.should eql(proc)
|
21
|
+
block.options.should eql(:option_1 => 10, :option2 => "abcd", :header => true)
|
22
|
+
|
23
|
+
@base.header(:last_name, :header => "LAST NAME", &proc)
|
24
|
+
block = @base.blocks[:last_name_header]
|
25
|
+
block.should be_present
|
26
|
+
block.should be_a(Blocks::Container)
|
27
|
+
block.block.should eql(proc)
|
28
|
+
block.options.should eql(:header => "LAST NAME")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not require options to be passed" do
|
32
|
+
proc = Proc.new {}
|
33
|
+
@base.header(:last_name, &proc)
|
34
|
+
block = @base.blocks[:last_name_header]
|
35
|
+
block.should be_present
|
36
|
+
block.should be_a(Blocks::Container)
|
37
|
+
block.block.should eql(proc)
|
38
|
+
block.options.should eql(:header => true)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#footer" do
|
43
|
+
it "should define a block named footer_content with the specified options" do
|
44
|
+
proc = Proc.new {}
|
45
|
+
@base.footer :option_1 => "First Option", &proc
|
46
|
+
block = @base.blocks[:footer_content]
|
47
|
+
block.should be_present
|
48
|
+
block.should be_a(Blocks::Container)
|
49
|
+
block.block.should eql(proc)
|
50
|
+
block.options.should eql(:option_1 => "First Option")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not require options to be passed" do
|
54
|
+
proc = Proc.new {}
|
55
|
+
@base.footer(&proc)
|
56
|
+
block = @base.blocks[:footer_content]
|
57
|
+
block.should be_present
|
58
|
+
block.should be_a(Blocks::Container)
|
59
|
+
block.block.should eql(proc)
|
60
|
+
block.options.should eql({})
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# describe "#table_html" do
|
65
|
+
#
|
66
|
+
# end
|
67
|
+
|
68
|
+
describe "#header_column_html" do
|
14
69
|
it "should return an empty hash if header_column_html is not passed in" do
|
15
|
-
header_column_html = @
|
70
|
+
header_column_html = @base.header_column_html(@column)
|
16
71
|
header_column_html.should eql({})
|
17
72
|
end
|
18
73
|
|
19
74
|
it "should evaluate any procs for header_column_html" do
|
20
|
-
header_column_html = @
|
75
|
+
header_column_html = @base.header_column_html(@column, :header_column_html => {:class => lambda {|column| "#{column.name}_header"}})
|
21
76
|
header_column_html[:class].should eql "#{@column.name}_header"
|
22
77
|
end
|
23
78
|
|
24
79
|
it "should join the 'sorting' class with any other header_column_html class provided" do
|
25
80
|
@view.expects(:params).returns({})
|
26
|
-
header_column_html = @
|
81
|
+
header_column_html = @base.header_column_html(@column, :header_column_html => {:class => "c1 c2"}, :sortable => true)
|
27
82
|
header_column_html[:class].should eql "c1 c2 sorting"
|
28
83
|
end
|
29
84
|
|
30
85
|
it "should add a 'sorting' class to the header_column_html class if a column is sortable" do
|
31
86
|
@view.expects(:params).returns({})
|
32
|
-
header_column_html = @
|
87
|
+
header_column_html = @base.header_column_html(@column, :sortable => true)
|
33
88
|
header_column_html[:class].should eql "sorting"
|
34
89
|
end
|
35
90
|
|
36
91
|
it "should add a 'sorting_asc' class to the header_column_html class if a column is sortable and it is already sorted in asc order" do
|
37
92
|
@view.expects(:params).at_least_once.returns(:order => @column.name.to_s, :sort_mode => "asc")
|
38
|
-
header_column_html = @
|
93
|
+
header_column_html = @base.header_column_html(@column, :sortable => true)
|
39
94
|
header_column_html[:class].should eql "sorting_asc"
|
40
95
|
end
|
41
96
|
|
42
97
|
it "should add a 'sorting_desc' class to the header_column_html class if a column is sortable and it is already sorted in desc order" do
|
43
98
|
@view.expects(:params).at_least_once.returns(:order => @column.name.to_s, :sort_mode => "desc")
|
44
|
-
header_column_html = @
|
99
|
+
header_column_html = @base.header_column_html(@column, :sortable => true)
|
45
100
|
header_column_html[:class].should eql "sorting_desc"
|
46
101
|
end
|
47
102
|
|
48
103
|
it "should add a 'sorting' class to the header_column_html class if a column is sortable and it is reset mode" do
|
49
104
|
@view.expects(:params).at_least_once.returns(:order => @column.name.to_s, :sort_mode => "reset")
|
50
|
-
header_column_html = @
|
105
|
+
header_column_html = @base.header_column_html(@column, :sortable => true)
|
51
106
|
header_column_html[:class].should eql "sorting"
|
52
107
|
end
|
53
108
|
end
|
54
109
|
|
55
|
-
describe "header_sort_link
|
110
|
+
describe "#header_sort_link" do
|
56
111
|
before(:each) do
|
57
112
|
@view.stubs(:capture).returns(@column.name.to_s.titleize)
|
58
113
|
end
|
@@ -60,37 +115,37 @@ describe TableFor::HelperMethods do
|
|
60
115
|
it "should be able to generate a sort link for a column if that column is sortable" do
|
61
116
|
@view.expects(:params).at_least_once.returns({})
|
62
117
|
@view.expects(:link_to).with(@column.name.to_s.titleize, "?order=#{@column.name}&sort_mode=asc").returns "my link"
|
63
|
-
@
|
118
|
+
@base.header_sort_link(@column, :sortable => true).should eql "my link"
|
64
119
|
end
|
65
120
|
|
66
121
|
it "should be able to generate a sort link for a column if that column is sortable and it is already sorted in asc order" do
|
67
122
|
@view.expects(:params).at_least_once.returns(:order => @column.name.to_s, :sort_mode => "asc")
|
68
123
|
@view.expects(:link_to).with(@column.name.to_s.titleize, "?order=#{@column.name}&sort_mode=desc").returns "my link"
|
69
|
-
@
|
124
|
+
@base.header_sort_link(@column, :sortable => true).should eql "my link"
|
70
125
|
end
|
71
126
|
|
72
127
|
it "should be able to generate a sort link for a column if that column is sortable and it is already sorted in desc order" do
|
73
128
|
@view.expects(:params).at_least_once.returns(:order => @column.name.to_s, :sort_mode => "desc")
|
74
129
|
@view.expects(:link_to).with(@column.name.to_s.titleize, "?order=#{@column.name}&sort_mode=reset").returns "my link"
|
75
|
-
@
|
130
|
+
@base.header_sort_link(@column, :sortable => true).should eql "my link"
|
76
131
|
end
|
77
132
|
|
78
133
|
it "should be able specify the sort_url for a sort link" do
|
79
134
|
@view.expects(:params).at_least_once.returns({})
|
80
135
|
@view.expects(:link_to).with(@column.name.to_s.titleize, "/users?order=#{@column.name}&sort_mode=asc").returns "my link"
|
81
|
-
@
|
136
|
+
@base.header_sort_link(@column, :sort_url => "/users", :sortable => true).should eql "my link"
|
82
137
|
end
|
83
138
|
|
84
139
|
it "should be able specify the order field for a sort link" do
|
85
140
|
@view.expects(:params).at_least_once.returns({})
|
86
141
|
@view.expects(:link_to).with(@column.name.to_s.titleize, "?order=first_name%2Clast_name&sort_mode=asc").returns "my link"
|
87
|
-
@
|
142
|
+
@base.header_sort_link(@column, :order => "first_name,last_name", :sortable => true).should eql "my link"
|
88
143
|
end
|
89
144
|
|
90
145
|
it "should remove the action and controller params when generating the url" do
|
91
146
|
@view.expects(:params).at_least_once.returns(:controller => "users", :action => "show")
|
92
147
|
@view.expects(:link_to).with(@column.name.to_s.titleize, "?order=#{@column.name}&sort_mode=asc").returns "my link"
|
93
|
-
@
|
148
|
+
@base.header_sort_link(@column, :sortable => true) { @column.name.to_s.titleize }.should eql "my link"
|
94
149
|
end
|
95
150
|
end
|
96
151
|
end
|
@@ -11,7 +11,7 @@ describe TableFor::ViewAdditions do
|
|
11
11
|
@column = stub(:name => :my_column)
|
12
12
|
end
|
13
13
|
|
14
|
-
describe "table_for
|
14
|
+
describe "#table_for" do
|
15
15
|
it "should call render_template on the TableFor::Base instance" do
|
16
16
|
TableFor::Base.expects(:new).returns(mock(:render_template => ""))
|
17
17
|
@view.table_for(@records)
|
data/table-for.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "table-for"
|
8
|
-
s.version = "3.
|
8
|
+
s.version = "3.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Hunter"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-11-04"
|
13
13
|
s.description = "table-for is a table builder for an array of objects, easily allowing overriding of how any aspect of the table is generated"
|
14
14
|
s.email = "hunterae@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,12 +32,11 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/table_for.rb",
|
33
33
|
"lib/table_for/base.rb",
|
34
34
|
"lib/table_for/engine.rb",
|
35
|
-
"lib/table_for/helper_methods.rb",
|
36
35
|
"lib/table_for/view_additions.rb",
|
37
36
|
"rails/init.rb",
|
38
37
|
"spec/integration/table_for_spec.rb",
|
39
38
|
"spec/spec_helper.rb",
|
40
|
-
"spec/table_for/
|
39
|
+
"spec/table_for/base_spec.rb",
|
41
40
|
"spec/table_for/view_additions_spec.rb",
|
42
41
|
"table-for.gemspec"
|
43
42
|
]
|
@@ -52,7 +51,7 @@ Gem::Specification.new do |s|
|
|
52
51
|
|
53
52
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
53
|
s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
|
55
|
-
s.add_runtime_dependency(%q<with_template>, ["~> 0.0.
|
54
|
+
s.add_runtime_dependency(%q<with_template>, ["~> 0.0.6"])
|
56
55
|
s.add_development_dependency(%q<rspec-rails>, [">= 2.0.0.beta.20"])
|
57
56
|
s.add_development_dependency(%q<mocha>, ["= 0.10.3"])
|
58
57
|
s.add_development_dependency(%q<xml-simple>, ["= 1.1.1"])
|
@@ -64,7 +63,7 @@ Gem::Specification.new do |s|
|
|
64
63
|
s.add_development_dependency(%q<debugger>, [">= 0"])
|
65
64
|
else
|
66
65
|
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
67
|
-
s.add_dependency(%q<with_template>, ["~> 0.0.
|
66
|
+
s.add_dependency(%q<with_template>, ["~> 0.0.6"])
|
68
67
|
s.add_dependency(%q<rspec-rails>, [">= 2.0.0.beta.20"])
|
69
68
|
s.add_dependency(%q<mocha>, ["= 0.10.3"])
|
70
69
|
s.add_dependency(%q<xml-simple>, ["= 1.1.1"])
|
@@ -77,7 +76,7 @@ Gem::Specification.new do |s|
|
|
77
76
|
end
|
78
77
|
else
|
79
78
|
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
80
|
-
s.add_dependency(%q<with_template>, ["~> 0.0.
|
79
|
+
s.add_dependency(%q<with_template>, ["~> 0.0.6"])
|
81
80
|
s.add_dependency(%q<rspec-rails>, [">= 2.0.0.beta.20"])
|
82
81
|
s.add_dependency(%q<mocha>, ["= 0.10.3"])
|
83
82
|
s.add_dependency(%q<xml-simple>, ["= 1.1.1"])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table-for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.0.
|
37
|
+
version: 0.0.6
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.0.
|
45
|
+
version: 0.0.6
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: rspec-rails
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -211,12 +211,11 @@ files:
|
|
211
211
|
- lib/table_for.rb
|
212
212
|
- lib/table_for/base.rb
|
213
213
|
- lib/table_for/engine.rb
|
214
|
-
- lib/table_for/helper_methods.rb
|
215
214
|
- lib/table_for/view_additions.rb
|
216
215
|
- rails/init.rb
|
217
216
|
- spec/integration/table_for_spec.rb
|
218
217
|
- spec/spec_helper.rb
|
219
|
-
- spec/table_for/
|
218
|
+
- spec/table_for/base_spec.rb
|
220
219
|
- spec/table_for/view_additions_spec.rb
|
221
220
|
- table-for.gemspec
|
222
221
|
homepage: http://github.com/hunterae/table-for
|
@@ -234,7 +233,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
234
233
|
version: '0'
|
235
234
|
segments:
|
236
235
|
- 0
|
237
|
-
hash:
|
236
|
+
hash: -2937228185400889819
|
238
237
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
238
|
none: false
|
240
239
|
requirements:
|
@@ -1,101 +0,0 @@
|
|
1
|
-
module TableFor
|
2
|
-
module HelperMethods
|
3
|
-
module InstanceMethods
|
4
|
-
def header(name, options={}, &block)
|
5
|
-
define("#{name.to_s}_header", options.reverse_merge(:header => true), &block)
|
6
|
-
end
|
7
|
-
|
8
|
-
def footer(options={}, &block)
|
9
|
-
define(:footer_content, options, &block)
|
10
|
-
end
|
11
|
-
|
12
|
-
def table_html(options)
|
13
|
-
if options[:table_html]
|
14
|
-
options[:table_html].reverse_merge!(:class => TableFor.default_table_class) if TableFor.default_table_class
|
15
|
-
options[:table_html]
|
16
|
-
elsif TableFor.default_table_class
|
17
|
-
{:class => TableFor.default_table_class}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def header_column_html(column, options={})
|
22
|
-
header_column_html = call_each_hash_value_with_params(options[:header_column_html], column)
|
23
|
-
if options[:sortable]
|
24
|
-
order = options[:order] ? options[:order].to_s : column.name.to_s
|
25
|
-
sort_class = (view.params[:order] != order || view.params[:sort_mode] == "reset") ? "sorting" : (view.params[:sort_mode] == "desc" ? "sorting_desc" : "sorting_asc")
|
26
|
-
header_column_html[:class] = (header_column_html[:class] ? "#{header_column_html[:class]} #{sort_class}" : sort_class)
|
27
|
-
end
|
28
|
-
header_column_html
|
29
|
-
end
|
30
|
-
|
31
|
-
def header_cell_content(column, options={})
|
32
|
-
unless options[:header] == false
|
33
|
-
header_sort_link(column, options) do
|
34
|
-
if options[:header]
|
35
|
-
call_with_params options[:header], column
|
36
|
-
elsif column.anonymous
|
37
|
-
nil
|
38
|
-
else
|
39
|
-
I18n.t("#{translation_lookup_prefix}.#{column.name.to_s.underscore}", :default => column.name.to_s.titleize)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def cell_content(record, column, options={})
|
46
|
-
if options[:link_url] || options[:link_action] || options[:link_method] || options[:link_confirm] || options[:link]
|
47
|
-
url = options[:link_url] ? call_with_params(options[:link_url], record) : [options[:link_action], options[:link_namespace], record].flatten
|
48
|
-
end
|
49
|
-
|
50
|
-
if options[:formatter]
|
51
|
-
if options[:formatter].is_a?(Proc)
|
52
|
-
content = call_with_params(options[:formatter], record.send(column.name), options)
|
53
|
-
else
|
54
|
-
content = record.send(column.name).try(*options[:formatter])
|
55
|
-
end
|
56
|
-
elsif options[:data] || [:edit, :show, :delete].include?(column.name)
|
57
|
-
content = call_with_params(options[:data], record)
|
58
|
-
else
|
59
|
-
content = record.send(column.name)
|
60
|
-
end
|
61
|
-
|
62
|
-
if content.blank? || url.blank? || options[:link] == false
|
63
|
-
content
|
64
|
-
elsif url
|
65
|
-
view.link_to content, url, {:method => options[:link_method], :confirm => options[:link_confirm]}.merge(options[:link_html])
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def set_current_record(record)
|
70
|
-
self.current_record = record
|
71
|
-
end
|
72
|
-
|
73
|
-
def header_sort_link(column, options={}, &block)
|
74
|
-
if options[:sortable] && (options[:header] || !column.anonymous)
|
75
|
-
order = options[:order] ? options[:order].to_s : column.name.to_s
|
76
|
-
sort_mode = (view.params[:order] != order || view.params[:sort_mode] == "reset") ? "asc" : (view.params[:sort_mode] == "desc" ? "reset" : "desc")
|
77
|
-
parameters = view.params.merge(:order => order, :sort_mode => sort_mode)
|
78
|
-
parameters.delete(:action)
|
79
|
-
parameters.delete(:controller)
|
80
|
-
url = options[:sort_url] ? options[:sort_url] : ""
|
81
|
-
view.link_to view.capture(self, &block), "#{url}?#{parameters.to_query}"
|
82
|
-
else
|
83
|
-
view.capture(self, &block)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
private
|
88
|
-
def translation_lookup_prefix
|
89
|
-
if global_options[:records].respond_to?(:model)
|
90
|
-
"activerecord.attributes.#{global_options[:records].model.to_s.underscore}"
|
91
|
-
elsif global_options[:records].all? {|record| record.is_a?(ActiveRecord::Base) && record.class == global_options[:records].first.class }
|
92
|
-
"activerecord.attributes.#{global_options[:records].first.class.to_s.underscore}"
|
93
|
-
elsif global_options[:records].all? {|record| record.class == global_options[:records].first.class }
|
94
|
-
"tables.columns.#{global_options[:records].first.class.to_s.underscore}"
|
95
|
-
else
|
96
|
-
"tables.columns"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|