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

* Remove names from key theme colors (#62)

Fixes #62
tags/v0.4.2
Garrick Aden-Buie пре 3 година
родитељ
комит
21269a0fec
No known key found for this signature in database
9 измењених фајлова са 40 додато и 16 уклоњено
  1. +2
    -0
      R/style_duo.R
  2. +4
    -0
      R/style_duo_accent.R
  3. +4
    -0
      R/style_duo_accent_inverse.R
  4. +3
    -0
      R/style_mono_accent.R
  5. +3
    -0
      R/style_mono_accent_inverse.R
  6. +3
    -0
      R/style_mono_dark.R
  7. +3
    -0
      R/style_mono_light.R
  8. +15
    -15
      R/style_xaringan.R
  9. +3
    -1
      inst/scripts/generate_theme_functions.R

+ 2
- 0
R/style_duo.R Прегледај датотеку

outfile = "xaringan-themer.css" outfile = "xaringan-themer.css"
) { ) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
primary_color <- unname(primary_color)
secondary_color <- unname(secondary_color)
colors <- c(primary = primary_color, secondary = secondary_color, colors) colors <- c(primary = primary_color, secondary = secondary_color, colors)
eval(parse(text = call_style_xaringan())) eval(parse(text = call_style_xaringan()))
} }

+ 4
- 0
R/style_duo_accent.R Прегледај датотеку

outfile = "xaringan-themer.css" outfile = "xaringan-themer.css"
) { ) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
primary_color <- unname(primary_color)
secondary_color <- unname(secondary_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(primary = primary_color, secondary = secondary_color, white = white_color, black = black_color, colors) colors <- c(primary = primary_color, secondary = secondary_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan())) eval(parse(text = call_style_xaringan()))
} }

+ 4
- 0
R/style_duo_accent_inverse.R Прегледај датотеку

outfile = "xaringan-themer.css" outfile = "xaringan-themer.css"
) { ) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
primary_color <- unname(primary_color)
secondary_color <- unname(secondary_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(primary = primary_color, secondary = secondary_color, white = white_color, black = black_color, colors) colors <- c(primary = primary_color, secondary = secondary_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan())) eval(parse(text = call_style_xaringan()))
} }

+ 3
- 0
R/style_mono_accent.R Прегледај датотеку

outfile = "xaringan-themer.css" outfile = "xaringan-themer.css"
) { ) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
base_color <- unname(base_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(base = base_color, white = white_color, black = black_color, colors) colors <- c(base = base_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan())) eval(parse(text = call_style_xaringan()))
} }

+ 3
- 0
R/style_mono_accent_inverse.R Прегледај датотеку

outfile = "xaringan-themer.css" outfile = "xaringan-themer.css"
) { ) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
base_color <- unname(base_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(base = base_color, white = white_color, black = black_color, colors) colors <- c(base = base_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan())) eval(parse(text = call_style_xaringan()))
} }

+ 3
- 0
R/style_mono_dark.R Прегледај датотеку

outfile = "xaringan-themer.css" outfile = "xaringan-themer.css"
) { ) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
base_color <- unname(base_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(base = base_color, white = white_color, black = black_color, colors) colors <- c(base = base_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan())) eval(parse(text = call_style_xaringan()))
} }

+ 3
- 0
R/style_mono_light.R Прегледај датотеку

outfile = "xaringan-themer.css" outfile = "xaringan-themer.css"
) { ) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
base_color <- unname(base_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(base = base_color, white = white_color, black = black_color, colors) colors <- c(base = base_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan())) eval(parse(text = call_style_xaringan()))
} }

+ 15
- 15
R/style_xaringan.R Прегледај датотеку

