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
@@ -1,9 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen::Directions::BakeIndex
4
+ # Bake directions for eob index
5
+ #
2
6
  class V1
3
7
  renderable
4
8
 
5
9
  class Term
6
- attr_reader :text, :id, :group_by, :page_title
10
+ attr_reader :text
11
+ attr_reader :id
12
+ attr_reader :group_by
13
+ attr_reader :page_title
7
14
 
8
15
  def initialize(text:, id:, group_by:, page_title:)
9
16
  @text = text.strip
@@ -37,8 +44,12 @@ module Kitchen::Directions::BakeIndex
37
44
  @term_text = @term_text.uncapitalize
38
45
  end
39
46
 
47
+ def capitalize_term_text!
48
+ @term_text = @term_text.capitalize
49
+ end
50
+
40
51
  def <=>(other)
41
- self.sortable <=> other.sortable
52
+ sortable <=> other.sortable
42
53
  end
43
54
 
44
55
  protected
@@ -64,7 +75,8 @@ module Kitchen::Directions::BakeIndex
64
75
  def <=>(other)
65
76
  return -1 if force_first
66
77
  return 1 if other.force_first
67
- self.name <=> other.name
78
+
79
+ name <=> other.name
68
80
  end
69
81
 
70
82
  protected
@@ -76,6 +88,11 @@ module Kitchen::Directions::BakeIndex
76
88
  different_caps_item = @items_by_term_text[term.text.uncapitalize]
77
89
  different_caps_item&.uncapitalize_term_text!
78
90
 
91
+ unless different_caps_item
92
+ different_caps_item = @items_by_term_text[term.text.capitalize]
93
+ different_caps_item&.capitalize_term_text!
94
+ end
95
+
79
96
  (different_caps_item || IndexItem.new(term_text: term.text)).tap do |item|
80
97
  @items.add(item)
81
98
  end
@@ -107,31 +124,42 @@ module Kitchen::Directions::BakeIndex
107
124
  end
108
125
 
109
126
  def bake(book:)
110
- @metadata_elements = book.metadata.search(%w(.authors .publishers .print-style
111
- .permissions [data-type='subject'])).copy
127
+ @metadata_elements = book.metadata.children_to_keep.copy
112
128
  @index = Index.new
113
129
 
114
130
  book.pages.terms.each do |term_element|
115
- # Markup the term
116
131
  page = term_element.ancestor(:page)
117
132
  term_element.id = "auto_#{page.id}_term#{term_element.count_in(:book)}"
133
+ page_title = page.title.text
134
+ add_term_to_index(term_element, page_title)
135
+ end
118
136
 
119
- group_by = term_element.text.strip[0]
120
- if !group_by.match? (/\w/)
121
- group_by = I18n.t(:eob_index_symbols_group)
122
- end
123
- term_element['group-by'] = group_by
137
+ book.chapters.composite_pages.terms.each do |term_element|
138
+ page = term_element.ancestor(:composite_page)
139
+ chapter = term_element.ancestor(:chapter)
140
+ term_element.id = "auto_composite_page_term#{term_element.count_in(:book)}"
141
+ chapter_number = chapter.count_in(:book)
142
+ page_title = "#{chapter_number} #{page.title.text.strip}".strip
143
+ add_term_to_index(term_element, page_title)
144
+ end
145
+
146
+ book.first('body').append(child: render(file: 'v1.xhtml.erb'))
147
+ end
124
148
 
125
- # Add it to our index object
126
- @index.add_term(Term.new(
149
+ def add_term_to_index(term_element, page_title)
150
+ group_by = term_element.text.strip[0]
151
+ group_by = I18n.t(:eob_index_symbols_group) unless group_by.match?(/\w/)
152
+ term_element['group-by'] = group_by
153
+
154
+ # Add it to our index object
155
+ @index.add_term(
156
+ Term.new(
127
157
  text: term_element.text,
128
158
  id: term_element.id,
129
159
  group_by: group_by,
130
- page_title: page.title.text.gsub(/\n/,'')
131
- ))
132
- end
133
-
134
- book.first("body").append(child: render(file: 'v1.xhtml.erb'))
160
+ page_title: page_title.gsub(/\n/, '')
161
+ )
162
+ )
135
163
  end
136
164
 
137
165
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ # Bake directions for link placeholders
6
+ #
7
+ module BakeLinkPlaceholders
8
+ def self.v1(book:)
9
+ book.search('a').each do |anchor|
10
+ next unless anchor.text == '[link]'
11
+
12
+ id = anchor[:href][1..-1]
13
+ replacement = book.pantry(name: :link_text).get(id)
14
+ if replacement.present?
15
+ anchor.replace_children(with: replacement)
16
+ else
17
+ # TODO: log a warning!
18
+ puts "warning! could not find a replacement for '[link]' on an element with ID '#{id}'"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,13 +1,15 @@
1
+ # frozen-string-literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
5
+ # Wraps any math contained in a <p> tag
6
+ # with a <span> with class 'os-math-in-para'
3
7
  module BakeMathInParagraph
