openstax_kitchen 9.1.0 → 11.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -0
  3. data/Gemfile.lock +2 -2
  4. data/lib/kitchen/chapter_element.rb +8 -0
  5. data/lib/kitchen/composite_page_element.rb +8 -0
  6. data/lib/kitchen/directions/bake_annotation_classes/main.rb +12 -0
  7. data/lib/kitchen/directions/bake_annotation_classes/v1.rb +32 -0
  8. data/lib/kitchen/directions/bake_chapter_glossary/main.rb +3 -2
  9. data/lib/kitchen/directions/bake_chapter_glossary/v1.rb +10 -1
  10. data/lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb +46 -0
  11. data/lib/kitchen/directions/bake_chapter_introductions/bake_chapter_outline.rb +14 -0
  12. data/lib/kitchen/directions/bake_chapter_introductions/main.rb +43 -0
  13. data/lib/kitchen/directions/bake_chapter_introductions/v1.rb +56 -0
  14. data/lib/kitchen/directions/bake_chapter_introductions/v2.rb +91 -0
  15. data/lib/kitchen/directions/bake_chapter_key_concepts/v1.rb +11 -21
  16. data/lib/kitchen/directions/bake_chapter_references/v1.rb +1 -3
  17. data/lib/kitchen/directions/bake_chapter_solutions/main.rb +7 -2
  18. data/lib/kitchen/directions/bake_chapter_solutions/v1.rb +11 -9
  19. data/lib/kitchen/directions/bake_chapter_summary.rb +1 -2
  20. data/lib/kitchen/directions/bake_custom_sections/main.rb +14 -0
  21. data/lib/kitchen/directions/bake_custom_sections/v1.rb +42 -0
  22. data/lib/kitchen/directions/bake_eoc_section_content/change_subsection_title_tag.rb +13 -0
  23. data/lib/kitchen/directions/bake_equations.rb +2 -3
  24. data/lib/kitchen/directions/bake_example.rb +9 -12
  25. data/lib/kitchen/directions/bake_figure.rb +5 -3
  26. data/lib/kitchen/directions/bake_first_elements.rb +15 -2
  27. data/lib/kitchen/directions/bake_folio.rb +12 -0
  28. data/lib/kitchen/directions/bake_free_response/v1.rb +1 -1
  29. data/lib/kitchen/directions/bake_further_research.rb +1 -3
  30. data/lib/kitchen/directions/bake_handbook/main.rb +11 -0
  31. data/lib/kitchen/directions/bake_handbook/v1.rb +74 -0
  32. data/lib/kitchen/directions/bake_iframes/main.rb +11 -0
  33. data/lib/kitchen/directions/bake_iframes/v1.rb +25 -0
  34. data/lib/kitchen/directions/bake_index/main.rb +2 -2
  35. data/lib/kitchen/directions/bake_index/v1.rb +39 -7
  36. data/lib/kitchen/directions/bake_index/v1.xhtml.erb +3 -3
  37. data/lib/kitchen/directions/bake_injected_exercise.rb +18 -0
  38. data/lib/kitchen/directions/bake_injected_exercise_question.rb +71 -0
  39. data/lib/kitchen/directions/bake_link_placeholders.rb +15 -2
  40. data/lib/kitchen/directions/bake_lists_with_para.rb +17 -0
  41. data/lib/kitchen/directions/bake_notes/bake_autotitled_notes.rb +5 -5
  42. data/lib/kitchen/directions/bake_notes/bake_note_subtitle.rb +6 -2
  43. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/main.rb +13 -3
  44. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/v1.rb +29 -25
  45. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/v2.rb +22 -17
  46. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/v3.rb +27 -22
  47. data/lib/kitchen/directions/bake_numbered_exercise/main.rb +3 -2
  48. data/lib/kitchen/directions/bake_numbered_exercise/v1.rb +6 -5
  49. data/lib/kitchen/directions/bake_numbered_table/bake_table_body.rb +57 -16
  50. data/lib/kitchen/directions/bake_numbered_table/main.rb +4 -4
  51. data/lib/kitchen/directions/bake_numbered_table/v1.rb +4 -4
  52. data/lib/kitchen/directions/bake_numbered_table/v2.rb +4 -4
  53. data/lib/kitchen/directions/bake_toc.rb +8 -1
  54. data/lib/kitchen/directions/bake_unit_page_title/main.rb +11 -0
  55. data/lib/kitchen/directions/bake_unit_page_title/v1.rb +23 -0
  56. data/lib/kitchen/directions/eoc_section_title_link_snippet.rb +32 -21
  57. data/lib/kitchen/directions/move_custom_section_to_eoc_container/main.rb +4 -3
  58. data/lib/kitchen/directions/move_custom_section_to_eoc_container/v1.rb +19 -3
  59. data/lib/kitchen/directions/move_exercises_to_eoc/v1.rb +1 -2
  60. data/lib/kitchen/directions/move_exercises_to_eoc/v2.rb +11 -30
  61. data/lib/kitchen/directions/move_exercises_to_eoc/v3.rb +1 -2
  62. data/lib/kitchen/directions/move_solutions_to_answer_key/move_solutions_from_exercise_section.rb +34 -0
  63. data/lib/kitchen/directions/move_solutions_to_answer_key/move_solutions_from_numbered_note.rb +27 -0
  64. data/lib/kitchen/directions/move_solutions_to_answer_key/solution_area_snippet.rb +12 -0
  65. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb +1 -1
  66. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/contemporary_math.rb +40 -0
  67. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/default.rb +1 -1
  68. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/precalculus.rb +18 -39
  69. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/uphysics.rb +6 -48
  70. data/lib/kitchen/directions/move_solutions_to_answer_key/v1.rb +10 -3
  71. data/lib/kitchen/element_base.rb +36 -4
  72. data/lib/kitchen/element_enumerator_base.rb +35 -0
  73. data/lib/kitchen/example_element.rb +9 -3
  74. data/lib/kitchen/exercise_element.rb +8 -0
  75. data/lib/kitchen/figure_element.rb +11 -0
  76. data/lib/kitchen/injected_question_element.rb +77 -0
  77. data/lib/kitchen/injected_question_element_enumerator.rb +21 -0
  78. data/lib/kitchen/note_element.rb +8 -1
  79. data/lib/kitchen/page_element.rb +12 -9
  80. data/lib/kitchen/selectors/base.rb +6 -0
  81. data/lib/kitchen/selectors/standard_1.rb +3 -0
  82. data/lib/kitchen/solution_element_enumerator.rb +21 -0
  83. data/lib/kitchen/table_element.rb +25 -0
  84. data/lib/kitchen/version.rb +1 -1
  85. data/lib/locales/en.yml +10 -4
  86. data/lib/locales/es.yml +8 -4
  87. data/lib/locales/pl.yml +52 -7
  88. metadata +30 -8
  89. data/lib/kitchen/directions/bake_chapter_introductions/chapter_introduction.xhtml.erb +0 -0
  90. data/lib/kitchen/directions/bake_chapter_introductions.rb +0 -65
  91. data/lib/kitchen/directions/bake_notes/bake_note_iframes.rb +0 -27
  92. data/lib/kitchen/directions/bake_theorem/main.rb +0 -11
  93. data/lib/kitchen/directions/bake_theorem/v1.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df33d6b0ba524fe49e9e5310bcdb730406576a3b88f0462e2eedd932d08fc0cf
