8000 Calculating the column styles and margins only if the child element i… · stephancom/activeadmin@5144637 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5144637

Browse files
author
Vineeth B S
committed
Calculating the column styles and margins only if the child element is of type column.
1 parent 48a8674 commit 5144637

File tree

4 files chan 8000 ged

+73
-3
lines changed

4 files changed

+73
-3
lines changed

features/show/columns.feature

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Feature: Show - Columns
2+
3+
Columns in show page
4+
5+
Background:
6+
Given a post with the title "Hello World" written by "Jane Doe" exists
7+
8+
Scenario:
9+
Given a show configuration of:
10+
"""
11+
ActiveAdmin.register Post do
12+
13+
show do
14+
columns do
15+
end
16+
end
17+
18+
end
19+
"""
20+
Then I should see a columns container
21+
And I should see 0 column
22+
23+
Scenario:
24+
Given a show configuration of:
25+
"""
26+
ActiveAdmin.register Post do
27+
28+
show do
29+
columns do
30+
column do
31+
end
32+
column do
33+
end
34+
end
35+
end
36+
37+
end
38+
"""
39+
Then I should see a columns container
40+
And I should see 2 columns
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Then /^I should see a columns container$/ do
2+
expect(page).to have_css '.columns'
3+
end
4+
5+
Then /^I should see (a|\d+) columns?$/ do |count|
6+
count = count == 'a' ? 1 : count.to_i
7+
expect(page).to have_css '.column', count: count
8+
end

lib/active_admin/views/components/columns.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,24 @@ def calculate_columns!
9393
all_margins_width = margin_size * (span_count - 1)
9494
column_width = (100.00 - all_margins_width) / span_count
9595

96-
children.each_with_index do |col, i|
96+
columns.each_with_index do |column, i|
9797
is_last_column = i == (columns_count - 1)
98-
col.set_column_styles(column_width, margin_size, is_last_column)
98+
column.set_column_styles(column_width, margin_size, is_last_column)
9999
end
100100
end
101101

102102
def columns_span_count
103103
count = 0
104-
children.each {|column| count += column.span_size }
104+
columns.each do |column|
105+
count += column.span_size
106+
end
105107

106108
count
107109
end
108110

111+
def columns
112+
children.select { |child| child.is_a?(Column) }
113+
end
109114
end
110115

111116
class Column < ActiveAdmin::Component

spec/unit/views/components/columns_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
describe ActiveAdmin::Views::Columns do
44

5+
describe "Rendering zero columns" do
6+
let(:cols) do
7+
render_arbre_component do
8+
columns do
9+
end
10+
end
11+
end
12+
13+
it "should have the class .columns" do
14+
expect(cols.class_list).to include("columns")
15+
end
16+
17+
it "should have one column" do
18+
expect(cols.children.first.class_list).not_to include("column")
19+
end
20+
end
21+
522
describe "Rendering one column" do
623
let(:cols) do
724
render_arbre_component do

0 commit comments

Comments
 (0)
0