openstax_kitchen 2.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/devcontainer.json +37 -17
  3. data/.github/config.yml +14 -0
  4. data/.github/workflows/tests.yml +5 -15
  5. data/.gitignore +2 -2
  6. data/.inch.yml +6 -0
  7. data/.rubocop.yml +65 -0
  8. data/CHANGELOG.md +85 -1
  9. data/Gemfile +5 -3
  10. data/Gemfile.lock +65 -17
  11. data/README.md +65 -11
  12. data/Rakefile +5 -3
  13. data/bin/console +4 -3
  14. data/docker/Dockerfile +36 -0
  15. data/docker/Dockerfile.ci +10 -0
  16. data/docker/bash +5 -1
  17. data/docker/build +10 -0
  18. data/docker/ci +15 -0
  19. data/docker/run +9 -0
  20. data/docker/tag_and_push_latest +17 -0
  21. data/lefthook.yml +6 -0
  22. data/lib/kitchen/ancestor.rb +38 -1
  23. data/lib/kitchen/book_document.rb +20 -2
  24. data/lib/kitchen/book_element.rb +40 -5
  25. data/lib/kitchen/book_element_enumerator.rb +4 -0
  26. data/lib/kitchen/book_recipe.rb +15 -1
  27. data/lib/kitchen/chapter_element.rb +43 -6
  28. data/lib/kitchen/chapter_element_enumerator.rb +9 -1
  29. data/lib/kitchen/clipboard.rb +35 -4
  30. data/lib/kitchen/composite_chapter_element.rb +21 -6
  31. data/lib/kitchen/composite_page_element.rb +35 -7
  32. data/lib/kitchen/composite_page_element_enumerator.rb +9 -1
  33. data/lib/kitchen/config.rb +20 -6
  34. data/lib/kitchen/counter.rb +9 -2
  35. data/lib/kitchen/debug/print_recipe_error.rb +53 -35
  36. data/lib/kitchen/directions/.rubocop.yml +22 -0
  37. data/lib/kitchen/directions/bake_appendix.rb +4 -4
  38. data/lib/kitchen/directions/bake_chapter_glossary/main.rb +18 -0
  39. data/lib/kitchen/directions/bake_chapter_glossary/v1.rb +30 -0
  40. data/lib/kitchen/directions/bake_chapter_introductions.rb +7 -7
  41. data/lib/kitchen/directions/bake_chapter_key_concepts/main.rb +16 -0
  42. data/lib/kitchen/directions/bake_chapter_key_concepts/v1.rb +35 -0
  43. data/lib/kitchen/directions/bake_chapter_key_equations.rb +30 -20
  44. data/lib/kitchen/directions/bake_chapter_references/main.rb +16 -0
  45. data/lib/kitchen/directions/bake_chapter_references/v1.rb +35 -0
  46. data/lib/kitchen/directions/bake_chapter_section_exercises/main.rb +11 -0
  47. data/lib/kitchen/directions/bake_chapter_section_exercises/v1.rb +28 -0
  48. data/lib/kitchen/directions/bake_chapter_summary.rb +45 -36
  49. data/lib/kitchen/directions/bake_chapter_title/main.rb +11 -0
  50. data/lib/kitchen/directions/bake_chapter_title/v1.rb +24 -0
  51. data/lib/kitchen/directions/bake_checkpoint.rb +44 -0
  52. data/lib/kitchen/directions/bake_composite_chapters.rb +14 -0
  53. data/lib/kitchen/directions/bake_composite_pages.rb +2 -2
  54. data/lib/kitchen/directions/bake_equations.rb +37 -0
  55. data/lib/kitchen/directions/bake_example.rb +39 -11
  56. data/lib/kitchen/directions/bake_figure.rb +8 -5
  57. data/lib/kitchen/directions/bake_first_elements.rb +16 -0
  58. data/lib/kitchen/directions/bake_footnotes/main.rb +2 -2
  59. data/lib/kitchen/directions/bake_footnotes/v1.rb +6 -5
  60. data/lib/kitchen/directions/bake_free_response/free_response.xhtml.erb +10 -0
  61. data/lib/kitchen/directions/bake_free_response/main.rb +11 -0
  62. data/lib/kitchen/directions/bake_free_response/v1.rb +29 -0
  63. data/lib/kitchen/directions/bake_further_research.rb +59 -0
  64. data/lib/kitchen/directions/bake_index/main.rb +2 -2
  65. data/lib/kitchen/directions/bake_index/v1.rb +46 -18
  66. data/lib/kitchen/directions/bake_link_placeholders.rb +24 -0
  67. data/lib/kitchen/directions/bake_math_in_paragraph.rb +5 -3
  68. data/lib/kitchen/directions/bake_non_introduction_pages.rb +26 -0
  69. data/lib/kitchen/directions/bake_notes/bake_autotitled_notes.rb +29 -0
  70. data/lib/kitchen/directions/bake_notes/bake_note_subtitle.rb +22 -0
  71. data/lib/kitchen/directions/bake_notes/bake_numbered_notes.rb +51 -0
  72. data/lib/kitchen/directions/bake_notes/bake_unclassified_notes.rb +30 -0
  73. data/lib/kitchen/directions/bake_numbered_exercise/main.rb +15 -0
  74. data/lib/kitchen/directions/bake_numbered_exercise/v1.rb +47 -0
  75. data/lib/kitchen/directions/bake_numbered_table/main.rb +4 -4
  76. data/lib/kitchen/directions/bake_numbered_table/v1.rb +37 -18
  77. data/lib/kitchen/directions/bake_page_abstracts.rb +30 -0
  78. data/lib/kitchen/directions/bake_preface/main.rb +11 -0
  79. data/lib/kitchen/directions/bake_preface/v1.rb +18 -0
  80. data/lib/kitchen/directions/bake_references/main.rb +16 -0
  81. data/lib/kitchen/directions/bake_references/v1.rb +48 -0
  82. data/lib/kitchen/directions/bake_stepwise.rb +8 -12
  83. data/lib/kitchen/directions/bake_suggested_reading.rb +31 -0
  84. data/lib/kitchen/directions/bake_theorem/main.rb +11 -0
  85. data/lib/kitchen/directions/bake_theorem/v1.rb +28 -0
  86. data/lib/kitchen/directions/bake_toc.rb +49 -22
  87. data/lib/kitchen/directions/bake_unit_title/main.rb +11 -0
  88. data/lib/kitchen/directions/bake_unit_title/v1.rb +23 -0
  89. data/lib/kitchen/directions/bake_unnumbered_tables.rb +7 -5
  90. data/lib/kitchen/directions/book_answer_key_container/eob_solutions_container.xhtml.erb +9 -0
  91. data/lib/kitchen/directions/book_answer_key_container/main.rb +11 -0
  92. data/lib/kitchen/directions/book_answer_key_container/v1.rb +13 -0
  93. data/lib/kitchen/directions/chapter_review_container/chapter_review.xhtml.erb +9 -0
  94. data/lib/kitchen/directions/chapter_review_container/main.rb +11 -0
  95. data/lib/kitchen/directions/chapter_review_container/v1.rb +13 -0
  96. data/lib/kitchen/directions/eoc_section_title_link_snippet.rb +20 -0
  97. data/lib/kitchen/directions/move_exercises_to_eoc/main.rb +27 -0
  98. data/lib/kitchen/directions/move_exercises_to_eoc/v1.rb +36 -0
  99. data/lib/kitchen/directions/move_exercises_to_eoc/v2.rb +49 -0
  100. data/lib/kitchen/directions/move_solutions_to_answer_key/main.rb +14 -0
  101. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/american_government.rb +19 -0
  102. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb +41 -0
  103. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/uphysics.rb +63 -0
  104. data/lib/kitchen/directions/move_solutions_to_answer_key/v1.rb +34 -0
  105. data/lib/kitchen/directions/move_title_text_into_span.rb +2 -2
  106. data/lib/kitchen/document.rb +83 -13
  107. data/lib/kitchen/element.rb +20 -3
  108. data/lib/kitchen/element_base.rb +373 -63
  109. data/lib/kitchen/element_enumerator.rb +8 -0
  110. data/lib/kitchen/element_enumerator_base.rb +297 -28
  111. data/lib/kitchen/element_enumerator_factory.rb +64 -53
  112. data/lib/kitchen/element_factory.rb +27 -12
  113. data/lib/kitchen/errors.rb +5 -0
  114. data/lib/kitchen/example_element.rb +21 -6
  115. data/lib/kitchen/example_element_enumerator.rb +9 -1
  116. data/lib/kitchen/exercise_element.rb +42 -0
  117. data/lib/kitchen/exercise_element_enumerator.rb +21 -0
  118. data/lib/kitchen/figure_element.rb +36 -5
  119. data/lib/kitchen/figure_element_enumerator.rb +9 -1
  120. data/lib/kitchen/metadata_element.rb +34 -0
  121. data/lib/kitchen/metadata_element_enumerator.rb +21 -0
  122. data/lib/kitchen/mixins/block_error_if.rb +24 -4
  123. data/lib/kitchen/note_element.rb +48 -20
  124. data/lib/kitchen/note_element_enumerator.rb +9 -1
  125. data/lib/kitchen/oven.rb +66 -15
  126. data/lib/kitchen/page_element.rb +84 -14
  127. data/lib/kitchen/page_element_enumerator.rb +9 -1
  128. data/lib/kitchen/pantry.rb +28 -1
  129. data/lib/kitchen/patches/nokogiri.rb +59 -2
  130. data/lib/kitchen/patches/renderable.rb +9 -3
  131. data/lib/kitchen/patches/string.rb +8 -0
  132. data/lib/kitchen/recipe.rb +69 -32
  133. data/lib/kitchen/reference_element.rb +27 -0
  134. data/lib/kitchen/references_element_enumerator.rb +20 -0
  135. data/lib/kitchen/search_history.rb +43 -4
  136. data/lib/kitchen/search_query.rb +106 -0
  137. data/lib/kitchen/selector.rb +24 -0
  138. data/lib/kitchen/selectors/base.rb +65 -0
  139. data/lib/kitchen/selectors/standard_1.rb +21 -0
  140. data/lib/kitchen/table_element.rb +55 -7
  141. data/lib/kitchen/table_element_enumerator.rb +9 -1
  142. data/lib/kitchen/templates/eob_section_title_template.xhtml.erb +10 -0
  143. data/lib/kitchen/templates/eoc_section_title_template.xhtml.erb +10 -0
  144. data/lib/kitchen/term_element.rb +15 -4
  145. data/lib/kitchen/term_element_enumerator.rb +9 -1
  146. data/lib/kitchen/transliterations.rb +7 -5
  147. data/lib/kitchen/type_casting_element_enumerator.rb +17 -1
  148. data/lib/kitchen/unit_element.rb +45 -0
  149. data/lib/kitchen/unit_element_enumerator.rb +20 -0
  150. data/lib/kitchen/utils.rb +10 -13
  151. data/lib/kitchen/version.rb +5 -1
  152. data/lib/locales/en.yml +18 -7
  153. data/lib/locales/pl.yml +24 -0
  154. data/lib/openstax_kitchen.rb +44 -42
  155. data/openstax_kitchen.gemspec +26 -20
  156. data/tutorials/00/solution1.rb +9 -0
  157. data/tutorials/00/solution2.rb +8 -0
  158. data/tutorials/01/solution1.rb +18 -0
  159. data/tutorials/01/solution2.rb +26 -0
  160. data/tutorials/02/solution1.rb +31 -0
  161. data/tutorials/03/{solution_1.rb → solution1.rb} +6 -4
  162. data/tutorials/03/solution2.rb +18 -0
  163. data/tutorials/04/{solution_1.rb → solution1.rb} +4 -2
  164. data/tutorials/04/{solution_2.rb → solution2.rb} +6 -4
  165. data/tutorials/05/solution1.rb +11 -0
  166. data/tutorials/check_it +16 -15
  167. data/tutorials/setup_my_recipes +7 -6
  168. metadata +149 -24
  169. data/Dockerfile +0 -19
  170. data/docker-compose.yml +0 -12
  171. data/docker/entrypoint +0 -9
  172. data/lib/kitchen/directions/bake_chapter_glossary.rb +0 -34
  173. data/lib/kitchen/directions/bake_exercises.rb +0 -164
  174. data/lib/kitchen/directions/bake_notes.rb +0 -58
  175. data/tutorials/00/solution_1.rb +0 -7
  176. data/tutorials/00/solution_2.rb +0 -6
  177. data/tutorials/01/solution_1.rb +0 -16
  178. data/tutorials/01/solution_2.rb +0 -24
  179. data/tutorials/02/solution_1.rb +0 -29
  180. data/tutorials/03/solution_2.rb +0 -15
  181. data/tutorials/05/solution_1.rb +0 -9
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeChapterTitle
6
+ def self.v1(book:)
7
+ V1.new.bake(book: book)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeChapterTitle
4
+ class V1
5
+ def bake(book:)
6
+ book.chapters.each do |chapter|
7
+ fix_up_chapter_title(chapter: chapter)
8
+ end
9
+ end
10
+
11
+ def fix_up_chapter_title(chapter:)
12
+ heading = chapter.at('h1[2]')
13
+ heading[:id] = "chapTitle#{chapter.count_in(:book)}"
14
+ heading.replace_children(with:
15
+ <<~HTML
16
+ <span class="os-part-text">#{I18n.t(:chapter)} </span>
17
+ <span class="os-number">#{chapter.count_in(:book)}</span>
18
+ <span class="os-divider"> </span>
19
+ <span data-type="" itemprop="" class="os-text">#{heading.text}</span>
20
+ HTML
21
+ )
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeCheckpoint
6
+ def self.v1(checkpoint:, number:)
7
+ checkpoint.wrap_children(class: 'os-note-body')
8
+
9
+ checkpoint.prepend(child:
10
+ <<~HTML
11
+ <div class="os-title">
12
+ <span class="os-title-label">#{I18n.t(:checkpoint)} </span>
13
+ <span class="os-number">#{number}</span>
14
+ <span class="os-divider"> </span>
15
+ </div>
16
+ HTML
17
+ )
18
+
19
+ exercise = checkpoint.exercises.first!
20
+ exercise.search("[data-type='commentary']").trash
21
+
22
+ problem = exercise.problem
23
+ problem.wrap_children(class: 'os-problem-container')
24
+
25
+ solution = exercise.solution
26
+ exercise.add_class('unnumbered') unless solution.present?
27
+ return unless solution.present?
28
+
29
+ solution.id = "#{exercise.id}-solution"
30
+ exercise.add_class('os-hasSolution')
31
+
32
+ solution.replace_children(with:
33
+ <<~HTML
34
+ <span class="os-divider"> </span>
35
+ <a class="os-number" href="##{exercise.id}">#{number}</a>
36
+ <div class="os-solution-container">#{solution.children}</div>
37
+ HTML
38
+ )
39
+
40
+ exercise.add_class('unnumbered')
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeCompositeChapters
6
+ def self.v1(book:)
7
+ book.search("[data-type='composite-chapter']").each do |chapter|
8
+ chapter.first("[data-type='document-title']").id =
9
+ "composite-chapter-#{chapter.count_in(:book)}"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
3
5
  module BakeCompositePages
