Skip to content

Commit e503b59

Browse files
committed
Add thead, tbody and tfoot components with specs and docs
1 parent cf82a65 commit e503b59

File tree

8 files changed

+133
-27
lines changed

8 files changed

+133
-27
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%tbody{@tag_attributes}
2+
- if block_given?
3+
= yield
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Matestack::Ui::Core::Tbody
2+
class Tbody < Matestack::Ui::Core::Component::Static
3+
4+
end
5+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%tfoot{@tag_attributes}
2+
- if block_given?
3+
= yield
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Matestack::Ui::Core::Tfoot
2+
class Tfoot < Matestack::Ui::Core::Component::Static
3+
4+
end
5+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%thead{@tag_attributes}
2+
- if block_given?
3+
= yield
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Matestack::Ui::Core::Thead
2+
class Thead < Matestack::Ui::Core::Component::Static
3+
4+
end
5+
end

docs/components/table.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,31 @@ Implementing a simple, hard coded table.
2323

2424
```ruby
2525
table class: "foo" do
26-
tr class: "bar" do
27-
th text: "First"
28-
th text: "Matestack"
29-
th text: "Table"
26+
thead do
27+
tr class: "bar" do
28+
th text: "First"
29+
th text: "Matestack"
30+
th text: "Table"
31+
end
3032
end
31-
tr do
32-
td text: "One"
33-
td text: "Two"
34-
td text: "Three"
33+
tbody do
34+
tr do
35+
td text: "One"
36+
td text: "Two"
37+
td text: "Three"
38+
end
39+
tr do
40+
td text: "Uno"
41+
td text: "Dos"
42+
td text: "Tres"
43+
end
3544
end
36-
tr do
37-
td text: "Uno"
38-
td text: "Dos"
39-
td text: "Tres"
45+
tfoot do
46+
tr do
47+
td text: "Eins"
48+
td text: "Zwei"
49+
td text: "Drei"
50+
end
4051
end
4152
end
4253
```

spec/usage/components/table_th_tr_td_spec.rb renamed to spec/usage/components/table_spec.rb

Lines changed: 86 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require_relative '../../support/utils'
22
include Utils
33

4-
describe 'Table Components table, th, tr, td', type: :feature, js: true do
4+
describe 'Table Components table, th, tr, td, thead, tbody, tfoot', type: :feature, js: true do
55

66
it 'Example 1' do
77

@@ -10,20 +10,31 @@ class ExamplePage < Matestack::Ui::Page
1010
def response
1111
components {
1212
table class: 'foo' do
13-
tr class: 'bar' do
14-
th text: 'First'
15-
th text: 'Matestack'
16-
th text: 'Table'
13+
thead class: 'head' do
14+
tr class: 'bar' do
15+
th text: 'First'
16+
th text: 'Matestack'
17+
th text: 'Table'
18+
end
1719
end
18-
tr do
19-
td text: 'One'
20-
td text: 'Two'
21-
td text: 'Three'
20+
tbody class: 'body' do
21+
tr do
22+
td text: 'One'
23+
td text: 'Two'
24+
td text: 'Three'
25+
end
26+
tr do
27+
td text: 'Uno'
28+
td text: 'Dos'
29+
td text: 'Tres'
30+
end
2231
end
23-
tr do
24-
td text: 'Uno'
25-
td text: 'Dos'
26-
td text: 'Tres'
32+
tfoot class: 'foot' do
33+
tr do
34+
td text: 'Eins'
35+
td text: 'Zwei'
36+
td text: 'Drei'
37+
end
2738
end
2839
end
2940
}
@@ -37,12 +48,14 @@ def response
3748

3849
expected_static_output = <<~HTML
3950
<table class="foo">
40-
<tbody>
51+
<thead class="head">
4152
<tr class="bar">
4253
<th>First</th>
4354
<th>Matestack</th>
4455
<th>Table</th>
4556
</tr>
57+
</thead>
58+
<tbody class="body">
4659
<tr>
4760
<td>One</td>
4861
<td>Two</td>
@@ -54,13 +67,20 @@ def response
5467
<td>Tres</td>
5568
</tr>
5669
</tbody>
70+
<tfoot class="foot">
71+
<tr>
72+
<td>Eins</td>
73+
<td>Zwei</td>
74+
<td>Drei</td>
75+
</tr>
76+
</tfoot>
5777
</table>
5878
HTML
5979

6080
expect(stripped(static_output)).to include(stripped(expected_static_output))
6181
end
6282

63-
it 'Example 2' do
83+
it 'Example 2, when thead, tbody, tfoot are omitted, then tbody is implied' do
6484

6585
class ExamplePage < Matestack::Ui::Page
6686

@@ -137,4 +157,55 @@ def response
137157
expect(stripped(static_output)).to include(stripped(expected_static_output))
138158
end
139159

160+
it 'Example 2, with only thead, then tbody is implied for other rows' do
161+
162+
class ExamplePage < Matestack::Ui::Page
163+
164+
def response
165+
components {
166+
table do
167+
thead do
168+
tr do
169+
th text: 'First'
170+
th text: 'Matestack'
171+
th text: 'Table'
172+
end
173+
end
174+
tr do
175+
td text: 'One'
176+
td text: 'Two'
177+
td text: 'Three'
178+
end
179+
end
180+
}
181+
end
182+
183+
end
184+
185+
visit '/example'
186+
187+
static_output = page.html
188+
189+
expected_static_output = <<~HTML
190+
<table>
191+
<thead>
192+
<tr>
193+
<th>First</th>
194+
<th>Matestack</th>
195+
<th>Table</th>
196+
</tr>
197+
</thead>
198+
<tbody>
199+
<tr>
200+
<td>One</td>
201+
<td>Two</td>
202+
<td>Three</td>
203+
</tr>
204+
</tbody>
205+
</table>
206+
HTML
207+
208+
expect(stripped(static_output)).to include(stripped(expected_static_output))
209+
end
210+
140211
end

0 commit comments

Comments
 (0)