openstax_kitchen 9.2.0 → 11.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +71 -0
  3. data/Gemfile.lock +3 -3
  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_accessibility_fixes.rb +11 -0
  7. data/lib/kitchen/directions/bake_annotation_classes/main.rb +12 -0
  8. data/lib/kitchen/directions/bake_annotation_classes/v1.rb +32 -0
  9. data/lib/kitchen/directions/bake_chapter_glossary/main.rb +3 -2
  10. data/lib/kitchen/directions/bake_chapter_glossary/v1.rb +10 -1
  11. data/lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb +48 -0
  12. data/lib/kitchen/directions/bake_chapter_introductions/bake_chapter_outline.rb +14 -0
  13. data/lib/kitchen/directions/bake_chapter_introductions/main.rb +43 -0
  14. data/lib/kitchen/directions/bake_chapter_introductions/v1.rb +16 -0
  15. data/lib/kitchen/directions/bake_chapter_introductions/v2.rb +91 -0
  16. data/lib/kitchen/directions/bake_chapter_key_concepts/v1.rb +11 -21
  17. data/lib/kitchen/directions/bake_chapter_references/v1.rb +3 -3
  18. data/lib/kitchen/directions/bake_chapter_solutions/main.rb +7 -2
  19. data/lib/kitchen/directions/bake_chapter_solutions/v1.rb +11 -9
  20. data/lib/kitchen/directions/bake_chapter_summary.rb +1 -2
  21. data/lib/kitchen/directions/bake_custom_sections/main.rb +14 -0
  22. data/lib/kitchen/directions/bake_custom_sections/v1.rb +42 -0
  23. data/lib/kitchen/directions/bake_eoc_section_content/change_subsection_title_tag.rb +13 -0
  24. data/lib/kitchen/directions/bake_equations.rb +2 -3
  25. data/lib/kitchen/directions/bake_example.rb +11 -14
  26. data/lib/kitchen/directions/bake_figure.rb +5 -3
  27. data/lib/kitchen/directions/bake_first_elements.rb +12 -7
  28. data/lib/kitchen/directions/bake_folio.rb +12 -0
  29. data/lib/kitchen/directions/bake_footnotes/v1.rb +5 -1
  30. data/lib/kitchen/directions/bake_free_response/v1.rb +3 -1
  31. data/lib/kitchen/directions/bake_further_research.rb +1 -3
  32. data/lib/kitchen/directions/bake_handbook/main.rb +11 -0
  33. data/lib/kitchen/directions/bake_handbook/v1.rb +74 -0
  34. data/lib/kitchen/directions/bake_iframes/main.rb +11 -0
  35. data/lib/kitchen/directions/bake_iframes/v1.rb +25 -0
  36. data/lib/kitchen/directions/bake_index/main.rb +2 -2
  37. data/lib/kitchen/directions/bake_index/v1.rb +39 -7
  38. data/lib/kitchen/directions/bake_index/v1.xhtml.erb +3 -3
  39. data/lib/kitchen/directions/bake_injected_exercise.rb +18 -0
  40. data/lib/kitchen/directions/bake_injected_exercise_question.rb +71 -0
  41. data/lib/kitchen/directions/bake_link_placeholders.rb +15 -2
  42. data/lib/kitchen/directions/bake_lists_with_para.rb +17 -0
  43. data/lib/kitchen/directions/bake_notes/bake_autotitled_notes.rb +5 -5
  44. data/lib/kitchen/directions/bake_notes/bake_note_subtitle.rb +6 -2
  45. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/main.rb +13 -3
  46. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/v1.rb +29 -25
  47. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/v2.rb +22 -17
  48. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/v3.rb +30 -22
  49. data/lib/kitchen/directions/bake_numbered_exercise/main.rb +3 -2
  50. data/lib/kitchen/directions/bake_numbered_exercise/v1.rb +6 -5
  51. data/lib/kitchen/directions/bake_numbered_table/bake_table_body.rb +57 -16
  52. data/lib/kitchen/directions/bake_numbered_table/main.rb +4 -4
  53. data/lib/kitchen/directions/bake_numbered_table/v1.rb +6 -4
  54. data/lib/kitchen/directions/bake_numbered_table/v2.rb +6 -4
  55. data/lib/kitchen/directions/bake_toc.rb +8 -1
  56. data/lib/kitchen/directions/bake_unit_page_title/main.rb +11 -0
  57. data/lib/kitchen/directions/bake_unit_page_title/v1.rb +23 -0
  58. data/lib/kitchen/directions/eoc_section_title_link_snippet.rb +32 -21
  59. data/lib/kitchen/directions/move_custom_section_to_eoc_container/main.rb +4 -3
  60. data/lib/kitchen/directions/move_custom_section_to_eoc_container/v1.rb +19 -3
  61. data/lib/kitchen/directions/move_exercises_to_eoc/v1.rb +1 -2
  62. data/lib/kitchen/directions/move_exercises_to_eoc/v2.rb +11 -30
  63. data/lib/kitchen/directions/move_exercises_to_eoc/v3.rb +1 -2
  64. data/lib/kitchen/directions/move_solutions_to_answer_key/move_solutions_from_exercise_section.rb +34 -0
  65. data/lib/kitchen/directions/move_solutions_to_answer_key/move_solutions_from_numbered_note.rb +27 -0
  66. data/lib/kitchen/directions/move_solutions_to_answer_key/solution_area_snippet.rb +12 -0
  67. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb +1 -1
  68. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/contemporary_math.rb +40 -0
  69. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/default.rb +1 -1
  70. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/precalculus.rb +18 -39
  71. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/uphysics.rb +6 -48
  72. data/lib/kitchen/directions/move_solutions_to_answer_key/v1.rb +10 -3
  73. data/lib/kitchen/element_base.rb +36 -4
  74. data/lib/kitchen/element_enumerator_base.rb +35 -0
  75. data/lib/kitchen/example_element.rb +9 -3
  76. data/lib/kitchen/exercise_element.rb +16 -0
  77. data/lib/kitchen/figure_element.rb +11 -0
  78. data/lib/kitchen/injected_question_element.rb +77 -0
  79. data/lib/kitchen/injected_question_element_enumerator.rb +21 -0
  80. data/lib/kitchen/note_element.rb +8 -1
  81. data/lib/kitchen/page_element.rb +12 -9
  82. data/lib/kitchen/selectors/base.rb +6 -0
  83. data/lib/kitchen/selectors/standard_1.rb +3 -0
  84. data/lib/kitchen/solution_element_enumerator.rb +21 -0
  85. data/lib/kitchen/table_element.rb +25 -0
  86. data/lib/kitchen/version.rb +1 -1
  87. data/lib/locales/en.yml +10 -4
  88. data/lib/locales/es.yml +8 -4
  89. data/lib/locales/pl.yml +52 -7
  90. metadata +30 -7
  91. data/lib/kitchen/directions/bake_chapter_introductions/chapter_introduction.xhtml.erb +0 -0
  92. data/lib/kitchen/directions/bake_chapter_introductions.rb +0 -65
  93. data/lib/kitchen/directions/bake_notes/bake_note_iframes.rb +0 -27
  94. data/lib/kitchen/directions/bake_theorem/main.rb +0 -11
  95. 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: ddd15ebcb9ead1f1e6301bfc025a93bb3ca7e75d2e412eae3a63d3496574eea5
