Compare commits

...

7 Commits

Author SHA1 Message Date
Alan Dipert
e2ae14ca5a simplify buildMask() 2020-04-09 04:30:22 +00:00
Alan Dipert
4b87aa3252 simplify buildMask() 2020-04-09 04:29:30 +00:00
Alan Dipert
d0417c75d6 minor 2020-04-09 03:45:56 +00:00
Alan Dipert
00998b3e14 simplify buildMask() 2020-04-09 03:31:32 +00:00
Alan Dipert
f013fcb5fd Revert minor in mock session 2020-04-08 22:54:27 +00:00
Alan Dipert
45f1e5fe50 mask creation: clean up, document, and align with rlang::new_data_mask() 2020-04-08 22:52:54 +00:00
Alan Dipert
d7feddb131 Improve makeMask comment 2020-04-08 16:50:20 +00:00
3 changed files with 45 additions and 21 deletions

View File

@@ -354,3 +354,4 @@ importFrom(htmltools,validateCssUnit)
importFrom(htmltools,withTags)
importFrom(promises,"%...!%")
importFrom(promises,"%...>%")
importFrom(rlang,env_clone)

View File

@@ -1,13 +1,31 @@
# Create a "data mask" suitable for passing to rlang::eval_tidy. Bindings in
# `env` and bindings in the parent of `env` are merged into a single named list.
# Bindings in `env` take precedence over bindings in the parent of `env`.
#' @noRd
makeMask <- function(env) {
stopifnot(length(rlang::env_parents(env)) > 1)
child <- as.list(env)
parent <- as.list(rlang::env_parent(env))
parent_only <- setdiff(names(parent), names(child))
append(child, parent[parent_only])
# Constructs an rlang::eval_tidy() data mask with semantics appropriate for use
# in testServer().
#
# env is assumed to be session$env, or the environment captured by invoking a
# module under test.
#
# Consider the following module definition and its enclosing environment:
#
# x <- 1
# m <- function(id) {
# y <- 2
# moduleServer(id, function(input, output, session){
# z <- 3
# })
# }
#
# The data mask returned by this function should include z, session,
# output, input, y, and id, but *not* x. Definitions not masked are
# resolved in the environment in which testServer() is called.
#
# env is cloned because rlang::new_data_mask() mutates the parent of its `top`
# argument.
#' @importFrom rlang env_clone
buildMask <- function(env) {
if (identical(parent.env(env), emptyenv()))
stop("env must have a non-empty parent")
clone <- env_clone(env, env_clone(parent.env(env), emptyenv()))
rlang::new_data_mask(clone, parent.env(clone))
}
#' @noRd
@@ -112,7 +130,7 @@ testServer <- function(app, expr, ...) {
withReactiveDomain(
session,
withr::with_options(list(`shiny.allowoutputreads` = TRUE), {
rlang::eval_tidy(quosure, makeMask(session$env), rlang::caller_env())
rlang::eval_tidy(quosure, buildMask(session$env), rlang::caller_env())
})
)
)

View File

@@ -4,29 +4,34 @@
\alias{markdown}
\title{Insert inline Markdown}
\usage{
markdown(mds, extensions = TRUE, ...)
markdown(mds, extensions = TRUE, .noWS = NULL, ...)
}
\arguments{
\item{mds}{A character vector of Markdown source to convert to HTML. If the
vector has more than one element, resulting HTML is concatenated.}
vector has more than one element, a single-element character vector of
concatenated HTML is returned.}
\item{extensions}{Enable Github syntax extensions, defaults to \code{TRUE}.}
\item{extensions}{Enable Github syntax extensions; defaults to \code{TRUE}.}
\item{.noWS}{Character vector used to omit some of the whitespace that would
normally be written around generated HTML. Valid options include \code{before},
\code{after}, and \code{outside} (equivalent to \code{before} and \code{end}).}
\item{...}{Additional arguments to pass to \code{\link[commonmark:markdown_html]{commonmark::markdown_html()}}.
These arguments are \emph{\link[rlang:dyn-dots]{dynamic}}.}
}
\value{
an \code{html}-classed character vector of rendered HTML
a character vector marked as HTML.
}
\description{
This function accepts a character vector of
\href{https://en.wikipedia.org/wiki/Markdown}{Markdown}-syntax text and renders
it to HTML that may be included in a UI.
This function accepts
\href{https://en.wikipedia.org/wiki/Markdown}{Markdown}-syntax text and returns
HTML that may be included in Shiny UIs.
}
\details{
Prior to interpretation as Markdown, leading whitespace is trimmed from text
with \code{\link[glue:trim]{glue::trim()}}. This makes it possible to insert Markdown and for it to
be processed correctly even when the call to \code{markdown()} is indented.
Leading whitespace is trimmed from Markdown text with \code{\link[glue:trim]{glue::trim()}}.
Whitespace trimming ensures Markdown is processed correctly even when the
call to \code{markdown()} is indented within surrounding R code.
By default, \link[commonmark:extensions]{Github extensions} are enabled, but this
can be disabled by passing \code{extensions = FALSE}.