-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify module quarto template with params
instead of using python f-strings. now the template code is regular quarto, rather than needing to escape curly braces
- Loading branch information
1 parent
ac9cc6b
commit e140283
Showing
6 changed files
with
66 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
ruamel.yaml | ||
ruamel.yaml.string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,81 @@ | ||
--- | ||
title: "{title}" | ||
subtitle: "{subtitle}" | ||
execute: | ||
echo: false | ||
echo: false | ||
engine: knitr | ||
--- | ||
|
||
<!-- This file is generated automatically from a template: docs/templates/modules.qmd--> | ||
<!-- This file is generated automatically from a template (docs/templates/modules.qmd) by docs/create-listings.py --> | ||
|
||
```{{r deps}} | ||
```{r deps} | ||
#| message: false | ||
library(dplyr) | ||
library(glue) | ||
library(here) | ||
library(knitr) | ||
library(tidyr) | ||
library(yaml) | ||
meta <- yaml::read_yaml(here("{yaml_file}")) | ||
yaml_to_df <- function(y) {{ | ||
meta <- yaml::read_yaml(here(params$nf_yaml_file)) | ||
yaml_to_df <- function(y) { | ||
dat <- as.data.frame(y) %>% t() %>% as.data.frame() | ||
dat['names'] <- rownames(dat) | ||
dat <- as_tibble(dat) | ||
dat %>% | ||
separate_wider_delim(names, '.', names = c('name', 'value')) %>% | ||
pivot_wider(names_from = value, values_from = V1) | ||
}} | ||
} | ||
``` | ||
|
||
```sh | ||
nf-core {module_type} \ | ||
nf-core `r params$module_type` \ | ||
--git-remote https://github.com/CCBR/nf-modules \ | ||
install {module_name} | ||
install `r params$module_name` | ||
``` | ||
|
||
[{{{{< fa brands github >}}}} https://github.com/CCBR/nf-modules/tree/main/{module_path}](https://github.com/CCBR/nf-modules/tree/main/{module_path}) | ||
[{{< fa brands github >}} https://github.com/CCBR/nf-modules/.../`r params$module_path`](https://github.com/CCBR/nf-modules/tree/main/`r params$module_path`) | ||
|
||
|
||
## {{{{< fa arrow-right-to-bracket >}}}} Input | ||
## {{< fa arrow-right-to-bracket >}} Input | ||
|
||
```{{r input}} | ||
```{r input} | ||
#| message: false | ||
meta$input %>% yaml_to_df() %>% kable() | ||
``` | ||
|
||
## {{{{< fa arrow-right-from-bracket >}}}} Output | ||
## {{< fa arrow-right-from-bracket >}} Output | ||
|
||
```{{r output}} | ||
```{r output} | ||
#| message: false | ||
meta$output %>% yaml_to_df() %>% kable() | ||
``` | ||
|
||
```{{r tools-markdown}} | ||
```{r tools-markdown} | ||
#| output: asis | ||
home_symbol <- '{{{{< fa solid globe >}}}}' | ||
book_symbol <- '{{{{< fa solid book >}}}}' | ||
code_symbol <- '{{{{< fa regular file-code >}}}}' | ||
home_symbol <- '{{< fa solid globe >}}' | ||
book_symbol <- '{{< fa solid book >}}' | ||
code_symbol <- '{{< fa regular file-code >}}' | ||
if ('tools' %in% names(meta)) {{ | ||
if ('tools' %in% names(meta)) { | ||
tools_df <- meta$tools %>% yaml_to_df() | ||
for (colname in c('tool_dev_url', 'homepage', 'documentation')) {{ | ||
if (!(colname %in% colnames(tools_df))) {{ | ||
for (colname in c('tool_dev_url', 'homepage', 'documentation')) { | ||
if (!(colname %in% colnames(tools_df))) { | ||
tools_df[colname] <- NA_character_ | ||
}} | ||
}} | ||
} | ||
} | ||
markdown <- tools_df %>% | ||
mutate(name = glue("### {{ name }}"), | ||
home = case_when(!is.na(homepage) ~ glue("[{{ home_symbol }} Home]({{ homepage }})"), | ||
mutate(name = glue("### { name }"), | ||
home = case_when(!is.na(homepage) ~ glue("[{ home_symbol } Home]({ homepage })"), | ||
TRUE ~ ""), | ||
docs = case_when(!is.na(documentation) ~ glue("[{{ book_symbol }} Docs]({{ documentation }})"), | ||
docs = case_when(!is.na(documentation) ~ glue("[{ book_symbol } Docs]({ documentation })"), | ||
TRUE ~ ""), | ||
code = case_when(!is.na(tool_dev_url) ~ glue("[{{ code_symbol }} Code]({{ tool_dev_url }})"), | ||
code = case_when(!is.na(tool_dev_url) ~ glue("[{ code_symbol } Code]({ tool_dev_url })"), | ||
TRUE ~ ""), | ||
links = paste(home, docs, code, glue("`{{ licence }}`"), | ||
links = paste(home, docs, code, glue("`{ licence }`"), | ||
sep = "   "), | ||
markdown = glue("{{ name }}", "{{ links }}", "{{ description }}", | ||
markdown = glue("{ name }", "{ links }", "{ description }", | ||
.sep = '\n\n') | ||
) %>% | ||
pull(markdown) | ||
cat('## {{{{< fa screwdriver-wrench >}}}} Tools \n\n') | ||
cat('## {{< fa screwdriver-wrench >}} Tools \n\n') | ||
cat(paste(markdown, collapse = "\n\n")) | ||
}} | ||
} | ||
``` |