lib/asciidoctor/table.rb in asciidoctor-1.5.2 vs lib/asciidoctor/table.rb in asciidoctor-1.5.3

- old
+ new

@@ -71,22 +71,22 @@ def initialize parent, attributes super parent, :table @rows = Rows.new @columns = [] - @has_header_option = attributes.has_key? 'header-option' + @has_header_option = attributes.key? 'header-option' # smell like we need a utility method here # to resolve an integer width from potential bogus input pcwidth = attributes['width'] pcwidth_intval = pcwidth.to_i.abs if pcwidth_intval == 0 && pcwidth != '0' || pcwidth_intval > 100 pcwidth_intval = 100 end @attributes['tablepcwidth'] = pcwidth_intval - if @document.attributes.has_key? 'pagewidth' + if @document.attributes.key? 'pagewidth' @attributes['tableabswidth'] ||= ((@attributes['tablepcwidth'].to_f / 100) * @document.attributes['pagewidth']).round end end @@ -134,11 +134,11 @@ # QUESTION why does AsciiDoc use an array for head? is it # possible to have more than one based on the syntax? @rows.head = [head] end - if num_body_rows > 0 && attributes.has_key?('footer-option') + if num_body_rows > 0 && attributes.key?('footer-option') @rows.foot = [@rows.body.pop] end nil end @@ -173,11 +173,11 @@ width = ((@attributes['width'].to_f / total_width) * 100).floor else width = even_width end @attributes['colpcwidth'] = width - if parent.attributes.has_key? 'tableabswidth' + if parent.attributes.key? 'tableabswidth' @attributes['colabswidth'] = ((width.to_f / 100) * parent.attributes['tableabswidth']).round end nil end @@ -213,12 +213,12 @@ end if attributes @colspan = attributes.delete('colspan') @rowspan = attributes.delete('rowspan') # TODO eventualy remove the style attribute from the attributes hash - #@style = attributes.delete('style') if attributes.has_key? 'style' - @style = attributes['style'] if attributes.has_key? 'style' + #@style = attributes.delete('style') if attributes.key? 'style' + @style = attributes['style'] if attributes.key? 'style' update_attributes(attributes) end # only allow AsciiDoc cells in non-header rows if @style == :asciidoc && !column.table.header_row? # FIXME hide doctitle from nested document; temporary workaround to fix @@ -303,11 +303,11 @@ end else @format = Table::DEFAULT_DATA_FORMAT end - @delimiter = if @format == 'psv' && !(attributes.has_key? 'separator') && table.document.nested? + @delimiter = if @format == 'psv' && !(attributes.key? 'separator') && table.document.nested? '!' else attributes['separator'] || Table::DEFAULT_DELIMITERS[@format] end @delimiter_re = /#{Regexp.escape @delimiter}/ @@ -435,17 +435,17 @@ def close_cell(eol = false) cell_text = @buffer.strip @buffer = '' if @format == 'psv' cell_spec = take_cell_spec - if cell_spec.nil? - warn "asciidoctor: ERROR: #{@last_cursor.line_info}: table missing leading separator, recovering automatically" - cell_spec = {} - repeat = 1 - else + if cell_spec repeat = cell_spec.fetch('repeatcol', 1) cell_spec.delete('repeatcol') + else + warn %(asciidoctor: ERROR: #{@last_cursor.line_info}: table missing leading separator, recovering automatically) + cell_spec = {} + repeat = 1 end else cell_spec = nil repeat = 1 if @format == 'csv' @@ -461,20 +461,24 @@ end end end 1.upto(repeat) do |i| - # make column resolving an operation + # TODO make column resolving an operation if @col_count == -1 - @table.columns << (column = Table::Column.new(@table, @current_row.size + i - 1)) - if cell_spec && (cell_spec.has_key? 'colspan') && (extra_cols = cell_spec['colspan'].to_i - 1) > 0 + @table.columns << (column = Table::Column.new(@table, @table.columns.size + i - 1)) + if cell_spec && (cell_spec.key? 'colspan') && (extra_cols = cell_spec['colspan'].to_i - 1) > 0 + offset = @table.columns.size extra_cols.times do |j| - @table.columns << Table::Column.new(@table, @current_row.size + i + j - 1) + @table.columns << Table::Column.new(@table, offset + j) end end else # QUESTION is this right for cells that span columns? - column = @table.columns[@current_row.size] + unless (column = @table.columns[@current_row.size]) + warn %(asciidoctor: ERROR: #{@last_cursor.line_info}: dropping cell because it exceeds specified number of columns) + return + end end cell = Table::Cell.new(column, cell_text, cell_spec, @last_cursor) @last_cursor = @reader.cursor unless !cell.rowspan || cell.rowspan == 1