# NOT RUN {
# Raw Sass input
sass("foo { margin: 122px * .3; }")
# List of inputs, including named variables
sass(list(
list(width = "122px"),
"foo { margin: $width * .3; }"
))
# Compile a .scss file
example_file <- system.file("examples/example-full.scss", package = "sass")
sass(sass_file(example_file))
# Import a file
tmp_file <- tempfile()
writeLines("foo { margin: $width * .3; }", tmp_file)
sass(list(
list(width = "122px"),
sass_file(tmp_file)
))
# }
# NOT RUN {
# ======================
# Caching examples
# ======================
# Very slow to compile
fib_sass <- "@function fib($x) {
@if $x <= 1 {
@return $x
}
@return fib($x - 2) + fib($x - 1);
}
body {
width: fib(27);
}"
# The first time this runs it will be very slow
system.time(sass(fib_sass))
# But on subsequent calls, it should be very fast
system.time(sass(fib_sass))
# sass() can be called with cache=NULL; it will be slow
system.time(sass(fib_sass, cache = NULL))
# Clear the cache
sass_cache_get()$reset()
# }
# NOT RUN {
# }
# NOT RUN {
# Example of disabling cache by setting the default cache to NULL.
# Disable the default cache (save the original one first, so we can restore)
old_cache <- sass_cache_get()
sass_cache_set(NULL)
# Will be slow, because no cache
system.time(sass(fib_sass))
# Restore the original cache
sass_cache_set(old_cache)
# }
Run the code above in your browser using DataLab