ソースを参照

Move template_variables into internal data, created via script in data-raw/

tags/v0.3.0
コミット
7d8a000dc6
8個のファイルの変更123行の追加97行の削除
  1. +1
    -0
      .Rbuildignore
  2. +2
    -0
      DESCRIPTION
  3. バイナリ
      R/sysdata.rda
  4. +34
    -0
      R/utils_theme-gen.R
  5. +1
    -1
      README.Rmd
  6. +81
    -92
      data-raw/theme_template_variables.R
  7. +2
    -1
      inst/scripts/generate_theme_functions.R
  8. +2
    -3
      make.R

+ 1
- 0
.Rbuildignore ファイルの表示

@@ -15,3 +15,4 @@
^pkgdown$
^vignettes/fonts\.Rmd$
^vignettes/themes\.Rmd$
^data-raw$

+ 2
- 0
DESCRIPTION ファイルの表示

@@ -14,6 +14,8 @@ Description: Create and edit your xaringan CSS files from within
License: MIT + file LICENSE
URL: https://github.com/gadenbuie/xaringanthemer
BugReports: https://github.com/gadenbuie/xaringanthemer/issues
Depends:
R (>= 2.10)
Imports:
colorspace,
glue,

バイナリ
R/sysdata.rda ファイルの表示


+ 34
- 0
R/utils_theme-gen.R ファイルの表示

@@ -0,0 +1,34 @@
# nocov start
# Theme Generating Helpers ----------------------------------------------

plural_element <- function(css_name) {
is_mult <- grepl(",|and|or", css_name)
is_class <- grepl("^\\.", css_name)
ifelse(is_class,
ifelse(is_mult, "classes", "class"),
ifelse(is_mult, "elements", "element")
)
}

element_description <- function(element) {
out <- rep("", length(element))
multiple <- grepl("multiple", element)
out[multiple] <- "Used in multiple CSS rules."

ifelse(
multiple | is.na(element) | element == "",
out,
glue::glue("Modifies the `{element}` {plural_element(element)}.")
)
}

describe_css_variable <- function(css_variable = NULL) {
if (is.null(css_variable) || is.na(css_variable)) return("")
glue::glue(
" The value of this variable is also stored as a CSS variable that can be ",
"referenced with `var({css_variable})` in any argument of a style ",
"function or in custom CSS."
)
}

# nocov end

+ 1
- 1
README.Rmd ファイルの表示

@@ -81,7 +81,7 @@ The arguments of each theme function are named so that you can first think of th
Here are some of the `text_` theme options:

