Skip to content

Commit

Permalink
lazy style eval
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 15, 2024
1 parent 1216f30 commit 3ff950c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#' @keywords internal
#' @export
knit_print.tinytable <- function(x, ...) {
m <- meta(x)
# lazy styles get evaluated here, at the very end
x <- eval_style(x)

if (m$output == "html") {
if (meta(x)$output == "html") {
# from htmltools:::html_preserve
# GPL3
inline <- grepl(x, "\n", fixed = TRUE)
Expand All @@ -15,7 +16,7 @@ knit_print.tinytable <- function(x, ...) {
out <- sprintf("\n```{=html}\n%s\n```\n", x)
}

} else if (m$output %in% c("latex", "markdown")) {
} else if (meta(x)$output %in% c("latex", "markdown")) {
out <- x
}

Expand Down
5 changes: 3 additions & 2 deletions R/save_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
#' }
#'
save_tt <- function(x, filename, overwrite = FALSE) {

m <- meta(x)


assert_string(filename)
assert_flag(overwrite)
if (file.exists(filename) && !overwrite) {
Expand All @@ -30,6 +28,9 @@ save_tt <- function(x, filename, overwrite = FALSE) {
stop("`x` must be an object produced by the `tinytable::tt()` function.", call. = FALSE)
}

# evaluate styles at the very end of the pipeline
x <- eval_style(x)

write(x, file = filename)

return(invisible(TRUE))
Expand Down
1 change: 0 additions & 1 deletion R/style_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ style_tt <- function (x,
"\\tinytableDefineColor{%s}{HTML}{%s}",
sub("^#", "c", h), sub("^#", "", h))
cal <- call("style_tabularray", body = b)
browser()
out <- meta(out, "lazy_style", c(meta(out)$lazy_style, list(cal)))
}
}
Expand Down

0 comments on commit 3ff950c

Please sign in to comment.