Skip to content

Commit 5c534a2

Browse files
committed
Merge branch gh-pages of carpentries/styles
2 parents 6ea2e6c + 4f78e17 commit 5c534a2

6 files changed

Lines changed: 68 additions & 44 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ _site
1313
.bundle/
1414
.vendor/
1515
.docker-vendor/
16-
Gemfile.lock
16+
Gemfile.lock
17+
.*history

Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export SHELL = /bin/bash
66

77
# Settings
88
MAKEFILES=Makefile $(wildcard *.mk)
9-
JEKYLL_VERSION=3.8.5
109
JEKYLL=bundle install --path .vendor/bundle && bundle update && bundle exec jekyll
1110
PARSER=bin/markdown_ast.rb
1211
DST=_site
@@ -54,11 +53,14 @@ site : lesson-md
5453

5554
## * docker-serve : use Docker to serve the site
5655
docker-serve :
57-
docker run --rm -it --volume ${PWD}:/srv/jekyll \
58-
--volume=${PWD}/.docker-vendor/bundle:/usr/local/bundle \
59-
-p 127.0.0.1:4000:4000 \
60-
jekyll/jekyll:${JEKYLL_VERSION} \
61-
bin/run-make-docker-serve.sh
56+
docker pull carpentries/lesson-docker:latest
57+
docker run --rm -it \
58+
-v $${PWD}:/home/rstudio \
59+
-p 4000:4000 \
60+
-p 8787:8787 \
61+
-e USERID=$$(id -u) \
62+
-e GROUPID=$$(id -g) \
63+
carpentries/lesson-docker:latest
6264

6365
## * repo-check : check repository settings
6466
repo-check :

_includes/links.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
[pandoc]: https://pandoc.org/
3636
[paper-now]: https://github.com/PeerJ/paper-now
3737
[python-gapminder]: https://swcarpentry.github.io/python-novice-gapminder/
38-
[pyyaml]: https://pypi.python.org/pypi/PyYAML
38+
[pyyaml]: https://pypi.org/project/PyYAML/
3939
[r-markdown]: https://rmarkdown.rstudio.com/
4040
[rstudio]: https://www.rstudio.com/
4141
[ruby-install-guide]: https://www.ruby-lang.org/en/downloads/

assets/css/lesson.scss

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $color-brand: #2b3990 !default;
1010

1111
// code boxes
1212
$color-error: #bd2c00 !default;
13+
$color-warning: #cda01d !default;
1314
$color-output: #303030 !default;
1415
$color-source: #360084 !default;
1516

@@ -36,9 +37,10 @@ $color-testimonial: #fc8dc1 !default;
3637
border-radius: 4px 0 0 4px;
3738
}
3839

39-
.error { @include cdSetup($color-error); }
40-
.output { @include cdSetup($color-output); }
41-
.source { @include cdSetup($color-source); }
40+
.error { @include cdSetup($color-error); }
41+
.warning { @include cdSetup($color-warning); }
42+
.output { @include cdSetup($color-output); }
43+
.source { @include cdSetup($color-source); }
4244

4345
.bash, .language-bash { @include cdSetup($color-source); }
4446
.make, .language-make { @include cdSetup($color-source); }
@@ -48,6 +50,7 @@ $color-testimonial: #fc8dc1 !default;
4850
.sql, .language-sql { @include cdSetup($color-source); }
4951

5052
.error::before,
53+
.warning:before,
5154
.output::before,
5255
.source::before,
5356
.bash::before, .language-bash::before,
@@ -56,13 +59,14 @@ $color-testimonial: #fc8dc1 !default;
5659
.python::before, .language-python::before,
5760
.r::before, .language-r::before,
5861
.sql::before, .language-sql::before {
59-
background-color: #f2eff6;
60-
display: block;
61-
font-weight: bold;
62-
padding: 5px 10px;
62+
background-color: #f2eff6;
63+
display: block;
64+
font-weight: bold;
65+
padding: 5px 10px;
6366
}
6467

