hyper-kitten-tables 0.1.1.alpha1.01 → 0.1.1.alpha1.02
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a7cc7e1640ed688e557f128a119a29b3b0c3fa23e7d72c780e25c0a0fb0d475
|
4
|
+
data.tar.gz: b73418d323c3b21fff12db386cdaf0a92acc004f4f312efe295bd4d02b4648bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99f943366db9398c96c42e8821994e3a0c700b09910082eda245246115675d61e40be67dac33dcf2aa6b206f591fd6889a536250e363157acc6a5af636d14755
|
7
|
+
data.tar.gz: 52be614b4aa8fb97b96cfb5d741b91794d622bf2111fa5812fae6db26fae8083694e9f4f55d2778e0874bce7e3a7a02964fa740f59756dfdeb03f45d9a39fd2d
|
@@ -11,11 +11,12 @@ module HyperKittenTables
|
|
11
11
|
|
12
12
|
def_delegators :@view_context, :content_tag, :capture, :request
|
13
13
|
|
14
|
-
const_set :Column, Struct.new(:name, :method_name, :sort_key, :block, :sortable, :options)
|
14
|
+
const_set :Column, Struct.new(:name, :method_name, :sort_key, :block, :sortable, :options, :header_options)
|
15
15
|
end
|
16
16
|
|
17
|
-
def initialize(collection: [], requested_columns: [], &block)
|
17
|
+
def initialize(collection: [], requested_columns: [], sortable_column_default: false, &block)
|
18
18
|
@collection = collection
|
19
|
+
@sortable_column_default = sortable_column_default
|
19
20
|
@columns = []
|
20
21
|
|
21
22
|
@table_options = {}
|
@@ -28,13 +29,13 @@ module HyperKittenTables
|
|
28
29
|
yield self if block_given?
|
29
30
|
end
|
30
31
|
|
31
|
-
def td(name, method_name: nil, sort_key: nil, sortable:
|
32
|
+
def td(name, method_name: nil, sort_key: nil, sortable: @sortable_column_default, header_options: {}, **options, &block)
|
32
33
|
if method_name.nil?
|
33
34
|
method_name = name.to_s.parameterize.underscore
|
34
35
|
name = name.to_s.titleize unless block_given?
|
35
36
|
end
|
36
37
|
sort_key = method_name if sort_key.blank?
|
37
|
-
@columns << self.class::Column.new(name, method_name, sort_key, block, sortable, options)
|
38
|
+
@columns << self.class::Column.new(name, method_name, sort_key, block, sortable, options, header_options)
|
38
39
|
end
|
39
40
|
|
40
41
|
def define_header_sort_url(&block)
|
@@ -93,12 +94,13 @@ module HyperKittenTables
|
|
93
94
|
content_tag(:thead, @thead_options) do
|
94
95
|
content_tag(:tr, @tr_options) do
|
95
96
|
visible_columns.map do |column|
|
97
|
+
header_options = @th_options.merge(column.header_options)
|
96
98
|
if column.sortable
|
97
|
-
content_tag(:th,
|
99
|
+
content_tag(:th, header_options) do
|
98
100
|
header_sort_url(column, query_params).html_safe
|
99
101
|
end
|
100
102
|
else
|
101
|
-
content_tag(:th, column.name,
|
103
|
+
content_tag(:th, column.name, header_options)
|
102
104
|
end
|
103
105
|
end.join.html_safe
|
104
106
|
end
|
@@ -26,12 +26,17 @@ RSpec.describe HyperKittenTables::Components::Table do
|
|
26
26
|
it "with custom column options" do
|
27
27
|
user = User.new("Hyper Kitten")
|
28
28
|
component = described_class.new(collection: [user]) do |table|
|
29
|
-
table.td(:name, sortable: false, class: "custom-class")
|
29
|
+
table.td(:name, sortable: false, class: "custom-class", header_options: { class: "custom-class" })
|
30
30
|
end
|
31
31
|
|
32
|
-
render component
|
32
|
+
response = render component
|
33
33
|
|
34
34
|
assert_select "table" do
|
35
|
+
assert_select "thead" do
|
36
|
+
assert_select "tr" do
|
37
|
+
assert_select "th.custom-class", text: "Name"
|
38
|
+
end
|
39
|
+
end
|
35
40
|
assert_select "tbody" do
|
36
41
|
assert_select "tr" do
|
37
42
|
assert_select "td.custom-class", text: "Hyper Kitten"
|
@@ -168,6 +173,43 @@ RSpec.describe HyperKittenTables::Components::Table do
|
|
168
173
|
end
|
169
174
|
end
|
170
175
|
|
176
|
+
it "with global sortable default set to false" do
|
177
|
+
component = described_class.new(collection: [], requested_columns: ["Name"], sortable_column_default: false) do |table|
|
178
|
+
table.td(:name)
|
179
|
+
end
|
180
|
+
|
181
|
+
html = render component
|
182
|
+
|
183
|
+
assert_select "table" do
|
184
|
+
assert_select "thead" do
|
185
|
+
assert_select "tr" do
|
186
|
+
assert_select "th", text: "Name"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
it "with global sortable default set to true" do
|
193
|
+
component = described_class.new(collection: [], requested_columns: ["Name"], sortable_column_default: true) do |table|
|
194
|
+
table.define_header_sort_url { |c, p| "<a href='example.com'>#{c.name}</a>" }
|
195
|
+
table.td(:name)
|
196
|
+
end
|
197
|
+
|
198
|
+
html = render component
|
199
|
+
|
200
|
+
assert_select "table" do
|
201
|
+
assert_select "thead" do
|
202
|
+
assert_select "tr" do
|
203
|
+
assert_select "th" do
|
204
|
+
assert_select "a", text: "Name" do
|
205
|
+
assert_select "[href=?]", "example.com"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
171
213
|
it "with a footer " do
|
172
214
|
component = described_class.new(collection: []) do |table|
|
173
215
|
table.td(:name, sortable: false)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyper-kitten-tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.1.alpha1.
|
4
|
+
version: 0.1.1.alpha1.02
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Klina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|