Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions R/rd-r6-field.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ format_r6_field_section <- function(fields, title, css_class) {

c(
paste0("\\section{", title, "}{"),
rd_if_html(paste0('<div class="', css_class, '">')),
"\\describe{",
paste0(map_chr(fields, format), collapse = "\n\n"),
"}",
rd_if_html("</div>"),
paste0(" ", rd_if_html(paste0('<div class="', css_class, '">'))),
" \\describe{",
paste0(" ", map_chr(fields, format), collapse = "\n\n"),
" }",
paste0(" ", rd_if_html("</div>")),
"}"
)
}
2 changes: 1 addition & 1 deletion R/rd-r6-methods-inherited.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ format.rd_r6_inherited <- function(x, ...) {

# Plain version: just the method name, no link
plain <- sprintf("<code>%s</code>", label)
items <- paste0("<li>", ifelse(topic_ok, linked, plain), "</li>")
items <- paste0(" <li>", ifelse(topic_ok, linked, plain), "</li>")

rd_if_html(paste(
c(details, "<ul>", items, "</ul>", "</details>"),
Expand Down
18 changes: 11 additions & 7 deletions R/rd-r6-methods-self.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ format.rd_r6_method <- function(x, ...) {
push <- function(...) lines <<- c(lines, ...)
push_subsection <- function(title, ...) {
push(
paste0("\\subsection{", title, "}{"),
...,
"}\n"
paste0(" \\subsection{", title, "}{"),
paste0(" ", c(...)),
" }"
)
}

Expand All @@ -48,8 +48,12 @@ format.rd_r6_method <- function(x, ...) {
# Description
if (length(x$description) > 0) {
push(
sub("\n?\n?$", "\n\n", head(x$description, -1)),
utils::tail(x$description, 1)
paste0(
" ",
sub("\n?\n?$", "\n\n", head(x$description, -1)),
recycle0 = TRUE
),
paste0(" ", utils::tail(x$description, 1), recycle0 = TRUE)
)
}

Expand All @@ -71,7 +75,7 @@ format.rd_r6_method <- function(x, ...) {
"Arguments",
rd_if_html('<div class="arguments">'),
"\\describe{",
paste0("\\item{\\code{", nms, "}}{", vals, "}"),
paste0(" \\item{\\code{", nms, "}}{", vals, "}"),
"}",
rd_if_html("</div>")
)
Expand Down Expand Up @@ -102,7 +106,7 @@ format.rd_r6_method <- function(x, ...) {
}

# End
push("}")
push("}\n")

lines
}
Expand Down
6 changes: 3 additions & 3 deletions R/rd-r6-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ format.rd_r6_methods <- function(x, ...) {
push("\\section{Methods}{")
push(
"\\subsection{Public methods}{",
"\\itemize{",
sprintf("\\item \\href{#%s}{%s}", dest, code),
"}",
" \\itemize{",
sprintf(" \\item \\href{#%s}{%s}", dest, code),
" }",
"}"
)
push(format(x$inherited))
Expand Down
114 changes: 56 additions & 58 deletions tests/testthat/_snaps/rd-r6-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
cat(format(docs), sep = "\n")
Output
\section{Public fields}{
\if{html}{\out{<div class="r6-fields">}}
\describe{
\item{\code{x}}{A number.}
\if{html}{\out{<div class="r6-fields">}}
\describe{
\item{\code{x}}{A number.}

\item{\code{y}}{A string.}
}
\if{html}{\out{</div>}}
\item{\code{y}}{A string.}
}
\if{html}{\out{</div>}}
}

# format.rd_r6_class with active bindings
Expand All @@ -26,11 +26,11 @@
cat(format(docs), sep = "\n")
Output
\section{Active bindings}{
\if{html}{\out{<div class="r6-active-bindings">}}
\describe{
\item{\code{val}}{A value.}
}
\if{html}{\out{</div>}}
\if{html}{\out{<div class="r6-active-bindings">}}
\describe{
\item{\code{val}}{A value.}
}
\if{html}{\out{</div>}}
}

# format.rd_r6_class with no inherited methods
Expand All @@ -43,23 +43,23 @@
}
\section{Methods}{
\subsection{Public methods}{
\itemize{
\item \href{#method-C2-meth1}{\code{C2$meth1()}}
}
\itemize{
\item \href{#method-C2-meth1}{\code{C2$meth1()}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-C2-meth1"></a>}}
\if{latex}{\out{\hypertarget{method-C2-meth1}{}}}
\subsection{\code{C2$meth1()}}{
method1
\subsection{Usage}{
\if{html}{\out{<div class="r">}}
\preformatted{C2$meth1()}
\if{html}{\out{</div>}}
method1
\subsection{Usage}{
\if{html}{\out{<div class="r">}}
\preformatted{C2$meth1()}
\if{html}{\out{</div>}}
}
}

}
}

# format.rd_r6_class with inherited methods

Expand All @@ -71,49 +71,48 @@
}
\section{Methods}{
\subsection{Public methods}{
\itemize{
\item \href{#method-B-shared}{\code{B$shared()}}
\item \href{#method-B-clone}{\code{B$clone()}}
}
\itemize{
\item \href{#method-B-shared}{\code{B$shared()}}
\item \href{#method-B-clone}{\code{B$clone()}}
}
}
\if{html}{\out{<details open><summary>Inherited methods</summary>
<ul>
<li><code>R_GlobalEnv::A$only_a()</code></li>
<li><code>R_GlobalEnv::A$only_a()</code></li>
</ul>
</details>}}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-B-shared"></a>}}
\if{latex}{\out{\hypertarget{method-B-shared}{}}}
\subsection{\code{B$shared()}}{
Method from B.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}
\preformatted{B$shared()}
\if{html}{\out{</div>}}
Method from B.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}
\preformatted{B$shared()}
\if{html}{\out{</div>}}
}
}

}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-B-clone"></a>}}
\if{latex}{\out{\hypertarget{method-B-clone}{}}}
\subsection{\code{B$clone()}}{
The objects of this class are cloneable with this method.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}
\preformatted{B$clone(deep = FALSE)}
\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{deep}}{Whether to make a deep clone.}
}
\if{html}{\out{</div>}}
The objects of this class are cloneable with this method.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}
\preformatted{B$clone(deep = FALSE)}
\if{html}{\out{</div>}}
}
\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{deep}}{Whether to make a deep clone.}
}
\if{html}{\out{</div>}}
}
}

}
}

