openstax_kitchen 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) 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 +1 -1
  6. data/.inch.yml +6 -0
  7. data/.rubocop.yml +65 -0
  8. data/CHANGELOG.md +16 -0
  9. data/Gemfile +5 -3
  10. data/Gemfile.lock +54 -5
  11. data/README.md +58 -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 +16 -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 +24 -3
  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 -3
  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 +20 -1
  31. data/lib/kitchen/composite_page_element.rb +25 -2
  32. data/lib/kitchen/composite_page_element_enumerator.rb +8 -0
  33. data/lib/kitchen/config.rb +14 -7
  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.rb +10 -7
  39. data/lib/kitchen/directions/bake_chapter_introductions.rb +6 -6
  40. data/lib/kitchen/directions/bake_chapter_key_equations.rb +9 -6
  41. data/lib/kitchen/directions/bake_chapter_summary.rb +16 -13
  42. data/lib/kitchen/directions/bake_chapter_title/main.rb +11 -0
  43. data/lib/kitchen/directions/bake_chapter_title/v1.rb +24 -0
  44. data/lib/kitchen/directions/bake_composite_pages.rb +2 -2
  45. data/lib/kitchen/directions/bake_example.rb +6 -4
  46. data/lib/kitchen/directions/bake_exercises/main.rb +11 -0
  47. data/lib/kitchen/directions/bake_exercises/v1.rb +166 -0
  48. data/lib/kitchen/directions/bake_figure.rb +8 -5
  49. data/lib/kitchen/directions/bake_footnotes/main.rb +2 -2
  50. data/lib/kitchen/directions/bake_footnotes/v1.rb +4 -4
  51. data/lib/kitchen/directions/bake_index/main.rb +2 -2
  52. data/lib/kitchen/directions/bake_index/v1.rb +22 -15
  53. data/lib/kitchen/directions/bake_link_placeholders.rb +24 -0
  54. data/lib/kitchen/directions/bake_math_in_paragraph.rb +5 -3
  55. data/lib/kitchen/directions/bake_notes.rb +8 -8
  56. data/lib/kitchen/directions/bake_numbered_table/main.rb +2 -2
  57. data/lib/kitchen/directions/bake_numbered_table/v1.rb +21 -16
  58. data/lib/kitchen/directions/bake_page_abstracts.rb +14 -0
  59. data/lib/kitchen/directions/bake_preface/main.rb +11 -0
  60. data/lib/kitchen/directions/bake_preface/v1.rb +18 -0
  61. data/lib/kitchen/directions/bake_stepwise.rb +7 -7
  62. data/lib/kitchen/directions/bake_suggested_reading.rb +26 -0
  63. data/lib/kitchen/directions/bake_toc.rb +41 -22
  64. data/lib/kitchen/directions/bake_unit_title/main.rb +11 -0
  65. data/lib/kitchen/directions/bake_unit_title/v1.rb +23 -0
  66. data/lib/kitchen/directions/bake_unnumbered_tables.rb +7 -5
  67. data/lib/kitchen/directions/move_title_text_into_span.rb +2 -2
  68. data/lib/kitchen/document.rb +72 -13
  69. data/lib/kitchen/element.rb +11 -0
  70. data/lib/kitchen/element_base.rb +276 -56
  71. data/lib/kitchen/element_enumerator.rb +8 -0
  72. data/lib/kitchen/element_enumerator_base.rb +210 -28
  73. data/lib/kitchen/element_enumerator_factory.rb +59 -52
  74. data/lib/kitchen/element_factory.rb +27 -12
  75. data/lib/kitchen/errors.rb +5 -0
  76. data/lib/kitchen/example_element.rb +19 -1
  77. data/lib/kitchen/example_element_enumerator.rb +9 -1
  78. data/lib/kitchen/figure_element.rb +36 -2
  79. data/lib/kitchen/figure_element_enumerator.rb +9 -1
  80. data/lib/kitchen/metadata_element.rb +28 -0
  81. data/lib/kitchen/metadata_element_enumerator.rb +21 -0
  82. data/lib/kitchen/mixins/block_error_if.rb +24 -4
  83. data/lib/kitchen/note_element.rb +37 -7
  84. data/lib/kitchen/note_element_enumerator.rb +9 -1
  85. data/lib/kitchen/oven.rb +66 -15
  86. data/lib/kitchen/page_element.rb +62 -13
  87. data/lib/kitchen/page_element_enumerator.rb +9 -1
  88. data/lib/kitchen/pantry.rb +28 -1
  89. data/lib/kitchen/patches/nokogiri.rb +19 -2
  90. data/lib/kitchen/patches/renderable.rb +9 -3
  91. data/lib/kitchen/patches/string.rb +8 -0
  92. data/lib/kitchen/recipe.rb +38 -34
  93. data/lib/kitchen/search_history.rb +43 -4
  94. data/lib/kitchen/search_query.rb +84 -0
  95. data/lib/kitchen/selectors/base.rb +26 -0
  96. data/lib/kitchen/selectors/standard_1.rb +8 -0
  97. data/lib/kitchen/table_element.rb +54 -3
  98. data/lib/kitchen/table_element_enumerator.rb +9 -1
  99. data/lib/kitchen/term_element.rb +15 -1
  100. data/lib/kitchen/term_element_enumerator.rb +9 -1
  101. data/lib/kitchen/transliterations.rb +7 -5
  102. data/lib/kitchen/type_casting_element_enumerator.rb +17 -1
  103. data/lib/kitchen/unit_element.rb +39 -0
  104. data/lib/kitchen/unit_element_enumerator.rb +20 -0
  105. data/lib/kitchen/utils.rb +10 -13
  106. data/lib/kitchen/version.rb +5 -1
  107. data/lib/locales/en.yml +6 -0
  108. data/lib/openstax_kitchen.rb +43 -42
  109. data/openstax_kitchen.gemspec +26 -20
  110. data/tutorials/00/solution1.rb +9 -0
  111. data/tutorials/00/solution2.rb +8 -0
  112. data/tutorials/01/solution1.rb +18 -0
  113. data/tutorials/01/solution2.rb +26 -0
  114. data/tutorials/02/solution1.rb +31 -0
  115. data/tutorials/03/{solution_1.rb → solution1.rb} +6 -4
  116. data/tutorials/03/solution2.rb +18 -0
  117. data/tutorials/04/{solution_1.rb → solution1.rb} +4 -2
  118. data/tutorials/04/{solution_2.rb → solution2.rb} +6 -4
  119. data/tutorials/05/solution1.rb +11 -0
  120. data/tutorials/check_it +16 -15
  121. data/tutorials/setup_my_recipes +7 -6
  122. metadata +101 -22
  123. data/Dockerfile +0 -19
  124. data/docker-compose.yml +0 -12
  125. data/docker/entrypoint +0 -9
  126. data/lib/kitchen/directions/bake_exercises.rb +0 -164
  127. data/tutorials/00/solution_1.rb +0 -7
  128. data/tutorials/00/solution_2.rb +0 -6
  129. data/tutorials/01/solution_1.rb +0 -16
  130. data/tutorials/01/solution_2.rb +0 -24
  131. data/tutorials/02/solution_1.rb +0 -29
  132. data/tutorials/03/solution_2.rb +0 -15
  133. data/tutorials/05/solution_1.rb +0 -9
