Skip to content

Commit b1c33d0

Browse files
Unit numbering in bake_folio
1 parent 8fe7508 commit b1c33d0

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

lib/kitchen/directions/bake_folio.rb

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
module Kitchen
44
module Directions
55
module BakeFolio
6-
def self.v1(book:, options: { new_approach: false })
7-
options.reverse_merge!(new_approach: false)
8-
V1.new.bake(book: book, options: options)
6+
def self.v1(book:, chapters: nil, options: {})
7+
options.reverse_merge!(
8+
new_approach: false,
9+
numbering_options: { mode: :chapter_page, separator: '.' })
10+
V1.new.bake(
11+
book: book,
12+
chapters: chapters || book.chapters,
13+
options: options)
914
end
1015

1116
class V1
@@ -56,19 +61,27 @@ def create_para
5661
end
5762
end
5863

59-
def bake(book:, options:)
64+
def bake(book:, chapters:, options:)
6065
book['data-pdf-folio-preface-message'] = I18n.t(:"folio.preface")
6166
book['data-pdf-folio-access-message'] = I18n.t(:"folio.access_for_free")
6267

6368
return unless options[:new_approach]
6469

6570
# TODO: apply to all books and remove an option
66-
67-
book.chapters.each do |chapter|
68-
chapter_folio(chapter: chapter)
69-
module_folio(chapter: chapter)
70-
eoc_folio(chapter: chapter, klass: 'folio-eoc-left')
71-
eoc_folio(chapter: chapter, klass: 'folio-eoc-right')
71+
numbering_options = options[:numbering_options]
72+
chapters.each do |chapter|
73+
chapter_folio(chapter: chapter, numbering_options: numbering_options)
74+
module_folio(chapter: chapter, numbering_options: numbering_options)
75+
eoc_folio(
76+
chapter: chapter,
77+
klass: 'folio-eoc-left',
78+
numbering_options: numbering_options
79+
)
80+
eoc_folio(
81+
chapter: chapter,
82+
klass: 'folio-eoc-right',
83+
numbering_options: numbering_options
84+
)
7285
end
7386

7487
appendix_folio(book: book, klass: 'folio-appendix-left')
@@ -78,23 +91,23 @@ def bake(book:, options:)
7891
eob_folio(book: book, klass: 'folio-eob-right')
7992
end
8093

81-
def chapter_folio(chapter:)
94+
def chapter_folio(chapter:, numbering_options:)
8295
chapter_para = FolioParaWithNumber.new(
8396
klass: 'folio-chapter',
8497
title: chapter.title,
85-
title_number: chapter.count_in(:book).to_s
98+
title_number: chapter.os_number(numbering_options)
8699
)
87100

88101
chapter_para.create_para
89102
end
90103

91-
def module_folio(chapter:)
104+
def module_folio(chapter:, numbering_options:)
92105
# Introduction para
93106
chapter.pages('$.introduction').each do |page|
94107
intro_para = FolioParaWithNumber.new(
95108
klass: 'folio-module',
96109
title: page.search('h2[data-type="document-title"]').first,
97-
title_number: chapter.count_in(:book).to_s
110+
title_number: chapter.os_number(numbering_options)
98111
)
99112

100113
intro_para.create_para
@@ -105,19 +118,19 @@ def module_folio(chapter:)
105118
module_para = FolioParaWithNumber.new(
106119
klass: 'folio-module',
107120
title: page.title,
108-
title_number: "#{chapter.count_in(:book)}.#{page.count_in(:chapter)}"
121+
title_number: page.os_number(numbering_options)
109122
)
110123

111124
module_para.create_para
112125
end
113126
end
114127

115-
def eoc_folio(chapter:, klass:)
128+
def eoc_folio(chapter:, klass:, numbering_options:)
116129
chapter.search(' > .os-eoc').each do |eoc_page|
117130
eoc_para = FolioParaWithNumber.new(
118131
klass: klass,
119132
title: eoc_page.search('h2[data-type="document-title"]').first,
120-
title_number: chapter.count_in(:book).to_s
133+
title_number: chapter.os_number(numbering_options)
121134
)
122135

123136
eoc_para.create_para

0 commit comments

Comments
 (0)