diff --git a/CHANGELOG.md b/CHANGELOG.md index 618b33c..22e2aee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # [v0.1.1](https://github.com/JamesxX/dining-table/releases/tags/v0.1.1) ## Added +- `.make(..args)` now takes `header` (none, auto, array) and `footer` (none, array) as arguments ## Removed diff --git a/src/impl.typ b/src/impl.typ index 2db4df6..47e34b1 100644 --- a/src/impl.typ +++ b/src/impl.typ @@ -134,6 +134,8 @@ #let make( columns: (), data: (), + header: auto, + footer: none, hline: none, toprule: toprule, midrule: midrule, @@ -171,11 +173,18 @@ columns: query-result.map( it=>{if it.width.value != none {it.width.value} else {auto}} ), - table.header( - table.hline(stroke: toprule), - ..build-header(columns, max-depth: max-depth), - table.hline(stroke: midrule, y: max-depth), - ), + ..(if header != none { + (table.hline(stroke: toprule, y:0),) + (table.header( + ..if header == auto{ + build-header(columns, max-depth: max-depth) + (table.hline(stroke: midrule, y: max-depth),) + } else { + header + (table.hline(stroke: midrule),) + } + ),) + } else {(table.hline(stroke: toprule, y:0),)}), ..args, ..( for entry in data{ @@ -187,7 +196,13 @@ if hline != none {(hline,)} } ), - table.hline(stroke: bottomrule) + if footer == none {table.hline(stroke: bottomrule)} else { + table.footer( + table.hline(stroke: midrule), + ..footer, + table.hline(stroke: bottomrule) + ) + } ) + if (notes != none) {note.display-style(notes)} // ADDED } diff --git a/tests/topdown/footer/ref/1.png b/tests/topdown/footer/ref/1.png new file mode 100644 index 0000000..27fcd28 Binary files /dev/null and b/tests/topdown/footer/ref/1.png differ diff --git a/tests/topdown/footer/ref/2.png b/tests/topdown/footer/ref/2.png new file mode 100644 index 0000000..df48e51 Binary files /dev/null and b/tests/topdown/footer/ref/2.png differ diff --git a/tests/topdown/footer/ref/3.png b/tests/topdown/footer/ref/3.png new file mode 100644 index 0000000..fbb8f2b Binary files /dev/null and b/tests/topdown/footer/ref/3.png differ diff --git a/tests/topdown/footer/ref/4.png b/tests/topdown/footer/ref/4.png new file mode 100644 index 0000000..7076228 Binary files /dev/null and b/tests/topdown/footer/ref/4.png differ diff --git a/tests/topdown/footer/test.typ b/tests/topdown/footer/test.typ new file mode 100644 index 0000000..8fff703 --- /dev/null +++ b/tests/topdown/footer/test.typ @@ -0,0 +1,23 @@ +#import "../ledger.typ": * +#set text(size: 11pt) +#set page(height: 5cm, margin: 1em) +#dining-table.make(columns: example, + footer: none, + data: data, + notes: dining-table.note.display-list +) + +#v(0.5cm) + +#dining-table.make(columns: example, + footer: ( + table.cell( + colspan: 3, fill: none, + align(right, strong(smallcaps[total])), + ), + [#{7*100}],[00], + [#{7*99}],[00] + ), + data: data, + notes: dining-table.note.display-list +) \ No newline at end of file diff --git a/tests/topdown/header-none/ref/1.png b/tests/topdown/header-none/ref/1.png new file mode 100644 index 0000000..ee0b271 Binary files /dev/null and b/tests/topdown/header-none/ref/1.png differ diff --git a/tests/topdown/header-none/ref/2.png b/tests/topdown/header-none/ref/2.png new file mode 100644 index 0000000..50d5ead Binary files /dev/null and b/tests/topdown/header-none/ref/2.png differ diff --git a/tests/topdown/header-none/ref/3.png b/tests/topdown/header-none/ref/3.png new file mode 100644 index 0000000..d363c02 Binary files /dev/null and b/tests/topdown/header-none/ref/3.png differ diff --git a/tests/topdown/header-none/ref/4.png b/tests/topdown/header-none/ref/4.png new file mode 100644 index 0000000..ac20c22 Binary files /dev/null and b/tests/topdown/header-none/ref/4.png differ diff --git a/tests/topdown/header-none/ref/5.png b/tests/topdown/header-none/ref/5.png new file mode 100644 index 0000000..1506f0d Binary files /dev/null and b/tests/topdown/header-none/ref/5.png differ diff --git a/tests/topdown/header-none/ref/6.png b/tests/topdown/header-none/ref/6.png new file mode 100644 index 0000000..b330841 Binary files /dev/null and b/tests/topdown/header-none/ref/6.png differ diff --git a/tests/topdown/header-none/test.typ b/tests/topdown/header-none/test.typ new file mode 100644 index 0000000..b707425 --- /dev/null +++ b/tests/topdown/header-none/test.typ @@ -0,0 +1,13 @@ +#import "../ledger.typ": * +#set text(size: 11pt) +#set page(height: 3.5cm, margin: 1em) +#dining-table.make(columns: example, + header: none, + data: data, + notes: dining-table.note.display-list +) + +#dining-table.make(columns: example, + data: data, + notes: dining-table.note.display-list +) \ No newline at end of file diff --git a/tests/topdown/ledger.typ b/tests/topdown/ledger.typ new file mode 100644 index 0000000..04093d5 --- /dev/null +++ b/tests/topdown/ledger.typ @@ -0,0 +1,80 @@ +#import "/src/lib.typ" as dining-table + +#let data = ( + ( + date: datetime.today(), + particulars: lorem(05), + ledger: [JRS123] + dining-table.note.make[Hello World], + amount: (unit: $100$, decimal: $00$), + total: (unit: $99$, decimal: $00$), + ), +)*7 + +#import "@preview/typpuccino:0.1.0" +#let bg-fill-1 = typpuccino.latte.base +#let bg-fill-2 = typpuccino.latte.mantle + +#let example = ( + ( + key: "date", + header: align(left)[Date], + display: (it)=>it.display(auto), + fill: bg-fill-1, + align: start, + gutter: 0.5em, + ), + ( + key: "particulars", + header: text(tracking: 5pt)[Particulars], + width: 1fr, + gutter: 0.5em, + ), + ( + key: "ledger", + header: [Ledger], + fill: bg-fill-2, + width: 2cm, + gutter: 0.5em, + ), + ( + header: align(center)[Amount], + fill: bg-fill-1, + gutter: 0.5em, + hline: arguments(stroke: dining-table.lightrule), + children: ( + ( + key: "amount.unit", + header: align(left)[£], + width: 5em, + align: right, + vline: arguments(stroke: dining-table.lightrule), + gutter: 0em, + ), + ( + key: "amount.decimal", + header: align(right, text(number-type: "old-style")[.00]), + align: left + ), + ) + ), + ( + header: align(center)[Total], + gutter: 0.5em, + hline: arguments(stroke: dining-table.lightrule), + children: ( + ( + key: "total.unit", + header: align(left)[£], + width: 5em, + align: right, + vline: arguments(stroke: dining-table.lightrule), + gutter: 0em, + ), + ( + key: "total.decimal", + header: align(right, text(number-type: "old-style")[.00]), + align: left + ), + ) + ), +) diff --git a/tests/topdown/ledger/test.typ b/tests/topdown/ledger/test.typ index 312fc5d..d831057 100644 --- a/tests/topdown/ledger/test.typ +++ b/tests/topdown/ledger/test.typ @@ -1,84 +1,4 @@ -#import "/src/lib.typ" as dining-table - -#let data = ( - ( - date: datetime.today(), - particulars: lorem(05), - ledger: [JRS123] + dining-table.note.make[Hello World], - amount: (unit: $100$, decimal: $00$), - total: (unit: $99$, decimal: $00$), - ), -)*7 - -#import "@preview/typpuccino:0.1.0" -#let bg-fill-1 = typpuccino.latte.base -#let bg-fill-2 = typpuccino.latte.mantle - -#let example = ( - ( - key: "date", - header: align(left)[Date], - display: (it)=>it.display(auto), - fill: bg-fill-1, - align: start, - gutter: 0.5em, - ), - ( - key: "particulars", - header: text(tracking: 5pt)[Particulars], - width: 1fr, - gutter: 0.5em, - ), - ( - key: "ledger", - header: [Ledger], - fill: bg-fill-2, - width: 2cm, - gutter: 0.5em, - ), - ( - header: align(center)[Amount], - fill: bg-fill-1, - gutter: 0.5em, - hline: arguments(stroke: dining-table.lightrule), - children: ( - ( - key: "amount.unit", - header: align(left)[£], - width: 5em, - align: right, - vline: arguments(stroke: dining-table.lightrule), - gutter: 0em, - ), - ( - key: "amount.decimal", - header: align(right, text(number-type: "old-style")[.00]), - align: left - ), - ) - ), - ( - header: align(center)[Total], - gutter: 0.5em, - hline: arguments(stroke: dining-table.lightrule), - children: ( - ( - key: "total.unit", - header: align(left)[£], - width: 5em, - align: right, - vline: arguments(stroke: dining-table.lightrule), - gutter: 0em, - ), - ( - key: "total.decimal", - header: align(right, text(number-type: "old-style")[.00]), - align: left - ), - ) - ), -) - +#import "../ledger.typ": * #set text(size: 11pt) #set page(height: auto, margin: 1em) #dining-table.make(columns: example,