@@ -1,19 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "byebug"
5
- require "rainbow"
4
+ require 'bundler/setup'
5
+ require 'byebug'
6
+ require 'rainbow'
6
7
 
7
8
  Dir.chdir(__dir__)
8
- tutorial_numbers = Dir.glob("*").select{|f| File.directory?(f) && f.match?(/\d\d/)}
9
+ tutorial_numbers = Dir.glob('*').select { |f| File.directory?(f) && f.match?(/\d\d/) }
9
10
 
10
11
  tutorial_numbers.each do |tutorial_number|
11
12
  file_name = File.expand_path("#{tutorial_number}/my_recipe.rb", __dir__)
12
13
  if File.exist?(file_name)
13
- puts "Skipped making recipe skeleton; my_recipe.rb exists in tutorials folder '#{tutorial_number}'"
14
+ puts "Skipped making recipe skeleton; my_recipe.rb exists in tutorials folder #{tutorial_number}"
14
15
  next
15
16
  else
16
- File.open(file_name, "w") do |f|
17
+ File.open(file_name, 'w') do |f|
17
18
  f.write <<~CONTENTS
18
19
  # This file is IGNORED by Git
19
20
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_kitchen
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-18 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: nokogiri
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rainbow
28
+ name: i18n
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: activesupport
42
+ name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: i18n
56
+ name: rainbow
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: yard
84
+ name: inch
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -122,6 +122,62 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: yard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
125
181
  description: OpenStax content baking library