```{r, results='asis', echo=FALSE}
source(here::here("R/theme_settings.R"))
load(here::here("R", "sysdata.rda"))
tvv <- template_variables$variable
cat(paste0("- `", tvv[grepl("^text_", tvv)][1:5], "`"), sep = "\n")
cat("- *and more ...*")

R/theme_settings.R → data-raw/theme_template_variables.R ファイルの表示

@@ -1,65 +1,65 @@
#nocov start
template_variables <- tibble::tribble(
~ variable, ~ default, ~ element, ~ description
, "text_color", "#000", "body", "Text Color"
, "header_color", "#000", "h1, h2, h3", "Header Color"
, "background_color", "#FFF", ".remark-slide-content", "Slide Background Color"
, "link_color", "rgb(249, 38, 114)", "a, a > code", "Link Color"
, "text_bold_color", "{NULL}", "strong", "Bold Text Color"
, "text_slide_number_color", "{inverse_background_color}", ".remark-slide-number", "Slide Number Color"
, "padding", "16px 64px 16px 64px", ".remark-slide-content", "Slide Padding in `top right [bottom left]` format"
, "background_image", "{NULL}", ".remark-slide-content", "Background image applied to each *and every* slide. Set `title_slide_background_image = \"none\"` to remove the background image from the title slide"
, "background_size", "{NULL}", ".remark-slide-content", "Background image size, requires `background_image` to be set. If `background_image` is set, `background_size` will default to `cover` so the backround fills the screen. If both `background_image` and `background_position` are set, will default to 100 percent"
, "background_position", "{NULL}", ".remark-slide-content", "Background image position, requires `background_image` to be set, and it is recommended to adjust `background_size`"
, "code_highlight_color", "rgba(255,255,0,0.5)", ".remark-code-line-highlighted", "Code Line Highlight"
, "code_inline_color", "#000", ".remark-inline-code", "Inline Code Color"
, "code_inline_background_color", "{NULL}", ".remark-inline-code", "Inline Code Background Color"
, "code_inline_font_size", "1em", ".remark-inline-code", "Inline Code Text Font Size"
, "inverse_background_color", "#272822", ".inverse", "Inverse Background Color"
, "inverse_text_color", "#d6d6d6", ".inverse", "Inverse Text Color"
, "inverse_text_shadow", "{FALSE}", ".inverse", "Enables Shadow on text of inverse slides"
, "inverse_header_color", "#f3f3f3", ".inverse h1, .inverse h2, .inverse h3", "Inverse Header Color"
, "title_slide_text_color", "{inverse_text_color}", ".title-slide", "Title Slide Text Color"
, "title_slide_background_color", "{inverse_background_color}", ".title-slide", "Title Slide Background Color"
, "title_slide_background_image", "{NULL}", ".title-slide", "Title Slide Background Image URL"
, "title_slide_background_size", "{NULL}", ".title-slide", "Title Slide Background Image Size, defaults to \"cover\" if background image is set"
, "title_slide_background_position", "{NULL}", ".title-slide", "Title Slide Background Image Position"
, "footnote_color", "{NULL}", ".footnote", "Footnote text color (if `NA`, then it will be the same color as `text_color`)"
, "footnote_font_size", "0.9em", ".footnote", "Footnote font size"
, "footnote_position_bottom", "60px", ".footnote", "Footnote location from bottom of screen"
, "left_column_subtle_color", "#777", ".left-column h2, .left-column h3", "Left Column Text (not last)"
, "left_column_selected_color", "#000", ".left-column h2:last-of-type, .left-column h3:last-child", "Left Column Current Selection"
, "blockquote_left_border_color", "lightgray", "blockquote", "Blockquote Left Border Color"
, "table_border_color", "#666", "table: border-top, border-bottom", "Table top/bottom border"
, "table_row_border_color", "#ddd", "table thead th: border-bottom", "Table row inner bottom border"
, "table_row_even_background_color", "#eee", "thead, tfoot, tr:nth-child(even)", "Table Even Row Background Color"
, "base_font_size", "20px", "html", "Base Font Size for All Slide Elements (must be `px`)"
, "text_font_size", "1rem", ".remark-slide-content", "Slide Body Text Font Size"
, "header_h1_font_size", "2.75rem", ".remark-slide-content h1", "h1 Header Text Font Size"
, "header_h2_font_size", "2.25rem", ".remark-slide-content h2", "h2 Header Text Font Size"
, "header_h3_font_size", "1.75rem", ".remark-slide-content h3", "h3 Header Text Font Size"
, "header_background_auto", "{FALSE}", "", "Add background under slide title automatically for h1 header elements. If not enabled, use `class: header_background` to enable"
, "header_background_color", "{header_color}", ".remark-slide-content h1", "Background Color for h1 Header with Background"
, "header_background_text_color", "{background_color}", ".remark-slide-content h1", "Text Color for h1 Header with Background"
, "header_background_padding", "{NULL}", ".remark-slide-content h1", "Padding for h1 Header with Background"
, "header_background_content_padding_top", "7rem", ".remark-slide-content", "Top Padding for Content in Slide with Header with Background"
, "header_background_ignore_classes", "{c('normal', 'inverse', 'title', 'middle', 'bottom')}", ".remark-slide-content", "Slide Classes Where Header with Background will not be Applied"
, "text_slide_number_font_size", "0.9em", ".remark-slide-number", "Slide Number Text Font Size"
, "text_font_google", "{NULL}", "body", "Use `google_font()` to specify body font"
, "text_font_family", "Noto Sans", "body", "Body Text Font Family (xaringan default is `'Droid Serif'`)"
, "text_font_weight", "normal", "body", "Body Text Font Weight"
, "text_font_url", "https://fonts.googleapis.com/css?family=Noto+Sans:400,400i,700,700i&display=swap", "@import url()", "Body Text Font URL(s)"
, "text_font_family_fallback", "-apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, Ubuntu, roboto, noto, segoe ui, arial", "body", "Body Text Font Fallbacks"
, "text_font_base", "sans-serif", "body", "Body Text Base Font (Total Failure Fallback)"
, "header_font_google", "{NULL}", "body", "Use `google_font()` to specify header font"
, "header_font_family", "Cabin", "h1, h2, h3", "Header Font Family (xaringan default is `'Yanone Kaffeesatz'`)"
, "header_font_weight", "600", "h1, h2, h3", "Header Font Weight"
, "header_font_url", "https://fonts.googleapis.com/css?family=Cabin:600,600i&display=swap", "@import url", "Header Font URL"
, "code_font_google", "{NULL}", "body", "Use `google_font()` to specify code font"
, "code_font_family", "Source Code Pro", ".remark-code, .remark-inline-code", "Code Font Family"
, "code_font_size", "0.9rem", ".remark-inline", "Code Text Font Size"
, "code_font_url", "https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700&display=swap", "@import url", "Code Font URL"
, "code_font_family_fallback", "Menlo, Consolas, Monaco, Liberation Mono, Lucida Console", ".remark-code, .remark-inline-code", "Code Font Fallback"
~ variable, ~ default, ~ element, ~ description, ~ css_variable
, "text_color", "#000", "body", "Text Color", "--primary"
, "header_color", "#000", "h1, h2, h3", "Header Color", "--header-color"
, "background_color", "#FFF", ".remark-slide-content", "Slide Background Color", "--background-color"
, "link_color", "rgb(249, 38, 114)", "a, a > code", "Link Color", "--link-color"
, "text_bold_color", "{NULL}", "strong", "Bold Text Color", "--text-bold-color"
, "text_slide_number_color", "{inverse_background_color}", ".remark-slide-number", "Slide Number Color", NA_character_
, "padding", "16px 64px 16px 64px", ".remark-slide-content", "Slide Padding in `top right [bottom left]` format", NA_character_
, "background_image", "{NULL}", ".remark-slide-content", "Background image applied to each *and every* slide. Set `title_slide_background_image = \"none\"` to remove the background image from the title slide", NA_character_
, "background_size", "{NULL}", ".remark-slide-content", "Background image size, requires `background_image` to be set. If `background_image` is set, `background_size` will default to `cover` so the backround fills the screen. If both `background_image` and `background_position` are set, will default to 100 percent", NA_character_
, "background_position", "{NULL}", ".remark-slide-content", "Background image position, requires `background_image` to be set, and it is recommended to adjust `background_size`", NA_character_
, "code_highlight_color", "rgba(255,255,0,0.5)", ".remark-code-line-highlighted", "Code Line Highlight", "--code-highlight-color"
, "code_inline_color", "#000", ".remark-inline-code", "Inline Code Color", NA_character_
, "code_inline_background_color", "{NULL}", ".remark-inline-code", "Inline Code Background Color", NA_character_
, "code_inline_font_size", "1em", ".remark-inline-code", "Inline Code Text Font Size", "--code-inline-font-size"
, "inverse_background_color", "#272822", ".inverse", "Inverse Background Color", "--inverse-background-color"
, "inverse_text_color", "#d6d6d6", ".inverse", "Inverse Text Color", "--inverse-text-color"
, "inverse_text_shadow", "{FALSE}", ".inverse", "Enables Shadow on text of inverse slides", NA_character_
, "inverse_header_color", "#f3f3f3", ".inverse h1, .inverse h2, .inverse h3", "Inverse Header Color", "--inverse-header-color"
, "title_slide_text_color", "{inverse_text_color}", ".title-slide", "Title Slide Text Color", "--title-slide-text-color"
, "title_slide_background_color", "{inverse_background_color}", ".title-slide", "Title Slide Background Color", "--title-slide-background-color"
, "title_slide_background_image", "{NULL}", ".title-slide", "Title Slide Background Image URL", NA_character_
, "title_slide_background_size", "{NULL}", ".title-slide", "Title Slide Background Image Size, defaults to \"cover\" if background image is set", NA_character_
, "title_slide_background_position", "{NULL}", ".title-slide", "Title Slide Background Image Position", NA_character_
, "footnote_color", "{NULL}", ".footnote", "Footnote text color (if `NA`, then it will be the same color as `text_color`)", NA_character_
, "footnote_font_size", "0.9em", ".footnote", "Footnote font size", NA_character_
, "footnote_position_bottom", "60px", ".footnote", "Footnote location from bottom of screen", NA_character_
, "left_column_subtle_color", "#777", ".left-column h2, .left-column h3", "Left Column Text (not last)", NA_character_
, "left_column_selected_color", "#000", ".left-column h2:last-of-type, .left-column h3:last-child", "Left Column Current Selection", NA_character_
, "blockquote_left_border_color", "lightgray", "blockquote", "Blockquote Left Border Color", NA_character_
, "table_border_color", "#666", "table: border-top, border-bottom", "Table top/bottom border", NA_character_
, "table_row_border_color", "#ddd", "table thead th: border-bottom", "Table row inner bottom border", NA_character_
, "table_row_even_background_color", "#eee", "thead, tfoot, tr:nth-child(even)", "Table Even Row Background Color", NA_character_
, "base_font_size", "20px", "html", "Base Font Size for All Slide Elements (must be `px`)", "--base-font-size"
, "text_font_size", "1rem", ".remark-slide-content", "Slide Body Text Font Size", "--text-font-size"
, "header_h1_font_size", "2.75rem", ".remark-slide-content h1", "h1 Header Text Font Size", "--header-h1-font-size"
, "header_h2_font_size", "2.25rem", ".remark-slide-content h2", "h2 Header Text Font Size", "--header-h2-font-size"
, "header_h3_font_size", "1.75rem", ".remark-slide-content h3", "h3 Header Text Font Size", "--header-h3-font-size"
, "header_background_auto", "{FALSE}", "", "Add background under slide title automatically for h1 header elements. If not enabled, use `class: header_background` to enable", NA_character_
, "header_background_color", "{header_color}", ".remark-slide-content h1", "Background Color for h1 Header with Background", "--header-background-color"
, "header_background_text_color", "{background_color}", ".remark-slide-content h1", "Text Color for h1 Header with Background", "--header-background-text-color"
, "header_background_padding", "{NULL}", ".remark-slide-content h1", "Padding for h1 Header with Background", NA_character_
, "header_background_content_padding_top", "7rem", ".remark-slide-content", "Top Padding for Content in Slide with Header with Background", NA_character_
, "header_background_ignore_classes", "{c('normal', 'inverse', 'title', 'middle', 'bottom')}", ".remark-slide-content", "Slide Classes Where Header with Background will not be Applied", NA_character_
, "text_slide_number_font_size", "0.9em", ".remark-slide-number", "Slide Number Text Font Size", NA_character_
, "text_font_google", "{NULL}", "body", "Use `google_font()` to specify body font", NA_character_
, "text_font_family", "Noto Sans", "body", "Body Text Font Family (xaringan default is `'Droid Serif'`)", "--text-font-family"
, "text_font_weight", "normal", "body", "Body Text Font Weight", NA_character_
, "text_font_url", "https://fonts.googleapis.com/css?family=Noto+Sans:400,400i,700,700i&display=swap", "@import url()", "Body Text Font URL(s)", NA_character_
, "text_font_family_fallback", "-apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, Ubuntu, roboto, noto, segoe ui, arial", "body", "Body Text Font Fallbacks", "--text-font-family-fallback"
, "text_font_base", "sans-serif", "body", "Body Text Base Font (Total Failure Fallback)", "--text-font-base"
, "header_font_google", "{NULL}", "body", "Use `google_font()` to specify header font", NA_character_
, "header_font_family", "Cabin", "h1, h2, h3", "Header Font Family (xaringan default is `'Yanone Kaffeesatz'`)", "--header-font-family"
, "header_font_weight", "600", "h1, h2, h3", "Header Font Weight", NA_character_
, "header_font_url", "https://fonts.googleapis.com/css?family=Cabin:600,600i&display=swap", "@import url", "Header Font URL", NA_character_
, "code_font_google", "{NULL}", "body", "Use `google_font()` to specify code font", NA_character_
, "code_font_family", "Source Code Pro", ".remark-code, .remark-inline-code", "Code Font Family", "--code-font-family"
, "code_font_size", "0.9rem", ".remark-inline", "Code Text Font Size", "--code-font-size"
, "code_font_url", "https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700&display=swap", "@import url", "Code Font URL", NA_character_
, "code_font_family_fallback", "Menlo, Consolas, Monaco, Liberation Mono, Lucida Console", ".remark-code, .remark-inline-code", "Code Font Fallback", NA_character_
)