4
- data.tar.gz: 6a23406fdebb4676c22424d14ab805304789814e84302a685aa245e2bf87f846
3
+ metadata.gz: 4340461612470e8ddff3976af6bf342821a18f1e01c70d5c6d4dcbf08636ac24
4
+ data.tar.gz: 293967ff3cf8af70f6d9d5f5d20866c77608af41c279590b3abb39966813f048
5
5
  SHA512:
6
- metadata.gz: 3af05295d5045ec827b6e817443a4648591d138bc9d3cf697221187e26088badc6c76048f8b3902a167c073c1e9ee94b4c4f48934171428b649c879e23abd95f
7
- data.tar.gz: 35ce7b8d16222c5f338d2eb6e9749158980e075b2d09bfa82e034e74bcfad13b748b80bceb1941fc0a8b4d26cf834474a0e7699a7327b55c6e6e42bc1e122024
6
+ metadata.gz: 70eedaaa535e97066b5b5b0d80e9c8916ffb6de5ecdf063f7a58d2c984253771742832278e53f5ce8bea3f0f3c7cbdd97da058258e5ace42dda0da372243ff2d
7
+ data.tar.gz: 72001901b5c82c46bd835521d9a815d178cc6bcea04502fd6b9b10bf36309ed42028b92714fd003e1a0042c60ce9eb4ab505dc627d8dd763f9c6892ff1fee7ea
data/CHANGELOG.md CHANGED
@@ -6,6 +6,69 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [11.1.0] - 2021-08-30
10
+
11
+ * Update injected questions to synthesize ids during baking (minor)
12
+ * Fix `BakeListsWithPara` to copy all children from para not just text (minor)
13
+ * Implement labels with cases to `BakeAutotitledNotes` and `BakeNumberedNotes` (minor)
14
+ * Add ids to injected questions (minor)
15
+ * Create `BakeIframes` outer directory to allow bake iframes also from outside notes, remove `BakeNoteIFrames` module from notes directory (minor)
16
+ * Update the contemporary math `Strategy` to target injected solution sections (minor)
17
+ * Update `BakeNumberedNotes` to handle injected questions in notes (minor)
18
+ * Create `InjectedQuestionElement` and `InjectedQuestionElementEnumerator` classes (minor)
19
+ * Create `BakeInjectedExercise` and `BakeInjectedExerciseQuestion` directions (minor)
20
+ * Update `MoveSolutionsFromExerciseSection` and `MoveSolutionsFromNumberedNote` to move injected solutions (minor)
21
+ * Add `SolutionElementEnumerator` to support the above (minor)
22
+ * Remove multipart exercise baking from `BakeNumberedExercise`; this is now done in `InjectedExercise` directions (patch)
23
+ * Modify target labels to use grammatical cases (minor)
24
+ * Modify `BakeIndex` to bake multiple types of indexes (minor)
25
+ * Create `v2` in `BakeChapterIntroductions` that should replace `v1` (minor)
26
+ * Added a DEPRECATION warning in `v1` for `BakeChapterIntroductions` (minor)
27
+ * Added a bit more description to deprecation warning for `BakeChapterIntroductions.v1` (minor)
28
+
29
+ ## [11.0.0] - 2021-08-6
30
+
31
+ * Add `ChangeSubsectionTitleTag` direction for modifying eoc sections (minor)
32
+ * Add `MoveSolutionsFromNumberedNote`, `MoveSolutionsFromExerciseSection`, and `SolutionAreaSnippet` for answer key baking (minor)
33
+ * Refactor the following `Strategies`: contemporary math, precalculus, uphysics (minor)
34
+ * Fix `BakeUnitPageTite` to utilize only pages which are direct children of the unit (patch)
35
+ * Patch `BakeFirstElements` to include first figure elements (patch)
36
+ * Refactor `MoveCustomSectionToEocContainer` to remove `include_intro_page` (major)
37
+ * Update `BakeFirstElement` to optionally add the `has-first-inline-element` class (patch)
38
+ * Patch `BakeExample` crashing if an example has commentary but no title (patch)
39
+ * Refactor `EocSectionTitleLinkSnippet` to only have v1 with optional params (major)
40
+ * Adds `PageElement#count_in_chapter_without_intro_page` (minor)
41
+ * Adds `ChapterElement#has_introduction?` (minor)
42
+ * Adds `BakeFolio` to set spanish translation variables in the html tag for folio-pdf purposes (minor)
43
+ * Create `BakeCustomSections` direction for English Composition (minor)
44
+ * Create `BakeAnnotationClasses` v1 for English Composition (minor)
45
+
46
+ ## [10.0.0] - 2021-07-30
47
+
48
+ * Add support for baking multipart questions to `BakeNumberedExercise` (minor)
49
+ * Add `has_para` option to `BakeChapterGlossary` for books from Adaptarr (minor)
50
+ * Create `BakeListsWithPara` to remove paragraphs from lists in books created by Adaptarr (minor)
51
+ * Create `Strategy::ContemporaryMath` (minor)
52
+ * Stop `BakeTableBody` from blowing up when table doesn't have an ID (patch)
53
+ * Refactor `MoveExercisesToEOC::V2` & `BakeChapterKeyConcepts` to use `MoveCustomSectionToEocContainer` (minor)
54
+ * Add wrapper support for `MoveCustomSectionToEocContainer` (minor)
55
+ * Create `BakeHandbook` direction (minor)
56
+ * Add `ExampleElement#titles_to_rename` & refactor `BakeExample` (patch)
57
+ * Create `BakeUnitPageTitle` (minor)
58
+ * Fix `BakeExample` to skip baked exercises (patch)
59
+ * Add `FigureElement#figure_to_bake?` (minor)
60
+ * Remove `itemprop` attribute from `BakeChapterSummary` and `BakeFurtherResearch` (major)
61
+ * Fix `NoteElement#title` to exclude nested element titles (patch)
62
+ * Remove `BakeTheorem` (minor)
63
+ * Allow `BakeChapterSolutions` to bake solutions from multiple sections (minor)
64
+ * Add `.os-problem-container` to `BakeFirstElement` selectors (minor)
65
+ * Tweak `BakeExample` to not touch unbaked titles in captions (minor/patch)
66
+ * Tweak `BakeNumberedTables.v1` to cut extra white space (minor)
67
+
68
+ ## [9.2.0] - 2021-07-19
69
+
70
+ * Update `BakeFirstElements` to also add the `.has-first-inline-list` class (minor)
71
+
9
72
  ## [9.1.0] - 2021-07-16
