Skip to content

Reuse epoxy chunks #106

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

Merged
merged 19 commits into from
Aug 16, 2023
Merged

Reuse epoxy chunks #106

merged 19 commits into from
Aug 16, 2023

Conversation

gadenbuie
Copy link
Owner

@gadenbuie gadenbuie commented Aug 9, 2023

This PR adds a helper function to make it easier to reuse epoxy chunks as templates throughout a document.

```{epoxy movie-release}
{.emph title} was released in {year}.
```

```{r}
# Re-using the template we defined above
epoxy_use_chunk(bechdel[1, ], "movie-release")
```

```{r}
# Using in a dplyr pipeline
bechdel |>
  dplyr::filter(year == 1989) |>
  epoxy_use_chunk("movie-release")
```

Or you could even call it inline:

> `r epoxy_use_chunk(bechdel[2, ], "movie-release")`

📖 Preview the docs: http://pkg.garrickadenbuie.com/epoxy/preview/pr106/reference/epoxy_use_chunk.html

Name

I initially called this function epoxy_template_chunk(), but as I started to write the docs and setup pkgdown I've realized that I use the word template throughout epoxy. I think it's still correct – I use template to mean the text with the {.emph title} strings – but it might be clearer with another naming convention. I also envision another function that uses templates stored in files, so we need to accomodate at least a _file suffix.

Here are some other ideas I considered:

  • epoxy_reuse_chunk()
  • 🥇 epoxy_use_chunk()
  • epoxy_with_chunk()
  • epoxy_from_chunk()
  • epoxy_render_chunk()

After sitting on this for a bit, I've decided to go with epoxy_use_*() as the prefix, as in epoxy_use_chunk() and epoxy_use_file(). In addition to being the shortest function name, it's also a reasonable explanation of what happens. You aren't re-using just the template itself, you're also using all of the settings from the chunk (or from the file when that's implemented).

TODO

  • Choose final name: epoxy_use_chunk()
  • Is chunk option ordering correct?
    • function call > current chunk > template chunk > global chunk options (via current chunk)
    • The "current chunk" options are only the options explicitly set on the current chunk
    • Global chunk options container the current chunk opts (there's no other way), but that's okay.
  • Finish description
  • Add tests
  • NEWS

@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2023

📕 Preview documentation for this PR has been cleaned up.

@codecov-commenter
Copy link

codecov-commenter commented Aug 12, 2023

Codecov Report

Merging #106 (876baef) into main (089e6d8) will increase coverage by 0.23%.
The diff coverage is 100.00%.

❗ Current head 876baef differs from pull request most recent head 4bc2a61. Consider uploading reports for the commit 4bc2a61 to get more accurate results

@@            Coverage Diff             @@
##             main     #106      +/-   ##
==========================================
+ Coverage   95.71%   95.94%   +0.23%     
==========================================
  Files           9       11       +2     
  Lines         886      938      +52     
==========================================
+ Hits          848      900      +52     
  Misses         38       38              
Files Changed Coverage Δ
R/engines.R 94.15% <100.00%> (+0.03%) ⬆️
R/epoxy_use_chunk.R 100.00% <100.00%> (ø)
R/transformers.R 100.00% <100.00%> (ø)
R/utils-knitr.R 100.00% <100.00%> (ø)

@gadenbuie gadenbuie marked this pull request as ready for review August 14, 2023 13:25
@gadenbuie gadenbuie merged commit 345e89d into main Aug 16, 2023
@gadenbuie gadenbuie deleted the feat/template branch August 16, 2023 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants