Skip to content

Commit 8922887

Browse files
authored
Add bs_add_functions() and bs_add_mixins() (#311)
* Deprecate bs_add_declarations(); add bs_add_functions() and bs_add_mixins(); avoid use of sass_layer(declarations). Follow up to rstudio/sass#80 * Document (GitHub Actions) * update news * Update R/bs-theme-layers.R * Document (GitHub Actions) Co-authored-by: cpsievert <[email protected]>
1 parent 3fd3797 commit 8922887

File tree

11 files changed

+50
-18
lines changed

11 files changed

+50
-18
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Imports:
2222
grDevices,
2323
htmltools (>= 0.5.1),
2424
jsonlite,
25-
sass (>= 0.3.1.9001),
25+
sass (>= 0.3.1.9002),
2626
digest (>= 0.6.25),
2727
jquerylib (>= 0.1.3),
2828
rlang,

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export(bootstrap)
55
export(bootstrap_sass)
66
export(bootswatch_themes)
77
export(bs_add_declarations)
8+
export(bs_add_functions)
9+
export(bs_add_mixins)
810
export(bs_add_rules)
911
export(bs_add_variables)
1012
export(bs_bundle)

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
* Closed #227: `bs_themer()` now overlays a spinner during Sass compilation (#243).
1010
* Closed #278: `{bslib}` now includes `rmarkdown::html_document` templates demonstrating example usage with `{bslib}` and `{thematic}` (#288).
1111
* Closed #231: Upgraded from Bootstrap 4.5.3 to 4.6.0 (#254).
12-
* Closed #237: <blockquote> tags now have border-left/padding styles with version = 4 (to mirror the version = 3 behavior) (#239).
12+
* Closed #237: `<blockquote>` tags now have border-left/padding styles with `version = 4` (to mirror the `version = 3` behavior) (#239).
1313
* Closed #279: Warnings about low color contrasts are now suppressed by default, unless `shiny::devmode()` is enabled. To enable/disable these warnings, set the new `options(bslib.color_contrast_warnings = )` to `TRUE`/`FALSE` (#287).
14+
* Added new `bs_add_functions()`/`bs_add_mixins()` and deprecated `bs_add_declarations()` to reflect `sass::sass_layer()`'s new ability to place `functions` _before_ variable `defaults`. As a result, variable definitions may now use functions defined with `bs_add_functions()`. (#311)
1415

1516
## Bug fixes
1617

R/bs-theme-layers.R

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ bs_add_variables <- function(theme, ..., .where = "defaults", .default_flag = id
7777

7878
vars <- rlang::list2(...)
7979
if (any(names2(vars) == "")) stop("Variables must be named.", call. = FALSE)
80-
.where <- match.arg(.where, c("defaults", "declarations", "rules"))
8180

8281
# Workaround to the problem of 'blue' winning in the scenario of:
8382
# bs_add_variables("body-bg" = "blue")
@@ -126,11 +125,22 @@ bs_add_rules <- function(theme, rules) {
126125
bs_bundle(theme, sass_layer(rules = rules))
127126
}
128127

129-
#' @describeIn bs_bundle Add Sass [functions](https://sass-lang.com/documentation/at-rules/function) and [mixins](https://sass-lang.com/documentation/at-rules/mixin)
130-
#' @param declarations Sass functions and mixins.
128+
#' @describeIn bs_bundle Add additional [Sass
129+
#' functions](https://rstudio.github.io/sass/articles/sass.html#functions-1)
130+
#' @param functions A character vector or [sass::sass_file()] containing
131+
#' functions definitions.
131132
#' @export
132-
bs_add_declarations <- function(theme, declarations) {
133-
bs_bundle(theme, sass_layer(declarations = declarations))
133+
bs_add_functions <- function(theme, functions) {
134+
bs_bundle(theme, sass_layer(functions = functions))
135+
}
136+
137+
#' @describeIn bs_bundle Add additional [Sass
138+
#' mixins](https://rstudio.github.io/sass/articles/sass.html#mixins-1)
139+
#' @param mixins A character vector or [sass::sass_file()] containing
140+
#' mixin definitions.
141+
#' @export
142+
bs_add_mixins <- function(theme, mixins) {
143+
bs_bundle(theme, sass_layer(mixins = mixins))
134144
}
135145

136146
#' @describeIn bs_bundle Add additional [sass::sass_bundle()] objects to an existing `theme`.

R/bs-theme-preview.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ bs_get_variables <- function(theme, varnames) {
591591
css <- sass_partial(
592592
cssvars,
593593
# Add declarations to the current theme
594-
bs_bundle(theme, sass_layer(declarations = sassvars)),
594+
bs_bundle(theme, sass_layer(mixins = sassvars)),
595595
)
596596

597597
# Search the output for the block of properties we just generated, using the

R/bs-theme.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ bootstrap_bundle <- function(version) {
256256
# Don't name this "core" bundle so it can't easily be removed
257257
sass_layer(
258258
defaults = bs4_sass_files(c("deprecated", "functions", "variables")),
259-
declarations = bs4_sass_files("mixins")
259+
mixins = bs4_sass_files("mixins")
260260
),
261261
# Returns a _named_ list of bundles (i.e., these should be easily removed)
262262
!!!rule_bundles(
@@ -285,7 +285,7 @@ bootstrap_bundle <- function(version) {
285285
three = sass_bundle(
286286
sass_layer(
287287
defaults = bs3_sass_files("variables"),
288-
declarations = bs3_sass_files("mixins")
288+
mixins = bs3_sass_files("mixins")
289289
),
290290
# Should match https://github.com/twbs/bootstrap-sass/blob/master/assets/stylesheets/_bootstrap.scss
291291
!!!rule_bundles(
@@ -332,7 +332,7 @@ bootstrap_javascript <- function(version) {
332332
bs3compat_bundle <- function() {
333333
sass_layer(
334334
defaults = sass_file(system_file("bs3compat", "_defaults.scss", package = "bslib")),
335-
declarations = sass_file(system_file("bs3compat", "_declarations.scss", package = "bslib")),
335+
mixins = sass_file(system_file("bs3compat", "_declarations.scss", package = "bslib")),
336336
rules = sass_file(system_file("bs3compat", "_rules.scss", package = "bslib")),
337337
# Gyliphicon font files
338338
file_attachments = c(

R/deprecated.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,10 @@ bootstrap_sass <- function(rules = list(), theme = bs_theme_get(), ...) {
117117
theme$rules <- ""
118118
sass_partial(rules, theme)
119119
}
120+
121+
#' @rdname deprecated
122+
#' @export
123+
bs_add_declarations <- function(theme, declarations) {
124+
.Deprecated("bs_add_mixins")
125+
bs_bundle(theme, sass_layer(declarations = declarations))
126+
}

man/bs_bundle.Rd

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/deprecated.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-global.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test_that("Theme adding works as intended", {
4949

5050
# Can also override variables via declarations
5151
bs_global_add_variables(
52-
.where = "declarations",
52+
.where = "mixins",
5353
"primary" = "$secondary",
5454
"body-color" = "color-contrast($primary)"
5555
)

0 commit comments

Comments
 (0)