Skip to content

Commit

Permalink
fallback to 0.0 in case of no gutter, fixes #1343
Browse files Browse the repository at this point in the history
Prefer fetch for default value

Co-authored-by: André Jährling <[email protected]>
  • Loading branch information
afdev82 and andreavocado committed Apr 30, 2024
1 parent ce37403 commit bc5375d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/prawn/grid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ def subdivide(total, num, gutter)

def apply_gutter(options)
if options.key?(:gutter)
@gutter = Float(options[:gutter])
@gutter = Float(options.fetch(:gutter, 0.0))
@row_gutter = @gutter
@column_gutter = @gutter
else
@row_gutter = Float(options[:row_gutter])
@column_gutter = Float(options[:column_gutter])
@row_gutter = Float(options.fetch(:row_gutter, 0.0))
@column_gutter = Float(options.fetch(:column_gutter, 0.0))
@gutter = 0
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/prawn/document_grid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
expect(pdf.grid.gutter).to eq(0.1)
end

it 'allows definition of a grid without gutter' do
pdf.define_grid(columns: 3, rows: 5)
expect(pdf.grid.columns).to eq(3)
expect(pdf.grid.rows).to eq(5)
expect(pdf.grid.gutter).to eq(0.0)
end

it 'allows re-definition of a grid' do
pdf.define_grid(columns: 5, rows: 8, gutter: 0.1)
expect(pdf.grid.columns).to eq(5)
Expand Down

0 comments on commit bc5375d

Please sign in to comment.