table_helper 0.0.3 → 0.0.4
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.
- data/CHANGELOG +6 -0
- data/README +0 -1
- data/Rakefile +1 -1
- data/lib/table_helper/body.rb +1 -1
- data/lib/table_helper/body_row.rb +1 -1
- data/lib/table_helper/cell.rb +1 -1
- data/lib/table_helper/collection_table.rb +1 -1
- data/lib/table_helper/header.rb +72 -34
- data/lib/table_helper/row.rb +62 -31
- data/test/body_row_test.rb +5 -5
- data/test/header_builder_test.rb +48 -0
- data/test/header_test.rb +32 -12
- data/test/row_builder_test.rb +47 -0
- data/test/row_test.rb +40 -12
- metadata +6 -2
data/CHANGELOG
CHANGED
data/README
CHANGED
data/Rakefile
CHANGED
data/lib/table_helper/body.rb
CHANGED
@@ -94,7 +94,7 @@ module PluginAWeek #:nodoc:
|
|
94
94
|
row = BodyRow.new(object, @header)
|
95
95
|
row.alternate = alternate_rows ? index.send("#{@alternate_rows}?") : false
|
96
96
|
|
97
|
-
yield row, object, index if block_given?
|
97
|
+
yield row.builder, object, index if block_given?
|
98
98
|
|
99
99
|
row.html
|
100
100
|
end
|
data/lib/table_helper/cell.rb
CHANGED
@@ -34,7 +34,7 @@ module PluginAWeek #:nodoc:
|
|
34
34
|
# Indicates what type of content will be stored in this cell. This can
|
35
35
|
# either be set to either :data or :header.
|
36
36
|
def content_type=(value)
|
37
|
-
raise ArgumentError, "content_type must be set to :data or :header, was: #{value.inspect}"
|
37
|
+
raise ArgumentError, "content_type must be set to :data or :header, was: #{value.inspect}" unless [:data, :header].include?(value)
|
38
38
|
@content_type = value
|
39
39
|
end
|
40
40
|
|
data/lib/table_helper/header.rb
CHANGED
@@ -2,11 +2,56 @@ require 'table_helper/row'
|
|
2
2
|
|
3
3
|
module PluginAWeek #:nodoc:
|
4
4
|
module TableHelper
|
5
|
+
# Provides a blank class that can be used to build the columns for a header
|
6
|
+
class HeaderBuilder < BlankSlate
|
7
|
+
reveal :respond_to?
|
8
|
+
|
9
|
+
attr_reader :header
|
10
|
+
|
11
|
+
# Creates a builder for the given header
|
12
|
+
def initialize(header)
|
13
|
+
@header = header
|
14
|
+
end
|
15
|
+
|
16
|
+
# Proxies all missed methods to the header
|
17
|
+
def method_missing(*args)
|
18
|
+
header.send(*args)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Defines the accessor method for the given column name. For example, if
|
22
|
+
# a column with the name :title was defined, then the column would be able
|
23
|
+
# to be read and written like so:
|
24
|
+
#
|
25
|
+
# header.title #=> Accesses the title
|
26
|
+
# header.title "Page Title" #=> Creates a new column with "Page Title" as the content
|
27
|
+
def define_column(name)
|
28
|
+
method_name = name.to_s.gsub('-', '_')
|
29
|
+
|
30
|
+
klass = class << self; self; end
|
31
|
+
klass.class_eval do
|
32
|
+
define_method(method_name) do |*args|
|
33
|
+
header.row.builder.__send__(method_name, *args)
|
34
|
+
end
|
35
|
+
end unless klass.method_defined?(method_name)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Removes the definition for the given cp;i,m
|
39
|
+
def undef_column(name)
|
40
|
+
klass = class << self; self; end
|
41
|
+
klass.class_eval do
|
42
|
+
remove_method(name.gsub('-', '_'))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
5
47
|
# Represents the header of the table. In HTML, you can think of this as
|
6
48
|
# the <thead> tag of the table.
|
7
49
|
class Header < HtmlElement
|
8
50
|
# The actual header row
|
9
|
-
attr_reader
|
51
|
+
attr_reader :row
|
52
|
+
|
53
|
+
# The proxy class used externally to build the actual columns
|
54
|
+
attr_reader :builder
|
10
55
|
|
11
56
|
# Whether or not the header should be hidden when the collection is
|
12
57
|
# empty. Default is true.
|
@@ -23,6 +68,7 @@ module PluginAWeek #:nodoc:
|
|
23
68
|
|
24
69
|
@collection = collection
|
25
70
|
@row = Row.new
|
71
|
+
@builder = HeaderBuilder.new(self)
|
26
72
|
|
27
73
|
@hide_when_empty = true
|
28
74
|
@customized = true
|
@@ -38,11 +84,23 @@ module PluginAWeek #:nodoc:
|
|
38
84
|
end
|
39
85
|
end
|
40
86
|
|
87
|
+
# The current columns in this header, in the order in which they will be built
|
88
|
+
def columns
|
89
|
+
row.cells
|
90
|
+
end
|
91
|
+
|
41
92
|
# Gets the names of all of the columns being displayed in the table
|
42
93
|
def column_names
|
43
94
|
row.cell_names
|
44
95
|
end
|
45
96
|
|
97
|
+
# Clears all of the current columns from the header
|
98
|
+
def clear
|
99
|
+
# Remove all of the shortcut methods
|
100
|
+
column_names.each {|name| builder.undef_column(name)}
|
101
|
+
row.clear
|
102
|
+
end
|
103
|
+
|
46
104
|
# Creates a new column with the specified caption. Columns must be
|
47
105
|
# defined in the order in which they will be rendered.
|
48
106
|
#
|
@@ -61,37 +119,16 @@ module PluginAWeek #:nodoc:
|
|
61
119
|
# header.column :title, 'The Title', :class => 'pretty'
|
62
120
|
def column(name, *args)
|
63
121
|
# Clear the header row if this is being customized by the user
|
64
|
-
|
122
|
+
unless @customized
|
65
123
|
@customized = true
|
66
|
-
|
67
|
-
# Remove all of the shortcut methods
|
68
|
-
column_names.each do |column|
|
69
|
-
klass = class << self; self; end
|
70
|
-
klass.class_eval do
|
71
|
-
remove_method(column)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
@row.clear
|
124
|
+
clear
|
76
125
|
end
|
77
126
|
|
78
|
-
column =
|
127
|
+
column = row.cell(name, *args)
|
79
128
|
column.content_type = :header
|
80
129
|
column[:scope] ||= 'col'
|
81
130
|
|
82
|
-
|
83
|
-
name = name.to_s.gsub('-', '_')
|
84
|
-
unless respond_to?(name)
|
85
|
-
instance_eval <<-end_eval
|
86
|
-
def #{name}(*args)
|
87
|
-
if args.empty?
|
88
|
-
@row.#{name}
|
89
|
-
else
|
90
|
-
@row.#{name}(*args)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end_eval
|
94
|
-
end
|
131
|
+
builder.define_column(name)
|
95
132
|
|
96
133
|
column
|
97
134
|
end
|
@@ -105,14 +142,7 @@ module PluginAWeek #:nodoc:
|
|
105
142
|
end
|
106
143
|
|
107
144
|
private
|
108
|
-
|
109
|
-
'thead'
|
110
|
-
end
|
111
|
-
|
112
|
-
def content
|
113
|
-
@row.html
|
114
|
-
end
|
115
|
-
|
145
|
+
# Finds the class representing the objects within the collection
|
116
146
|
def class_for_collection(collection)
|
117
147
|
if collection.respond_to?(:proxy_reflection)
|
118
148
|
collection.proxy_reflection.klass
|
@@ -120,6 +150,14 @@ module PluginAWeek #:nodoc:
|
|
120
150
|
collection.first.class
|
121
151
|
end
|
122
152
|
end
|
153
|
+
|
154
|
+
def tag_name
|
155
|
+
'thead'
|
156
|
+
end
|
157
|
+
|
158
|
+
def content
|
159
|
+
@row.html
|
160
|
+
end
|
123
161
|
end
|
124
162
|
end
|
125
163
|
end
|
data/lib/table_helper/row.rb
CHANGED
@@ -2,13 +2,68 @@ require 'table_helper/cell'
|
|
2
2
|
|
3
3
|
module PluginAWeek #:nodoc:
|
4
4
|
module TableHelper
|
5
|
+
# Provides a blank class that can be used to build the cells for a row
|
6
|
+
class RowBuilder < BlankSlate
|
7
|
+
reveal :respond_to?
|
8
|
+
|
9
|
+
attr_reader :row
|
10
|
+
|
11
|
+
# Creates a builder for the given row
|
12
|
+
def initialize(row)
|
13
|
+
@row = row
|
14
|
+
end
|
15
|
+
|
16
|
+
# Proxies all missed methods to the row
|
17
|
+
def method_missing(*args)
|
18
|
+
row.send(*args)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Defines the builder method for the given cell name. For example, if
|
22
|
+
# a cell with the name :title was defined, then the cell would be able
|
23
|
+
# to be read and written like so:
|
24
|
+
#
|
25
|
+
# row.title #=> Accesses the title
|
26
|
+
# row.title "Page Title" #=> Creates a new cell with "Page Title" as the content
|
27
|
+
def define_cell(name)
|
28
|
+
method_name = name.gsub('-', '_')
|
29
|
+
|
30
|
+
klass = class << self; self; end
|
31
|
+
klass.class_eval do
|
32
|
+
define_method(method_name) do |*args|
|
33
|
+
if args.empty?
|
34
|
+
row.cells[name]
|
35
|
+
else
|
36
|
+
row.cell(name, *args)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end unless klass.method_defined?(method_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Removes the definition for the given cell
|
43
|
+
def undef_cell(name)
|
44
|
+
method_name = name.gsub('-', '_')
|
45
|
+
|
46
|
+
klass = class << self; self; end
|
47
|
+
klass.class_eval do
|
48
|
+
remove_method(method_name)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
5
53
|
# Represents a single row within a table. A row can consist of either
|
6
54
|
# data cells or header cells.
|
7
55
|
class Row < HtmlElement
|
56
|
+
# The proxy class used externally to build the actual cells
|
57
|
+
attr_reader :builder
|
58
|
+
|
59
|
+
# The current cells in this row, in the order in which they will be built
|
60
|
+
attr_reader :cells
|
61
|
+
|
8
62
|
def initialize #:nodoc:
|
9
63
|
super
|
10
64
|
|
11
65
|
@cells = ActiveSupport::OrderedHash.new
|
66
|
+
@builder = RowBuilder.new(self)
|
12
67
|
end
|
13
68
|
|
14
69
|
# Creates a new cell with the given name and generates shortcut
|
@@ -17,55 +72,31 @@ module PluginAWeek #:nodoc:
|
|
17
72
|
name = name.to_s if name
|
18
73
|
|
19
74
|
cell = Cell.new(name, *args)
|
20
|
-
|
21
|
-
|
22
|
-
define_cell_accessor(name) if name && !respond_to?(name)
|
75
|
+
cells[name] = cell
|
76
|
+
builder.define_cell(name) if name
|
23
77
|
|
24
78
|
cell
|
25
79
|
end
|
26
80
|
|
27
81
|
# The names of all cells in this row
|
28
82
|
def cell_names
|
29
|
-
|
83
|
+
cells.keys
|
30
84
|
end
|
31
85
|
|
32
86
|
# Clears all of the current cells from the row
|
33
87
|
def clear
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
remove_method(name)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
@cells.clear
|
88
|
+
# Remove all of the shortcut methods
|
89
|
+
cell_names.each {|name| builder.undef_cell(name)}
|
90
|
+
cells.clear
|
42
91
|
end
|
43
92
|
|
44
93
|
private
|
45
|
-
# Defines the accessor method for the given cell name. For example, if
|
46
|
-
# a cell with the name :title was defined, then the cell would be able
|
47
|
-
# to be read and written like so:
|
48
|
-
#
|
49
|
-
# row.title #=> Accesses the title
|
50
|
-
# row.title "Page Title" #=> Creates a new cell with "Page Title" as the content
|
51
|
-
def define_cell_accessor(name)
|
52
|
-
instance_eval <<-end_eval
|
53
|
-
def #{name.gsub('-', '_')}(*args)
|
54
|
-
if args.empty?
|
55
|
-
@cells[#{name.inspect}]
|
56
|
-
else
|
57
|
-
cell(#{name.inspect}, *args)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end_eval
|
61
|
-
end
|
62
|
-
|
63
94
|
def tag_name
|
64
95
|
'tr'
|
65
96
|
end
|
66
97
|
|
67
98
|
def content
|
68
|
-
|
99
|
+
cells.values.map(&:html).join
|
69
100
|
end
|
70
101
|
end
|
71
102
|
end
|
data/test/body_row_test.rb
CHANGED
@@ -29,11 +29,11 @@ class BodyRowTest < Test::Unit::TestCase
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_should_generate_cell_accessors
|
32
|
-
|
32
|
+
assert_nothing_raised {@row.builder.title}
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_should_override_default_cell_content_if_cell_specified
|
36
|
-
@row.title 'Hello World'
|
36
|
+
@row.builder.title 'Hello World'
|
37
37
|
assert_equal '<tr class="row"><td class="title">Hello World</td></tr>', @row.html
|
38
38
|
end
|
39
39
|
end
|
@@ -64,7 +64,7 @@ class BodyRowWithCustomAttributeTest < Test::Unit::TestCase
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_should_use_attribute_values_as_cell_content
|
67
|
-
@row.author_name 'John Doe'
|
67
|
+
@row.builder.author_name 'John Doe'
|
68
68
|
assert_equal '<tr class="row"><td class="title">Default Value</td><td class="author_name">John Doe</td></tr>', @row.html
|
69
69
|
end
|
70
70
|
end
|
@@ -82,12 +82,12 @@ class BodyRowWithMissingCellsTest < Test::Unit::TestCase
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_should_skip_missing_cells_if_colspan_replaces_missing_cells
|
85
|
-
@row.title 'Hello World', :colspan => 2
|
85
|
+
@row.builder.title 'Hello World', :colspan => 2
|
86
86
|
assert_equal '<tr class="row"><td class="title" colspan="2">Hello World</td></tr>', @row.html
|
87
87
|
end
|
88
88
|
|
89
89
|
def test_should_not_skip_missing_cells_if_colspan_doesnt_replace_missing_cells
|
90
|
-
@row.title 'Hello World'
|
90
|
+
@row.builder.title 'Hello World'
|
91
91
|
assert_equal '<tr class="row"><td class="title">Hello World</td><td class="author_name empty"></td></tr>', @row.html
|
92
92
|
end
|
93
93
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class HeaderBuilderByDefaultTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@header = PluginAWeek::TableHelper::Header.new([])
|
6
|
+
@builder = PluginAWeek::TableHelper::HeaderBuilder.new(@header)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_forward_missing_calls_to_row
|
10
|
+
assert_equal '<thead style="display: none;"><tr></tr></thead>', @builder.html
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class HeaderBuilderWithColumnsTest < Test::Unit::TestCase
|
15
|
+
def setup
|
16
|
+
@header = PluginAWeek::TableHelper::Header.new([])
|
17
|
+
@header.row.cell 'first-name'
|
18
|
+
|
19
|
+
@builder = PluginAWeek::TableHelper::HeaderBuilder.new(@header)
|
20
|
+
@builder.define_column('first-name')
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_should_create_column_reader
|
24
|
+
assert_nothing_raised {@builder.first_name}
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_read_column_without_arguments
|
28
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, @builder.first_name
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_write_cell_with_arguments
|
32
|
+
@builder.first_name 'Your Name'
|
33
|
+
assert_equal '<td class="first-name">Your Name</td>', @header.row.cells['first-name'].html
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class RowBuilderAfterUndefiningAColumnTest < Test::Unit::TestCase
|
38
|
+
def setup
|
39
|
+
@header = PluginAWeek::TableHelper::Header.new([])
|
40
|
+
@builder = PluginAWeek::TableHelper::HeaderBuilder.new(@header)
|
41
|
+
@builder.define_column('first-name')
|
42
|
+
@builder.undef_column('first-name')
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_not_have_cell_reader
|
46
|
+
assert_raise(NoMethodError) {@builder.first_name}
|
47
|
+
end
|
48
|
+
end
|
data/test/header_test.rb
CHANGED
@@ -56,11 +56,11 @@ class HeaderTest < Test::Unit::TestCase
|
|
56
56
|
def test_should_create_column_readers_if_column_names_found
|
57
57
|
header = PluginAWeek::TableHelper::Header.new([], Post)
|
58
58
|
|
59
|
-
|
60
|
-
assert_instance_of PluginAWeek::TableHelper::Cell, header.title
|
59
|
+
assert_nothing_raised {header.builder.title}
|
60
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, header.builder.title
|
61
61
|
|
62
|
-
|
63
|
-
assert_instance_of PluginAWeek::TableHelper::Cell, header.author_name
|
62
|
+
assert_nothing_raised {header.builder.title}
|
63
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, header.builder.author_name
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_should_create_column_reader_when_column_is_created
|
@@ -68,33 +68,33 @@ class HeaderTest < Test::Unit::TestCase
|
|
68
68
|
header.column :title
|
69
69
|
|
70
70
|
assert_equal ['title'], header.column_names
|
71
|
-
assert_instance_of PluginAWeek::TableHelper::Cell, header.title
|
71
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, header.builder.title
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_should_set_column_scope
|
75
75
|
header = PluginAWeek::TableHelper::Header.new([])
|
76
76
|
header.column :title
|
77
|
-
assert_equal 'col', header.title[:scope]
|
77
|
+
assert_equal 'col', header.columns['title'][:scope]
|
78
78
|
end
|
79
79
|
|
80
80
|
def test_should_allow_html_options_to_be_specified_for_new_columns
|
81
81
|
header = PluginAWeek::TableHelper::Header.new([])
|
82
82
|
header.column :title, 'Title', :class => 'pretty'
|
83
|
-
assert_equal 'title pretty', header.title[:class]
|
83
|
+
assert_equal 'title pretty', header.columns['title'][:class]
|
84
84
|
end
|
85
85
|
|
86
86
|
def test_should_use_column_name_for_default_content
|
87
87
|
header = PluginAWeek::TableHelper::Header.new([])
|
88
88
|
header.column :title
|
89
|
-
assert_equal '<th class="title" scope="col">Title</th>', header.title.html
|
89
|
+
assert_equal '<th class="title" scope="col">Title</th>', header.columns['title'].html
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_should_sanitize_column_names
|
93
93
|
header = PluginAWeek::TableHelper::Header.new([])
|
94
94
|
header.column 'the-title'
|
95
95
|
|
96
|
-
|
97
|
-
assert_instance_of PluginAWeek::TableHelper::Cell, header.the_title
|
96
|
+
assert_nothing_raised {header.builder.the_title}
|
97
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, header.builder.the_title
|
98
98
|
end
|
99
99
|
|
100
100
|
def test_should_clear_existing_columns_when_first_column_is_created
|
@@ -103,8 +103,8 @@ class HeaderTest < Test::Unit::TestCase
|
|
103
103
|
|
104
104
|
header.column :created_on
|
105
105
|
|
106
|
-
|
107
|
-
|
106
|
+
assert_raise(NoMethodError) {header.builder.title}
|
107
|
+
assert_raise(NoMethodError) {header.builder.author_name}
|
108
108
|
assert_equal ['created_on'], header.column_names
|
109
109
|
end
|
110
110
|
|
@@ -139,6 +139,26 @@ class HeaderTest < Test::Unit::TestCase
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
+
class HeaderWithConflictingColumnNamesTest < Test::Unit::TestCase
|
143
|
+
def setup
|
144
|
+
@header = PluginAWeek::TableHelper::Header.new([])
|
145
|
+
@header.column 'id'
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_should_be_able_to_read_cell
|
149
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, @header.builder.id
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_should_be_able_to_write_to_cell
|
153
|
+
@header.builder.id '1'
|
154
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, @header.builder.id
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_should_be_able_to_clear
|
158
|
+
assert_nothing_raised {@header.clear}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
142
162
|
class HeaderWithEmptyCollectionTest < Test::Unit::TestCase
|
143
163
|
def setup
|
144
164
|
@header = PluginAWeek::TableHelper::Header.new([])
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class RowBuilderByDefaultTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@row = PluginAWeek::TableHelper::Row.new
|
6
|
+
@builder = PluginAWeek::TableHelper::RowBuilder.new(@row)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_forward_missing_calls_to_row
|
10
|
+
assert_equal '<tr></tr>', @builder.html
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class RowBuilderWithCellsTest < Test::Unit::TestCase
|
15
|
+
def setup
|
16
|
+
@row = PluginAWeek::TableHelper::Row.new
|
17
|
+
@builder = PluginAWeek::TableHelper::RowBuilder.new(@row)
|
18
|
+
@builder.define_cell('first-name')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_create_cell_reader
|
22
|
+
assert_nothing_raised {@builder.first_name}
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_read_cell_without_arguments
|
26
|
+
@row.cells['first-name'] = PluginAWeek::TableHelper::Cell.new('first-name')
|
27
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, @builder.first_name
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_write_cell_with_arguments
|
31
|
+
@builder.first_name 'Your Name'
|
32
|
+
assert_equal '<td class="first-name">Your Name</td>', @row.cells['first-name'].html
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class RowBuilderAfterUndefiningACellTest < Test::Unit::TestCase
|
37
|
+
def setup
|
38
|
+
@row = PluginAWeek::TableHelper::Row.new
|
39
|
+
@builder = PluginAWeek::TableHelper::RowBuilder.new(@row)
|
40
|
+
@builder.define_cell('first-name')
|
41
|
+
@builder.undef_cell('first-name')
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_not_have_cell_reader
|
45
|
+
assert_raise(NoMethodError) {@builder.first_name}
|
46
|
+
end
|
47
|
+
end
|
data/test/row_test.rb
CHANGED
@@ -10,44 +10,52 @@ class RowByDefaultTest < Test::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_should_not_have_any_cells
|
13
|
+
assert @row.cells.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_not_have_any_cell_names
|
13
17
|
assert_equal [], @row.cell_names
|
14
18
|
end
|
19
|
+
|
20
|
+
def test_should_have_a_builder
|
21
|
+
assert_not_nil @row.builder
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
|
-
|
18
25
|
class RowTest < Test::Unit::TestCase
|
19
26
|
def setup
|
20
27
|
@row = PluginAWeek::TableHelper::Row.new
|
21
28
|
end
|
22
29
|
|
23
|
-
def
|
30
|
+
def test_should_create_cell_reader_after_building_cell
|
24
31
|
@row.cell :name
|
25
|
-
|
26
|
-
assert_instance_of PluginAWeek::TableHelper::Cell, @row.name
|
32
|
+
assert_nothing_raised {@row.builder.name}
|
33
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, @row.builder.name
|
27
34
|
end
|
28
35
|
|
29
36
|
def test_should_use_cell_name_for_class_name
|
30
37
|
@row.cell :name
|
31
|
-
assert_equal 'name', @row.name[:class]
|
38
|
+
assert_equal 'name', @row.cells['name'][:class]
|
32
39
|
end
|
33
40
|
|
34
41
|
def test_should_sanitize_cell_name_for_reader_method
|
35
42
|
@row.cell 'the-name'
|
36
43
|
|
37
|
-
|
38
|
-
|
44
|
+
@row.builder.the_name
|
45
|
+
assert_nothing_raised {@row.builder.the_name}
|
46
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, @row.builder.the_name
|
39
47
|
end
|
40
48
|
|
41
49
|
def test_should_use_unsanitized_cell_name_for_cell_class
|
42
50
|
@row.cell 'the-name'
|
43
51
|
assert_equal ['the-name'], @row.cell_names
|
44
|
-
assert_equal 'the-name', @row.
|
52
|
+
assert_equal 'the-name', @row.cells['the-name'][:class]
|
45
53
|
end
|
46
54
|
|
47
55
|
def test_should_allow_html_options_when_building_cell
|
48
56
|
@row.cell :name, 'Name', :class => 'pretty'
|
49
57
|
|
50
|
-
assert_equal 'name pretty', @row.name[:class]
|
58
|
+
assert_equal 'name pretty', @row.cells['name'][:class]
|
51
59
|
end
|
52
60
|
end
|
53
61
|
|
@@ -87,10 +95,10 @@ class RowWithCellsTest < Test::Unit::TestCase
|
|
87
95
|
end
|
88
96
|
|
89
97
|
def test_should_create_new_cell_if_cell_already_exists
|
90
|
-
old_cell = @row.name
|
98
|
+
old_cell = @row.cells['name']
|
91
99
|
|
92
100
|
@row.cell :name
|
93
|
-
assert_not_same old_cell, @row.name
|
101
|
+
assert_not_same old_cell, @row.cells['name']
|
94
102
|
end
|
95
103
|
|
96
104
|
def test_should_be_able_to_read_cell_after_clearing
|
@@ -98,7 +106,7 @@ class RowWithCellsTest < Test::Unit::TestCase
|
|
98
106
|
@row.cell :name
|
99
107
|
|
100
108
|
assert_equal ['name'], @row.cell_names
|
101
|
-
|
109
|
+
assert_nothing_raised {@row.builder.name}
|
102
110
|
end
|
103
111
|
end
|
104
112
|
|
@@ -113,3 +121,23 @@ class RowWithMultipleCellsTest < Test::Unit::TestCase
|
|
113
121
|
assert_equal '<tr><td class="name">Name</td><td class="location">Location</td></tr>', @row.html
|
114
122
|
end
|
115
123
|
end
|
124
|
+
|
125
|
+
class RowWithConflictingCellNamesTest < Test::Unit::TestCase
|
126
|
+
def setup
|
127
|
+
@row = PluginAWeek::TableHelper::Row.new
|
128
|
+
@row.cell :id
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_should_be_able_to_read_cell
|
132
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, @row.cells['id']
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_should_be_able_to_write_to_cell
|
136
|
+
@row.builder.id '1'
|
137
|
+
assert_instance_of PluginAWeek::TableHelper::Cell, @row.cells['id']
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_should_be_able_to_clear
|
141
|
+
assert_nothing_raised {@row.clear}
|
142
|
+
end
|
143
|
+
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.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
@@ -9,7 +9,7 @@ autorequire: table_helper
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-06-
|
12
|
+
date: 2008-06-15 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -33,10 +33,12 @@ files:
|
|
33
33
|
- lib/table_helper/cell.rb
|
34
34
|
- lib/table_helper/body_row.rb
|
35
35
|
- test/header_test.rb
|
36
|
+
- test/header_builder_test.rb
|
36
37
|
- test/collection_table_test.rb
|
37
38
|
- test/test_helper.rb
|
38
39
|
- test/row_test.rb
|
39
40
|
- test/footer_test.rb
|
41
|
+
- test/row_builder_test.rb
|
40
42
|
- test/body_row_test.rb
|
41
43
|
- test/cell_test.rb
|
42
44
|
- test/html_element_test.rb
|
@@ -75,9 +77,11 @@ specification_version: 2
|
|
75
77
|
summary: Adds a helper method for generating HTML tables from collections
|
76
78
|
test_files:
|
77
79
|
- test/header_test.rb
|
80
|
+
- test/header_builder_test.rb
|
78
81
|
- test/collection_table_test.rb
|
79
82
|
- test/row_test.rb
|
80
83
|
- test/footer_test.rb
|
84
|
+
- test/row_builder_test.rb
|
81
85
|
- test/body_row_test.rb
|
82
86
|
- test/cell_test.rb
|
83
87
|
- test/html_element_test.rb
|