Skip to content

Commit

Permalink
fix: chapters method and show
Browse files Browse the repository at this point in the history
  • Loading branch information
js2264 committed Dec 19, 2023
1 parent 3c6a80b commit cdcf11a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions R/BiocBook-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ setMethod("chapters", signature("BiocBook"), function(object) {
file.path('inst', 'assets', '_book.yml'),
criterion = is_biocbook, path = path(object)
)
chaps <- yaml::read_yaml(book.yml)$book$chapters
if (is.list(chaps)) {
chaps <- unlist(chaps)
chaps <- chaps[names(chaps) != 'part'] |> unlist() |> unname()
}
chapters <- rprojroot::find_root_file(
file.path('inst', yaml::read_yaml(book.yml)$book$chapters),
file.path('inst', chaps),
criterion = is_biocbook, path = path(object)
)
purrr::map(chapters, ~ {
Expand Down Expand Up @@ -86,12 +91,14 @@ setMethod("show", signature("BiocBook"), function(object) {
d <- cli::cli_div(theme = list(ul = list(`margin-left` = 2, before = "")))
cli::cli_ul(cli::col_grey(releases(object)))
cli::cli_end(d)
cat(paste0("- Chapters(", length(chapters(object)), "):\n"))
chaps <- chapters(object)
chaps_names <- names(chaps) |> gsub(' \\{.*}$', '', x = _)
cat(paste0("- Chapters(", length(chaps), "):\n"))
d <- cli::cli_div(theme = list(ul = list(`margin-left` = 2, before = "")))
cli::cli_ul(paste0(
cli::col_grey(stringr::str_trunc(names(chapters(object)), 30) |> stringr::str_pad(31, "right")),
cli::col_grey(stringr::str_trunc(chaps_names, 30) |> stringr::str_pad(31, "right")),
' [',
cli::col_cyan(gsub(path(object), "", chapters(object))),
cli::col_cyan(gsub(path(object), "", chaps)),
']')
)
cli::cli_end(d)
Expand Down

0 comments on commit cdcf11a

Please sign in to comment.