table_helper 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/Rakefile +1 -1
- data/lib/table_helper/footer.rb +5 -0
- data/lib/table_helper/header.rb +11 -1
- data/test/app_root/app/models/person.rb +2 -0
- data/test/app_root/db/migrate/001_create_people.rb +11 -0
- data/test/test_helper.rb +3 -0
- data/test/unit/footer_test.rb +15 -2
- data/test/unit/header_test.rb +18 -0
- metadata +8 -1
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
== master
|
2
2
|
|
3
|
+
== 0.2.1 / 2009-04-25
|
4
|
+
|
5
|
+
* Automatically determine the colspan for the last footer to match the number of headers
|
6
|
+
* Fix default headers including all model columns when using :select in the collection query
|
7
|
+
|
3
8
|
== 0.2.0 / 2009-04-25
|
4
9
|
|
5
10
|
* Reorganize documentation
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
|
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = 'table_helper'
|
8
|
-
s.version = '0.2.
|
8
|
+
s.version = '0.2.1'
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.summary = 'Adds a helper method for generating HTML tables from collections'
|
11
11
|
|
data/lib/table_helper/footer.rb
CHANGED
@@ -25,6 +25,11 @@ module TableHelper
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def html #:nodoc:
|
28
|
+
# Force the last cell to span the remaining columns
|
29
|
+
cells = row.cells.values
|
30
|
+
colspan = table.header.columns.length - cells[0..-2].inject(0) {|count, (name, cell)| count += (cell[:colspan] || 1).to_i}
|
31
|
+
cells.last[:colspan] ||= colspan if colspan > 1
|
32
|
+
|
28
33
|
html_options = @html_options.dup
|
29
34
|
html_options[:style] = "display: none; #{html_options[:style]}".strip if table.empty? && hide_when_empty
|
30
35
|
|
data/lib/table_helper/header.rb
CHANGED
@@ -33,7 +33,17 @@ module TableHelper
|
|
33
33
|
# pre-fill the header with those columns so that the user doesn't
|
34
34
|
# have to
|
35
35
|
klass = table.klass
|
36
|
-
|
36
|
+
if klass && klass.respond_to?(:column_names)
|
37
|
+
if !table.empty? && klass < ActiveRecord::Base
|
38
|
+
# Make sure only the attributes that have been loaded are used
|
39
|
+
column_names = table.collection.first.attributes.keys
|
40
|
+
else
|
41
|
+
# Assume all attributes are loaded
|
42
|
+
column_names = klass.column_names
|
43
|
+
end
|
44
|
+
|
45
|
+
column(*column_names.map(&:to_sym))
|
46
|
+
end
|
37
47
|
|
38
48
|
@customized = false
|
39
49
|
end
|
data/test/test_helper.rb
CHANGED
@@ -3,6 +3,9 @@ $:.unshift("#{File.dirname(__FILE__)}/../../plugin_test_helper/lib")
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'plugin_test_helper'
|
5
5
|
|
6
|
+
# Run the migrations
|
7
|
+
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
|
8
|
+
|
6
9
|
Test::Unit::TestCase.class_eval do
|
7
10
|
private
|
8
11
|
def assert_html_equal(expected, actual)
|
data/test/unit/footer_test.rb
CHANGED
@@ -44,8 +44,8 @@ end
|
|
44
44
|
|
45
45
|
class FooterWithCellsTest < Test::Unit::TestCase
|
46
46
|
def setup
|
47
|
-
table = TableHelper::CollectionTable.new([Object.new])
|
48
|
-
@footer = TableHelper::Footer.new(table)
|
47
|
+
@table = TableHelper::CollectionTable.new([Object.new])
|
48
|
+
@footer = TableHelper::Footer.new(@table)
|
49
49
|
@cell = @footer.cell :total, 20
|
50
50
|
end
|
51
51
|
|
@@ -63,6 +63,19 @@ class FooterWithCellsTest < Test::Unit::TestCase
|
|
63
63
|
end_str
|
64
64
|
assert_html_equal expected, @footer.html
|
65
65
|
end
|
66
|
+
|
67
|
+
def test_should_include_colspan_if_more_headers_than_footers
|
68
|
+
@table.header :title, :name, :value
|
69
|
+
|
70
|
+
expected = <<-end_str
|
71
|
+
<tfoot>
|
72
|
+
<tr>
|
73
|
+
<td class="object-total" colspan="3">20</td>
|
74
|
+
</tr>
|
75
|
+
</tfoot>
|
76
|
+
end_str
|
77
|
+
assert_html_equal expected, @footer.html
|
78
|
+
end
|
66
79
|
end
|
67
80
|
|
68
81
|
class FooterWithEmptyCollectionTest < Test::Unit::TestCase
|
data/test/unit/header_test.rb
CHANGED
@@ -250,3 +250,21 @@ class HeaderWithCustomHtmlOptionsTest < Test::Unit::TestCase
|
|
250
250
|
assert_html_equal expected, @header.html
|
251
251
|
end
|
252
252
|
end
|
253
|
+
|
254
|
+
class HeaderWithModelsTest < ActiveRecord::TestCase
|
255
|
+
def setup
|
256
|
+
Person.create(:first_name => 'John', :last_name => 'Smith')
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_should_include_all_columns_if_not_selecting_columns
|
260
|
+
table = TableHelper::CollectionTable.new(Person.all)
|
261
|
+
@header = TableHelper::Header.new(table)
|
262
|
+
assert_equal %w(first_name id last_name), @header.column_names.sort
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_should_only_include_selected_columns_if_specified_in_query
|
266
|
+
table = TableHelper::CollectionTable.new(Person.all(:select => 'first_name'))
|
267
|
+
@header = TableHelper::Header.new(table)
|
268
|
+
assert_equal %w(first_name), @header.column_names.sort
|
269
|
+
end
|
270
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
@@ -45,6 +45,13 @@ files:
|
|
45
45
|
- test/unit/row_builder_test.rb
|
46
46
|
- test/helpers
|
47
47
|
- test/helpers/table_helper_test.rb
|
48
|
+
- test/app_root
|
49
|
+
- test/app_root/db
|
50
|
+
- test/app_root/db/migrate
|
51
|
+
- test/app_root/db/migrate/001_create_people.rb
|
52
|
+
- test/app_root/app
|
53
|
+
- test/app_root/app/models
|
54
|
+
- test/app_root/app/models/person.rb
|
48
55
|
- CHANGELOG.rdoc
|
49
56
|
- init.rb
|
50
57
|
- LICENSE
|