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
|
# File 'lib/kitchen/directions/bake_custom_sections/v1.rb', line 5
def bake(chapter:, custom_sections_properties:)
custom_sections_properties.each do |_custom_section_name, property|
title_text = I18n.t(:"custom-sections.#{property[:class]}")
property_class = property[:class]
inject = property[:inject]
chapter.search(".#{property_class}").each do |custom_section|
case inject
when 'title'
custom_section_title = custom_section.first('h2')
custom_section_title_os_text = custom_section_title.first('.os-text')
custom_section_title_sibling = custom_section.first('h2 + div')
div_id = custom_section_title_sibling['id']
custom_section_title_sibling.trash
custom_section_title.append(sibling:
" <h3 class=\"os-subtitle\" id=\"\#{div_id}\">\#{custom_section_title_os_text.text}</h3>\n HTML\n )\n custom_section_title_os_text.replace_children(with: title_text)\n when 'subtitle'\n custom_section_title = custom_section.titles.first\n custom_section_title.name = 'h4'\n custom_section_title.prepend(sibling:\n <<~HTML\n <h3 class=\"os-title\">\#{title_text}</h3>\n HTML\n )\n when 'title_prefix'\n custom_section_title = custom_section.titles.first\n custom_section_title.replace_children(with: \"\#{title_text}: \" +\n custom_section_title.text)\n end\n end\n end\nend\n"
|