4
-
5
6
  def self.v1(book:)
6
7
  book.search("[data-type='composite-page']").each do |page|
7
8
  page.id = "composite-page-#{page.count_in(:book)}"
8
9
  end
9
10
  end
10
-
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeEquations
6
+ def self.v1(book:, number_decorator: :none)
7
+ book.chapters.search('[data-type="equation"]:not(.unnumbered)').each do |eq|
8
+ chapter = eq.ancestor(:chapter)
9
+ number = "#{chapter.count_in(:book)}.#{eq.count_in(:chapter)}"
10
+
11
+ # Store label information
12
+ equation_label = "#{I18n.t(:equation)} #{number}"
13
+ book.pantry(name: :link_text).store equation_label, label: eq.id
14
+
15
+ decorated_number =
16
+ case number_decorator
17
+ when :none
18
+ number
19
+ when :parentheses
20
+ "(#{number})"
21
+ else
22
+ raise "Unsupported number_decorator '#{number_decorator}'"
23
+ end
24
+
25
+ # Bake the equation
26
+ eq.append(child:
27
+ <<~HTML
28
+ <div class="os-equation-number">
29
+ <span class="os-number">#{decorated_number}</span>
30
+ </div>
31
+ HTML
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,15 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
3
5
  module BakeExample
4
-
5
6
  def self.v1(example:, number:, title_tag:)
6
- example.replace_children(with:
7
- <<~HTML
8
- <div class="body">
9
- #{example.children}
10
- </div>
11
- HTML
12
- )
7
+ example.wrap_children(class: 'body')
13
8
 
14
9
  example.prepend(child:
15
10
  <<~HTML
@@ -21,11 +16,44 @@ module Kitchen
21
16
  HTML
22
17
  )
23
18
 
24
- example.document.pantry(name: :link_text).store "#{I18n.t(:example_label)} #{number}", label: example.id
19
+ example.document
20
+ .pantry(name: :link_text)
21
+ .store("#{I18n.t(:example_label)} #{number}", label: example.id)
25
22
 
26
- example.titles.each {|title| title.name = "h4"}
27
- end
23
+ example.titles.each do |title|
24
+ next if title.parent.has_class?('os-caption-container')
28
25
 
26
+ title.name = 'h4'
27
+ end
28
+
29
+ example.exercises.each do |exercise|
30
+ if (problem = exercise.problem)
31
+ problem.titles.each { |title| title.name = 'h4' }
32
+ problem.wrap_children(class: 'os-problem-container')
33
+ end
34
+
35
+ if (solution = exercise.solution)
36
+ solution.replace_children(with:
37
+ <<~HTML
38
+ <h4 data-type="solution-title">
39
+ <span class="os-title-label">#{I18n.t(:solution)} </span>
40
+ </h4>
41
+ <div class="os-solution-container">#{solution.children}</div>
42
+ HTML
43
+ )
44
+ end
45
+
46
+ exercise.add_class('unnumbered')
47
+
48
+ commentary = exercise.first('[data-type="commentary"]')
49
+ next unless commentary.present?
50
+
51
+ commentary_title = commentary.titles.first
52
+ commentary_title.name = 'h4'
53
+ commentary_title['data-type'] = 'commentary-title'
54
+ commentary_title.wrap_children('span', class: 'os-title-label')
55
+ end
56
+ end
29
57
  end
30
58
  end
31
59
  end
@@ -1,21 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
3
5
  module BakeFigure
4
-
5
6
  def self.v1(figure:, number:)
6
- figure.wrap(%Q(<div class="os-figure#{' has-splash' if figure.has_class?('splash')}">))
7
+ figure.wrap(%(<div class="os-figure#{' has-splash' if figure.has_class?('splash')}">))
7
8
 
8
- figure.document.pantry(name: :link_text).store "Figure #{number}", label: figure.id
9
+ figure.pantry(name: :link_text).store "#{I18n.t(:figure)} #{number}", label: figure.id
10
+ title = figure.title&.cut
9
11
 
10
12
  caption = figure.caption&.cut
11
13
  figure.append(sibling:
12
14
  <<~HTML
13
15
  <div class="os-caption-container">
14
- <span class="os-title-label">Figure </span>
16
+ <span class="os-title-label">#{I18n.t(:figure)} </span>
15
17
  <span class="os-number">#{number}</span>
16
18
  <span class="os-divider"> </span>
19
+ #{"<span class=\"os-title\" data-type=\"title\" id=\"#{title.id}\">#{title.children}</span>" if title}
17
20
  <span class="os-divider"> </span>
18
- #{'<span class="os-caption">' + caption.children.to_s + '</span>'if caption}
21
+ #{"<span class=\"os-caption\">#{caption.children}</span>" if caption}
19
22
  </div>
20
23
  HTML
21
24
  )
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeFirstElements
6
+ def self.v1(within:, selectors:)
7
+ selectors.each do |selector|
8
+ within.search("#{selector}:first-child").each do |problem|
9
+ problem.add_class('first-element')
10
+ problem.parent.add_class('has-first-element')
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
3
5
  module BakeFootnotes
4
-
5
6
  def self.v1(book:)
6
7
  V1.new.bake(book: book)
7
8
  end
8
-
9
9
  end
10
10
  end
11
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen::Directions::BakeFootnotes
2
4
  class V1
3
5
 
@@ -6,7 +8,8 @@ module Kitchen::Directions::BakeFootnotes
6
8
  # appendices, etc) or within chapters. Tackle each case separately
7
9
 
8
10
  book.body.element_children.only(Kitchen::PageElement,
9
- Kitchen::CompositePageElement).each do |page|
11
+ Kitchen::CompositePageElement,
12
+ Kitchen::CompositeChapterElement).each do |page|
10
13
  bake_footnotes_within(page)
