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
|
# File 'lib/kitchen/directions/bake_example.rb', line 6
def self.v1(example:, number:, title_tag:, numbered_solutions: false, cases: false)
example.wrap_children(class: 'body')
example.prepend(child:
<<~HTML
<#{title_tag} class="os-title">
<span class="os-title-label">#{I18n.t("example#{'.nominative' if cases}")} </span>
<span class="os-number">#{number}</span>
<span class="os-divider"> </span>
</#{title_tag}>
HTML
)
example.target_label(label_text: 'example', custom_content: number, cases: 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')
end
exercise.solutions.each do |solution|
solution_number = if 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>
#{solution_number}
</h4>
<div class="os-solution-container">#{solution.children}</div>
HTML
)
end
exercise.add_class('unnumbered')
= exercise.first('div[data-type="commentary"]')
next unless .present?
= .titles.first
next unless .present? && .parent['data-type'] != 'list'
.name = 'h4'
['data-type'] = 'commentary-title'
.wrap_children('span', class: 'os-title-label')
end
end
|