# format.rd_r6_class with markdown sections

Expand All @@ -122,31 +121,30 @@
Output
\section{Methods}{
\subsection{Public methods}{
\itemize{
\item \href{#method-C-meth}{\code{C$meth()}}
}
\itemize{
\item \href{#method-C-meth}{\code{C$meth()}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-C-meth"></a>}}
\if{latex}{\out{\hypertarget{method-C-meth}{}}}
\subsection{\code{C$meth()}}{
Method description.
Method description.

\subsection{Description section}{
Description section body.
}
\subsection{Usage}{
\if{html}{\out{<div class="r">}}
\preformatted{C$meth()}
\if{html}{\out{</div>}}
}

\subsection{Details}{
\subsection{Details section}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}
\preformatted{C$meth()}
\if{html}{\out{</div>}}
}
\subsection{Details}{
\subsection{Details section}{
Details section body.
}
}
}

}
}

22 changes: 11 additions & 11 deletions tests/testthat/_snaps/rd-r6-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
cat(format(fields), sep = "\n")
Output
\section{Public fields}{
\if{html}{\out{<div class="r6-fields">}}
\describe{
\item{\code{x}}{A number.}
\if{html}{\out{<div class="r6-fields">}}
\describe{
\item{\code{x}}{A number.}

\item{\code{y}}{A string.}
}
\if{html}{\out{</div>}}
\item{\code{y}}{A string.}
}
\if{html}{\out{</div>}}
}

# format.rd_r6_bindings produces Active bindings section
Expand All @@ -62,10 +62,10 @@
cat(format(bindings), sep = "\n")
Output
\section{Active bindings}{
\if{html}{\out{<div class="r6-active-bindings">}}
\describe{
\item{\code{val}}{A value.}
}
\if{html}{\out{</div>}}
\if{html}{\out{<div class="r6-active-bindings">}}
\describe{
\item{\code{val}}{A value.}
}
\if{html}{\out{</div>}}
}

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/rd-r6-methods-inherited.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Output
\if{html}{\out{<details open><summary>Inherited methods</summary>
<ul>
<li><code>pkg::A$foo()</code></li>
<li><code>pkg::A$bar()</code></li>
<li><code>pkg::A$foo()</code></li>
<li><code>pkg::A$bar()</code></li>
</ul>
</details>}}

Loading
Loading