From ab3fb9b107d3d07e6375f80aab3de9f4e71b6567 Mon Sep 17 00:00:00 2001 From: jomaway Date: Wed, 22 May 2024 12:38:51 +0200 Subject: [PATCH] refactor: removed underlines from functionnames --- lib/asserts.typ | 22 +++++++++++----------- lib/gen.typ | 40 ++++++++++++++++++++-------------------- lib/states.typ | 12 ++++++------ lib/utils.typ | 16 ++++++++-------- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/lib/asserts.typ b/lib/asserts.typ index 6bb54f0..b88d139 100644 --- a/lib/asserts.typ +++ b/lib/asserts.typ @@ -1,14 +1,14 @@ #import "@preview/oxifmt:0.2.0": strfmt -#let assert_dict(arg, var_name) = { +#let assert-dict(arg, var_name) = { assert.eq(type(arg),dictionary, message: strfmt("expected {} to be a dictionary, found {}",var_name, type(arg))); } /// fail if field is not a bf-field -#let assert_bf-field(field) = { - assert_dict(field, "field") +#let assert-bf-field(field) = { + assert-dict(field, "field") let bf-type = field.at("bf-type", default: none) assert.eq(bf-type, "bf-field", message: strfmt("expected bf-type of 'bf-field', found {}",bf-type)); let field-type = field.at("field-type", default: none) @@ -16,8 +16,8 @@ } /// fail if field is not a bf-field of type data-field -#let assert_data-field(field) = { - assert_bf-field(field); +#let assert-data-field(field) = { + assert-bf-field(field); let field-type = field.at("field-type", default: none) assert.eq(field-type, "data-field", message: strfmt("expected field-type == data-field, found {}",field-type)) let size = field.data.size; @@ -25,8 +25,8 @@ } /// fail if field is not a bf-field of type data-field -#let assert_note-field(field) = { - assert_bf-field(field); +#let assert-note-field(field) = { + assert-bf-field(field); // Check for correct field-type let field-type = field.at("field-type", default: none) assert.eq(field-type, "note-field", message: strfmt("expected field-type == note-field, found {}",field-type)) @@ -39,13 +39,13 @@ } /// fail if it does not match -#let assert_header-field(field) = { - assert_bf-field(field); +#let assert-header-field(field) = { + assert-bf-field(field); } /// fail if cell is not a bf-cell -#let assert_bf-cell(cell) = { - assert_dict(cell, "cell"); +#let assert-bf-cell(cell) = { + assert-dict(cell, "cell"); // Check bf-type let bf-type = cell.at("bf-type", default: none) assert.eq(bf-type, "bf-cell", message: strfmt("expected bf-type of 'bf-cell', found {}",bf-type)); diff --git a/lib/gen.typ b/lib/gen.typ index df93776..d4080fc 100644 --- a/lib/gen.typ +++ b/lib/gen.typ @@ -3,7 +3,7 @@ #import "asserts.typ": * #import "states.typ": * -#let assert_level_cols(levels, cols, side) = { +#let assert-level_cols(levels, cols, side) = { if (cols != auto) { cols = if (int == type(cols)) { cols } else if (array == type(cols)) { cols.len() } else { panic(strfmt("expected {} argument to be auto, int or array, found {}",if (side == "left") {"pre"} else {"post"} ,type(cols) )) } @@ -16,9 +16,9 @@ // collect metadata into an dictionary let bh = fields.find(f => is-header-field(f)) // check level indentation for annotations - let (pre_levels, post_levels) = _get_max_annotation_levels(fields.filter(f => is-note-field(f) )) - assert_level_cols(pre_levels, args.side.left_cols, "left") - assert_level_cols(post_levels, args.side.right_cols, "right") + let (pre_levels, post_levels) = get-max-annotation-levels(fields.filter(f => is-note-field(f) )) + assert-level_cols(pre_levels, args.side.left_cols, "left") + assert-level_cols(post_levels, args.side.right_cols, "right") // check if msb value is valid assert(args.msb in (left,right), message: strfmt("expected left or right for msb, found {}", args.msb)) let meta = ( @@ -81,7 +81,7 @@ /// Index all fields #let index_fields(fields) = { fields.enumerate().map(((idx, f)) => { - assert_bf-field(f) + assert-bf-field(f) dict_insert_and_return(f, "field-index", idx) }) } @@ -111,7 +111,7 @@ // note fields for f in _fields.filter(f => is-note-field(f)) { let row = if (f.data.row == auto) { - let anchor = _get_index_of_next_data_field(f.field-index, _fields) + let anchor = get-index-of-next-data-field(f.field-index, _fields) let anchor_field = fields.find(f => f.field-index == anchor) int( if (meta.msb == left) { (meta.size - anchor_field.data.range.end)/bpr } else { anchor_field.data.range.start/bpr }) } else { @@ -119,7 +119,7 @@ } let data = dict_insert_and_return(f.data, "row", row) let field = dict_insert_and_return(f, "data", data) - assert_note-field(field); + assert-note-field(field); fields.push(field) } @@ -153,7 +153,7 @@ let idx = 0; for field in data_fields { - assert_data-field(field) + assert-data-field(field) let len = field.data.size let slice_idx = 0; @@ -223,7 +223,7 @@ let bpr = meta.cols.main for field in note_fields { - assert_note-field(field) + assert-note-field(field) let side = field.data.side let level = field.data.level @@ -254,7 +254,7 @@ let _cells = () for header in header_fields { - assert_header-field(header) + assert-header-field(header) let nums = header.data.at("numbers", default: ()) + header.data.at("labels").keys().map(k => int(k)) let cell = nums.filter(num => num >= header.data.range.start and num < header.data.range.end).dedup().map(num =>{ @@ -325,14 +325,14 @@ /// map bf custom cells to tablex cells #let map_cells(cells) = { cells.map(c => { - assert_bf-cell(c) + assert-bf-cell(c) let body = if is-header-cell(c) { let label_text = c.label.text let label_num = c.label.num context { style(styles => { - set text(if c.format.text-size == auto { _get_header_font_size() } else { c.format.text-size }) + set text(if c.format.text-size == auto { get-default-header-font-size() } else { c.format.text-size }) set align(center + bottom) let size = measure(label_text, styles).width stack(dir: ttb, spacing: 0pt, @@ -350,14 +350,14 @@ } else { { [ - #if (is-data-cell(c) and (_get_field_font_size() != auto)) { + #if (is-data-cell(c) and (get-default-field-font-size() != auto)) { [ - #set text(_get_field_font_size()); + #set text(get-default-field-font-size()); #c.label ] - } else if (is-note-cell(c) and (_get_note_font_size() != auto)) { + } else if (is-note-cell(c) and (get-default-note-font-size() != auto)) { [ - #set text(_get_note_font_size()); + #set text(get-default-note-font-size()); #c.label ] } else { c.label } @@ -382,8 +382,8 @@ /// produce the final output #let generate_table(meta, cells) = { let table = context { - let rows = if (meta.rows.main == auto) { _get_row_height() } else { meta.rows.main } - if (type(rows) == array) { rows = rows.map(r => if (r == auto) { _get_row_height() } else { r } )} + let rows = if (meta.rows.main == auto) { get-default-row-height() } else { meta.rows.main } + if (type(rows) == array) { rows = rows.map(r => if (r == auto) { get-default-row-height() } else { r } )} // somehow grid_header still needs to exists. let grid_header = if (meta.header != none) { @@ -420,8 +420,8 @@ ([/* top left*/], align(bottom, box( width: 100%, - fill: if (meta.header.fill != auto) { meta.header.fill } else { _get_header_background() }, - stroke: if (meta.header.stroke != auto) { meta.header.stroke } else { _get_header_border() }, + fill: if (meta.header.fill != auto) { meta.header.fill } else { get-default-header-background() }, + stroke: if (meta.header.stroke != auto) { meta.header.stroke } else { get-default-header-border() }, grid_header )), [/*top right*/],) diff --git a/lib/states.typ b/lib/states.typ index 65df47e..7059da7 100644 --- a/lib/states.typ +++ b/lib/states.typ @@ -26,26 +26,26 @@ } -#let _get_row_height() = { +#let get-default-row-height() = { default_row_height.get() } -#let _get_header_font_size() = { +#let get-default-header-font-size() = { default_header_font_size.get() } -#let _get_field_font_size() = { +#let get-default-field-font-size() = { default_field_font_size.get() } -#let _get_note_font_size() = { +#let get-default-note-font-size() = { default_note_font_size.get() } -#let _get_header_background() = { +#let get-default-header-background() = { default_header_background.get() } -#let _get_header_border() = { +#let get-default-header-border() = { default_header_border.get() } \ No newline at end of file diff --git a/lib/utils.typ b/lib/utils.typ index 92eabda..e631601 100644 --- a/lib/utils.typ +++ b/lib/utils.typ @@ -9,7 +9,7 @@ } #let _get_field_type(field) = { - assert_bf-field(field); + assert-bf-field(field); return field.at("field-type", default: none); } @@ -21,24 +21,24 @@ /// Check if a given field is a data-field #let is-data-field(field) = { - assert_bf-field(field); + assert-bf-field(field); field.at("field-type", default: none) == "data-field" } /// Check if a given field is a note-field #let is-note-field(field) = { - assert_bf-field(field); + assert-bf-field(field); field.at("field-type", default: none) == "note-field" } /// Check if a given field is a header-field #let is-header-field(field) = { - assert_bf-field(field); + assert-bf-field(field); field.at("field-type", default: none) == "header-field" } /// Return the index of the next data-field -#let _get_index_of_next_data_field(idx, fields) = { +#let get-index-of-next-data-field(idx, fields) = { let res = fields.sorted(key: f => f.field-index).find(f => f.field-index > idx and is-data-field(f)) if res != none { res.field-index } else { none } } @@ -54,11 +54,11 @@ } /// calculates the max annotation level for both sides -#let _get_max_annotation_levels(annotations) = { +#let get-max-annotation-levels(annotations) = { let left_max_level = -1 let right_max_level = -1 for field in annotations { - assert_bf-field(field) + assert-bf-field(field) let (side, level, ..) = field.data; if (side == left) { left_max_level = calc.max(left_max_level,level) @@ -109,7 +109,7 @@ } /// Return the current index of a field or cell -#let _get_index(f) = { +#let get-index(f) = { if is-bf-field(f) { return f.field-index } else if is-bf-cell(f) {