Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indent bug for tables without headers (issue piotrmurach/tty-table/issues/45) #44

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/tty/table/renderer/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ def render_data
# @api private
def render_header(row, data_border)
top_line = data_border.top_line
return top_line unless row.is_a?(TTY::Table::Header)
unless row.is_a?(TTY::Table::Header)
return Indentation.indent(top_line, @indent)
end
header = [top_line, data_border.row_line(row)]
if !border.separator || border.separator?(0)
header << data_border.middle_line
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/renderer/ascii/indentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@
end
end
end

RSpec.describe TTY::Table::Renderer::ASCII, 'indentation without headers' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

it "indents top border correctly" do
table = TTY::Table.new
table << ["a1","a2","a3"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/WordArray: Use %w or %W for an array of words.
Layout/SpaceAfterComma: Space missing after comma.

table << ["b1","b2","b3"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/WordArray: Use %w or %W for an array of words.
Layout/SpaceAfterComma: Space missing after comma.

expect(table.render(:ascii, indent: 3)).to eql([
" +--+--+--+",
" |a1|a2|a3|",
" |b1|b2|b3|",
" +--+--+--+"
].join("\n"))
end
end