Replaces the rules for a sass_layer() object with new rules, and compile it.
This is useful when (for example) you want to compile a set of rules using
variables derived from a theme, but you do not want the resulting CSS for the
entire theme – just the CSS for the specific rules passed in.
Usage
sass_partial(
rules,
bundle,
options = sass_options_get(),
output = NULL,
write_attachments = NA,
cache = sass_cache_get(),
cache_key_extra = NULL
)Arguments
- rules
A set of sass rules, which will be used instead of the rules from
layer.- bundle
A
sass_bundle()orsass_layer()object.- options
Compiler
sass_options().- output
Specifies path to output file for compiled CSS. May be a character string or
output_template()- write_attachments
If the input contains
sass_layer()objects that have file attachments, andoutputis notNULL, then copy the file attachments to the directory ofoutput. (Defaults toNA, which merely emits a warning if file attachments are present, but does not write them to disk; the side-effect of writing extra files is subtle and potentially destructive, as files may be overwritten.)- cache
This can be a directory to use for the cache, a FileCache object created by
sass_file_cache(), orFALSEorNULLfor no caching.- cache_key_extra
additional information to considering when computing the cache key. This should include any information that could possibly influence the resulting CSS that isn't already captured by
input. For example, ifinputcontains something like"@import sass_file.scss"you may want to include thefile.mtime()ofsass_file.scss(or, perhaps, apackageVersion()ifsass_file.scssis bundled with an R package).
Examples
theme <- sass_layer(
defaults = sass_file(system.file("examples/variables.scss", package = "sass")),
rules = sass_file(system.file("examples/rules.scss", package = "sass"))
)
# Compile the theme
sass(theme)
#> /* CSS */
#> body {
#> background-color: #333;
#> color: white;
#> font-size: 16px;
#> }
#>
# Sometimes we want to use the variables from the theme to compile other sass
my_rules <- ".someclass { background-color: $bg; color: $fg; }"
sass_partial(my_rules, theme)
#> /* CSS */
#> .someclass {
#> background-color: #333;
#> color: white;
#> }
#>