diff --git a/R/build_tt.R b/R/build_tt.R index f648e06f..cb5cf600 100644 --- a/R/build_tt.R +++ b/R/build_tt.R @@ -66,10 +66,7 @@ build_tt <- function(x, output = NULL) { # markdown styles need to be applied before creating the table, otherwise there's annoying parsing, etc. if (x@output %in% c("markdown", "gfm", "dataframe")) { - for (l in x@lazy_style) { - l[["x"]] <- x - x <- eval(l) - } + # TODO } # draw the table @@ -86,18 +83,18 @@ build_tt <- function(x, output = NULL) { x <- eval(l) } - if (x@output == "typst") { - if (is.null(x@theme[[1]]) || is.function(x@theme[[1]]) || isTRUE(x@theme[[1]] %in% c("default", "striped"))) { - # reverse the order of the lines to allow overwriting defaults - x <- style_tt(x, i = nrow(x), line = "b", line_width = 0.1) - if (x@nhead > 0) { - x <- style_tt(x, i = -x@nhead + 1, line = "t", line_width = 0.1) - x <- style_tt(x, i = 1, line = "t", line_width = 0.05) - } else { - x <- style_tt(x, i = 1, line = "t", line_width = 0.1) - } - } - } + # if (x@output == "typst") { + # if (is.null(x@theme[[1]]) || is.function(x@theme[[1]]) || isTRUE(x@theme[[1]] %in% c("default", "striped"))) { + # # reverse the order of the lines to allow overwriting defaults + # x <- style_tt(x, i = nrow(x), line = "b", line_width = 0.1) + # if (x@nhead > 0) { + # x <- style_tt(x, i = -x@nhead + 1, line = "t", line_width = 0.1) + # x <- style_tt(x, i = 1, line = "t", line_width = 0.05) + # } else { + # x <- style_tt(x, i = 1, line = "t", line_width = 0.1) + # } + # } + # } if (!x@output %in% c("markdown", "gfm", "dataframe")) { for (l in x@lazy_style) { @@ -109,13 +106,7 @@ build_tt <- function(x, output = NULL) { } } - if (x@output == "typst") { - x <- style_apply_typst(x) - } else if (x@output == "html") { - x <- style_apply_bootstrap(x) - } else if (x@output == "latex") { - x <- style_apply_tabularray(x) - } + x <- style_eval(x) x <- finalize(x) diff --git a/R/group_tabularray.R b/R/group_tabularray.R index 60027cd0..99285579 100644 --- a/R/group_tabularray.R +++ b/R/group_tabularray.R @@ -53,7 +53,7 @@ group_tabularray_col <- function(x, j, ihead, ...) { j = z, align = "c", colspan = max(j[[k]]) - min(j[[k]]) + 1) - x <- do.call(style_eval, args) + x <- do.call(style_tt, args) } return(x) diff --git a/R/style_bootstrap.R b/R/style_bootstrap.R index c8c9a9a8..67a7a020 100644 --- a/R/style_bootstrap.R +++ b/R/style_bootstrap.R @@ -30,12 +30,6 @@ setMethod( bootstrap_css_rule = NULL, ...) { - return(x) - }) - - - -style_apply_bootstrap <- function(x) { if (length(x@bootstrap_css_rule) == 1) { x@table_string <- bootstrap_setting(x@table_string, x@bootstrap_css_rule, component = "css") @@ -150,6 +144,6 @@ style_apply_bootstrap <- function(x) { } return(x) -} +}) diff --git a/R/style_grid.R b/R/style_grid.R index 630bc498..b5598660 100644 --- a/R/style_grid.R +++ b/R/style_grid.R @@ -1,6 +1,3 @@ - - - #' tinytable S4 method #' #' @keywords internal @@ -90,5 +87,5 @@ style_grid_internal <- function(x, setMethod( f = "style_eval", signature = "tinytable_grid", - definition = style_grid_internal + definition = identity ) diff --git a/R/style_grid_dataframe.R b/R/style_grid_dataframe.R index 432c6b45..296c5cd3 100644 --- a/R/style_grid_dataframe.R +++ b/R/style_grid_dataframe.R @@ -3,7 +3,7 @@ #' @keywords internal setMethod(f = "style_eval", signature = "tinytable_dataframe", - definition = style_grid_internal + definition = identity ) diff --git a/R/style_tabularray.R b/R/style_tabularray.R index 8dd80cf2..81294590 100644 --- a/R/style_tabularray.R +++ b/R/style_tabularray.R @@ -24,12 +24,8 @@ setMethod( tabularray_outer = NULL, ...) { - return(x) - }) -style_apply_tabularray <- function(x) { - sty <- x@style sty$i <- sty$i + x@nhead @@ -113,14 +109,14 @@ style_apply_tabularray <- function(x) { } - clean <- function(x) { - x <- gsub("^\\s*,", "", x) - x <- gsub(",\\s*,", ",,", x) - x <- gsub("\\s+", " ", x) - x <- gsub(",+", ",", x) - x <- gsub("^[,|\\s]*", "", x, perl = TRUE) - x <- trimws(x) - return(x) + clean <- function(k) { + k <- gsub("^\\s*,", "", k) + k <- gsub(",\\s*,", ",,", k) + k <- gsub("\\s+", " ", k) + k <- gsub(",+", ",", k) + k <- gsub("^[,|\\s]*", "", k, perl = TRUE) + k <- trimws(k) + return(k) } rec$set <- clean(set) @@ -186,7 +182,8 @@ style_apply_tabularray <- function(x) { } return(x) -} + +}) hlines_tabularray <- function(k) { diff --git a/R/style_tt.R b/R/style_tt.R index 6e98e16d..234f2c1f 100644 --- a/R/style_tt.R +++ b/R/style_tt.R @@ -150,6 +150,17 @@ style_tt <- function (x, out <- x + assert_choice(alignv, c("t", "m", "b"), null.ok = TRUE) + + assert_style_tt( + x = out, i = i, j = j, bold = bold, italic = italic, monospace = monospace, underline = underline, strikeout = strikeout, + color = color, background = background, fontsize = fontsize, align = align, + colspan = colspan, rowspan = rowspan, indent = indent, + line = line, line_color = line_color, line_width = line_width, + tabularray_inner = tabularray_inner, tabularray_outer = tabularray_outer, bootstrap_css = bootstrap_css, + bootstrap_css_rule = bootstrap_css_rule) + + if (!is.null(bootstrap_class)) { out@bootstrap_class <- bootstrap_class } @@ -246,39 +257,6 @@ style_tt <- function (x, # This is a very bad idea. Breaks a ton of things. We need unique IDs. # out@id <- get_id("tinytable_") - cal <- call("style_tt_lazy", - # out <- style_tt_lazy( - # x should not be in here otherwise the object becomes very big - i = i, - j = j, - bold = bold, - italic = italic, - monospace = monospace, - underline = underline, - strikeout = strikeout, - color = color, - background = background, - fontsize = fontsize, - align = align, - alignv = alignv, - colspan = colspan, - rowspan = rowspan, - indent = indent, - line = line, - line_color = line_color, - line_width = line_width, - tabularray_inner = tabularray_inner, - tabularray_outer = tabularray_outer, - bootstrap_css = bootstrap_css, - bootstrap_css_rule = bootstrap_css_rule, - output = output) - - if (isTRUE(list(...)[["tt_build_now"]])) { - out <- eval(cal) - } else { - out@lazy_style <- c(out@lazy_style, list(cal)) - } - assert_function(finalize, null.ok = TRUE) if (is.function(finalize)) { out@lazy_finalize <- c(out@lazy_finalize, list(finalize)) @@ -289,50 +267,6 @@ style_tt <- function (x, -style_tt_lazy <- function (x, - i, - j, - bold, - italic, - monospace, - underline, - strikeout, - color, - background, - fontsize, - align, - alignv, - colspan, - rowspan, - indent, - line, - line_color, - line_width, - tabularray_inner, - tabularray_outer, - bootstrap_css, - bootstrap_css_rule, - output) { - - out <- x - - # alignv can only be a single character for now - assert_choice(alignv, c("t", "m", "b"), null.ok = TRUE) - - assert_style_tt( - x = out, i = i, j = j, bold = bold, italic = italic, monospace = monospace, underline = underline, strikeout = strikeout, - color = color, background = background, fontsize = fontsize, align = align, - colspan = colspan, rowspan = rowspan, indent = indent, - line = line, line_color = line_color, line_width = line_width, - tabularray_inner = tabularray_inner, tabularray_outer = tabularray_outer, bootstrap_css = bootstrap_css, - bootstrap_css_rule = bootstrap_css_rule) - - out <- style_eval(x = out, i = i, j = j, bold = bold, italic = italic, monospace = monospace, underline = underline, strikeout = strikeout, color = color, background = background, fontsize = fontsize, align = align, alignv = alignv, colspan = colspan, rowspan = rowspan, indent = indent, tabularray_inner = tabularray_inner, tabularray_outer = tabularray_outer, bootstrap_css = bootstrap_css, bootstrap_css_rule = bootstrap_css_rule, line = line, line_color = line_color, line_width = line_width) - - return(out) -} - - assert_style_tt <- function (x, i, j, diff --git a/R/style_typst.R b/R/style_typst.R index e6930c5e..f1f27aa6 100644 --- a/R/style_typst.R +++ b/R/style_typst.R @@ -25,12 +25,8 @@ setMethod( indent = 0, midrule = FALSE, # undocumented, only used by `group_tt()` ...) { - return(x) - }) - -style_apply_typst <- function(x) { sty <- x@style # gutters are used for group_tt(j) but look ugly with cell fill @@ -138,7 +134,7 @@ style_apply_typst <- function(x) { } return(x) -} +}) split_chunks <- function(x) { diff --git a/R/theme_tt.R b/R/theme_tt.R index ca570ef7..2f62791e 100644 --- a/R/theme_tt.R +++ b/R/theme_tt.R @@ -193,7 +193,7 @@ theme_bootstrap <- function(x, ...) { tab <- gsub("|", " ", tab, fixed = TRUE) table@table_string <- paste(tab, collapse = "\n") } else if (isTRUE(table@output == "typst")) { - table <- style_eval(table, i = 0:nrow(table), line = "bt", line_width = 0.05, line_color = "silver") + table <- style_tt(table, i = 0:nrow(table), line = "bt", line_width = 0.05, line_color = "silver") } return(table) } @@ -257,14 +257,14 @@ theme_multipage <- function(x, table@table_string <- tab - table <- style_eval(table, tabularray_outer = cap) + table <- style_tt(table, tabularray_outer = cap) if (rowhead > 0) { - table <- style_eval(table, tabularray_inner = sprintf("rowhead=%s", rowhead)) + table <- style_tt(table, tabularray_inner = sprintf("rowhead=%s", rowhead)) } if (rowfoot > 0) { - table <- style_eval(table, tabularray_inner = sprintf("rowfoot=%s", rowfoot)) + table <- style_tt(table, tabularray_inner = sprintf("rowfoot=%s", rowfoot)) } return(table)