126
182
  email:
127
183
  - jpslav@gmail.com
@@ -130,13 +186,15 @@ extensions: []
130
186
  extra_rdoc_files: []
131
187
  files:
132
188
  - ".devcontainer/devcontainer.json"
189
+ - ".github/config.yml"
133
190
  - ".github/workflows/tests.yml"
134
191
  - ".gitignore"
192
+ - ".inch.yml"
135
193
  - ".rspec"
194
+ - ".rubocop.yml"
136
195
  - ".solargraph.yml"
137
196
  - CHANGELOG.md
138
197
  - CODE_OF_CONDUCT.md
139
- - Dockerfile
140
198
  - Gemfile
141
199
  - Gemfile.lock
142
200
  - LICENSE.txt
@@ -145,9 +203,14 @@ files:
145
203
  - bin/console
146
204
  - bin/setup
147
205
  - codecov.yaml
148
- - docker-compose.yml
206
+ - docker/Dockerfile
207
+ - docker/Dockerfile.ci
149
208
  - docker/bash
150
- - docker/entrypoint
209
+ - docker/build
210
+ - docker/ci
211
+ - docker/run
212
+ - docker/tag_and_push_latest
213
+ - lefthook.yml
151
214
  - lib/kitchen/ancestor.rb
152
215
  - lib/kitchen/book_document.rb
153
216
  - lib/kitchen/book_element.rb
@@ -162,26 +225,37 @@ files:
162
225
  - lib/kitchen/config.rb
163
226
  - lib/kitchen/counter.rb
164
227
  - lib/kitchen/debug/print_recipe_error.rb
228
+ - lib/kitchen/directions/.rubocop.yml
165
229
  - lib/kitchen/directions/bake_appendix.rb
166
230
  - lib/kitchen/directions/bake_chapter_glossary.rb
167
231
  - lib/kitchen/directions/bake_chapter_introductions.rb
168
232
  - lib/kitchen/directions/bake_chapter_key_equations.rb
169
233
  - lib/kitchen/directions/bake_chapter_summary.rb
234
+ - lib/kitchen/directions/bake_chapter_title/main.rb
235
+ - lib/kitchen/directions/bake_chapter_title/v1.rb
170
236
  - lib/kitchen/directions/bake_composite_pages.rb
171
237
  - lib/kitchen/directions/bake_example.rb
172
- - lib/kitchen/directions/bake_exercises.rb
238
+ - lib/kitchen/directions/bake_exercises/main.rb
239
+ - lib/kitchen/directions/bake_exercises/v1.rb
173
240
  - lib/kitchen/directions/bake_figure.rb
174
241
  - lib/kitchen/directions/bake_footnotes/main.rb
175
242
  - lib/kitchen/directions/bake_footnotes/v1.rb
176
243
  - lib/kitchen/directions/bake_index/main.rb
177
244
  - lib/kitchen/directions/bake_index/v1.rb
178
245
  - lib/kitchen/directions/bake_index/v1.xhtml.erb
246
+ - lib/kitchen/directions/bake_link_placeholders.rb
179
247
  - lib/kitchen/directions/bake_math_in_paragraph.rb
180
248
  - lib/kitchen/directions/bake_notes.rb
181
249
  - lib/kitchen/directions/bake_numbered_table/main.rb
