diff --git a/DESCRIPTION b/DESCRIPTION index 78d31603..c1d39ffa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,7 @@ Package: htmltools Type: Package Title: Tools for HTML -Version: 0.3.6.9001 -Date: 2017-04-26 +Version: 0.3.6.9002 Author: RStudio, Inc. Maintainer: Joe Cheng Description: Tools for HTML generation and output. diff --git a/NEWS b/NEWS index cd18ebe1..2c9849b3 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,10 @@ -htmltools 0.3.6.9001 +htmltools 0.3.6.9002 -------------------------------------------------------------------------------- +* The `knit_print` methods are explicitly registered as S3 methods when both + knitr and htmltools are loaded. This means that neither shiny nor htmltools + need to be attached for the `knit_print` methods to work. (#108) + * Updated RcppExports for new version of Rcpp. (#93) * `as.character.shiny.tags()` will handle non-ASCII attributes correctly if they diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 00000000..4f36f59a --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,30 @@ +register_s3_method <- function(pkg, generic, class, fun = NULL) { + stopifnot(is.character(pkg), length(pkg) == 1) + stopifnot(is.character(generic), length(generic) == 1) + stopifnot(is.character(class), length(class) == 1) + + if (is.null(fun)) { + fun <- get(paste0(generic, ".", class), envir = parent.frame()) + } else { + stopifnot(is.function(fun)) + } + + if (pkg %in% loadedNamespaces()) { + registerS3method(generic, class, fun, envir = asNamespace(pkg)) + } + + # Always register hook in case package is later unloaded & reloaded + setHook( + packageEvent(pkg, "onLoad"), + function(...) { + registerS3method(generic, class, fun, envir = asNamespace(pkg)) + } + ) +} + + +.onLoad <- function(...) { + register_s3_method("knitr", "knit_print", "shiny.tag") + register_s3_method("knitr", "knit_print", "html") + register_s3_method("knitr", "knit_print", "shiny.tag.list") +}