Skip to content

Commit

Permalink
Merge pull request #7 from shinyworks/standalone
Browse files Browse the repository at this point in the history
Add standalone version.
  • Loading branch information
jonthegeek authored Oct 28, 2024
2 parents 3f3577a + 6d9fba7 commit dfe4dce
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 0.1.0
Date: 2024-10-26 20:06:24 UTC
SHA: 2bee70bc83117035f27771c14607ebc7a9747f4f
3 changes: 2 additions & 1 deletion R/fav.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ fav <- function(name, ...) {

#' Add data URI prefix to base64-encoded icon
#'
#' @param fav_base64
#' @param fav_base64 A base64-encoded character vector generated by
#' [.fav_encode()].
#'
#' @return The base64-encoded icon with the data URI prefix.
#' @keywords internal
Expand Down
64 changes: 64 additions & 0 deletions R/standalone-fav.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ---
# repo: shinyworks/favawesome
# file: standalone-fav.R
# last-updated: 2024-10-28
# license: https://unlicense.org
# imports: [fontawesome, htmltools, jsonlite, rsvg]
# ---
#
# Provides the fav() function from {favawesome} as stand-alone code for use in
# packages that can't import favawesome. See usethis::use_standalone() for usage
# details.
#
# ## Changelog
#
# 2024-10-28:
#
# * Initial version.

# nocov start

#' Use Font Awesome icons as favicons
#'
#' Generate the html necessary to use a Font Awesome icon as the favicon (the
#' icon that appears on browser tabs) for a Shiny app or other HTML document.
#'
#' @return A `shiny.tag` (see [htmltools::tag()]) that can be used to embed a
#' favicon in a Shiny app or other HTML document.
#' @noRd
favawesome_icon <- function(name, ...) {
fav_base64 <- .standalone_fav_encode(name, ...)
fav_href <- .standalone_fav_as_href(fav_base64)
htmltools::tags$head(
htmltools::tags$link(rel = "icon", type = "image/png", href = fav_href)
)
}

#' Load Font Awesome icon and encode
#'
#' @return A base64-encoded character vector representing the icon png.
#' @noRd
.standalone_fav_encode <- function(name, ...) {
jsonlite::base64_enc(
rsvg::rsvg_png(
charToRaw(
fontawesome::fa(name, ...)
),
width = 32,
height = 32
)
)
}

#' Add data URI prefix to base64-encoded icon
#'
#' @param fav_base64 A base64-encoded character vector generated by
#' `.fav_encode()`.
#'
#' @return The base64-encoded icon with the data URI prefix.
#' @noRd
.standalone_fav_as_href <- function(fav_base64) {
paste0("data:image/png;base64,", fav_base64)
}

# nocov end
3 changes: 2 additions & 1 deletion man/dot-fav_as_href.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dfe4dce

Please sign in to comment.