182
250
  - lib/kitchen/directions/bake_numbered_table/v1.rb
251
+ - lib/kitchen/directions/bake_page_abstracts.rb
252
+ - lib/kitchen/directions/bake_preface/main.rb
253
+ - lib/kitchen/directions/bake_preface/v1.rb
183
254
  - lib/kitchen/directions/bake_stepwise.rb
255
+ - lib/kitchen/directions/bake_suggested_reading.rb
184
256
  - lib/kitchen/directions/bake_toc.rb
257
+ - lib/kitchen/directions/bake_unit_title/main.rb
258
+ - lib/kitchen/directions/bake_unit_title/v1.rb
185
259
  - lib/kitchen/directions/bake_unnumbered_tables.rb
186
260
  - lib/kitchen/directions/move_title_text_into_span.rb
187
261
  - lib/kitchen/document.rb
@@ -196,6 +270,8 @@ files:
196
270
  - lib/kitchen/example_element_enumerator.rb
197
271
  - lib/kitchen/figure_element.rb
198
272
  - lib/kitchen/figure_element_enumerator.rb
273
+ - lib/kitchen/metadata_element.rb
274
+ - lib/kitchen/metadata_element_enumerator.rb
199
275
  - lib/kitchen/mixins/block_error_if.rb
200
276
  - lib/kitchen/note_element.rb
201
277
  - lib/kitchen/note_element_enumerator.rb
@@ -208,6 +284,7 @@ files:
208
284
  - lib/kitchen/patches/string.rb
209
285
  - lib/kitchen/recipe.rb
210
286
  - lib/kitchen/search_history.rb
287
+ - lib/kitchen/search_query.rb
211
288
  - lib/kitchen/selectors/base.rb
212
289
  - lib/kitchen/selectors/standard_1.rb
213
290
  - lib/kitchen/table_element.rb
@@ -216,6 +293,8 @@ files:
216
293
  - lib/kitchen/term_element_enumerator.rb
217
294
  - lib/kitchen/transliterations.rb
218
295
  - lib/kitchen/type_casting_element_enumerator.rb
296
+ - lib/kitchen/unit_element.rb
297
+ - lib/kitchen/unit_element_enumerator.rb
219
298
  - lib/kitchen/utils.rb
220
299
  - lib/kitchen/version.rb
221
300
  - lib/locales/en.yml
@@ -224,26 +303,26 @@ files:
224
303
  - openstax_kitchen.gemspec
225
304
  - tutorials/00/expected_baked.html
226
305
  - tutorials/00/raw.html
227
- - tutorials/00/solution_1.rb
228
- - tutorials/00/solution_2.rb
306
+ - tutorials/00/solution1.rb
307
+ - tutorials/00/solution2.rb
229
308
  - tutorials/01/expected_baked.html
230
309
  - tutorials/01/raw.html
231
- - tutorials/01/solution_1.rb
232
- - tutorials/01/solution_2.rb
310
+ - tutorials/01/solution1.rb
311
+ - tutorials/01/solution2.rb
233
312
  - tutorials/02/expected_baked.html
234
313
  - tutorials/02/raw.html
235
- - tutorials/02/solution_1.rb
314
+ - tutorials/02/solution1.rb
236
315
  - tutorials/03/expected_baked.html
237
316
  - tutorials/03/raw.html
238
- - tutorials/03/solution_1.rb
239
- - tutorials/03/solution_2.rb
317
+ - tutorials/03/solution1.rb
318
+ - tutorials/03/solution2.rb
240
319
  - tutorials/04/expected_baked.html
241
320
  - tutorials/04/raw.html
242
- - tutorials/04/solution_1.rb
243
- - tutorials/04/solution_2.rb
321
+ - tutorials/04/solution1.rb
322
+ - tutorials/04/solution2.rb
244
323
  - tutorials/05/expected_baked.html
245
324
  - tutorials/05/raw.html
246
- - tutorials/05/solution_1.rb
325
+ - tutorials/05/solution1.rb
247
326
  - tutorials/check_it