force(code_font_family) force(code_font_family)
force(code_font_url) force(code_font_url)
force(code_font_family_fallback) force(code_font_family_fallback)
# the defaults are google fonts # the defaults are google fonts
is_default <- function(type, suffix) { is_default <- function(type, suffix) {
# check if font arg value is from xaringanthemer_font_default # check if font arg value is from xaringanthemer_font_default
r_set_font_is_google <- glue::glue("{var}_font_is_google <- {var_is_google}") r_set_font_is_google <- glue::glue("{var}_font_is_google <- {var_is_google}")
eval(parse(text = r_set_font_is_google)) eval(parse(text = r_set_font_is_google))
} }
# Make sure font names are wrapped in quotes if they have spaces # Make sure font names are wrapped in quotes if they have spaces
f_args <- names(formals(sys.function())) f_args <- names(formals(sys.function()))
for (var in f_args[grepl("font_family$", f_args)]) { for (var in f_args[grepl("font_family$", f_args)]) {
eval(parse(text = paste0(var, "<-quote_elements_w_spaces(", var, ")"))) eval(parse(text = paste0(var, "<-quote_elements_w_spaces(", var, ")")))
} }
} }
# Warn if base_font_size isn't absolute # Warn if base_font_size isn't absolute
css_abs_units <- c("cm", "mm", "Q", "in", "pc", "pt", "px") css_abs_units <- c("cm", "mm", "Q", "in", "pc", "pt", "px")
if (!grepl(paste(tolower(css_abs_units), collapse = "|"), tolower(base_font_size))) { if (!grepl(paste(tolower(css_abs_units), collapse = "|"), tolower(base_font_size))) {
immediate. = TRUE immediate. = TRUE
) )
} }
# If certain colors aren't in hexadecimal it may cause problems with theme_xaringan() # If certain colors aren't in hexadecimal it may cause problems with theme_xaringan()
# TODO: at some point I'd rather be able to process CSS colors or variables # TODO: at some point I'd rather be able to process CSS colors or variables
colors_used_by_theme_xaringan <- list( colors_used_by_theme_xaringan <- list(
) )
colors_used_by_theme_xaringan <- purrr::discard(colors_used_by_theme_xaringan, is.null) colors_used_by_theme_xaringan <- purrr::discard(colors_used_by_theme_xaringan, is.null)
colors_are_hex <- purrr::map_lgl(colors_used_by_theme_xaringan, check_color_is_hex, throw = NULL) colors_are_hex <- purrr::map_lgl(colors_used_by_theme_xaringan, check_color_is_hex, throw = NULL)
if (any(!colors_are_hex)) { if (any(!colors_are_hex)) {
colors_better_as_hex <- names(colors_used_by_theme_xaringan)[!colors_are_hex] colors_better_as_hex <- names(colors_used_by_theme_xaringan)[!colors_are_hex]
colors_better_as_hex <- paste(colors_better_as_hex, collapse = ", ") colors_better_as_hex <- paste(colors_better_as_hex, collapse = ", ")
warning( warning(
glue::glue("Colors that will be used by `theme_xaringan()` need to be in ", glue::glue("Colors that will be used by `theme_xaringan()` need to be in ",
"hexadecimal format: {colors_better_as_hex}"),
"hexadecimal format: {colors_better_as_hex}"),
immediate. = TRUE, immediate. = TRUE,
call. = FALSE call. = FALSE
) )
} }
# Use font_..._google args to overwrite font args # Use font_..._google args to overwrite font args
for (var in f_args[grepl("font_google$", f_args)]) { for (var in f_args[grepl("font_google$", f_args)]) {
gf <- eval(parse(text = var)) gf <- eval(parse(text = var))
} }
eval(parse(text = paste0(group, "_font_is_google <- 1"))) eval(parse(text = paste0(group, "_font_is_google <- 1")))
} }
extra_font_imports <- if (is.null(extra_fonts)) "" else list2fonts(extra_fonts) extra_font_imports <- if (is.null(extra_fonts)) "" else list2fonts(extra_fonts)
extra_font_imports <- paste(extra_font_imports, collapse = "\n") extra_font_imports <- paste(extra_font_imports, collapse = "\n")
# convert NA arguments to NULL # convert NA arguments to NULL
for (var in f_args) { for (var in f_args) {
val <- eval(parse(text = var)) val <- eval(parse(text = var))
is_na <- length(val) == 0 is_na <- length(val) == 0
if (is_na) assign(var, NULL, envir = sys.frame(sys.nframe())) if (is_na) assign(var, NULL, envir = sys.frame(sys.nframe()))
} }
# prepare variables for template # prepare variables for template
body_font_family <- paste(c(text_font_family, text_font_family_fallback, text_font_base), collapse = ", ") body_font_family <- paste(c(text_font_family, text_font_family_fallback, text_font_base), collapse = ", ")
background_size_fallback <- if (is.null(background_position)) "cover" else "100%" background_size_fallback <- if (is.null(background_position)) "cover" else "100%"
title_slide_background_image %??% "cover" title_slide_background_image %??% "cover"
) )
table_row_even_background_color <- table_row_even_background_color %||% background_color table_row_even_background_color <- table_row_even_background_color %||% background_color
# stash theme settings in package env # stash theme settings in package env
lapply(f_args, function(n) assign(n, get(n), envir = xaringanthemer_env)) lapply(f_args, function(n) assign(n, get(n), envir = xaringanthemer_env))
for (font_is_google in paste0(c("text", "code", "header"), "_font_is_google")) { for (font_is_google in paste0(c("text", "code", "header"), "_font_is_google")) {
envir = xaringanthemer_env envir = xaringanthemer_env
) )
} }
xaringanthemer_version <- utils::packageVersion("xaringanthemer") xaringanthemer_version <- utils::packageVersion("xaringanthemer")
# prepare header background object # prepare header background object
needs_leading_dot <- !grepl("^\\.", header_background_ignore_classes) needs_leading_dot <- !grepl("^\\.", header_background_ignore_classes)
header_background_ignore_classes[needs_leading_dot] <- paste0( header_background_ignore_classes[needs_leading_dot] <- paste0(
content_padding_top = header_background_content_padding_top, content_padding_top = header_background_content_padding_top,
ignore = header_background_ignore_classes ignore = header_background_ignore_classes
) )
colors <- prepare_colors(colors) colors <- prepare_colors(colors)
tf <- system.file("resources", "template.css", package = "xaringanthemer") tf <- system.file("resources", "template.css", package = "xaringanthemer")
template <- readLines(tf, warn = FALSE) template <- readLines(tf, warn = FALSE)
template <- paste(template, collapse = "\n") template <- paste(template, collapse = "\n")

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



include_theme_colors <- function(theme_colors = NULL) { include_theme_colors <- function(theme_colors = NULL) {
if (is.null(theme_colors)) return(NULL) if (is.null(theme_colors)) return(NULL)
unname <- glue::glue("{theme_colors} <- unname({theme_colors})")
unname <- paste(unname, collapse = "\n ")
x <- glue::glue('{names(theme_colors)} = {theme_colors}') x <- glue::glue('{names(theme_colors)} = {theme_colors}')
x <- paste(x, collapse = ", ") x <- paste(x, collapse = ", ")
glue::glue(" colors <- c({x}, colors)")
glue::glue(" {unname}\n colors <- c({x}, colors)", .trim = FALSE)
} }


# ---- Write Xaringan Theme Function ---- # ---- Write Xaringan Theme Function ----

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