set_default <- function(tv, ...) {
@@ -76,7 +76,7 @@ template_mono_light <- tibble::tribble(
, "white_color", "{lighten_color(base_color, 0.9)}", "multiple", "Brightest color used, default is a very light version of `base_color`"
, "black_color", "{darken_color(base_color, 0.3)}", "multiple", "Darkest color used, default is a very dark, version of `base_color`"
)
template_mono_light <- do.call('rbind', list(template_mono_light, template_variables))
template_mono_light <- dplyr::bind_rows(template_mono_light, template_variables)
template_mono_light <- set_default(
template_mono_light,
text_color = "{black_color}",
@@ -100,7 +100,7 @@ template_mono_dark <- tibble::tribble(
, "white_color", "{lighten_color(base_color, 0.8)}", "multiple", "Brightest color used, default is a very light version of `base_color`"
, "black_color", "{darken_color(base_color, 0.85)}", "multiple", "Darkest color used, default is a very dark, version of `base_color`"
)
template_mono_dark <- do.call('rbind', list(template_mono_dark, template_variables))
template_mono_dark <- dplyr::bind_rows(template_mono_dark, template_variables)
template_mono_dark <- set_default(
template_mono_dark,
text_color = "{white_color}",
@@ -124,7 +124,7 @@ template_mono_accent <- tibble::tribble(
, "white_color", "#FFFFFF", "multiple", "Brightest color used"
, "black_color", "#272822", "multiple", "Darkest color used"
)
template_mono_accent <- do.call('rbind', list(template_mono_accent, template_variables))
template_mono_accent <- dplyr::bind_rows(template_mono_accent, template_variables)
template_mono_accent <- set_default(
template_mono_accent,
text_color = "{black_color}",
@@ -148,7 +148,7 @@ template_mono_accent_inverse <- tibble::tribble(
, "white_color", "#FFFFFF", "multiple", "Brightest color used, default is a very light version of `base_color`"
, "black_color", "{darken_color(base_color, 0.9)}", "multiple", "Darkest color used, default is a very dark, version of `base_color`"
)
template_mono_accent_inverse <- do.call('rbind', list(template_mono_accent_inverse, template_variables))
template_mono_accent_inverse <- dplyr::bind_rows(template_mono_accent_inverse, template_variables)
template_mono_accent_inverse <- set_default(
template_mono_accent_inverse,
text_color = "{white_color}",
@@ -173,7 +173,7 @@ template_duo_light <- tibble::tribble(
, "white_color", "{lighten_color(primary_color, 0.99)}", "multiple", "Brightest color used, default is a very light version of `primary_color`"
, "black_color", "{darken_color(secondary_color, 0.9)}", "multiple", "Darkest color used, default is a very dark version of `secondary_color`"
)
template_duo_light <- do.call('rbind', list(template_duo_light, template_variables))
template_duo_light <- dplyr::bind_rows(template_duo_light, template_variables)
template_duo_light <- set_default(
template_duo_light,
text_color = "{black_color}",
@@ -196,7 +196,7 @@ template_duo <- tibble::tribble(
, "primary_color", "#1F4257", "multiple", "Duotone Primary Color"
, "secondary_color", "#F97B64", "multiple", "Duotone Secondary Color"
)
template_duo <- do.call('rbind', list(template_duo, template_variables))
template_duo <- dplyr::bind_rows(template_duo, template_variables)
template_duo <- set_default(
template_duo,
text_color = "{choose_dark_or_light(primary_color, darken_color(primary_color, 0.9), lighten_color(secondary_color, 0.99))}",
@@ -223,7 +223,7 @@ template_duo_accent <- tibble::tribble(
, "white_color", "#FFFFFF", "multiple", "Brightest color used"
, "black_color", "#000000", "multiple", "Darkest color used"
)
template_duo_accent <- do.call('rbind', list(template_duo_accent, template_variables))
template_duo_accent <- dplyr::bind_rows(template_duo_accent, template_variables)
template_duo_accent <- set_default(
template_duo_accent,
text_color = "{black_color}",
@@ -327,28 +327,17 @@ template_solarized_dark <- set_default(
table_row_even_background_color = solarized$base02
)


# Theme Generating Helpers ----------------------------------------------


plural_element <- function(css_name) {
is_mult <- grepl(",|and|or", css_name)
is_class <- grepl("^\\.", css_name)
ifelse(is_class,
ifelse(is_mult, "classes", "class"),
ifelse(is_mult, "elements", "element")
)
}

element_description <- function(element) {
out <- rep("", length(element))
multiple <- grepl("multiple", element)
out[multiple] <- "Used in multiple CSS rules."

ifelse(
multiple | is.na(element) | element == "",
out,
glue::glue("Modifies the `{element}` {plural_element(element)}.")
)
}
#nocov end
usethis::use_data(
template_variables,
template_mono_accent,
template_mono_accent_inverse,
template_mono_light,
template_mono_dark,
template_duo,
template_duo_light,
template_duo_accent,
template_duo_accent_inverse,
template_solarized_light,
template_solarized_dark,
internal = TRUE
)

+ 2
- 1
inst/scripts/generate_theme_functions.R ファイルの表示

@@ -1,4 +1,5 @@
source(here::here("R/theme_settings.R"))
source(here::here("R/utils_theme-gen.R"))
load(here::here("R/sysdata.rda"))
# R/theme_settings.R contains element_description() and plural_elements()

setup_theme_function <- function(

+ 2
- 3
make.R ファイルの表示

@@ -1,7 +1,6 @@
setwd(here::here("inst/scripts"))
callr::rscript("data-raw/theme_template_variables.R")
message("Building theme functions")
source("generate_theme_functions.R")
setwd(here::here())
callr::rscript("generate_theme_functions.R", wd = here::here("inst/scripts"))
message("Writing documentation")
devtools::document()


読み込み中…
キャンセル
保存