10
73
 
11
74
  * Add `BakeNoteIFrames` direction (minor)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openstax_kitchen (9.1.0)
4
+ openstax_kitchen (11.1.0)
5
5
  activesupport
6
6
  i18n
7
7
  nokogiri
@@ -99,7 +99,7 @@ GEM
99
99
  tins (~> 1.0)
100
100
  tins (1.26.0)
101
101
  sync
102
- twitter_cldr (6.6.0)
102
+ twitter_cldr (6.7.0)
103
103
  camertron-eprun
104
104
  cldr-plurals-runtime-rb (~> 1.1)
105
105
  tzinfo
@@ -44,6 +44,14 @@ module Kitchen
44
44
  pages('$.introduction').first
45
45
  end
46
46
 
47
+ # Returns true if the chapter has an introduction
48
+ #
49
+ # @return [Boolean]
50
+ #
51
+ def has_introduction?
52
+ @has_introduction ||= introduction_page.present?
53
+ end
54
+
47
55
  # Returns an enumerator for the glossaries
48
56
  #
49
57
  # @return [ElementEnumerator]
@@ -41,6 +41,14 @@ module Kitchen
41
41
  has_class?('os-index-container')
42
42
  end
43
43
 
44
+ # Returns true if this page is a book index of type
45
+ #
46
+ # @return [Boolean]
47
+ #
48
+ def is_index_of_type?
49
+ (self[:class] || '').match?(/os-index-.+-container/)
50
+ end
51
+
44
52
  # In books we can find two types of EOB References.
