Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Imports:
grDevices,
htmltools (>= 0.4.0.9003),
jsonlite,
sass (>= 0.2.0.9001),
sass (>= 0.2.0.9002),
jquerylib (>= 0.1.2),
rlang
Suggests:
Expand Down
60 changes: 13 additions & 47 deletions R/bs_sass.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,55 +58,23 @@ bootstrap <- function(theme = bs_theme_get(),
theme <- as_bs_theme(theme)
version <- theme_version(theme)
minified <- isTRUE(sass_options$output_style %in% c("compressed", "compact"))
output_css <- if (minified) "bootstrap-custom.min.css" else "bootstrap-custom.css"
js <- bootstrap_javascript(version, minified)

cache_key <- sass::sass_hash(list(
theme,
sass_options,
get_exact_version(version),
utils::packageVersion("bootstraplib")
))

# Temp dir for building the HTML dependencies
output_path <- file.path(
tempdir(),
"bootstraplib",
paste0("bootstrap-", cache_key)
)

# If the output path already exists, then we don't need to write anything.
if (!dir.exists(output_path)) {
dir.create(output_path, recursive = TRUE)

# Compile sass in temp dir
sass::sass(
c(
if (inherits(jquery, "html_dependency")) list(jquery) else jquery,
sass::sass_html_dependencies(
input = theme,
name = "bootstrap",
version = get_exact_version(version),
stylesheet = if (minified) "bootstrap-custom.min.css" else "bootstrap-custom.css",
cache_key = list(get_exact_version(version), utils::packageVersion("bootstraplib")),
options = sass_options,
output = file.path(output_path, output_css),
write_attachments = TRUE,
cache = cache,
write_attachments = TRUE
)

file.copy(js, output_path)
}

c(
if (inherits(jquery, "html_dependency")) list(jquery) else jquery,
list(
htmlDependency(
"bootstrap",
if (version %in% "3") version_bs3 else version_bs4,
src = output_path,
meta = c(
name = "viewport",
content = "width=device-width, initial-scale=1, shrink-to-fit=no"
),
stylesheet = output_css,
script = basename(js)
script = bootstrap_javascript(version, TRUE),
meta = c(
name = "viewport",
content = "width=device-width, initial-scale=1, shrink-to-fit=no"
)
),
theme$html_deps
)
)
}

Expand All @@ -120,5 +88,3 @@ bootstrap_sass <- function(rules = list(), theme = bs_theme_get(), ...) {
theme$rules <- ""
sass::sass(input = list(theme, rules), ...)
}