forked from swirldev/swirl_courses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomTests.R
53 lines (41 loc) · 1.42 KB
/
customTests.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Put custom tests in this file.
notify <- function() {
e <- get("e", parent.frame())
if(e$val == "No") return(TRUE)
good <- FALSE
while(!good) {
# Get info
name <- readline_clean("What is your full name? ")
address <- readline_clean("What is the email address of the person you'd like to notify? ")
# Repeat back to them
message("\nDoes everything look good?\n")
message("Your name: ", name, "\n", "Send to: ", address)
yn <- select.list(c("Yes", "No"), graphics = FALSE)
if(yn == "Yes") good <- TRUE
}
# Get course and lesson names
course_name <- attr(e$les, "course_name")
lesson_name <- attr(e$les, "lesson_name")
subject <- paste(name, "just completed", course_name, "-", lesson_name)
body = ""
# Send email
swirl:::email(address, subject, body)
hrule()
message("I just tried to create a new email with the following info:\n")
message("To: ", address)
message("Subject: ", subject)
message("Body: <empty>")
message("\nIf it didn't work, you can send the same email manually.")
hrule()
# Return TRUE to satisfy swirl and return to course menu
TRUE
}
readline_clean <- function(prompt = "") {
wrapped <- strwrap(prompt, width = getOption("width") - 2)
mes <- stringr::str_c("| ", wrapped, collapse = "\n")
message(mes)
readline()
}
hrule <- function() {
message("\n", paste0(rep("#", getOption("width") - 2), collapse = ""), "\n")
}