Skip to content

Commit

Permalink
BREAKING: Remove div, span, mdapply, as_markdown (#7)
Browse files Browse the repository at this point in the history
- Remove div, span, and as_markdown as they have been superseded by qto_div, qt_span, and qto_block
- Remove as_markdown, as it is superseded by calling qto_block(map_qto))
  • Loading branch information
ElianHugh authored Dec 16, 2023
1 parent c102a7b commit beef3ed
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 509 deletions.
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(print,quarto_block)
export(as_markdown)
export(div)
export(map_qto)
export(mdapply)
export(qto_attributes)
export(qto_block)
export(qto_callout)
Expand All @@ -20,7 +17,6 @@ export(qto_pagebreak)
export(qto_shortcode)
export(qto_span)
export(qto_video)
export(span)
export(with_body_column)
export(with_margin_column)
export(with_page_column)
Expand Down
1 change: 0 additions & 1 deletion R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#'
#' @return character vector of length 1
#' @seealso
#' - [as_markdown()]
#' - [knitr::asis_output()]
#'
#' @export
Expand Down
65 changes: 0 additions & 65 deletions R/elements.R

This file was deleted.

44 changes: 0 additions & 44 deletions R/misc.R

This file was deleted.

84 changes: 72 additions & 12 deletions R/with.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,107 @@ handle_extensions <- function(extension, valid_extensions) {
#'
#' See [the Quarto documentation for a full list
#' of available extension options](https://quarto.org/docs/authoring/article-layout.html#available-columns).
#' @param outset should the outset affix be applied to the column class?
#' @param outset If `TRUE`, the ouset affix is applied to the column class
#' @param extension affix to apply to column class
#' @inheritParams div
#' @inheritParams qto_div
#' @inheritDotParams qto_div
#' @export
#' @examples
#' with_body_column("Hello world!")
#' @return character vector of length 1
#' @rdname page-layout
with_body_column <- function(..., attr = NULL, outset = FALSE, extension = NULL) {
with_body_column <- function(...,
outset = FALSE,
id = NULL,
class = NULL,
extension = NULL,
.attributes = NULL,
call = caller_env()) {
extension_string <- handle_extensions(extension, c("left", "right"))
outset_string <- ifelse(isTRUE(outset), "-outset", "")
cls <- sprintf(".column-body%s%s", outset_string, extension_string)
div(..., attr = c(cls, attr))
.attributes <- c(cls, as.list(.attributes))
.attributes <- list_drop_empty(.attributes)
qto_div(
...,
id = id,
.attributes = .attributes,
call = call
)
}

#' @export
#' @rdname page-layout
with_page_column <- function(..., attr = NULL, extension = NULL) {
with_page_column <- function(...,
id = NULL,
class = NULL,
extension = NULL,
.attributes = NULL,
call = caller_env()) {
extension_string <- handle_extensions(extension, c("left", "right"))
cls <- sprintf(".column-page%s", extension_string)
div(..., attr = c(cls, attr))
.attributes <- c(cls, as.list(.attributes))
.attributes <- list_drop_empty(.attributes)
qto_div(
...,
id = id,
.attributes = .attributes,
call = call
)
}

#' @export
#' @rdname page-layout
with_screen_inset_column <- function(..., attr = NULL, extension = NULL) {
with_screen_inset_column <- function(...,
id = NULL,
class = NULL,
extension = NULL,
.attributes = NULL,
call = caller_env()) {
extension_string <- handle_extensions(extension, c("left", "right", "shaded"))
cls <- sprintf(".column-screen-inset%s", extension_string)
div(..., attr = c(cls, attr))
.attributes <- c(cls, as.list(.attributes))
.attributes <- list_drop_empty(.attributes)
qto_div(
...,
id = id,
.attributes = .attributes,
call = call
)
}

#' @export
#' @rdname page-layout
with_screen_column <- function(..., attr = NULL, extension = NULL) {
with_screen_column <- function(...,
id = NULL,
class = NULL,
extension = NULL,
.attributes = NULL,
call = caller_env()) {
extension_string <- handle_extensions(extension, c("left", "right"))
cls <- sprintf(".column-screen%s", extension_string)
div(..., attr = c(cls, attr))
.attributes <- c(cls, as.list(.attributes))
.attributes <- list_drop_empty(.attributes)
qto_div(
...,
id = id,
.attributes = .attributes,
call = call
)
}

#' @export
#' @rdname page-layout
with_margin_column <- function(..., attr = NULL) {
div(..., attr = c(".column-margin", attr))
with_margin_column <- function(...,
id = NULL,
.attributes = NULL,
call = caller_env()) {
.attributes <- c(".column-margin", as.list(.attributes))
.attributes <- list_drop_empty(.attributes)
qto_div(
...,
id = id,
.attributes = .attributes,
call = call
)
}
42 changes: 2 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,46 +122,8 @@ print(fig_example)
We can leverage the `apply` family of functions ability to loop over
list elements to simplify creating many divs at once.

Normally this would require a workaround to allow for printing directly
as markdown content, but `{quartools}` exports the `mdapply` function
(read: “markdown apply”) which allows for directly printing the result
as valid markdown content:

``` r
input <- list(
list(type = "tip", msg = "a tip"),
list(type = "warning", msg = "a warning"),
list(type = "message", msg = "a message")
)

mdapply(input, function(x) div(x$msg, attr = sprintf(".callout-%s", x$type))) |>
print()
```



:::{.callout-tip}

a tip

:::


:::{.callout-warning}

a warning

:::


:::{.callout-message}

a message

:::

`map_qto()` is a similar alternative and allows users to set the
function using the `.type` parameter:
`map_qto()` allows users to set the function using the `.type`
parameter:

``` r
qto_list <- map_qto(list("This is a note.", "And this is a note.", "And this is a note"), .type = "callout")
Expand Down
15 changes: 1 addition & 14 deletions README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,7 @@ print(fig_example)

We can leverage the `apply` family of functions ability to loop over list elements to simplify creating many divs at once.

Normally this would require a workaround to allow for printing directly as markdown content, but `{quartools}` exports the `mdapply` function (read: "markdown apply") which allows for directly printing the result as valid markdown content:

```{r}
input <- list(
list(type = "tip", msg = "a tip"),
list(type = "warning", msg = "a warning"),
list(type = "message", msg = "a message")
)
mdapply(input, function(x) div(x$msg, attr = sprintf(".callout-%s", x$type))) |>
print()
```

`map_qto()` is a similar alternative and allows users to set the function using the `.type` parameter:
`map_qto()` allows users to set the function using the `.type` parameter:

```{r}
qto_list <- map_qto(list("This is a note.", "And this is a note.", "And this is a note"), .type = "callout")
Expand Down
27 changes: 0 additions & 27 deletions man/as_markdown.Rd

This file was deleted.

40 changes: 0 additions & 40 deletions man/div.Rd

This file was deleted.

Loading

0 comments on commit beef3ed

Please sign in to comment.