openstax_kitchen 3.2.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/CHANGELOG.md +42 -1
  4. data/Gemfile.lock +13 -14
  5. data/docker/ci +0 -1
  6. data/lib/kitchen/book_element.rb +16 -2
  7. data/lib/kitchen/chapter_element.rb +8 -11
  8. data/lib/kitchen/chapter_element_enumerator.rb +1 -1
  9. data/lib/kitchen/composite_chapter_element.rb +7 -11
  10. data/lib/kitchen/composite_page_element.rb +15 -10
  11. data/lib/kitchen/composite_page_element_enumerator.rb +1 -1
  12. data/lib/kitchen/config.rb +7 -0
  13. data/lib/kitchen/directions/bake_chapter_glossary/main.rb +18 -0
  14. data/lib/kitchen/directions/bake_chapter_glossary/v1.rb +30 -0
  15. data/lib/kitchen/directions/bake_chapter_introductions.rb +1 -1
  16. data/lib/kitchen/directions/bake_chapter_key_concepts/main.rb +7 -2
  17. data/lib/kitchen/directions/bake_chapter_key_concepts/v1.rb +12 -7
  18. data/lib/kitchen/directions/bake_chapter_key_equations.rb +26 -21
  19. data/lib/kitchen/directions/bake_chapter_summary.rb +48 -42
  20. data/lib/kitchen/directions/bake_equations.rb +1 -1
  21. data/lib/kitchen/directions/bake_example.rb +5 -1
  22. data/lib/kitchen/directions/bake_figure.rb +1 -1
  23. data/lib/kitchen/directions/{bake_problem_first_elements.rb → bake_first_elements.rb} +2 -2
  24. data/lib/kitchen/directions/bake_footnotes/v1.rb +2 -1
  25. data/lib/kitchen/directions/bake_free_response/free_response.xhtml.erb +10 -0
  26. data/lib/kitchen/directions/bake_free_response/main.rb +11 -0
  27. data/lib/kitchen/directions/bake_free_response/v1.rb +29 -0
  28. data/lib/kitchen/directions/bake_further_research.rb +59 -0
  29. data/lib/kitchen/directions/bake_index/v1.rb +35 -14
  30. data/lib/kitchen/directions/bake_link_placeholders.rb +1 -1
  31. data/lib/kitchen/directions/bake_notes/bake_note_subtitle.rb +4 -0
  32. data/lib/kitchen/directions/bake_notes/bake_numbered_notes.rb +9 -21
  33. data/lib/kitchen/directions/bake_numbered_exercise/main.rb +6 -2
  34. data/lib/kitchen/directions/bake_numbered_exercise/v1.rb +25 -12
  35. data/lib/kitchen/directions/bake_numbered_table/v1.rb +1 -1
  36. data/lib/kitchen/directions/bake_page_abstracts.rb +1 -1
  37. data/lib/kitchen/directions/bake_references/main.rb +16 -0
  38. data/lib/kitchen/directions/bake_references/v1.rb +48 -0
  39. data/lib/kitchen/directions/bake_suggested_reading.rb +5 -0
  40. data/lib/kitchen/directions/bake_toc.rb +4 -2
  41. data/lib/kitchen/directions/{bake_book_answer_key → book_answer_key_container}/eob_solutions_container.xhtml.erb +0 -0
  42. data/lib/kitchen/directions/{bake_book_answer_key → book_answer_key_container}/main.rb +1 -1
  43. data/lib/kitchen/directions/{bake_book_answer_key → book_answer_key_container}/v1.rb +1 -1
  44. data/lib/kitchen/directions/{bake_chapter_review → chapter_review_container}/chapter_review.xhtml.erb +0 -0
  45. data/lib/kitchen/directions/{bake_chapter_review → chapter_review_container}/main.rb +1 -1
  46. data/lib/kitchen/directions/{bake_chapter_review → chapter_review_container}/v1.rb +1 -1
  47. data/lib/kitchen/directions/eoc_section_title_link_snippet.rb +1 -1
  48. data/lib/kitchen/directions/move_exercises_to_eoc/main.rb +27 -0
  49. data/lib/kitchen/directions/{bake_chapter_review_exercises → move_exercises_to_eoc}/v1.rb +8 -10
  50. data/lib/kitchen/directions/{bake_chapter_review_exercises → move_exercises_to_eoc}/v2.rb +8 -9
  51. data/lib/kitchen/directions/{bake_chapter_answer_key → move_solutions_to_answer_key}/main.rb +1 -1
  52. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/american_government.rb +19 -0
  53. data/lib/kitchen/directions/{bake_chapter_answer_key → move_solutions_to_answer_key}/strategies/calculus.rb +1 -1
  54. data/lib/kitchen/directions/{bake_chapter_answer_key → move_solutions_to_answer_key}/strategies/uphysics.rb +5 -3
  55. data/lib/kitchen/directions/{bake_chapter_answer_key → move_solutions_to_answer_key}/v1.rb +3 -1
  56. data/lib/kitchen/document.rb +11 -0
  57. data/lib/kitchen/element.rb +9 -3
  58. data/lib/kitchen/element_base.rb +61 -10
  59. data/lib/kitchen/element_enumerator_base.rb +9 -1
  60. data/lib/kitchen/element_enumerator_factory.rb +9 -5
  61. data/lib/kitchen/element_factory.rb +3 -3
  62. data/lib/kitchen/example_element.rb +8 -11
  63. data/lib/kitchen/example_element_enumerator.rb +1 -1
  64. data/lib/kitchen/exercise_element.rb +5 -8
  65. data/lib/kitchen/exercise_element_enumerator.rb +1 -1
  66. data/lib/kitchen/figure_element.rb +8 -11
  67. data/lib/kitchen/figure_element_enumerator.rb +1 -1
  68. data/lib/kitchen/metadata_element.rb +8 -2
  69. data/lib/kitchen/metadata_element_enumerator.rb +1 -1
  70. data/lib/kitchen/note_element.rb +8 -11
  71. data/lib/kitchen/note_element_enumerator.rb +1 -1
  72. data/lib/kitchen/page_element.rb +20 -7
  73. data/lib/kitchen/page_element_enumerator.rb +1 -1
  74. data/lib/kitchen/reference_element.rb +27 -0
  75. data/lib/kitchen/references_element_enumerator.rb +20 -0
  76. data/lib/kitchen/search_query.rb +25 -3
  77. data/lib/kitchen/selector.rb +24 -0
  78. data/lib/kitchen/selectors/base.rb +39 -0
  79. data/lib/kitchen/selectors/standard_1.rb +13 -0
  80. data/lib/kitchen/table_element.rb +8 -11
  81. data/lib/kitchen/table_element_enumerator.rb +1 -1
  82. data/lib/kitchen/templates/eob_section_title_template.xhtml.erb +10 -0
  83. data/lib/kitchen/templates/eoc_section_title_template.xhtml.erb +10 -0
  84. data/lib/kitchen/term_element.rb +5 -8
  85. data/lib/kitchen/term_element_enumerator.rb +1 -1
  86. data/lib/kitchen/unit_element.rb +13 -7
  87. data/lib/kitchen/unit_element_enumerator.rb +1 -1
  88. data/lib/kitchen/version.rb +1 -1
  89. data/lib/locales/en.yml +3 -0
  90. data/lib/openstax_kitchen.rb +1 -0
  91. metadata +30 -22
  92. data/lib/kitchen/directions/bake_chapter_glossary.rb +0 -39
  93. data/lib/kitchen/directions/bake_chapter_key_concepts/key_concepts.xhtml.erb +0 -16
  94. data/lib/kitchen/directions/bake_chapter_review_exercises/main.rb +0 -15
  95. data/lib/kitchen/directions/bake_chapter_review_exercises/review_exercises.xhtml.erb +0 -10
  96. data/lib/kitchen/directions/bake_exercises/main.rb +0 -12
  97. data/lib/kitchen/directions/bake_exercises/v1.rb +0 -169
  98. data/lib/kitchen/directions/bake_notes/bake_notes.rb +0 -48
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kitchen
4
- module Directions
5
- # Bake directons for eoc glossary
6
- #
7
- module BakeChapterGlossary
8
- def self.v1(chapter:, metadata_source:, append_to: nil)
9
- metadata_elements = metadata_source.children_to_keep.copy
10
-
11
- definitions = chapter.glossaries.search('dl').cut
12
- definitions.sort_by! do |definition|
13
- [definition.first('dt').text.downcase, definition.first('dd').text.downcase]
14
- end
15
-
16
- chapter.glossaries.trash
17
-
18
- return if definitions.none?
19
-
20
- append_to_element = append_to || chapter
21
-
22
- append_to_element.append(child:
23
- <<~HTML
24
- <div class="os-eoc os-glossary-container" data-type="composite-page" data-uuid-key="glossary">
25
- <h2 data-type="document-title">
26
- <span class="os-text">#{I18n.t(:eoc_key_terms_title)}</span>
27
- </h2>
28
- <div data-type="metadata" style="display: none;">
29
- <h1 data-type="document-title" itemprop="name">#{I18n.t(:eoc_key_terms_title)}</h1>
30
- #{metadata_elements.paste}
31
- </div>
32
- #{definitions.paste}
33
- </div>
34
- HTML
35
- )
36
- end
37
- end
38
- end
39
- end
@@ -1,16 +0,0 @@
1
- <div class="os-eoc os-key-concepts-container" data-type="composite-page" data-uuid-key=".key-concepts">
2
- <h2 data-type="document-title">
3
- <span class="os-text"><%= I18n.t(:eoc_key_concepts) %></span>
4
- </h2>
5
- <div data-type="metadata" style="display: none;">
6
- <h1 data-type="document-title" itemprop="name"><%= I18n.t(:eoc_key_concepts) %></h1>
7
- <%= @metadata_elements.paste %>
8
- </div>
9
- <div class="os-key-concepts">
10
- <% @key_concepts.each do |key_concept| %>
11
- <div class="os-section-area">
12
- <%= key_concept %>
13
- </div>
14
- <% end %>
15
- </div>
16
- </div>
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kitchen
4
- module Directions
5
- module BakeChapterReviewExercises
6
- def self.v1(chapter:, metadata_source:, append_to:, klass:)
7
- V1.new.bake(chapter: chapter, metadata_source: metadata_source, append_to: append_to, klass: klass)
8
- end
9
-
10
- def self.v2(chapter:, metadata_source:, append_to:, klass:)
11
- V2.new.bake(chapter: chapter, metadata_source: metadata_source, append_to: append_to, klass: klass)
12
- end
13
- end
14
- end
15
- end
@@ -1,10 +0,0 @@
1
- <div class="os-eoc os-<%=@klass%>-container" data-type="composite-page" data-uuid-key=".<%=@klass%>">
2
- <h3 data-type="document-title">
3
- <span class="os-text"><%= @title %></span>
4
- </h3>
5
- <div data-type="metadata" style="display: none;">
6
- <h1 data-type="document-title" itemprop="name"><%= I18n.t(:eoc_exercises_title) %></h1>
7
- <%= @metadata.paste %>
8
- </div>
9
- <%= @content %>
10
- </div>
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kitchen
4
- module Directions
5
- module BakeExercises
6
- def self.v1(book:)
7
- warn 'WARNING! deprecated direction used: BakeExecises'
8
- V1.new.bake(book: book)
9
- end
10
- end
11
- end
12
- end
@@ -1,169 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kitchen::Directions::BakeExercises
4
- class V1
5
- renderable
6
- def bake(book:)
7
- metadata_elements = book.metadata.children_to_keep.copy
8
-
9
- solutions_clipboards = []
10
-
11
- book.chapters.each do |chapter|
12
- exercise_clipboard = Kitchen::Clipboard.new
13
- solution_clipboard = Kitchen::Clipboard.new
14
- solutions_clipboards.push(solution_clipboard)
15
-
16
- chapter.non_introduction_pages.each do |page|
17
- exercise_section = page.exercises
18
- exercise_section.titles.first&.trash
19
-
20
- bake_exercise_section_title(
21
- exercise_section: exercise_section, page: page, chapter: chapter)
22
-
23
- exercise_section.exercises.each do |exercise|
24
- exercise.document.pantry(name: :link_text).store(
25
- "#{I18n.t(:exercise_label)} #{chapter.count_in(:book)}.#{exercise.count_in(:chapter)}",
26
- label: exercise.id
27
- )
28
- bake_exercise_in_place(exercise: exercise)
29
- exercise.solution&.cut(to: solution_clipboard)
30
- end
31
-
32
- exercise_section.cut(to: exercise_clipboard)
33
- end
34
-
35
- next if exercise_clipboard.none?
36
-
37
- chapter.append(child:
38
- <<~HTML
39
- <div class="os-eoc os-exercises-container" data-type="composite-page" data-uuid-key=".exercises">
40
- <h2 data-type="document-title">
41
- <span class="os-text">#{I18n.t(:eoc_exercises_title)}</span>
42
- </h2>
43
- <div data-type="metadata" style="display: none;">
44
- <h1 data-type="document-title" itemprop="name">#{I18n.t(:eoc_exercises_title)}</h1>
45
- #{metadata_elements.paste}
46
- </div>
47
- #{exercise_clipboard.paste}
48
- </div>
49
- HTML
50
- )
51
- end
52
-
53
- # Store a paste here to use at end so that uniquifyied IDs match legacy baking
54
- eob_metadata = metadata_elements.paste
55
- solutions = solutions_clipboards.map.with_index do |solution_clipboard, index|
56
- <<~HTML
57
- <div class="os-eob os-solution-container" data-type="composite-page" data-uuid-key=".solution#{index + 1}">
58
- <h2 data-type="document-title">
59
- <span class="os-text">#{I18n.t(:chapter)} #{index + 1}</span>
60
- </h2>
61
- <div data-type="metadata" style="display: none;">
62
- <h1 data-type="document-title" itemprop="name">#{I18n.t(:chapter)} #{index + 1}</h1>
63
- #{metadata_elements.paste}
64
- </div>
65
- #{solution_clipboard.paste}
66
- </div>
67
- HTML
68
- end
69
-
70
- return if solutions.none?
71
-
72
- book.body.append(child:
73
- <<~HTML
74
- <div class="os-eob os-solution-container" data-type="composite-chapter" data-uuid-key=".solution">
75
- <h1 data-type="document-title" id="composite-chapter-1">
76
- <span class="os-text">#{I18n.t(:eoc_answer_key_title)}</span>
77
- </h1>
78
- <div data-type="metadata" style="display: none;">
79
- <h1 data-type="document-title" itemprop="name">#{I18n.t(:eoc_answer_key_title)}</h1>
80
- #{eob_metadata}
81
- </div>
82
- #{solutions.join("\n")}
83
- </div>
84
- HTML
85
- )
86
- end
87
-
88
- def bake_exercise_section_title(exercise_section:, chapter:, page:)
89
- exercise_section_title = page.title.copy
90
- exercise_section_title.name = 'h3'
91
- exercise_section_title.replace_children(with: <<~HTML
92
- <span class="os-number">#{chapter.count_in(:book)}.#{page.count_in(:chapter)}</span>
93
- <span class="os-divider"> </span>
94
- <span class="os-text" data-type="" itemprop="">#{exercise_section_title.children}</span>
95
- HTML
96
- )
97
- exercise_section.prepend(child:
98
- <<~HTML
99
- <a href="##{page.title.id}">
100
- #{exercise_section_title.paste}
101
- </a>
102
- HTML
103
- )
104
- end
105
-
106
- def bake_exercise_in_place(exercise:)
107
- # Bake an exercise in place going from:
108
- #
109
- # <div data-type="exercise" id="exerciseId">
110
- # <div data-type="problem" id="problemId">
111
- # Problem Content
112
- # </div>
113
- # <div data-type="solution" id="solutionId">
114
- # Solution Content
115
- # </div>
116
- # </div>
117
- #
118
- # to
119
- #
120
- # <div data-type="exercise" id="exerciseId" class="os-hasSolution">
121
- # <div data-type="problem" id="problemId">
122
- # <a class="os-number" href="#exerciseId-solution">1</a>
123
- # <span class="os-divider">. </span>
124
- # <div class="os-problem-container ">
125
- # Problem Content
126
- # </div>
127
- # </div>
128
- # <div data-type="solution" id="exerciseId-solution">
129
- # <a class="os-number" href="#exerciseId">1</a>
130
- # <span class="os-divider">. </span>
131
- # <div class="os-solution-container ">
132
- # Solution Content
133
- # </div>
134
- # </div>
135
- # </div>
136
- #
137
- # If there is no solution, don't add the 'os-hasSolution' class and don't
138
- # link the number.
139
-
140
- problem = exercise.problem
141
- solution = exercise.solution
142
- count_in = exercise.count_in(:chapter)
143
- problem_number = "<span class='os-number'>#{count_in}</span>"
144
-
145
- if solution.present?
146
- solution.id = "#{exercise.id}-solution"
147
-
148
- exercise.add_class('os-hasSolution')
149
- problem_number = "<a href='##{solution.id}' class='os-number'>#{count_in}</a>"
150
-
151
- solution.replace_children(with:
152
- <<~HTML
153
- <a class="os-number" href="##{exercise.id}">#{count_in}</a>
154
- <span class="os-divider">. </span>
155
- <div class="os-solution-container ">#{solution.children}</div>
156
- HTML
157
- )
158
- end
159
-
160
- problem.replace_children(with:
161
- <<~HTML
162
- #{problem_number}
163
- <span class="os-divider">. </span>
164
- <div class="os-problem-container ">#{problem.children}</div>
165
- HTML
166
- )
167
- end
168
- end
169
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kitchen
4
- module Directions
5
- module BakeNotes
6
- def self.v1(book:)
7
- warn 'WARNING! deprecated direction used: BakeNotes'
8
-
9
- book.notes('$:not(.checkpoint):not(.theorem)').each do |note|
10
- title = note.title&.cut
11
-
12
- note.wrap_children(class: 'os-note-body')
13
-
14
- if title
15
- if note.indicates_autogenerated_title?
16
- note.prepend(child:
17
- <<~HTML
18
- <h3 class="os-title" data-type="title">
19
- <span class="os-title-label">#{note.autogenerated_title}</span>
20
- </h3>
21
- HTML
22
- )
23
-
24
- title.name = 'h4'
25
- title.add_class('os-subtitle')
26
- title.wrap_children('span', class: 'os-subtitle-label')
27
- note.first!('.os-note-body').prepend(child: title.raw)
28
- else
29
- title.name = 'h3'
30
- title.add_class('os-title')
31
- title.wrap_children('span', data_type: '', id: title.id, class: 'os-title-label')
32
- title.remove_attribute('id')
33
- note.prepend(child: title.raw)
34
- end
35
- else
36
- note.prepend(child:
37
- <<~HTML
38
- <h3 class="os-title" data-type="title">
39
- <span class="os-title-label">#{note.autogenerated_title}</span>
40
- </h3>
41
- HTML
42
- )
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end