Quillon.Commands.Table (Quillon v0.1.0)

Copy Markdown View Source

Table manipulation commands.

Provides operations for adding and removing rows and columns from tables.

Summary

Functions

Add an empty column to a table at the given index.

Add an empty row to a table at the given index.

Remove a column from a table at the given index.

Remove a row from a table at the given index.

Functions

add_column(arg, index)

@spec add_column(tuple(), non_neg_integer()) :: tuple()

Add an empty column to a table at the given index.

Index 0 inserts at the beginning of each row, index equal to column count appends at the end.

Examples

iex> cell = {:table_cell, %{colspan: 1, rowspan: 1}, []}
iex> row = {:table_row, %{header: false}, [cell]}
iex> table = {:table, %{}, [row]}
iex> {:table, %{}, [updated_row]} = Quillon.Commands.Table.add_column(table, 1)
iex> {:table_row, %{header: false}, cells} = updated_row
iex> length(cells)
2

add_row(arg, index)

@spec add_row(tuple(), non_neg_integer()) :: tuple()

Add an empty row to a table at the given index.

Index 0 inserts at the beginning, index equal to row count appends at the end. The new row will have the same number of cells as existing rows.

Examples

iex> table = {:table, %{}, [{:table_row, %{header: false}, [{:table_cell, %{colspan: 1, rowspan: 1}, []}]}]}
iex> {:table, %{}, rows} = Quillon.Commands.Table.add_row(table, 1)
iex> length(rows)
2

remove_column(arg, index)

@spec remove_column(tuple(), non_neg_integer()) :: tuple()

Remove a column from a table at the given index.

Returns the table unchanged if the index is out of bounds or if it's the last column.

Examples

iex> cell1 = {:table_cell, %{colspan: 1, rowspan: 1}, []}
iex> cell2 = {:table_cell, %{colspan: 1, rowspan: 1}, []}
iex> row = {:table_row, %{header: false}, [cell1, cell2]}
iex> table = {:table, %{}, [row]}
iex> {:table, %{}, [updated_row]} = Quillon.Commands.Table.remove_column(table, 0)
iex> {:table_row, %{header: false}, cells} = updated_row
iex> length(cells)
1

remove_row(arg, index)

@spec remove_row(tuple(), non_neg_integer()) :: tuple()

Remove a row from a table at the given index.

Returns the table unchanged if the index is out of bounds or if it's the last row.

Examples

iex> row1 = {:table_row, %{header: false}, [{:table_cell, %{colspan: 1, rowspan: 1}, []}]}
iex> row2 = {:table_row, %{header: false}, [{:table_cell, %{colspan: 1, rowspan: 1}, []}]}
iex> table = {:table, %{}, [row1, row2]}
iex> {:table, %{}, rows} = Quillon.Commands.Table.remove_row(table, 0)
iex> length(rows)
1