4
-
5
8
  def self.v1(book:)
6
- book.search("p m|math").each do |math|
9
+ book.search('p m|math', '//p//math | //p//m').each do |math|
7
10
  math.wrap("<span class='os-math-in-para'>")
8
11
  end
9
12
  end
10
-
11
13
  end
12
14
  end
13
15
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeNonIntroductionPages
6
+ def self.v1(chapter:)
7
+ chapter.non_introduction_pages.each do |page|
8
+ number = "#{chapter.count_in(:book)}.#{page.count_in(:chapter)}"
9
+
10
+ page.search("div[data-type='description']").each(&:trash)
11
+ page.add_class('chapter-content-module')
12
+
13
+ title = page.title
14
+ title.name = 'h2'
15
+ title.replace_children(with:
16
+ <<~HTML
17
+ <span class="os-number">#{number}</span>
18
+ <span class="os-divider"> </span>
19
+ <span data-type="" itemprop="" class="os-text">#{title.text}</span>
20
+ HTML
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeAutotitledNotes
6
+ def self.v1(book:, classes:)
7
+ book.notes.each do |note|
8
+ next unless (note.classes & classes).any?
9
+
10
+ bake_note(note: note)
11
+ end
12
+ end
13
+
14
+ def self.bake_note(note:)
15
+ note.wrap_children(class: 'os-note-body')
16
+
17
+ BakeNoteSubtitle.v1(note: note)
18
+
19
+ note.prepend(child:
20
+ <<~HTML
21
+ <h3 class="os-title" data-type="title">
22
+ <span class="os-title-label">#{note.autogenerated_title}</span>
23
+ </h3>
24
+ HTML
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeNoteSubtitle
6
+ def self.v1(note:)
7
+ title = note.title&.cut
8
+
9
+ return unless title
10
+
11
+ # Store label information
12
+ note_label = title.children
13
+ note.pantry(name: :link_text).store note_label, label: note.id
14
+
15
+ title.name = 'h4'
16
+ title.add_class('os-subtitle')
17
+ title.wrap_children('span', class: 'os-subtitle-label')
18
+ note.first!('.os-note-body').prepend(child: title.to_s)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeNumberedNotes
6
+ def self.v1(book:, classes:)
7
+ classes.each do |klass|
8
+ book.chapters.notes("$.#{klass}").each do |note|
9
+ bake_note(note: note)
10
+ note.exercises.each do |exercise|
11
+ bake_note_exercise(note: note, exercise: exercise)
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ def self.bake_note(note:)
18
+ note.wrap_children(class: 'os-note-body')
19
+
20
+ chapter_count = note.ancestor(:chapter).count_in(:book)
21
+ note_count = note.count_in(:chapter)
22
+ note.prepend(child:
23
+ <<~HTML
24
+ <h3 class="os-title">
25
+ <span class="os-title-label">#{note.autogenerated_title}</span>
26
+ <span class="os-number">#{chapter_count}.#{note_count}</span>
27
+ <span class="os-divider"> </span>
28
+ </h3>
29
+ HTML
30
+ )
31
+
32
+ return unless note['use-subtitle']
33
+
34
+ BakeNoteSubtitle.v1(note: note)
35
+ end
36
+
37
+ def self.bake_note_exercise(note:, exercise:)
38
+ exercise.add_class('unnumbered')
39
+ # bake problem
40
+ exercise.problem.wrap_children('div', class: 'os-problem-container')
41
+ exercise.problem.first('strong')&.trash
42
+ exercise.search('[data-type="commentary"]').each(&:trash)
43
+ return unless exercise.solution
44
+
45
+ # bake solution in place
46
+ BakeNumberedExercise.bake_solution_v1(
47
+ exercise: exercise, number: note.first('.os-number').text, divider: ' ')
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeUnclassifiedNotes
6
+ def self.v1(book:)
7
+ book.notes.each do |note|
8
+ next unless note.classes.empty?
9
+
10
+ bake_note(note: note)
11
+ end
12
+ end
13
+
14
+ def self.bake_note(note:)
15
+ note.wrap_children(class: 'os-note-body')
16
+
17
+ title = note.title&.cut
18
+ return unless title
19
+
20
+ note.prepend(child:
21
+ <<~HTML
22
+ <h3 class="os-title" data-type="title">
23
+ <span class="os-title-label" data-type="" id="#{title[:id]}">#{title.children}</span>
24
+ </h3>
25
+ HTML
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeNumberedExercise
6
+ def self.v1(exercise:, number:, suppress_solution: false)
7
+ V1.new.bake(exercise: exercise, number: number, suppress_solution: suppress_solution)
8
+ end
9
+
10
+ def self.bake_solution_v1(exercise:, number:, divider: '. ')
11
+ V1.new.bake_solution(exercise: exercise, number: number, divider: divider)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeNumberedExercise
4
+ class V1
5
+ def bake(exercise:, number:, suppress_solution: false)
6
+ problem = exercise.problem
7
+ solution = exercise.solution
8
+
9
+ exercise.pantry(name: :link_text).store(
10
+ "#{I18n.t(:exercise_label)} #{exercise.ancestor(:chapter).count_in(:book)}.#{number}",
11
+ label: exercise.id
12
+ )
13
+ problem_number = "<span class='os-number'>#{number}</span>"
14
+
15
+ if solution.present?
16
+ if suppress_solution
17
+ solution.trash
18
+ else
19
+ problem_number = "<a class='os-number' href='##{exercise.id}-solution'>#{number}</a>"
20
+ bake_solution(exercise: exercise, number: number)
21
+ end
22
+ end
23
+
24
+ problem.replace_children(with:
25
+ <<~HTML
26
+ #{problem_number}
27
+ <span class='os-divider'>. </span>
28
+ <div class="os-problem-container">#{problem.children}</div>
29
+ HTML
30
+ )
31
+ end
32
+
33
+ def bake_solution(exercise:, number:, divider: '. ')
34
+ solution = exercise.solution
35
+ solution.id = "#{exercise.id}-solution"
36
+ exercise.add_class('os-hasSolution')
37
+
38
+ solution.replace_children(with:
39
+ <<~HTML
40
+ <a class='os-number' href='##{exercise.id}'>#{number}</a>
41
+ <span class='os-divider'>#{divider}</span>
42
+ <div class="os-solution-container">#{solution.children}</div>
43
+ HTML
44
+ )
45
+ end
46
+ end
47
+ end
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
3
5
  module BakeNumberedTable
4
-
5
- def self.v1(table:, number:)
6
- V1.new.bake(table: table, number: number)
6
+ def self.v1(table:, number:, always_caption: false)
7
+ V1.new.bake(table: table, number: number, always_caption: always_caption)
7
8
  end
8
-
9
9
  end
10
10
  end
11
11
  end
@@ -1,13 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen::Directions::BakeNumberedTable
2
4
  class V1
3
5
 
4
- def bake(table:, number:)
5
- table.wrap(%Q(<div class="os-table">))
6
+ def bake(table:, number:, always_caption: false)
7
+ table.wrap(%(<div class="os-table">))
6
8
 
7
9
  table_label = "#{I18n.t(:table_label)} #{number}"
8
- table.document.pantry(name: :link_text).store table_label, label: table.id
10
+ table.pantry(name: :link_text).store table_label, label: table.id
9
11
 
10
12
  if table.top_titled?
13
+ table.parent.add_class('os-top-titled-container')
11
14
  table.prepend(sibling:
12
15
  <<~HTML
13
16
  <div class="os-table-title">#{table.title}</div>
@@ -16,31 +19,47 @@ module Kitchen::Directions::BakeNumberedTable
16
19
  table.title_row.trash
17
20
  end
18
21
 
19
- # TODO extra spaces added here to match legacy implementation, but probably not meaningful?
20
- new_summary = table_label + " "
21
- new_caption = ""
22
+ table.parent.add_class('os-column-header-container') if table.column_header?
23
+
24
+ # TODO: extra spaces added here to match legacy implementation, but probably not meaningful?
25
+ new_summary = "#{table_label} "
26
+ new_caption = ''
27
+ caption_title = ''
28
+
29
+ if (title = table.first("span[data-type='title']")&.cut)
30
+ new_summary += title.text
31
+ caption_title = <<~HTML
32
+ \n<span class="os-title" data-type="title">#{title.children}</span>
33
+ HTML
34
+ end
35
+
36
+ new_summary += ' '
22
37
 
23
38
  if (caption = table.caption&.cut)
24
39
  new_summary += caption.text
25
40
  new_caption = <<~HTML
26
41
  \n<span class="os-caption">#{caption.children}</span>
27
42
  HTML
43
+ elsif always_caption
44
+ new_caption = <<~HTML
45
+ \n<span class="os-caption"></span>
46
+ HTML
28
47
  end
29
48
 
30
49
  table[:summary] = new_summary
31
50
 
32
- if !table.unnumbered?
33
- table.append(sibling:
34
- <<~HTML
35
- <div class="os-caption-container">
36
- <span class="os-title-label">#{I18n.t(:table_label)} </span>
37
- <span class="os-number">#{number}</span>
38
- <span class="os-divider"> </span>
39
- <span class="os-divider"> </span>#{new_caption}
40
- </div>
41
- HTML
42
- )
43
- end
51
+ return if table.unnumbered?
52
+
53
+ table.append(sibling:
54
+ <<~HTML
55
+ <div class="os-caption-container">
56
+ <span class="os-title-label">#{I18n.t(:table_label)} </span>
57
+ <span class="os-number">#{number}</span>
58
+ <span class="os-divider"> </span>#{caption_title}
59
+ <span class="os-divider"> </span>#{new_caption}
60
+ </div>
61
+ HTML
62
+ )
44
63
  end
45
64
 
46
65
  end