Skip to content

Commit

Permalink
Merge pull request #100 from jhudsl/cansavvy/update-vignettes
Browse files Browse the repository at this point in the history
Update vignettes and examples
  • Loading branch information
cansavvy authored Feb 17, 2022
2 parents f0784e1 + 6ffae65 commit bfb3f00
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 297 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ vignettes/.httr-oauth$
^vignettes/quizzes$
^vignettes/references.bib$
^vignettes/toc_close.css$
^package_bundles/$
^package_bundles/leanbuild_0.1.2.tar.gz*
^package_bundles/leanbuild_0.1.2.tgz*
30 changes: 0 additions & 30 deletions .github/workflows/render-leanpub.yml

This file was deleted.

65 changes: 0 additions & 65 deletions .github/workflows/update-leanpub.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ inst/doc
.httr-oauth
tests/testthat/googlesheets_token.rds
run_test.R
/doc/
/Meta/
13 changes: 7 additions & 6 deletions R/bookdown_to_leanpub.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,16 @@ bookdown_to_leanpub <- function(path = ".",
#' @return A list of output files and diagnostics
#' @export
#'
#' @examples \dontrun{
#' @examples
#'
#' ottrpal::bookdown_to_embed_leanpub(base_url = "")
#' ottrpal::bookdown_to_embed_leanpub(
#' base_url = "https://jhudatascience.org/OTTR_Template/",
#' make_book_txt = TRUE,
#' quiz_dir = NULL)
#'
#' ottrpal::bookdown_to_embed_leanpub(chapt_img_key = "chapter_urls.tsv")
#' }
bookdown_to_embed_leanpub <- function(path = ".",
chapt_img_key = NULL,
bookdown_index = file.path("docs", "index.html"),
bookdown_index = file.path(base_url, "index.html"),
base_url = NULL,
clean_up = FALSE,
default_img = NULL,
Expand Down Expand Up @@ -205,7 +206,7 @@ bookdown_to_embed_leanpub <- function(path = ".",
stop("No base_url is supplied and no chapt_img_key file was supplied. Need one or the other.")
}
chapt_df <- get_chapters(
bookdown_index = bookdown_index,
bookdown_index = paste0(base_url, "index.html"),
base_url = base_url
)
}
Expand Down
71 changes: 36 additions & 35 deletions R/set_up.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,49 +209,50 @@ set_up_leanpub <- function(path = ".",
dir.create(output_dir, recursive = TRUE, showWarnings = FALSE)
}

# Declare regex for finding rmd files
rmd_regex <- "[.][R|r]md$"
if (!embed && render) {
# Declare regex for finding rmd files
rmd_regex <- "[.][R|r]md$"

# Get the path to the _bookdown.yml
path <- bookdown_path(path)

if (verbose) {
message(paste0("Looking for bookdown file in ", path))
}
rmd_files <- bookdown_rmd_files(path = path)
# Get the path to the _bookdown.yml
path <- bookdown_path(path)

if (verbose) {
message(paste0(c("Processing these files: ", rmd_files), collapse = "\n"))
}

if (render) {
if (verbose) {
message("Rendering the Book")
message(paste0("Looking for bookdown file in ", path))
}
# Get the index file path
index_file <- grep("index", rmd_files, ignore.case = TRUE, value = TRUE)

index_file <- normalizePath(index_file)
rmd_files <- bookdown_rmd_files(path = path)

if (length(index_file) == 0 || is.na(index_file)) {
index_file <- rmd_files[1]
if (verbose) {
message(paste0(c("Processing these files: ", rmd_files), collapse = "\n"))
}
message(paste("index_file is", index_file))

if (rmarkdown::pandoc_version() >= "2.11") {
output_format <- bookdown::gitbook(pandoc_args = "--citeproc")
output_format$pandoc$args <- c(output_format$pandoc$args, "--citeproc")
} else {
warning("Pandoc version is not greater than 2.11 so citations will not be able to be rendered properly")
output_format <- NULL

if (render) {
if (verbose) {
message("Rendering the Book")
}
# Get the index file path
index_file <- grep("index", rmd_files, ignore.case = TRUE, value = TRUE)

index_file <- normalizePath(index_file)

if (length(index_file) == 0 || is.na(index_file)) {
index_file <- rmd_files[1]
}
message(paste("index_file is", index_file))

if (rmarkdown::pandoc_version() >= "2.11") {
output_format <- bookdown::gitbook(pandoc_args = "--citeproc")
output_format$pandoc$args <- c(output_format$pandoc$args, "--citeproc")
} else {
warning("Pandoc version is not greater than 2.11 so citations will not be able to be rendered properly")
output_format <- NULL
}
bookdown::render_book(
input = index_file,
output_format = output_format,
clean_envir = FALSE
)
}
bookdown::render_book(
input = index_file,
output_format = output_format,
clean_envir = FALSE
)
}

# We only need to copy these things if we are not doing embed
if (!embed) {
if (verbose) message("Copying Resources")
Expand Down
7 changes: 7 additions & 0 deletions inst/extdata/Book.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1-Introduction.md
quiz_ch1.md
2-A-new-chapter.md
3-Topic-of-Section.md
About-this-Course.md
About-the-Authors.md
References.md
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions inst/extdata/resources/chapter_urls.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
url chapt_title img_path
https://jhudatascience.org/OTTR_Template/index.html About this Course resources/chapt_screen_images/index.png
https://jhudatascience.org/OTTR_Template/introduction.html 1 Introduction resources/chapt_screen_images/introduction.png
https://jhudatascience.org/OTTR_Template/a-new-chapter.html 2 A new chapter resources/chapt_screen_images/a-new-chapter.png
https://jhudatascience.org/OTTR_Template/topic-of-section.html 3 Topic of Section resources/chapt_screen_images/topic-of-section.png
https://jhudatascience.org/OTTR_Template/about-the-authors.html About the Authors resources/chapt_screen_images/about-the-authors.png
https://jhudatascience.org/OTTR_Template/references.html References resources/chapt_screen_images/references.png
11 changes: 5 additions & 6 deletions man/bookdown_to_embed_leanpub.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/set_up_leanpub.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bfb3f00

Please sign in to comment.