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

Make 'continue' button customisable in sub-topics #777

Merged
merged 7 commits into from
Jul 21, 2023
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# learnr (development version)

- You can now customize the "continue" button text in sub-topics by adding 'data-continue-text' with your custom label as a property of the section heading — e.g. `### Subtopic Title {data-continue-text="Show Solution"}` (@dave-mills #777).

# learnr 0.11.4

- Moved curl from Imports to Suggests. curl is only required when using an external evaluator (#776).

- The default `try_again` message for checkbox questions now prompts the student to "select every correct answer" regardless of whether the question was created by `question()` or `question_checkbox()` (#783).


# learnr 0.11.3

- Fixed an issue that prevented authors from using symbols, such as `T` or a variable, as the value of the `exercise` chunk option, which caused tutorials with chunks with `exercise = T` to fail to render (thanks @cknotz #757, #758).
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions learnr-js/format/tutorial-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,23 @@ $(document).ready(function () {
const sectionsDOM = $(topicElement).children('.section.level3')
sectionsDOM.each(function (sectionIndex, sectionElement) {
if (topic.progressiveReveal) {
let sectionButtonI18n = 'data-i18n="button.continue"'
let sectionButtonText = 'Continue'

if (sectionElement.dataset.continueText) {
// if custom text is specified, set button text
sectionButtonText = sectionElement.dataset.continueText
// and remove i18n (otherwise translation overwrites custom text)
sectionButtonI18n = ''
}

const continueButton = $(
'<button class="btn btn-default skip" id="' +
'continuebutton-' +
sectionElement.id +
'" data-section-id="' +
sectionElement.id +
'" data-i18n="button.continue">Continue</button>'
`<button
class="btn btn-default skip"
id="continuebutton-${sectionElement.id}"
data-section-id="${sectionElement.id}"
${sectionButtonI18n}
>${sectionButtonText}</button>`
)
continueButton.data('n_clicks', 0)
continueButton.on('click', handleSkipClick)
Expand Down
83 changes: 83 additions & 0 deletions tests/manual/continue-button/continue-button.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: "Tutorial"
output:
learnr::tutorial:
progressive: true
allow_skip: true
language: es
runtime: shiny_prerendered
---

```{r setup, include=FALSE}
library(learnr)
knitr::opts_chunk$set(echo = FALSE)
```


## Topic 1

### Exercise {data-continue-text="Go on..."}

*Here's a simple exercise with an empty code chunk provided for entering the answer.*

Write the R code required to add two plus two:

```{r two-plus-two, exercise=TRUE}

```

### Empty section

Nothing here, but the continue button should follow learnr's default (and be translated).

### Exercise with Code {data-continue-text="Topic Done!"}

*Here's an exercise with some prepopulated code as well as `exercise.lines = 5` to provide a bit more initial room to work.*

Now write a function that adds any two numbers and then call it:

```{r add-function, exercise=TRUE, exercise.lines = 5}
add <- function() {

}
```

## Topic 2

### Exercise with Hint {data-continue-text="Take the quiz"}

*Here's an exercise where the chunk is pre-evaluated via the `exercise.eval` option (so the user can see the default output we'd like them to customize). We also add a "hint" to the correct solution via the chunk immediate below labeled `print-limit-hint`.*

Modify the following code to limit the number of rows printed to 5:

```{r print-limit, exercise=TRUE, exercise.eval=TRUE}
mtcars
```

```{r print-limit-hint}
head(mtcars)
```

### Quiz {data-continue-text="Good work!"}

*You can include any number of single or multiple choice questions as a quiz. Use the `question` function to define a question and the `quiz` function for grouping multiple questions together.*

Some questions to verify that you understand the purposes of various base and recommended R packages:

```{r quiz}
quiz(
question("Which package contains functions for installing other R packages?",
answer("base"),
answer("tools"),
answer("utils", correct = TRUE),
answer("codetools")
),
question("Which of the R packages listed below are used to create plots?",
answer("lattice", correct = TRUE),
answer("tools"),
answer("stats"),
answer("grid", correct = TRUE)
)
)
```

Loading