248
327
  - tutorials/setup_my_recipes
249
328
  homepage: https://github.com/openstax/kitchen
@@ -262,7 +341,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
262
341
  requirements:
263
342
  - - ">="
264
343
  - !ruby/object:Gem::Version
265
- version: 2.3.0
344
+ version: 2.4.0
266
345
  required_rubygems_version: !ruby/object:Gem::Requirement
267
346
  requirements:
268
347
  - - ">="
data/Dockerfile DELETED
@@ -1,19 +0,0 @@
1
- FROM ruby:2.6-slim
2
-
3
- RUN apt-get update && \
4
- apt-get install -y --no-install-recommends \
5
- git \
6
- build-essential \
7
- && rm -rf /var/lib/apt/lists/*
8
-
9
- WORKDIR /code
10
- COPY . /code/
11
-
12
- RUN gem install bundler
13
- RUN bundle install
14
-
15
- # Install other things that make development good
16
- RUN gem install solargraph
17
- RUN bundle exec yard gems
18
-
19
- ENTRYPOINT ["/code/docker/entrypoint"]
data/docker-compose.yml DELETED
@@ -1,12 +0,0 @@
1
- version: '3.7'
2
- services:
3
- app:
4
- image: "openstax/kitchen"
5
- build: .
6
- volumes:
7
- - .:/code
8
- networks:
9
- - openstax
10
- networks:
11
- openstax:
12
- name: openstax
data/docker/entrypoint DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -e
3
-
4
- # uncomment this to load docker secrets into environment variables
5
- # export $(egrep -v '^#' /run/secrets/* | xargs)
6
-
7
- # exec "$@"
8
-
9
- tail -f /dev/null
@@ -1,164 +0,0 @@
1
- module Kitchen
2
- module Directions
3
- module BakeExercises
4
-
5
- def self.v1(book:)
6
- metadata_elements = book.metadata.search(%w(.authors .publishers .print-style
7
- .permissions [data-type='subject'])).copy
8
-
9
- solutions_clipboards = []
10
-
11
- book.chapters.each do |chapter|
12
- exercise_clipboard = Clipboard.new
13
- solution_clipboard = Clipboard.new
14
- solutions_clipboards.push(solution_clipboard)
15
-
16
- chapter.pages("$:not(.introduction)").each do |page|
17
- exercise_section = page.exercises
18
- exercise_section.first("[data-type='title']")&.trash
19
- exercise_section_title = page.title.copy
20
- exercise_section_title.name = "h3"
21
- exercise_section_title.replace_children(with: <<~HTML
22
- <span class="os-number">#{chapter.count_in(:book)}.#{page.count_in(:chapter)}</span>
23
- <span class="os-divider"> </span>
24
- <span class="os-text" data-type="" itemprop="">#{exercise_section_title.children}</span>
25
- HTML
26
- )
27
-
28
- exercise_section.prepend(child:
29
- <<~HTML
30
- <a href="##{page.title.id}">
31
- #{exercise_section_title.paste}
32
- </a>
33
- HTML
34
- )
35
-
36
- exercise_section.search("[data-type='exercise']").each do |exercise|
37
- exercise.document.pantry(name: :link_text).store(
38
- "#{I18n.t(:exercise_label)} #{chapter.count_in(:book)}.#{exercise.count_in(:chapter)}",
39
- label: exercise.id
40
- )
41
-
42
- bake_exercise_in_place(exercise: exercise)
43
- exercise.first("[data-type='solution']")&.cut(to: solution_clipboard)
44
- end
45
-
46
- exercise_section.cut(to: exercise_clipboard)
47
- end
48
-
49
- chapter.append(child:
50
- <<~HTML
51
- <div class="os-eoc os-exercises-container" data-type="composite-page" data-uuid-key=".exercises">
52
- <h2 data-type="document-title">
53
- <span class="os-text">#{I18n.t(:eoc_exercises_title)}</span>
54
- </h2>
55
- <div data-type="metadata" style="display: none;">
56
- <h1 data-type="document-title" itemprop="name">#{I18n.t(:eoc_exercises_title)}</h1>
57
- #{metadata_elements.paste}
58
- </div>
59
- #{exercise_clipboard.paste}
60
- </div>
61
- HTML
62
- ) unless exercise_clipboard.none?
63
- end
64
-
65
- # Store a paste here to use at end so that uniquifyied IDs match legacy baking
66
- eob_metadata = metadata_elements.paste
67
-
68
- solutions = solutions_clipboards.map.with_index do |solution_clipboard, index|
69
- <<~HTML
70
- <div class="os-eob os-solution-container " data-type="composite-page" data-uuid-key=".solution#{index+1}">
71
- <h2 data-type="document-title">
72
- <span class="os-text">#{index+1}</span>
73
- </h2>
74
- <div data-type="metadata" style="display: none;">
75
- <h1 data-type="document-title" itemprop="name">#{index+1}</h1>
76
- #{metadata_elements.paste}
77
- </div>
78
- #{solution_clipboard.paste}
79
- </div>
80
- HTML
81
- end
82
-
83
- book.first("body").append(child:
84
- <<~HTML
85
- <div class="os-eob os-solution-container " data-type="composite-chapter" data-uuid-key=".solution">
86
- <h1 data-type="document-title" id="composite-chapter-1">
87
- <span class="os-text">#{I18n.t(:eoc_answer_key_title)}</span>
88
- </h1>
89
- <div data-type="metadata" style="display: none;">
90
- <h1 data-type="document-title" itemprop="name">#{I18n.t(:eoc_answer_key_title)}</h1>
91
- #{eob_metadata}
92
- </div>
93
- #{solutions.join("\n")}
94
- </div>
95
- HTML
96
- ) unless solutions.none?
97
- end
98
-
99
- def self.bake_exercise_in_place(exercise:)
100
- # Bake an exercise in place going from:
101
- #
102
- # <div data-type="exercise" id="exerciseId">
103
- # <div data-type="problem" id="problemId">
104
- # Problem Content
105
- # </div>
106
- # <div data-type="solution" id="solutionId">
107
- # Solution Content
108
- # </div>
109
- # </div>
110
- #
111
- # to
112
- #
113
- # <div data-type="exercise" id="exerciseId" class="os-hasSolution">
114
- # <div data-type="problem" id="problemId">
115
- # <a class="os-number" href="#exerciseId-solution">1</a>
116
- # <span class="os-divider">. </span>
117
- # <div class="os-problem-container ">
118
- # Problem Content
119
- # </div>
120
- # </div>
121
- # <div data-type="solution" id="exerciseId-solution">
122
- # <a class="os-number" href="#exerciseId">1</a>
123
- # <span class="os-divider">. </span>
124
- # <div class="os-solution-container ">
125
- # Solution Content
126
- # </div>
127
- # </div>
128
- # </div>
129
- #
130
- # If there is no solution, don't add the 'os-hasSolution' class and don't
131
- # link the number.
132
-
133
- problem = exercise.first("[data-type='problem']")
134
- solution = exercise.first("[data-type='solution']")
135
-
136
- problem_number = "<span class='os-number'>#{exercise.count_in(:chapter)}</span>"
137
-
138
- if solution.present?
139
- solution.id = "#{exercise.id}-solution"
140
-
141
- exercise.add_class("os-hasSolution")
142
- problem_number = "<a href='##{solution.id}' class='os-number' >#{exercise.count_in(:chapter)}</a>"
143
-
144
- solution.replace_children(with:
145
- <<~HTML
146
- <a class="os-number" href="##{exercise.id}">#{exercise.count_in(:chapter)}</a>
147
- <span class="os-divider">. </span>
148
- <div class="os-solution-container ">#{solution.children}</div>
149
- HTML
150
- )
151
- end
152
-
153
- problem.replace_children(with:
154
- <<~HTML
155
- #{problem_number}
156
- <span class="os-divider">. </span>
157
- <div class="os-problem-container ">#{problem.children}</div>
158
- HTML
159
- )
160
- end
161
-
162
- end
163
- end
164
- end