Skip to content

Commit

Permalink
caption style start
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Dec 8, 2024
1 parent eac3e9b commit 323bbbd
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 48 deletions.
1 change: 1 addition & 0 deletions R/build_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ build_tt <- function(x, output = NULL) {

# apply the style_notes
x <- style_notes(x)
x <- style_caption(x)

for (th in x@lazy_theme) {
fn <- th[[1]]
Expand Down
1 change: 1 addition & 0 deletions R/class.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ setClass(
bootstrap_css_rule = "character",
css = "data.frame",
style = "data.frame",
style_caption = "list",
style_notes = "list",
lazy_format = "list",
lazy_group = "list",
Expand Down
3 changes: 2 additions & 1 deletion R/sanity.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ sanity_align <- function(align, i) {


sanitize_i <- function(i, x, pre_group_i = FALSE, lazy = TRUE) {
if (identical(i, "notes")) {
if (is.character(i)) {
assert_choice(i, c("notes", "caption"))
return(i)
}
out <- seq_len(nrow(x))
Expand Down
45 changes: 0 additions & 45 deletions R/style_notes.R
Original file line number Diff line number Diff line change
@@ -1,45 +0,0 @@
setGeneric(
name = "style_notes",
def = function(x, ...) standardGeneric("style_notes")
)

# default method
setMethod(
f = "style_notes",
signature = "ANY",
definition = function(x, ...) {
return(x)
})


# HTML: bootstrap
setMethod(
f = "style_notes",
signature = "tinytable_bootstrap",
definition = function(x, ...) {
styles <- x@style_notes
x@notes <- lapply(x@notes, style_string_html, styles)
return(x)
})


# LaTeX: tabularray
setMethod(
f = "style_notes",
signature = "tinytable_tabularray",
definition = function(x, ...) {
styles <- x@style_notes
x@notes <- lapply(x@notes, style_string_latex, styles)
return(x)
})


# Typst
setMethod(
f = "style_notes",
signature = "tinytable_typst",
definition = function(x, ...) {
styles <- x@style_notes
x@notes <- lapply(x@notes, style_string_typst, styles)
return(x)
})
40 changes: 40 additions & 0 deletions R/style_string.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,43 @@ style_string_typst <- function(n, styles) {
out <- sprintf(template, n)
return(out)
}



style_notes <- function(x) {
fun <- switch(x@output,
"typst" = style_string_typst,
"html" = style_string_html,
"html_portable" = style_string_html,
"latex" = style_string_latex,
function(k, ...) identity(k)
)
x@notes <- lapply(x@notes, fun, x@style_notes)
return(x)
}

style_notes <- function(x) {
fun <- switch(x@output,
"typst" = style_string_typst,
"html" = style_string_html,
"html_portable" = style_string_html,
"latex" = style_string_latex,
function(k, ...) identity(k)
)
x@notes <- lapply(x@notes, fun, x@style_notes)
return(x)
}

style_caption <- function(x) {
fun <- switch(x@output,
"typst" = style_string_typst,
"html" = style_string_html,
"html_portable" = style_string_html,
"latex" = style_string_latex,
function(k, ...) identity(k)
)
if (length(x@caption) > 0) {
x@caption <- fun(x@caption, x@style_caption)
}
return(x)
}
6 changes: 4 additions & 2 deletions R/style_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,17 @@ style_tt <- function(x,
tabularray_inner = tabularray_inner, tabularray_outer = tabularray_outer, bootstrap_css = bootstrap_css,
bootstrap_css_rule = bootstrap_css_rule)

if (identical(i, "notes")) {
out@style_notes <- list(
if (isTRUE(i %in% c("notes", "caption"))) {
tmp <- list(
color = color,
fontsize = fontsize,
italic = italic,
monospace = monospace,
strikeout = strikeout,
underline = underline
)
if (identical(i, "notes")) out@style_notes <- tmp
if (identical(i, "caption")) out@style_caption <- tmp
return(out)
}

Expand Down

0 comments on commit 323bbbd

Please sign in to comment.