From f46536c1ce08d722faca058e8a016a32df5fcfd5 Mon Sep 17 00:00:00 2001 From: Milan Malfait Date: Tue, 14 May 2024 14:36:35 +0100 Subject: [PATCH 1/5] Allow custom carpentry setting --- R/utils.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index 916e04847..633577f03 100644 --- a/R/utils.R +++ b/R/utils.R @@ -188,7 +188,9 @@ which_carpentry <- function(carpentry) { swc = "Software Carpentry", cp = "The Carpentries", incubator = "Carpentries Incubator", - lab = "Carpentries Lab" + lab = "Carpentries Lab", + # Default: match the input + carpentry ) } @@ -199,7 +201,9 @@ which_icon_carpentry <- function(carpentry) { swc = "software", cp = "carpentries", incubator = "incubator", - lab = "lab" + lab = "lab", + # Default: match the input + carpentry ) } From 7a5e4ba9a2075057c2dfe6232bbcfabf7bfb6d4d Mon Sep 17 00:00:00 2001 From: Milan Malfait Date: Tue, 25 Jun 2024 10:47:03 +0100 Subject: [PATCH 2/5] Add optional `carpentry_description` --- R/utils-yaml.R | 2 +- R/utils.R | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/utils-yaml.R b/R/utils-yaml.R index d76a99031..a160a85bb 100644 --- a/R/utils-yaml.R +++ b/R/utils-yaml.R @@ -177,7 +177,7 @@ create_pkgdown_yaml <- function(path) { branch = siQuote(usr$branch), contact = siQuote(usr$contact), # What carpentry are we dealing with? - carpentry_name = siQuote(which_carpentry(usr$carpentry)), + carpentry_name = siQuote(which_carpentry(usr$carpentry, usr$carpentry_description)), carpentry = siQuote(usr$carpentry), carpentry_icon = siQuote(which_icon_carpentry(usr$carpentry)), license = siQuote(usr$license), diff --git a/R/utils.R b/R/utils.R index 633577f03..954ec28f7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -181,7 +181,10 @@ create_description <- function(path) { desc$write(fs::path(path_site(path), "DESCRIPTION")) } -which_carpentry <- function(carpentry) { +which_carpentry <- function(carpentry, carpentry_description = NULL) { + if (!is.null(carpentry_description)) { + return(carpentry_description) + } switch(carpentry, lc = "Library Carpentry", dc = "Data Carpentry", From 07866e4d287a59d7b7976283dfffb6e3ee3d4d72 Mon Sep 17 00:00:00 2001 From: Milan Malfait Date: Tue, 25 Jun 2024 10:49:18 +0100 Subject: [PATCH 3/5] Add `carpentry_description` to the config template --- inst/templates/config-template.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/inst/templates/config-template.txt b/inst/templates/config-template.txt index a498314a6..74ae366d1 100644 --- a/inst/templates/config-template.txt +++ b/inst/templates/config-template.txt @@ -8,8 +8,15 @@ # lc: Library Carpentry # cp: Carpentries (to use for instructor training for instance) # incubator: The Carpentries Incubator +# Note that you can also use a custom carpentry type. For more info, +# see the varnish documentation. +# TODO: add link to varnish documentation once it's there carpentry: {{ carpentry }} +# Custom carpentry description +# This will be used as the alt text for the logo +# carpentry_description: "Custom Carpentry" + # Overall title for pages. title: {{ title }} From 43d207f9e932578f5e56d09303fb21166af544ea Mon Sep 17 00:00:00 2001 From: Milan Malfait Date: Tue, 25 Jun 2024 11:03:59 +0100 Subject: [PATCH 4/5] Test that `which_carpentry` works correctly --- tests/testthat/test-utils.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index e31956b49..b42a2bcfe 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -33,3 +33,15 @@ test_that("a sitemap can be generated for urls", { urls <- c("https://example.com/one", "https://example.com/two") expect_snapshot(urls_to_sitemap(urls)) }) + +test_that("which_carpentry_workshop works for default carpentries", { + expect_equal(which_carpentry("swc"), "Software Carpentry") + expect_equal(which_carpentry("dc"), "Data Carpentry") + expect_equal(which_carpentry("lc"), "Library Carpentry") + expect_equal(which_carpentry("cp"), "The Carpentries") +}) + +test_that("which_carpentry can take a custom description", { + expect_equal(which_carpentry("ice-cream", "Ice Cream Carpentry"), "Ice Cream Carpentry") + expect_equal(which_carpentry("mexican-guitars"), "mexican-guitars") +}) From a2666d817f0d4e8095b454892b313608b561d804 Mon Sep 17 00:00:00 2001 From: Milan Malfait Date: Tue, 25 Jun 2024 21:59:52 +0100 Subject: [PATCH 5/5] Update documentation reference Following updates in carpentries/sandpaper-docs#197 Co-authored-by: Erin Becker --- inst/templates/config-template.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inst/templates/config-template.txt b/inst/templates/config-template.txt index 74ae366d1..5612a6797 100644 --- a/inst/templates/config-template.txt +++ b/inst/templates/config-template.txt @@ -9,8 +9,7 @@ # cp: Carpentries (to use for instructor training for instance) # incubator: The Carpentries Incubator # Note that you can also use a custom carpentry type. For more info, -# see the varnish documentation. -# TODO: add link to varnish documentation once it's there +# see the documentation: https://carpentries.github.io/sandpaper-docs/editing.html carpentry: {{ carpentry }} # Custom carpentry description