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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/kitchen/directions/bake_example.rb', line 6
def self.v1(example:, number:, title_tag:, options: {
cases: false,
add_problem_title: false
})
options.reverse_merge!(
cases: false,
add_problem_title: false
)
example.wrap_children(class: 'body')
example.prepend(child:
<<~HTML
<
<span class="os-title-label">
<span class="os-number">
<span class="os-divider"> </span>
</
HTML
)
example.target_label(label_text: 'example', custom_content: number, cases: options[:cases])
example.titles_to_rename.each do |title|
title.name = 'h4'
end
example.exercises.each do |exercise|
next if exercise.baked?
if (problem = exercise.problem)
problem.wrap_children(class: 'os-problem-container')
if options[:add_problem_title]
problem.prepend(child:
<<~HTML
<h4 data-type="problem-title">
<span class="os-title-label">
</h4>
HTML
)
end
end
exercise.solutions.each do |solution|
# It's not used anymore, left just in case we gonna need this in next edition
#
# solution_number = if options[:numbered_solutions]
# "<span class=\"os-number\">#{solution.count_in(:example)}</span>"
# else
# ''
# end
solution.replace_children(with:
<<~HTML
<h4 data-type="solution-title">
<span class="os-title-label">#{I18n.t(:solution)}</span>
</h4>
<div class="os-solution-container">#{solution.children}</div>
HTML
)
end
exercise.add_class('unnumbered')
commentary = exercise.first('div[data-type=""]')
next unless commentary.present?
commentary_title = commentary.titles.first
next unless commentary_title.present? && commentary_title.parent['data-type'] != 'list'
commentary_title.name = 'h4'
commentary_title['data-type'] = 'commentary-title'
commentary_title.wrap_children('span', class: 'os-title-label')
end
end
|