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.
3
5
write_sass_layer_markers <- function (dir ) {
4
6
sass_markers <- " /*-- scss:functions --*/
5
7
// SPLIT: functions
@@ -190,7 +192,6 @@ theme_sass_split <- function(theme_sass_lines) {
190
192
theme_split
191
193
}
192
194
193
- # ' Fixes up Bootswatch mixin names to avoid conflicts with Bootstrap's own mixins.
194
195
fixup_bootswatch_mixins_file <- function (file ) {
195
196
# Some Bootswatch files include mixins that conflict with Bootstrap's own
196
197
# mixins. We need to rename these mixins to avoid the conflict. This does't
@@ -227,6 +228,10 @@ fixup_bootswatch_mixins_file <- function(file) {
227
228
writeLines(lines , file )
228
229
}
229
230
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.
230
235
fixup_bootswatch_mixins <- function (dep_files ) {
231
236
cli :: cli_progress_step(" Fix up Bootswatch mixin names" )
232
237
@@ -235,6 +240,8 @@ fixup_bootswatch_mixins <- function(dep_files) {
235
240
for (bsw_file in bsw_files ) {
236
241
fixup_bootswatch_mixins_file(bsw_file )
237
242
}
243
+
244
+ invisible (bsw_files )
238
245
}
239
246
240
247
# ' 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
319
326
)
320
327
}
321
328
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 ) {
323
337
path_preset_scss <- path(output_dir , " preset" , preset , " preset.scss" )
324
338
path_preset_compiled <- path(path_dir(path_preset_scss ), " preset.min.css" )
325
339
326
- verb <- if (preset %in% bundled_presets ) " Pre-compil" else " Test"
340
+ verb <- if (preset %in% presets_precompiled ) " Pre-compil" else " Test"
327
341
path_out <- " "
328
342
329
343
cli :: cli_progress_step(
@@ -344,7 +358,7 @@ compile_theme_sass <- function(preset, bundled_presets, output_dir) {
344
358
source_map_embed = FALSE
345
359
)
346
360
)
347
- if (preset %in% bundled_presets ) {
361
+ if (preset %in% presets_precompiled ) {
348
362
path_out <- path_rel(path_preset_compiled )
349
363
}
350
364
cli :: cli_progress_done()
@@ -359,14 +373,18 @@ compile_theme_sass <- function(preset, bundled_presets, output_dir) {
359
373
file_delete(path_preset_scss )
360
374
361
375
# Don't bundle precompiled Bootswatch files
362
- if (! preset %in% bundled_presets ) {
376
+ if (! preset %in% presets_precompiled ) {
363
377
file_delete(path_preset_compiled )
378
+ return (invisible ())
364
379
}
365
380
366
381
invisible (path_preset_compiled )
367
382
}
368
383
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 ) {
370
388
path_presets_py <- path_root(" shiny" , " ui" , " _theme_presets.py" )
371
389
cli :: cli_progress_step(" Generate {.path {path_rel(path_presets_py)}}" )
372
390
@@ -394,13 +412,16 @@ ShinyThemePresetsBundled: tuple[ShinyThemePreset, ...] = (
394
412
}
395
413
396
414
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 )),
398
416
path_presets_py
399
417
)
400
418
401
419
invisible (path_presets_py )
402
420
}
403
421
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.
404
425
copy_shiny_preset_to_base_bootstrap <- function () {
405
426
path_preset_shiny <- path_root(" shiny" , " www" , " shared" , " sass" , " preset" , " shiny" , " preset.min.css" )
406
427
path_bootstrap <- path_root(" shiny" , " www" , " shared" , " bootstrap" , " bootstrap.min.css" )
0 commit comments