Giter Club home page Giter Club logo

Comments (3)

robertpanzer avatar robertpanzer commented on May 24, 2024

Before doing anything in the Java space I played with building an extension in Ruby that would accept the widths.
I had to do this:

    test 'should create table with width' do
      input = 'table::[]'

      begin
        Asciidoctor::Extensions.register do
          block_macro :table do
            process do |parent, target, args|
              table = Asciidoctor::Table.new(parent, {})
              col1 = Asciidoctor::Table::Column.new(table, 0)
              table.columns << col1
              col2 = Asciidoctor::Table::Column.new(table, 1)
              table.columns << col2
              col1.set_attr 'width', 2
              col2.set_attr 'width', 3
              table.assign_column_widths(width_base=5, autowidth_cols=nil)
              table.rows.body << [
                Asciidoctor::Table::Cell.new(col1, 'first'),
                Asciidoctor::Table::Cell.new(col2, 'second')
              ]
              table.set_attr 'rowcount', table.rows.body.length
              table
            end
          end
        end

        output = convert_string_to_embedded input
        assert_equal output, <<~EOM.chomp
        <table class="tableblock frame-all grid-all stretch">
        <colgroup>
        <col width="40%">
        <col width="60%">
        </colgroup>
        <tbody>
        <tr>
        <td class="tableblock halign-left valign-top"><p class="tableblock">first</p></td>
        <td class="tableblock halign-left valign-top"><p class="tableblock">second</p></td>
        </tr>
        </tbody>
        </table>
        EOM
      ensure
        Asciidoctor::Extensions.unregister_all
      end
    end

(Please excuse if any of my Ruby art is making your eyes bleed)

If we just want to mimic the same API in AsciidoctorJ we could just add a method Table.assignColumnWidths().
This would iterate over all existing columns, and sum up the widths that are positive, and collect the columns with a negative width.
Then it would call the Ruby method

table.assign_column_widths(width_base=sum of positive widths, autowidth_cols=[columns with negative width])

I think I would prefer this over doing anything implicitly.

from asciidoctorj.

robertpanzer avatar robertpanzer commented on May 24, 2024

#1270 demonstrates this attempt and it seems to do the trick.

        // Create the table
        Table table = createTable(parent)
        table.grid = 'rows'
        table.title = "Github contributors of $target"

         // Create the columns 'Login' and 'Contributions'
         Column avatarColumn = createTableColumn(table, 0)
         avatarColumn.width = 1
         Column loginColumn = createTableColumn(table, 1)
         loginColumn.width = 2
         Column contributionsColumn = createTableColumn(table, 2)
         contributionsColumn.width = 2
         contributionsColumn.horizontalAlignment = Table.HorizontalAlignment.CENTER
         table.columns << avatarColumn
         table.columns << loginColumn
         table.columns << contributionsColumn
         table.assignColumnWidths()

from asciidoctorj.

mojavelinux avatar mojavelinux commented on May 24, 2024

I think I would prefer this over doing anything implicitly.

Seems reasonable to me!

from asciidoctorj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.