1#' Obtain a list of all available bootswatch themes.
2#'
3#' @param version the major version of Bootswatch.
4#' @param full_path whether to return a path to the installed theme.
5#' @export
6#' @return a character vector of Bootswatch themes.
7bootswatch_themes <- function(version = version_default(), full_path = FALSE) {
8  list.dirs(bootswatch_dist(version), full.names = full_path, recursive = FALSE)
9}
10
11#' Obtain a theme's Bootswatch theme name
12#'
13#' @inheritParams bs_theme_update
14#' @return the Bootswatch theme named used (if any) in the `theme`.
15#' @export
16theme_bootswatch <- function(theme) {
17  if (!is_bs_theme(theme)) return(NULL)
18
19  swatch <- grep("^bs_bootswatch_", class(theme), value = TRUE)
20  if (!length(swatch)) return(NULL)
21
22  sub("^bs_bootswatch_", "", swatch)
23}
24
25#' Obtain a theme's Bootstrap version
26#'
27#' @inheritParams bs_theme_update
28#' @return the major version of Bootstrap used in the `theme`.
29#' @export
30theme_version <- function(theme) {
31  if (!is_bs_theme(theme)) return(NULL)
32
33  version <- grep("^bs_version_", class(theme), value = TRUE)
34  sub("^bs_version_", "", version)
35}
36
37
38bootswatch_dist <- function(version) {
39  switch_version(
40    version,
41    five = lib_file("bsw5", "dist"),
42    four = lib_file("bsw4", "dist"),
43    three = lib_file("bsw3")
44  )
45}
46