6568
.error::before { background-color: #ffebe6; content: "Error"; }
69+
.warning:before { background-color: #f8f4e8; content:" Warning"; }
6670
.output::before { background-color: #efefef; content: "Output"; }
6771
.source::before { content: "Code"; }
6872
.bash::before, .language-bash::before { content: "Bash"; }

bin/chunk-options.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,23 @@ hook_in <- function(x, options) {
4848
hook_out <- function(x, options) {
4949
x <- gsub("\n$", "", x)
5050
stringr::str_c("\n\n~~~\n",
51-
paste0(x, collapse="\n"),
52-
"\n~~~\n{: .output}\n\n")
51+
paste0(x, collapse="\n"),
52+
"\n~~~\n{: .output}\n\n")
5353
}
5454

5555
hook_error <- function(x, options) {
5656
x <- gsub("\n$", "", x)
5757
stringr::str_c("\n\n~~~\n",
58-
paste0(x, collapse="\n"),
59-
"\n~~~\n{: .error}\n\n")
58+
paste0(x, collapse="\n"),
59+
"\n~~~\n{: .error}\n\n")
60+
}
61+
62+
hook_warning <- function(x, options) {
63+
x <- gsub("\n$", "", x)
64+
stringr::str_c("\n\n~~~\n",
65+
paste0(x, collapse = "\n"),
66+
"\n~~~\n{: .warning}\n\n")
6067
}
6168

62-
knit_hooks$set(source = hook_in, output = hook_out, warning = hook_error,
63-
error = hook_error, message = hook_out)
69+
knit_hooks$set(source = hook_in, output = hook_out, warning = hook_warning,
70+
error = hook_error, message = hook_out)

bin/generate_md_episodes.R

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
generate_md_episodes <- function() {
22

3-
library("methods")
4-
5-
if (!require("remotes", quietly = TRUE)) {
6-
install.packages("remotes", repos = c(CRAN = "https://cloud.r-project.org/"))
3+
if (!requireNamespace("renv", quietly = TRUE)) {
4+
install.packages("renv", repos = c(CRAN = "https://cloud.r-project.org/"))
75
}
86

9-
if (!require("requirements", quietly = TRUE)) {
10-
remotes::install_github("hadley/requirements")
7+
if (!requireNamespace("rprojroot", quietly = TRUE)) {
8+
install.packages("rprojroot", repos = c(CRAN = "https://cloud.r-project.org/"))
119
}
1210

11+
cfg <- rprojroot::has_file_pattern("^_config.y*ml$")
12+
root <- rprojroot::find_root(cfg)
13+
1314
required_pkgs <- unique(c(
1415
## Packages for episodes
15-
requirements:::req_dir("_episodes_rmd"),
16+
renv::dependencies(file.path(root, "_episodes_rmd"), progress = FALSE, error = "ignore")$Package,
1617
## Pacakges for tools
17-
requirements:::req_dir("bin")
18+
renv::dependencies(file.path(root, "bin"), progress = FALSE, error = "ignore")$Package
1819
))
1920

2021
missing_pkgs <- setdiff(required_pkgs, rownames(installed.packages()))
@@ -28,7 +29,8 @@ generate_md_episodes <- function() {
2829
if (require("knitr") && packageVersion("knitr") < '1.9.19')
2930
stop("knitr must be version 1.9.20 or higher")
3031

31-
## get the Rmd file to process from the command line, and generate the path for their respective outputs
32+
## get the Rmd file to process from the command line, and generate the path
33+
## for their respective outputs
3234
args <- commandArgs(trailingOnly = TRUE)
3335
if (!identical(length(args), 2L)) {
3436
stop("input and output file must be passed to the script")
@@ -40,20 +42,28 @@ generate_md_episodes <- function() {
4042
## knit the Rmd into markdown
4143
knitr::knit(src_rmd, output = dest_md)
4244

43-
# Read the generated md files and add comments advising not to edit them
44-
vapply(dest_md, function(y) {
45-
con <- file(y)
46-
mdfile <- readLines(con)
47-
if (mdfile[1] != "---")
48-
stop("Input file does not have a valid header")
49-
mdfile <- append(mdfile, "# Please do not edit this file directly; it is auto generated.", after = 1)
50-
mdfile <- append(mdfile, paste("# Instead, please edit",
51-
basename(y), "in _episodes_rmd/"), after = 2)
52-
writeLines(mdfile, con)
53-
close(con)
54-
return(paste("Warning added to YAML header of", y))
55-
},
56-
character(1))
45+
# Read the generated md files and add comments advising not to edit them
46+
add_no_edit_comment <- function(y) {
47+
con <- file(y)
48+
mdfile <- readLines(con)
49+
if (mdfile[1] != "---")
50+
stop("Input file does not have a valid header")
51+
mdfile <- append(
52+
mdfile,
53+
"# Please do not edit this file directly; it is auto generated.",
54+
after = 1
55+
)
56+
mdfile <- append(
57+
mdfile,
58+
paste("# Instead, please edit", basename(y), "in _episodes_rmd/"),
59+
after = 2
60+
)
61+
writeLines(mdfile, con)
62+
close(con)
63+
return(paste("Warning added to YAML header of", y))
64+
}
65+
66+
vapply(dest_md, add_no_edit_comment, character(1))
5767
}
5868

5969
generate_md_episodes()

0 commit comments

Comments
 (0)