Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a custom Carpentry type #585

Merged
merged 6 commits into from
Jul 26, 2024
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
2 changes: 1 addition & 1 deletion R/utils-yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 10 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,19 @@ 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",
swc = "Software Carpentry",
cp = "The Carpentries",
incubator = "Carpentries Incubator",
lab = "Carpentries Lab"
lab = "Carpentries Lab",
# Default: match the input
carpentry
milanmlft marked this conversation as resolved.
Show resolved Hide resolved
)
}

Expand All @@ -199,7 +204,9 @@ which_icon_carpentry <- function(carpentry) {
swc = "software",
cp = "carpentries",
incubator = "incubator",
lab = "lab"
lab = "lab",
# Default: match the input
carpentry
)
}

Expand Down
6 changes: 6 additions & 0 deletions inst/templates/config-template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
# 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 documentation: https://carpentries.github.io/sandpaper-docs/editing.html
carpentry: {{ carpentry }}

# Custom carpentry description
# This will be used as the alt text for the logo
# carpentry_description: "Custom Carpentry"
milanmlft marked this conversation as resolved.
Show resolved Hide resolved

# Overall title for pages.
title: {{ title }}

Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
Loading