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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/kitchen/directions/bake_injected_exercise/bake_injected_exercise_question.rb', line 9
def bake(question:, number:, only_number_solution:)
id = question.id
unless only_number_solution
label_number = "#{question.ancestor(:chapter).count_in(:book)}.#{number}"
question.target_label(label_text: 'exercise', custom_content: label_number)
end
if question.answers
case question.answers[:type]
when 'a'
alphabet = *('a'..'z')
else
raise('Unsupported list type for multiple choice options')
end
letter_answers = question.correct_answer_letters(alphabet)
end
if letter_answers.present?
question.append(child:
" <div data-type=\"question-solution\">\#{letter_answers.join(', ')}</div>\n HTML\n )\n end\n\n # Bake question\n unless only_number_solution\n problem_number = \"<span class='os-number'>\#{number}</span>\"\n if question.solution\n problem_number = \"<a class='os-number' href='#\#{id}-solution'>\#{number}</a>\"\n end\n end\n\n context = question.exercise_context_in_question&.cut&.paste\n\n question.prepend(child:\n <<~HTML\n \#{problem_number unless only_number_solution}\n \#{\"<span class='os-divider'>. </span>\" unless only_number_solution}\n <div class=\"os-problem-container\">\n \#{context if context.present?}\n \#{\"<span class='os-divider'>. </span>\" if context.present?}\n \#{question.stimulus&.cut&.paste}\n \#{question.stem.cut.paste}\n \#{question.answers&.cut&.paste}\n </div>\n HTML\n )\n\n # Bake solution\n solution = question.solution\n return unless solution\n\n question.add_class('os-hasSolution')\n solution.id = \"\#{id}-solution\"\n solution.replace_children(with:\n <<~HTML\n <a class='os-number' href='#\#{id}'>\#{number}</a>\n <span class='os-divider'>. </span>\n <div class=\"os-solution-container\">\#{solution.children}</div>\n HTML\n )\nend\n"
|