Преглед изворни кода

minor refactor of theme generation function

tags/v0.3.0
Garrick Aden-Buie пре 7 година
родитељ
комит
8c05d67c50
1 измењених фајлова са 20 додато и 13 уклоњено
  1. +20
    -13
      inst/scripts/generate_theme_functions.R

+ 20
- 13
inst/scripts/generate_theme_functions.R Прегледај датотеку

@@ -24,26 +24,33 @@ setup_theme_function <- function(
file = "",
body = NULL
) {
`%,%` <- function(x, y) c(x, y)
if (file == "clip" && !requireNamespace("clipr", quietly = TRUE)) file <- ""
tv <- template
null_default <- purrr::map_lgl(tv$default, is.null)
tv[null_default, 'default'] <- "{NULL}"
x <-
x <- c(
as.character(
glue::glue_data(
tv, "#' @param {variable} {description}. Defaults to {stringr::str_replace_all(default, '[{{}}]', '`')}. {element_description(element)}")) %,%
"#' @template extra_css" %,%
"#' @param outfile Customized xaringan CSS output file name, default is \"xaringan-themer.css\"" %,%
"#' @family themes" %,%
c(...) %,%
glue::glue("{f_name} <- function(") %,%
as.character(glue::glue_data(
tv, " {variable} = {ifelse(!stringr::str_detect(default, '^[{].+[}]$'), paste0('\"', default, '\"'), stringr::str_replace_all(default, '[{}]', ''))},")) %,%
" extra_css = NULL," %,%
" extra_fonts = NULL," %,%
" outfile = \"xaringan-themer.css\"" %,%
tv,
"#' @param {variable} {description}. ",
"Defaults to {stringr::str_replace_all(default, '[{{}}]', '`')}. ",
"{element_description(element)}")
),
"#' @template extra_css",
"#' @param outfile Customized xaringan CSS output file name, default is \"xaringan-themer.css\"",
"#' @family themes",
...,
glue::glue("{f_name} <- function("),
as.character(
glue::glue_data(
tv,
" {variable} = {ifelse(!stringr::str_detect(default, '^[{].+[}]$'), paste0('\"', default, '\"'), stringr::str_replace_all(default, '[{}]', ''))},")
),
" extra_css = NULL,",
" extra_fonts = NULL,",
" outfile = \"xaringan-themer.css\"",
") {"
)
if (!is.null(body)) x <- c(x, body, "}")
if (file == "clip") {
clipr::write_clip(x)

Loading…
Откажи
Сачувај