4
- data.tar.gz: 82af5aa1d8151438286f9e6cc21c052f5c7d1549b1966abaf3018f5578fb6f53
3
+ metadata.gz: e366a482a30f5cda88fe3c76731d3f187e727447cfc9ae1c13ff5e8bb99c1daa
4
+ data.tar.gz: 97db8d770c708fda67c566157989b0999fe12859eb515d52da73a86136ab9c29
5
5
  SHA512:
6
- metadata.gz: 268bf8bcf65bc1deb38d20e433b503e28eefc0048a5174bb7ea378354354f7c671e88b72378d03ad03ef077f2d15e5870c691bbdec358664e2f5c2c9344a9f33
7
- data.tar.gz: ef6c551bb52f90e7bf3301b38879cf2262a62dcc4b91b87c02c4ec944e30f71542dac6b4b3b65763e027737a13fd7b7a77ca86b57366025109b4539eb989f9f4
6
+ metadata.gz: d1b69721238c536696a265d4419f94944746a8a934f24c2e39d8beebe27b18fbd85b1da1599cf6cf326e2d44053b0927db0ab7edae3e24c1a5bfea44839555d9
7
+ data.tar.gz: 2b420da729d4282fc85f7b074c2848f83d7912a5ff75365ba91d6406b245a1442f0c3dd7074cc6744b44ba96cdc8d00a0a872b092f54a3865e0fd21daff3d81d
data/CHANGELOG.md CHANGED
@@ -6,6 +6,77 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [11.2.0] - 2021-09-10
10
+
11
+ * Adds `BakeAccessibilityFixes` direction for (minor)
12
+ * Remove deprecation warning from `BakeChapterIntroductions.v1` and adapted to be used like `.v2` (minor)
13
+ * Small class fix for `BakeFootnotes.v1` (patch)
14
+ * Fix `BakeNumberedNotes` to find related example better (minor)
15
+ * Small fix for parameter in `bake_note` definition (minor)
16
+ * Small fixes to return when no elements are found and not add an empty wrapper in `BakeChapterReferences` and
17
+ `BakeFreeResponse` (minor)
18
+ * Adding class `os-timeline-table-container` to numbered tables when required (minor)
19
+ * Fix `BakeExample` to catch the multiple solutions to one exercise (patch)
20
+
21
+ ## [11.1.0] - 2021-08-30
22
+
23
+ * Update injected questions to synthesize ids during baking (minor)
24
+ * Fix `BakeListsWithPara` to copy all children from para not just text (minor)
25
+ * Implement labels with cases to `BakeAutotitledNotes` and `BakeNumberedNotes` (minor)
26
+ * Add ids to injected questions (minor)
27
+ * Create `BakeIframes` outer directory to allow bake iframes also from outside notes, remove `BakeNoteIFrames` module from notes directory (minor)
28
+ * Update the contemporary math `Strategy` to target injected solution sections (minor)
29
+ * Update `BakeNumberedNotes` to handle injected questions in notes (minor)
30
+ * Create `InjectedQuestionElement` and `InjectedQuestionElementEnumerator` classes (minor)
31
+ * Create `BakeInjectedExercise` and `BakeInjectedExerciseQuestion` directions (minor)
32
+ * Update `MoveSolutionsFromExerciseSection` and `MoveSolutionsFromNumberedNote` to move injected solutions (minor)
33
+ * Add `SolutionElementEnumerator` to support the above (minor)
34
+ * Remove multipart exercise baking from `BakeNumberedExercise`; this is now done in `InjectedExercise` directions (patch)
35
+ * Modify target labels to use grammatical cases (minor)
36
+ * Modify `BakeIndex` to bake multiple types of indexes (minor)
37
+ * Create `v2` in `BakeChapterIntroductions` that should replace `v1` (minor)
38
+ * Added a DEPRECATION warning in `v1` for `BakeChapterIntroductions` (minor)
39
+ * Added a bit more description to deprecation warning for `BakeChapterIntroductions.v1` (minor)
40
+
41
+ ## [11.0.0] - 2021-08-6
42
+
43
+ * Add `ChangeSubsectionTitleTag` direction for modifying eoc sections (minor)
44
+ * Add `MoveSolutionsFromNumberedNote`, `MoveSolutionsFromExerciseSection`, and `SolutionAreaSnippet` for answer key baking (minor)
45
+ * Refactor the following `Strategies`: contemporary math, precalculus, uphysics (minor)
46
+ * Fix `BakeUnitPageTite` to utilize only pages which are direct children of the unit (patch)
47
+ * Patch `BakeFirstElements` to include first figure elements (patch)
48
+ * Refactor `MoveCustomSectionToEocContainer` to remove `include_intro_page` (major)
49
+ * Update `BakeFirstElement` to optionally add the `has-first-inline-element` class (patch)
50
+ * Patch `BakeExample` crashing if an example has commentary but no title (patch)
51
+ * Refactor `EocSectionTitleLinkSnippet` to only have v1 with optional params (major)
52
+ * Adds `PageElement#count_in_chapter_without_intro_page` (minor)
53
+ * Adds `ChapterElement#has_introduction?` (minor)
54
+ * Adds `BakeFolio` to set spanish translation variables in the html tag for folio-pdf purposes (minor)
55
+ * Create `BakeCustomSections` direction for English Composition (minor)
56
+ * Create `BakeAnnotationClasses` v1 for English Composition (minor)
57
+
58
+ ## [10.0.0] - 2021-07-30
59
+
60
+ * Add support for baking multipart questions to `BakeNumberedExercise` (minor)
61
+ * Add `has_para` option to `BakeChapterGlossary` for books from Adaptarr (minor)
62
+ * Create `BakeListsWithPara` to remove paragraphs from lists in books created by Adaptarr (minor)
63
+ * Create `Strategy::ContemporaryMath` (minor)
64
+ * Stop `BakeTableBody` from blowing up when table doesn't have an ID (patch)
65
+ * Refactor `MoveExercisesToEOC::V2` & `BakeChapterKeyConcepts` to use `MoveCustomSectionToEocContainer` (minor)
66
+ * Add wrapper support for `MoveCustomSectionToEocContainer` (minor)
67
+ * Create `BakeHandbook` direction (minor)
68
+ * Add `ExampleElement#titles_to_rename` & refactor `BakeExample` (patch)
69
+ * Create `BakeUnitPageTitle` (minor)
70
+ * Fix `BakeExample` to skip baked exercises (patch)
71
+ * Add `FigureElement#figure_to_bake?` (minor)
72
+ * Remove `itemprop` attribute from `BakeChapterSummary` and `BakeFurtherResearch` (major)
73
+ * Fix `NoteElement#title` to exclude nested element titles (patch)
74
+ * Remove `BakeTheorem` (minor)
75
+ * Allow `BakeChapterSolutions` to bake solutions from multiple sections (minor)
76
+ * Add `.os-problem-container` to `BakeFirstElement` selectors (minor)
77
+ * Tweak `BakeExample` to not touch unbaked titles in captions (minor/patch)
78
+ * Tweak `BakeNumberedTables.v1` to cut extra white space (minor)
79
+
9
80
  ## [9.2.0] - 2021-07-19