45
53
  #
46
54
  # One of them has form similar to footnotes. There are citation links in the text that provides
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeAnnotationClasses
6
+ def self.v1(chapter:)
7
+ V1.new.bake(
8
+ chapter: chapter)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeAnnotationClasses
4
+ class V1
5
+ def bake(chapter:)
6
+ chapter.search('p.annotation').each do |annotation|
7
+ annotation.wrap_children('span', class: 'os-text')
8
+ annotation.prepend(child:
9
+ <<~HTML
10
+ <div class="os-icons"></div>
11
+ HTML
12
+ )
13
+ end
14
+ annotation_icon_classes = %w[linguistic-icon
15
+ culture-icon
16
+ dreaming-icon
17
+ visual-icon
18
+ speech-icon
19
+ auditory-icon
20
+ kinesthetic-icon]
21
+ annotation_icon_classes.each do |annotation_icon_class|
22
+ chapter.search("p.#{annotation_icon_class}").each do |annotation_with_icon_class|
23
+ annotation_with_icon_class.search('div.os-icons').first.append(child:
24
+ <<~HTML
25
+ <span class = "#{annotation_icon_class}"></span>
26
+ HTML
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -5,12 +5,13 @@ module Kitchen
5
5
  # Bake directons for eoc glossary
6
6
  #
7
7
  module BakeChapterGlossary
8
- def self.v1(chapter:, metadata_source:, append_to: nil, uuid_prefix: nil)
8
+ def self.v1(chapter:, metadata_source:, append_to: nil, uuid_prefix: nil, has_para: false)
9
9
  V1.new.bake(
10
10
  chapter: chapter,
11
11
  metadata_source: metadata_source,
12
12
  append_to: append_to,
13
- uuid_prefix: uuid_prefix
13
+ uuid_prefix: uuid_prefix,
14
+ has_para: has_para
14
15
  )
15
16
  end
16
17
  end
@@ -21,9 +21,18 @@ module Kitchen::Directions::BakeChapterGlossary
21
21
  attr_reader :sortable
22
22
  end
23
23
 
24
- def bake(chapter:, metadata_source:, append_to: nil, uuid_prefix: '')
24
+ def bake(chapter:, metadata_source:, append_to: nil, uuid_prefix: '', has_para: false)
25
25
  @glossary = []
26
26
 
27
+ # Use for books created by Adaptarr, where dd contains paragraphs
28
+ # More info: https://github.com/openstax/kitchen/issues/284
29
+ if has_para
30
+ chapter.glossaries.search('dd').each do |description|
31
+ description_content = description.first('p').text
32
+ description.replace_children with: description_content
33
+ end
34
+ end
35
+
27
36
  chapter.glossaries.search('dl').each do |definition_element|
28
37
  @glossary.push(Definition.new(definition_element.cut))
29
38
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeChapterIntroductions
4
+ class BakeChapterObjectives
5
+ def bake(chapter:, strategy:)
6
+ case strategy
7
+ when :default
8
+ bake_as_note(chapter: chapter)
9
+ when :add_objectives
10
+ add_chapter_objectives(chapter: chapter)
11
+ when :none
12
+ ''
13
+ else
14
+ raise 'No such strategy'
15
+ end
16
+ end
17
+
18
+ def bake_as_note(chapter:)
19
+ chapter_objectives_note = chapter.notes('$.chapter-objectives').first
20
+
21
+ # trash existing title
22
+ chapter_objectives_note.titles.first&.trash
23
+ Kitchen::Directions::BakeAutotitledNotes.v1(
24
+ book: chapter,
25
+ classes: %w[chapter-objectives],
26
+ bake_subtitle: false
27
+ )
28
+
29
+ chapter_objectives_note.cut.paste
30
+ end
31
+
32
+ def add_chapter_objectives(chapter:)
33
+ chapter.non_introduction_pages.map do |page|
34
+ <<~HTML
35
+ <div class="os-chapter-objective">
36
+ <a class="os-chapter-objective" href="##{page.title[:id]}">
37
+ <span class="os-number">#{chapter.count_in(:book)}.#{page.count_in(:chapter)}</span>
38
+ <span class="os-divider"> </span>
39
+ <span data-type="" itemprop="" class="os-text">#{page.title.children[0].text}</span>
40
+ </a>
41
+ </div>
42
+ HTML
43
+ end.join('')
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeChapterIntroductions
4
+ class BakeChapterOutline
5
+ def bake(chapter_objectives_html:)
6
+ <<~HTML
7
+ <div class="os-chapter-outline">
8
+ <h3 class="os-title">#{I18n.t(:chapter_outline)}</h3>
9
+ #{chapter_objectives_html}
10
+ </div>
11
+ HTML
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeChapterIntroductions
6
+ def self.v1(book:)
7
+ V1.new.bake(
8
+ book: book
9
+ )
10
+ end
11
+
12
+ def self.v2(
13
+ book:,
14
+ strategy_options: {
15
+ strategy: :default, bake_chapter_outline: false, introduction_order: :v1
16
+ }
17
+ )
18
+ V2.new.bake(
19
+ book: book,
20
+ strategy_options: strategy_options
21
+ )
22
+ end
23
+
24
+ def self.bake_chapter_objectives(chapter:, strategy:)
25
+ BakeChapterObjectives.new.bake(
26
+ chapter: chapter,
27
+ strategy: strategy
28
+ )
29
+ end
30
+
31
+ def self.bake_chapter_outline(chapter_objectives_html:)
32
+ BakeChapterOutline.new.bake(
33
+ chapter_objectives_html: chapter_objectives_html
34
+ )
35
+ end
36
+
37
+ def self.v1_update_selectors(something_with_selectors)
38
+ something_with_selectors.selectors.title_in_introduction_page =
39
+ ".intro-text > [data-type='document-title']"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeChapterIntroductions
4
+ class V1
5
+ def bake(book:)
6
+ # <b>DEPRECATED:</b> Please use <tt>v2</tt> instead.
7
+ warn '[DEPRECATION] `BakeChapterIntroductions.v1` is deprecated. Please use `v2` instead.'
8
+
9
+ book.chapters.each do |chapter|
10
+ introduction_page = chapter.introduction_page
11
+
12
+ introduction_page.search("div[data-type='description']").trash
13
+ introduction_page.search("div[data-type='abstract']").trash
14
+
15
+ title = introduction_page.title.cut
16
+ title.name = 'h2'
17
+ Kitchen::Directions::MoveTitleTextIntoSpan.v1(title: title)
18
+
19
+ intro_content = introduction_page.search(
20
+ "> :not([data-type='metadata']):not(.splash):not(.has-splash)"
21
+ ).cut
22
+
23
+ chapter_objectives_html = chapter.non_introduction_pages.map do |page|
24
+ <<~HTML
25
+ <div class="os-chapter-objective">
26
+ <a class="os-chapter-objective" href="##{page.title[:id]}">
27
+ <span class="os-number">#{chapter.count_in(:book)}.#{page.count_in(:chapter)}</span>
28
+ <span class="os-divider"> </span>
29
+ <span data-type="" itemprop="" class="os-text">#{page.title.children[0].text}</span>
30
+ </a>
31
+ </div>
32
+ HTML
33
+ end.join('')
34
+
35
+ chapter_outline =
36
+ Kitchen::Directions::BakeChapterIntroductions.bake_chapter_outline(
37
+ chapter_objectives_html: chapter_objectives_html
38
+ )
39
+
40
+ introduction_page.append(child:
41
+ <<~HTML
42
+ <div class="intro-body">
43
+ #{chapter_outline}
44
+ <div class="intro-text">
45
+ #{title.paste}
46
+ #{intro_content.paste}
47
+ </div>
48
+ </div>
49
+ HTML
50
+ )
51
+ end
52
+
53
+ Kitchen::Directions::BakeChapterIntroductions.v1_update_selectors(book)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeChapterIntroductions
4
+ class V2
5
+ def bake(book:, strategy_options:)
6
+ book.chapters.each do |chapter|
7
+ introduction_page = chapter.introduction_page
8
+ title = bake_title(introduction_page: introduction_page)
9
+
10
+ chapter_intro_html =
11
+ Kitchen::Directions::BakeChapterIntroductions.bake_chapter_objectives(
12
+ chapter: chapter,
13
+ strategy: strategy_options[:strategy]
14
+ )
15
+
16
+ if strategy_options[:bake_chapter_outline]
17
+ chapter_intro_html =
18
+ Kitchen::Directions::BakeChapterIntroductions.bake_chapter_outline(
19
+ chapter_objectives_html: chapter_intro_html
20
+ )
21
+ end
22
+
23
+ case strategy_options[:introduction_order]
24
+ when :v1
25
+ v1_introduction_order(
26
+ introduction_page: introduction_page,
27
+ chapter_intro_html: chapter_intro_html,
28
+ title: title
29
+ )
30
+ when :v2
31
+ v2_introduction_order(
32
+ introduction_page: introduction_page,
33
+ chapter_intro_html: chapter_intro_html,
34
+ title: title
35
+ )
36
+ end
37
+ end
38
+
39
+ Kitchen::Directions::BakeChapterIntroductions.v1_update_selectors(book)
40
+ end
41
+
42
+ def v1_introduction_order(introduction_page:, chapter_intro_html:, title:)
43
+ intro_content = introduction_page.search(
44
+ "> :not([data-type='metadata']):not(.splash):not(.has-splash)"
45
+ ).cut
46
+
47
+ introduction_page.append(child:
48
+ <<~HTML
49
+ <div class="intro-body">
50
+ #{chapter_intro_html}
51
+ <div class="intro-text">
52
+ #{title.paste}
53
+ #{intro_content.paste}
54
+ </div>
55
+ </div>
56
+ HTML
57
+ )
58
+ end
59
+
60
+ def v2_introduction_order(introduction_page:, chapter_intro_html:, title:)
61
+ if chapter_intro_html.empty?
62
+ chapter_intro_html = introduction_page.notes('$.chapter-objectives').first&.cut&.paste
63
+ end
64
+ extra_content = introduction_page.search(
65
+ '> :not([data-type="metadata"]):not(.splash):not(.has-splash)'
66
+ ).cut
67
+
68
+ introduction_page.append(child:
69
+ <<~HTML
70
+ <div class="intro-body">
71
+ #{chapter_intro_html}
72
+ <div class="intro-text">
73
+ #{title.paste}
74
+ #{extra_content.paste}
75
+ </div>
76
+ </div>
77
+ HTML
78
+ )
79
+ end
80
+
81
+ def bake_title(introduction_page:)
82
+ introduction_page.search(
83
+ 'div[data-type="description"], div[data-type="abstract"]'
84
+ ).each(&:trash)
85
+
86
+ title = introduction_page.title.cut
87
+ title.name = 'h2'
88
+ Kitchen::Directions::MoveTitleTextIntoSpan.v1(title: title)
89
+ end
90
+ end
91
+ end