Skip to content

Commit 9bfe679

Browse files
committed
chore: document more functions in setup script
1 parent 1588238 commit 9bfe679

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

scripts/_functions_sass.R

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# We'll use these markers to split the final, full Sass file into four layers
2-
# using the same logic as `sass::sass_layer_file()` and Quarto.
1+
#' Write a Sass layer file used to split the final theme into four layers
2+
#' using the same logic as `sass::sass_layer_file()` and Quarto.
3+
#' @param dir The directory where the `_sass_layer_markers.css` file will be written.
4+
#' @return The path to the newly created Sass layer file.
35
write_sass_layer_markers <- function(dir) {
46
sass_markers <- "/*-- scss:functions --*/
57
// SPLIT: functions
@@ -190,7 +192,6 @@ theme_sass_split <- function(theme_sass_lines) {
190192
theme_split
191193
}
192194

193-
#' Fixes up Bootswatch mixin names to avoid conflicts with Bootstrap's own mixins.
194195
fixup_bootswatch_mixins_file <- function(file) {
195196
# Some Bootswatch files include mixins that conflict with Bootstrap's own
196197
# mixins. We need to rename these mixins to avoid the conflict. This does't
@@ -227,6 +228,10 @@ fixup_bootswatch_mixins_file <- function(file) {
227228
writeLines(lines, file)
228229
}
229230

231+
#' Fixes up Bootswatch mixin names to avoid conflicts with Bootstrap's own mixins.
232+
#' @param dep_files A character vector of paths to all Sass files to scan (looking for
233+
#' `_bootswatch.scss` files).
234+
#' @return A character vector of paths to all `_bootswatch.scss` files.
230235
fixup_bootswatch_mixins <- function(dep_files) {
231236
cli::cli_progress_step("Fix up Bootswatch mixin names")
232237

@@ -235,6 +240,8 @@ fixup_bootswatch_mixins <- function(dep_files) {
235240
for (bsw_file in bsw_files) {
236241
fixup_bootswatch_mixins_file(bsw_file)
237242
}
243+
244+
invisible(bsw_files)
238245
}
239246

240247
#' Copies the theme Sass files to the `shiny/www/shared/sass` directory.
@@ -319,11 +326,18 @@ prepare_and_write_theme_sass_files <- function(version, presets, path_sass_marke
319326
)
320327
}
321328

322-
compile_theme_sass <- function(preset, bundled_presets, output_dir) {
329+
#' Compiles the on-disk theme preset Sass files into CSS.
330+
#' @param preset The name of the preset.
331+
#' @param presets_precompiled A character vector of preset names that py-shiny will
332+
#' precompile and include in the package.
333+
#' @param output_dir The directory where the compiled CSS will be written.
334+
#' @return The path to the compiled CSS file if the preset is precompiled, otherwise
335+
#' `NULL`.
336+
compile_theme_sass <- function(preset, presets_precompiled, output_dir) {
323337
path_preset_scss <- path(output_dir, "preset", preset, "preset.scss")
324338
path_preset_compiled <- path(path_dir(path_preset_scss), "preset.min.css")
325339

326-
verb <- if (preset %in% bundled_presets) "Pre-compil" else "Test"
340+
verb <- if (preset %in% presets_precompiled) "Pre-compil" else "Test"
327341
path_out <- ""
328342

329343
cli::cli_progress_step(
@@ -344,7 +358,7 @@ compile_theme_sass <- function(preset, bundled_presets, output_dir) {
344358
source_map_embed = FALSE
345359
)
346360
)
347-
if (preset %in% bundled_presets) {
361+
if (preset %in% presets_precompiled) {
348362
path_out <- path_rel(path_preset_compiled)
349363
}
350364
cli::cli_progress_done()
@@ -359,14 +373,18 @@ compile_theme_sass <- function(preset, bundled_presets, output_dir) {
359373
file_delete(path_preset_scss)
360374

361375
# Don't bundle precompiled Bootswatch files
362-
if (!preset %in% bundled_presets) {
376+
if (!preset %in% presets_precompiled) {
363377
file_delete(path_preset_compiled)
378+
return(invisible())
364379
}
365380

366381
invisible(path_preset_compiled)
367382
}
368383

369-
write_python_preset_choices <- function(presets, bundled_presets) {
384+
#' Write the Python preset choices to `_theme_presets.py`.
385+
#' @param presets A character vector of preset names.
386+
#' @param presets_precompiled A character vector of preset names that were precompiled.
387+
write_python_preset_choices <- function(presets, presets_precompiled) {
370388
path_presets_py <- path_root("shiny", "ui", "_theme_presets.py")
371389
cli::cli_progress_step("Generate {.path {path_rel(path_presets_py)}}")
372390

@@ -394,13 +412,16 @@ ShinyThemePresetsBundled: tuple[ShinyThemePreset, ...] = (
394412
}
395413

396414
writeLines(
397-
sprintf(template, py_lines(presets), py_lines(presets), py_lines(bundled_presets)),
415+
sprintf(template, py_lines(presets), py_lines(presets), py_lines(presets_precompiled)),
398416
path_presets_py
399417
)
400418

401419
invisible(path_presets_py)
402420
}
403421

422+
#' Copy the compiled CSS from the Shiny preset to the base Bootstrap CSS file. It also
423+
#' replaces the `@import` statement in the Bootstrap CSS file with the correct path to
424+
#' the font CSS file to re-enable pre-downloaded fonts.
404425
copy_shiny_preset_to_base_bootstrap <- function() {
405426
path_preset_shiny <- path_root("shiny", "www", "shared", "sass", "preset", "shiny", "preset.min.css")
406427
path_bootstrap <- path_root("shiny", "www", "shared", "bootstrap", "bootstrap.min.css")

0 commit comments

Comments
 (0)