11
14
  end
12
15
 
@@ -26,12 +29,10 @@ module Kitchen::Directions::BakeFootnotes
26
29
  aside_id_to_footnote_number[aside_id] = footnote_number
27
30
  end
28
31
 
29
-
30
- container.search("aside").each do |aside|
32
+ container.search('aside').each do |aside|
31
33
  footnote_number = aside_id_to_footnote_number[aside.id]
32
- aside.prepend(child: "<div class='footnote-number'>#{footnote_number}</div>")
34
+ aside.prepend(child: "<div data-type='footnote-number'>#{footnote_number}</div>")
33
35
  end
34
-
35
36
  end
36
37
 
37
38
  end
@@ -0,0 +1,10 @@
1
+ <div class="os-eoc os-free-response-container" data-type="composite-page" data-uuid-key=".free-response">
2
+ <<%= @title_tag %> data-type="document-title">
3
+ <span class="os-text"><%= I18n.t(:eoc_free_response) %></span>
4
+ </<%= @title_tag %>>
5
+ <div data-type="metadata" style="display: none;">
6
+ <h1 data-type="document-title" itemprop="name"><%= I18n.t(:eoc_free_response) %></h1>
7
+ <%= @metadata_elements.paste %>
8
+ </div>
9
+ <%= @free_response_clipboard.paste %>
10
+ </div>
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeFreeResponse
6
+ def self.v1(chapter:, metadata_source:, append_to: nil)
7
+ V1.new.bake(chapter: chapter, metadata_source: metadata_source, append_to: append_to)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeFreeResponse
4
+ class V1
5
+ renderable
6
+
7
+ def bake(chapter:, metadata_source:, append_to:)
8
+ @metadata_elements = metadata_source.children_to_keep.copy
9
+
10
+ @free_response_clipboard = Kitchen::Clipboard.new
11
+ chapter.non_introduction_pages.each do |page|
12
+ free_response_questions = page.free_response
13
+ next if free_response_questions.none?
14
+
15
+ free_response_questions.search('h3').trash
16
+ title = Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: page)
17
+ free_response_questions.each do |free_response_question|
18
+ free_response_question.prepend(child: title)
19
+ free_response_question.cut(to: @free_response_clipboard)
20
+ end
21
+ end
22
+
23
+ append_to_element = append_to || chapter
24
+ @title_tag = append_to ? 'h3' : 'h2'
25
+
26
+ append_to_element.append(child: render(file: 'free_response.xhtml.erb'))
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ # Bake directions for further research
6
+ #
7
+ module BakeFurtherResearch
8
+ def self.v1(chapter:, metadata_source:, uuid_prefix: '.')
9
+ V1.new.bake(
10
+ chapter: chapter,
11
+ metadata_source: metadata_source,
12
+ uuid_prefix: uuid_prefix)
13
+ end
14
+
15
+ class V1
16
+ renderable
17
+ def bake(chapter:, metadata_source:, uuid_prefix: '.')
18
+ @metadata = metadata_source.children_to_keep.copy
19
+ @klass = 'further-research'
20
+ @title = I18n.t(:eoc_further_research_title)
21
+ @uuid_prefix = uuid_prefix
22
+
23
+ further_researches = Clipboard.new
24
+
25
+ chapter.non_introduction_pages.each do |page|
26
+ further_research = page.first('.further-research')
27
+ further_research.first("[data-type='title']")&.trash # get rid of old title if exists
28
+ further_research_title = page.title.copy
29
+ further_research_title.name = 'h3'
30
+ further_research_title.replace_children(with: <<~HTML
31
+ <span class="os-number">#{chapter.count_in(:book)}.#{page.count_in(:chapter)}</span>
32
+ <span class="os-divider"> </span>
33
+ <span class="os-text" data-type="" itemprop="">#{further_research_title.children}</span>
34
+ HTML
35
+ )
36
+
37
+ further_research.prepend(child:
38
+ <<~HTML
39
+ <a href="##{page.title.id}">
40
+ #{further_research_title.paste}
41
+ </a>
42
+ HTML
43
+ )
44
+ further_research.cut(to: further_researches)
45
+ end
46
+
47
+ return if further_researches.none?
48
+
49
+ @content = further_researches.paste
50
+
51
+ @in_composite_chapter = false
52
+
53
+ chapter.append(child: render(file:
54
+ '../templates/eoc_section_title_template.xhtml.erb'))
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
3
5
  module BakeIndex
4
-
5
6
  def self.v1(book:)
6
7
  V1.new.bake(book: book)
7
8
  end
8
-
9
9
  end
10
10
  end
11
11
  end