-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new sass_html_dependencies() function for more convenient htmlDependency bundling #46
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#' Compile Sass to CSS using LibSass, then return an HTML Dependencies | ||
#' | ||
#' Calls `sass(input, ...)` and wraps the output into a [htmltools::htmlDependency()]. | ||
#' | ||
#' @inheritParams sass | ||
#' @inheritParams htmltools::htmlDependency | ||
#' @param cache_key additional information to include in the `sass_hash()` call used to | ||
#' determine the output directory. This should include any information that could possibly | ||
#' influence the resulting CSS that isn't already captured by `input`. For example, if | ||
#' `input` contains something like `"@import sass_file.scss"` you may want to include the | ||
#' [file.mtime()] of `sass_file.scss` (or, perhaps, a [packageVersion()] if `sass_file.scss` | ||
#' is bundled with an R package). | ||
#' @param stylesheet Absolute file path(s) pointing to stylesheet(s) to include with the dependency | ||
#' | ||
#' @return returns a list of [htmltools::htmlDependency()] objects. The length | ||
#' of the list use 1 unless `input` contains [sass_layer()] object(s) that | ||
#' have `html_deps`. | ||
#' | ||
#' @export | ||
#' @seealso [sass()] | ||
#' @examples | ||
#' str(sass_html_dependencies( | ||
cpsievert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#' input = list(list(color = "red"), "body {color: $color}"), | ||
#' name = "foo", version = "1.0.0", | ||
#' stylesheet = "my-style.css" | ||
#' )) | ||
sass_html_dependencies <- function( | ||
cpsievert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
input, name, version, stylesheet, cache_key = NULL, | ||
cpsievert marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's kind of confusing how the One possibility: maybe all of the |
||
options = sass_options(), write_attachments = TRUE, cache = sass_cache_get(), | ||
script = NULL, meta = NULL, head = NULL) { | ||
|
||
key <- sass_hash(list(input, options, cache_key)) | ||
outDir <- file.path(tempdir(), paste(name, version, key, sep = "-")) | ||
if (!dir.exists(outDir)) dir.create(outDir) | ||
sass( | ||
input, output = file.path(outDir, stylesheet), options = options, | ||
write_attachments = write_attachments, cache = cache | ||
) | ||
|
||
if (!is.null(script)) { | ||
if (!all(fs::is_absolute_path(script))) { | ||
stop("script file paths must all be absolute file paths") | ||
} | ||
fs::file_copy(script, outDir, overwrite = TRUE) | ||
script <- basename(script) | ||
} | ||
|
||
c( | ||
list(htmltools::htmlDependency( | ||
name = name, version = version, | ||
src = c(file = outDir), | ||
stylesheet = stylesheet, | ||
script = script, | ||
meta = meta, head = head | ||
)), | ||
extract_layer(input)$html_deps | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.