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
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/kitchen/directions/bake_numbered_exercise/v1.rb', line 5
def bake(exercise:, number:, options:)
problem = exercise.problem
solution = exercise.solution
in_appendix = exercise.has_ancestor?(:page) && exercise.ancestor(:page).has_class?('appendix')
if in_appendix
label_number = number
title_label =
"<span class=\"os-title-label\">#{I18n.t("exercise#{
options[:cases] ? '.nominative' : ''
}")}</span>"
problem_divider = ''
else
label_number = "#{exercise.ancestor(:chapter).count_in(:book)}.#{number}"
title_label = ''
problem_divider = "<span class='os-divider'>. </span>"
end
exercise.target_label(
label_text: 'exercise', custom_content: label_number, cases: options[:cases]
)
problem_number = "<span class='os-number'>#{number}</span>"
suppress_solution =
case options[:suppress_solution_if]
when :even?, :odd?
number.send(options[:suppress_solution_if])
else
options[:suppress_solution_if]
end
if solution.present?
if suppress_solution
solution.trash
exercise.add_class('os-hasSolution-trashed') if options[:note_suppressed_solutions]
else
problem_number = \
if options[:solution_stays_put] || in_appendix
"<span class='os-number'>#{number}</span>"
else
"<a class='os-number' href='##{exercise.id}-solution'>#{number}</a>"
end
bake_solution(
exercise: exercise,
number: number,
solution_stays_put: options[:solution_stays_put],
in_appendix: in_appendix
)
end
end
problem.replace_children(with:
<<~HTML
#{title_label}
#{problem_number}#{problem_divider}
<div class="os-problem-container">#{problem.children}</div>
HTML
)
end
|