Skip to content

Commit 67da1f7

Browse files
authored
Merge pull request #123 from gadenbuie/rc-v1.0.0
2 parents 3d79f5b + 78afee0 commit 67da1f7

24 files changed

+803
-261
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: epoxy
22
Title: String Interpolation for Documents, Reports and Apps
3-
Version: 0.1.1.9000
3+
Version: 1.0.0
44
Authors@R: c(
55
person("Garrick", "Aden-Buie", , "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-7111-0077")),

NEWS.md

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1-
# epoxy (development version)
1+
# epoxy 1.0.0
22

3-
* `epoxy()` now adds a `.data` pronoun that allows you to refer to the list or
4-
data frame passed into either the `.data` argument of `epoxy()` or the `data`
5-
or `.data` chunk options. (#100)
3+
## Breaking Changes
4+
5+
* **Breaking change:** `epoxy_latex()` and the `epoxy_latex` chunk engine it
6+
powers now use `<<` and `>>` to delimit inline expressions. Where you
7+
previously may have used `<expr>`, please now use `<<expr>>`. This breaking
8+
change was necessary to allow the `expr` to include common R operators like
9+
`<` and `>`. (#107)
10+
11+
* **Breaking change:** the `whisker` engine is now powered by
12+
`epoxy_mustache()`, resulting in a few small changes. In particular, if you
13+
previously used a list for the `.data` chunk option in a `whisker` chunk, and
14+
relied on the `whisker` engine's special treatment of lists to iterate over
15+
their items, you'll need to specifically opt into this behavior by adding a
16+
`.vectorized = TRUE` chunk option.
17+
18+
This chunk engine still vectorizes over rows in a data frame by default, where
19+
it's much more likely to be the behavior you want, but bare lists require
20+
specifically opting in. (#103)
621

722
* `.data` is now the preferred chunk option for passing data frames or lists of
8-
data to epoxy chunks. It works in `whisker` and `epoxy` chunks, and is more
9-
consistent with the `.data` argument of `glue()` and `epoxy()`. (#102)
23+
data to epoxy chunks, where previously `data` was used in some places. It
24+
works in `whisker` and `epoxy` chunks, and is more consistent with the `.data`
25+
argument of `glue()` and `epoxy()`. (#102)
26+
27+
## New Features
1028

1129
* New `epoxy_mustache()` provides an epoxy-style interface to the
1230
[mustache](https://mustache.github.io/) templating language, using the
@@ -19,26 +37,29 @@
1937
`epoxy()`, `epoxy_html()` or other epoxy-provided knitr chunk or file as a
2038
template. `epoxy_use_chunk()` lets you re-use a template chunk with new data,
2139
and `epoxy_use_file()` lets you repeatedly use a template stored in a file.
22-
Both function also re-use the options from the template chunk or the options
40+
Both functions also re-use the options from the template chunk or the options
2341
set in the YAML from matter of the template file. See `?epoxy_use` for more
2442
details about how options for both functions are determined. (#106, #116)
2543

26-
* **Breaking change:** now that the `whisker` engine is powered by
27-
`epoxy_mustache()`, there have been a few small changes. In particular, if you
28-
previously used a list for the `.data` chunk option in a `whisker` chunk, and
29-
relied on the `whisker` engine's special treatment of lists to iterate over
30-
their items, you'll need to specifically opt into this behavior by adding a
31-
`.vectorized = TRUE` chunk option.
44+
## Improvements and bug fixes
3245

33-
This chunk engine still vectorizes over rows in a data frame by default, where
34-
it's much more likely to be the behavior you want, but bare lists require
35-
specifically opting in. (#103)
46+
* `epoxy()` now adds a `.data` pronoun that allows you to refer to the list or
47+
data frame passed into either the `.data` argument of `epoxy()` or the `data`
48+
or `.data` chunk options. (#100)
3649

37-
* **Breaking change:** `epoxy_latex()` and the `epoxy_latex` chunk engine it
38-
powers now use `<<` and `>>` to delimit inline expressions. Where you
39-
previously may have used `<expr>`, please now use `<<expr>>`. This breaking
40-
change was necessary to allow the `expr` to include common R operators like
41-
`<` and `>`. (#107)
50+
* `epoxy_html()` now supports inline transformations prefixed with `@` instead
51+
of `.`, e.g. `@strong` instead of `.strong`. Previously, you would have to
52+
place the inline transformer in a nested `{{ }}` block, e.g.
53+
`{{ {{ .strong expr }} }}`, but now you only need `{{@strong expr}}`. To combine the HTML transformer (`epoxy_transform_html()`) with the inline
54+
transformer, you still need to nest: `{{.text-muted {{@strong expr}}}}`
55+
creates `<span class="text-muted"><strong>{expr}</strong></span>`. (#120)
56+
57+
* `epoxy()`, and by extension the LaTex and HTML counterparts, and all `epoxy_*`
58+
knitr engines gain a `.collapse` argument to determine how a vector of
59+
epoxy-transformed templates should be collapsed. The default is `NULL`, which
60+
means that the output is returned as a vector. This argument is also useful in
61+
`epoxy_use_chunk()` and for knitr chunks being used as a vectorized template.
62+
(#115)
4263

4364
* Aded `.sentence` (alias `.sc`) to the list of inline transformers provided by
4465
`epoxy_transform_inline()`. This transformer will capitalize the first letter
@@ -49,27 +70,13 @@
4970
`as.character()` before applying `tools::toTitleCase()`, since `toTitleCase()`
5071
will throw an error for non-character inputs. (#112)
5172

52-
* `epoxy()`, and by extension the LaTex and HTML counterparts, and all `epoxy_*`
53-
knitr engines gain a `.collapse` argument to determine how a vector of
54-
epoxy-transformed templates should be collapsed. The default is `NULL`, which
55-
means that the output is returned as a vector. This argument is also useful in
56-
`epoxy_use_chunk()` and for knitr chunks being used as a vectorized template.
57-
(#115)
58-
59-
* Fixed an issue with `epoxy_inline_transform()` when used with custom
60-
delimiters (#116).
61-
6273
* `epoxy()`, `epoxy_html()`, `epoxy_latex()` and `epoxy_mustache()` (and their
6374
related knitr engines) will all collect remote `tbl_sql` tables before
6475
evaluation. This makes it much easier to pass data from a remote database
6576
using `{dplyr}` and `{dbplyr}`. (#117)
6677

67-
* `epoxy_html()` now supports inline transformations prefixed with `@` instead
68-
of `.`, e.g. `@strong` instead of `.strong`. Previously, you would have to
69-
place the inline transformer in a nested `{{ }}` block, e.g.
70-
`{{ {{ .strong expr }} }}`, but now you only need `{{@strong expr}}`. To combine the HTML transformer (`epoxy_transform_html()`) with the inline
71-
transformer, you still need to nest: `{{.text-muted {{@strong expr}}}}`
72-
creates `<span class="text-muted"><strong>{expr}</strong></span>`. (#120)
78+
* Fixed an issue with `epoxy_inline_transform()` when used with custom
79+
delimiters (#116).
7380

7481
# epoxy 0.1.1
7582

@@ -211,7 +218,7 @@ versions that were available on GitHub prior to the CRAN release.
211218
(#37).
212219

213220
* `epoxy_transform_collapse()` now uses the
214-
[and package](https://and.rossellhayes.com/), which provides language-aware
221+
[and package](https://github.com/rossellhayes/and/), which provides language-aware
215222
conjoining of strings. As a result, the `sep_and` and `sep_or` arguments of
216223
`epoxy_transform_collapse()` are deprecated and are silently ignored if
217224
provided (#45).

R/epoxy_use.R

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ epoxy_use_chunk <- function(.data = NULL, label, ...) {
111111
template$code,
112112
.data = .data,
113113
...,
114-
options = template$opts,
115-
engine = template$opts$engine
114+
options = template$opts
116115
)
117116
}
118117

@@ -135,19 +134,24 @@ epoxy_use_file <- function(.data = NULL, file, ...) {
135134
template,
136135
.data = .data,
137136
...,
138-
options = options,
139-
engine = options$engine %||% "epoxy"
137+
options = options
140138
)
141139
}
142140

143141
read_body_without_yaml <- function(path) {
144142
x <- readLines(path)
145143
x_trimmed <- trimws(x)
146144

145+
if (!any(nzchar(x_trimmed))) {
146+
rlang::abort(paste0("File '", path, "' is empty"))
147+
}
148+
147149
idx_nzchar <- which(nzchar(x_trimmed))[1]
148-
idx_start <- grep("^---$", x_trimmed)[1]
150+
idx_start <- grep("^---$", x_trimmed)
149151

150-
if (idx_nzchar < idx_start) {
152+
if (length(idx_start)) idx_start <- idx_start[1]
153+
154+
if (length(idx_start) == 0 || idx_nzchar < idx_start) {
151155
return(paste(x, collapse = "\n"))
152156
}
153157

@@ -170,7 +174,7 @@ epoxy_use_template <- function(
170174
.data = NULL,
171175
...,
172176
options = list(),
173-
engine = options$engine
177+
engine = NULL
174178
) {
175179
# For options, we want to apply options in this order:
176180
# 0. `.data` from this fn and `eval` from this chunk
@@ -190,17 +194,27 @@ epoxy_use_template <- function(
190194
opts <- purrr::list_assign(opts, !!!opts_current)
191195
opts <- purrr::list_assign(opts, !!!purrr::compact(opts_fn))
192196

197+
engine <- engine %||% options$engine %||% "epoxy"
198+
193199
fn <- switch(
194200
engine,
195201
epoxy = epoxy,
202+
html = ,
196203
epoxy_html = epoxy_html,
204+
latex = ,
197205
epoxy_latex = epoxy_latex,
198-
mustache = epoxy_mustache,
206+
mustache = ,
199207
whisker = epoxy_mustache,
200208
glue = epoxy,
201209
glue_html = epoxy_html,
202210
glue_latex = epoxy_latex,
203-
epoxy
211+
{
212+
rlang::warn(c(
213+
glue("Unexpected engine '{engine}', defaulting to `epoxy()`."),
214+
"i" = "Set an epoxy knitr engine in the chunk or file."
215+
))
216+
epoxy
217+
}
204218
)
205219

206220
call <- rlang::call2(

0 commit comments

Comments
 (0)