Class: Kitchen::Directions::BakeChapterIntroductions::V2
- Defined in:
- lib/kitchen/directions/bake_chapter_introductions/v2.rb
Instance Method Summary collapse
- #bake(book:, options:) ⇒ Object
- #bake_title(introduction_page:) ⇒ Object
- #order(options:, introduction_page:, chapter_intro_html:, title:) ⇒ Object
- #v1_introduction_order(introduction_page:, chapter_intro_html:, title:) ⇒ Object
- #v2_introduction_order(introduction_page:, chapter_intro_html:, title:) ⇒ Object
- #v3_introduction_order(introduction_page:, chapter_intro_html:, title:) ⇒ Object
Instance Method Details
#bake(book:, options:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kitchen/directions/bake_chapter_introductions/v2.rb', line 5 def bake(book:, options:) book.chapters.each do |chapter| introduction_page = chapter.introduction_page number = chapter.count_in(:book) title_label = chapter.title.search('.os-text').first&.text title_label = chapter.title.text if title_label.nil? introduction_page.target_label(label_text: 'chapter', custom_content: "#{number} #{title_label}", cases: [:cases]) unless [:block_target_label] title = bake_title(introduction_page: introduction_page) chapter_intro_html = Kitchen::Directions::BakeChapterIntroductions.bake_chapter_objectives( chapter: chapter, strategy: [:strategy] ) if [:bake_chapter_outline] chapter_intro_html = Kitchen::Directions::BakeChapterIntroductions.bake_chapter_outline( chapter_objectives_html: chapter_intro_html ) end order( options: , introduction_page: introduction_page, chapter_intro_html: chapter_intro_html, title: title ) end Kitchen::Directions::BakeChapterIntroductions.v1_update_selectors(book) end |
#bake_title(introduction_page:) ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/kitchen/directions/bake_chapter_introductions/v2.rb', line 123 def bake_title(introduction_page:) introduction_page.search( 'div[data-type="description"], div[data-type="abstract"]' ).each(&:trash) title = introduction_page.title.cut title.name = 'h2' title.id = "#{introduction_page.id}_titlecreatedbycookbook" Kitchen::Directions::MoveTitleChildrenIntoSpan.v1(title: title) end |
#order(options:, introduction_page:, chapter_intro_html:, title:) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/kitchen/directions/bake_chapter_introductions/v2.rb', line 40 def order(options:, introduction_page:, chapter_intro_html:, title:) case [:introduction_order] when :v1 v1_introduction_order( introduction_page: introduction_page, chapter_intro_html: chapter_intro_html, title: title ) when :v2 v2_introduction_order( introduction_page: introduction_page, chapter_intro_html: chapter_intro_html, title: title ) when :v3 v3_introduction_order( introduction_page: introduction_page, chapter_intro_html: chapter_intro_html, title: title ) end end |
#v1_introduction_order(introduction_page:, chapter_intro_html:, title:) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kitchen/directions/bake_chapter_introductions/v2.rb', line 63 def v1_introduction_order(introduction_page:, chapter_intro_html:, title:) intro_content = introduction_page.search( "> :not([data-type='metadata']):not(.splash):not(.has-splash)" ).cut introduction_page.append(child: <<~HTML <div class="intro-body"> #{chapter_intro_html} <div class="intro-text"> #{title.paste} #{intro_content.paste} </div> </div> HTML ) end |
#v2_introduction_order(introduction_page:, chapter_intro_html:, title:) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/kitchen/directions/bake_chapter_introductions/v2.rb', line 81 def v2_introduction_order(introduction_page:, chapter_intro_html:, title:) if chapter_intro_html.empty? chapter_intro_html = introduction_page.notes('$.chapter-objectives').first&.cut&.paste end extra_content = introduction_page.search( '> :not([data-type="metadata"]):not(.splash):not(.has-splash)' ).cut introduction_page.append(child: <<~HTML <div class="intro-body"> #{chapter_intro_html} <div class="intro-text"> #{title.paste} #{extra_content.paste} </div> </div> HTML ) end |
#v3_introduction_order(introduction_page:, chapter_intro_html:, title:) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/kitchen/directions/bake_chapter_introductions/v2.rb', line 102 def v3_introduction_order(introduction_page:, chapter_intro_html:, title:) intro_content = introduction_page.search( "> :not([data-type='metadata']):not(.splash):not(.has-splash):not(.unit-opener)" ).cut unit_opener_note = introduction_page.search('[data-type="note"].unit-opener').cut introduction_page.append(child: <<~HTML <div class="intro-body"> #{unit_opener_note.paste} #{chapter_intro_html} <div class="intro-text"> #{title.paste} #{intro_content.paste} </div> </div> HTML ) end |