rich-iannone / quarto-email

MIT License
4 stars 0 forks source link

allow scheduled email suppression #3

Closed aronatkins closed 1 year ago

aronatkins commented 1 year ago

The rsc_email_suppress_scheduled attribute is always false. Let a report author override this choice with code.

https://github.com/rich-iannone/quarto-email/blob/61443d78e378716819ef8ffc382d798e036c9b48/_extensions/quarto-email/quarto-email.lua#L253

Perhaps something like:

```{r}
if (profit < 0) {
  subject <- "the sky is falling"
  send_email <- TRUE
} else {
  subject <- "this is fine"
  send_email <- FALSE
}

The email body follows.

::: {.email}

::: {.subject} r#subject :::

::: {.scheduled_email} r#send_email :::

:::



The `scheduled_email` chunk would be evaluated by this filter as a "truthy" value.. somehow.
rich-iannone commented 1 year ago

@aronatkins This doesn't seem that bad to implement (though, it will be somewhat hacky). But I do want to be clear on the language here: do we want a truthy/falsy for sending the scheduled email (default is true), or, do we want to adhere strictly to the docs/blastula and ask for a bool based on suppressing the scheduled email?

If the former (as in the example, and thanks for that!) then the div class could be .email-scheduled. If the other case, we could use the longer .email-suppress-scheduled. I could even see having both, but up to you on this bit of API design.

aronatkins commented 1 year ago

The JSON field is rsc_email_suppress_report_attachment. When the JSON does not contain this field, a scheduled render will send email. When the document does not contain .email-suppress-scheduled or .email-scheduled, the JSON should not contain the rsc_email_suppress_report_attachment field.

If we were to choose only one, the "positive" field feels most natural.


To end up with `{"rsc_email_suppress_report_attachment": false}`:

::: {.email-scheduled}
TRUE
:::

To end up with `{"rsc_email_suppress_report_attachment": true}`:

::: {.email-scheduled}
FALSE
:::

This way, the Quarto document asks, "Should email be sent?" and not "Should email not be sent?"

rich-iannone commented 1 year ago

Thanks for clarifying. I've been making that change assuming the first, positive naming scheme.

rich-iannone commented 1 year ago

This is now done with https://github.com/rich-iannone/quarto-email/commit/d4f5df006a9a40975d99be07caac4331680946c6. Default for "rsc_email_suppress_scheduled" is unchanged ("false"). Tested with the example provided in both cases (locally and on Connect).

rich-iannone commented 1 year ago

The example doc I used:

---
format:
  html: default
filters:
  - rich-iannone/quarto-email
---

```{r}

profit <- 500

if (profit < 0) {
  subject <- "the sky is falling"
  send_email <- TRUE
} else {
  subject <- "this is fine"
  send_email <- FALSE
}

The email body follows.

::: {.email}

This email may or may not send.

::: {.subject} r#subject :::

::: {.email-scheduled} r#send_email :::

:::

rich-iannone commented 1 year ago

For testing in Python, there is this modified .qmd doc:

---
format:
  html: default
filters:
  - rich-iannone/quarto-email
---

```{python}

profit = -500

if profit < 0:
  subject = "the sky is falling"
  send_email = True
else:
  subject = "this is fine"
  send_email = False

The email body follows.

::: {.email}

This email may or may not send.

::: {.subject} {python} subject :::

::: {.email-scheduled} {python} send_email :::

:::



It currently does not work as inline Python code makes Quarto hang indefinitely (relevant issue: https://github.com/quarto-dev/quarto-cli/issues/7005). I'll try to find another way and/or see if there will be resolution on this.