Class: Kitchen::Directions::BakeFolio::V1

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/directions/bake_folio.rb

Defined Under Namespace

Classes: FolioPara, FolioParaWithNumber

Instance Method Summary collapse

Instance Method Details

#appendix_folio(book:, klass:) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/kitchen/directions/bake_folio.rb', line 127

def appendix_folio(book:, klass:)
  book.pages('$.appendix').each do |appendix_page|
    appendix_para = FolioParaWithNumber.new(
      klass: klass,
      title: appendix_page.title,
      title_number: [*('A'..'Z')][appendix_page.count_in(:book) - 1]
    )

    appendix_para.create_para
  end
end

#bake(book:, options:) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/kitchen/directions/bake_folio.rb', line 59

def bake(book:, options:)
  book['data-pdf-folio-preface-message'] = I18n.t(:"folio.preface")
  book['data-pdf-folio-access-message'] = I18n.t(:"folio.access_for_free")

  return unless options[:new_approach]

  # TODO: apply to all books and remove an option

  book.chapters.each do |chapter|
    chapter_folio(chapter: chapter)
    module_folio(chapter: chapter)
    eoc_folio(chapter: chapter, klass: 'folio-eoc-left')
    eoc_folio(chapter: chapter, klass: 'folio-eoc-right')
  end

  appendix_folio(book: book, klass: 'folio-appendix-left')
  appendix_folio(book: book, klass: 'folio-appendix-right')

  eob_folio(book: book, klass: 'folio-eob-left')
  eob_folio(book: book, klass: 'folio-eob-right')
end

#chapter_folio(chapter:) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/kitchen/directions/bake_folio.rb', line 81

def chapter_folio(chapter:)
  chapter_para = FolioParaWithNumber.new(
    klass: 'folio-chapter',
    title: chapter.title,
    title_number: chapter.count_in(:book).to_s
  )

  chapter_para.create_para
end

#eob_folio(book:, klass:) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/kitchen/directions/bake_folio.rb', line 139

def eob_folio(book:, klass:)
  eob_selectors = '.os-eob[data-type="composite-chapter"], ' \
                 '.os-eob[data-type="composite-page"]:not(.os-solutions-container)'

  book.search(eob_selectors).each do |eob_page|
    eob_para = FolioPara.new(
      klass: klass,
      title: eob_page.search('h1[data-type="document-title"]').first
    )

    eob_para.create_para
  end
end

#eoc_folio(chapter:, klass:) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/kitchen/directions/bake_folio.rb', line 115

def eoc_folio(chapter:, klass:)
  chapter.search(' > .os-eoc').each do |eoc_page|
    eoc_para = FolioParaWithNumber.new(
      klass: klass,
      title: eoc_page.search('h2[data-type="document-title"]').first,
      title_number: chapter.count_in(:book).to_s
    )

    eoc_para.create_para
  end
end

#module_folio(chapter:) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/kitchen/directions/bake_folio.rb', line 91

def module_folio(chapter:)
  # Introduction para
  chapter.pages('$.introduction').each do |page|
    intro_para = FolioParaWithNumber.new(
      klass: 'folio-module',
      title: page.search('h2[data-type="document-title"]').first,
      title_number: chapter.count_in(:book).to_s
    )

    intro_para.create_para
  end

  # Module para
  chapter.non_introduction_pages.each do |page|
    module_para = FolioParaWithNumber.new(
      klass: 'folio-module',
      title: page.title,
      title_number: "#{chapter.count_in(:book)}.#{page.count_in(:chapter)}"
    )

    module_para.create_para
  end
end