10
81
 
11
82
  * Update `BakeFirstElements` to also add the `.has-first-inline-list` class (minor)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openstax_kitchen (9.2.0)
4
+ openstax_kitchen (11.2.0)
5
5
  activesupport
6
6
  i18n
7
7
  nokogiri
@@ -11,7 +11,7 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activesupport (6.1.4)
14
+ activesupport (6.1.4.1)
15
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
16
  i18n (>= 1.6, < 2)
17
17
  minitest (>= 5.1)
@@ -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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeAccessibilityFixes
6
+ def self.v1(section:)
7
+ section.search('ol[data-number-style="lower-alpha"]').each { |ol| ol['type'] = 'a' }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -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,48 @@
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
+ return unless chapter_objectives_note.present?
22
+
23
+ # trash existing title
24
+ chapter_objectives_note.titles.first&.trash
25
+ Kitchen::Directions::BakeAutotitledNotes.v1(
26
+ book: chapter,
27
+ classes: %w[chapter-objectives],
28
+ bake_subtitle: false
29
+ )
30
+
31
+ chapter_objectives_note.cut.paste
32
+ end
33
+
34
+ def add_chapter_objectives(chapter:)
35
+ chapter.non_introduction_pages.map do |page|
36
+ <<~HTML
37
+ <div class="os-chapter-objective">
38
+ <a class="os-chapter-objective" href="##{page.title[:id]}">
39
+ <span class="os-number">#{chapter.count_in(:book)}.#{page.count_in(:chapter)}</span>
40
+ <span class="os-divider"> </span>
41
+ <span data-type="" itemprop="" class="os-text">#{page.title.children[0].text}</span>
42
+ </a>
43
+ </div>
44
+ HTML
45
+ end.join('')
46
+ end
47
+ end
48
+ 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,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeChapterIntroductions
4
+ class V1
5
+ def bake(book:)
6
+ Kitchen::Directions::BakeChapterIntroductions.v2(
7
+ book: book,
8
+ strategy_options: {
9
+ strategy: :add_objectives,
10
+ bake_chapter_outline: true,
11
+ introduction_order: :v1
12
+ }
13
+ )
14
+ end
15
+ end
16
+ 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