Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install rstudio/bslib@main and build bundles #8

Merged
merged 2 commits into from
Apr 26, 2023
Merged
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 MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ recursive-exclude * *.py[co]
recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif

recursive-include shinyswatch/bs5 *
recursive-include shinyswatch/bsw5 *
recursive-include shinyswatch/bsw5 *.min.css
49 changes: 38 additions & 11 deletions scripts/update_bootswatch.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/usr/bin/env Rscript

pak::pkg_install("rstudio/bslib")
# pak::pkg_install("cran::bslib")

library(bslib)
library(rlang)

bslib_info <- sessioninfo::package_info("bslib")
bslib_info_list <- bslib_info[bslib_info$package == "bslib", , drop = TRUE]
bslib_comment <- paste0("// {bslib} version: ", bslib_info_list$source)

# == Approach ================================================================
# We MUST use `{bslib}` themes as the original bootswatch themes
# have been modified to support Shiny markup. Ex: `.well`.
Expand Down Expand Up @@ -133,17 +140,37 @@ ignore <- Map(
)

# Write bundle to disk
sass::sass(
sass_bundle,
# Make a minimized output file
options = sass::sass_options_get(output_style = "compressed"),
output = file.path(out_dir, name, "bootswatch.min.css"),
cache = FALSE,
# Should be `TRUE` if font files are to be saved.
# However, we are not saving them as we are reverting the
# local font paths to the original CDN paths in the code above.
write_attachments = FALSE
)
for (info in list(
# In final package, we only need the minified CSS
list(output_style = "compressed", suffix = ".min.css"),
# Useful for comparing on updates / debugging
list(output_style = "expanded", suffix = ".css")
)) {
output_file <- file.path(out_dir, name, paste0("bootswatch", info$suffix))
sass::sass(
sass_bundle,
# Make a minimized output file
options = sass::sass_options_get(output_style = info$output_style),
output = output_file,
cache = FALSE,
# Should be `TRUE` if font files are to be saved.
# However, we are not saving them as we are reverting the
# local font paths to the original CDN paths in the code above.
write_attachments = FALSE
)
if (info$output_style == "expanded") {
# Add comments on where the file came from
writeLines(
c(
bslib_comment,
paste0("// bw: 5: ", ver),
paste0("// bsw5 theme: ", name),
readLines(output_file)
),
output_file
)
}
}
}
)

Expand Down
Loading