3
3
module Kitchen
4
4
module Directions
5
5
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 )
9
14
end
10
15
11
16
class V1
@@ -56,19 +61,27 @@ def create_para
56
61
end
57
62
end
58
63
59
- def bake ( book :, options :)
64
+ def bake ( book :, chapters : , options :)
60
65
book [ 'data-pdf-folio-preface-message' ] = I18n . t ( :"folio.preface" )
61
66
book [ 'data-pdf-folio-access-message' ] = I18n . t ( :"folio.access_for_free" )
62
67
63
68
return unless options [ :new_approach ]
64
69
65
70
# 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
+ )
72
85
end
73
86
74
87
appendix_folio ( book : book , klass : 'folio-appendix-left' )
@@ -78,23 +91,23 @@ def bake(book:, options:)
78
91
eob_folio ( book : book , klass : 'folio-eob-right' )
79
92
end
80
93
81
- def chapter_folio ( chapter :)
94
+ def chapter_folio ( chapter :, numbering_options : )
82
95
chapter_para = FolioParaWithNumber . new (
83
96
klass : 'folio-chapter' ,
84
97
title : chapter . title ,
85
- title_number : chapter . count_in ( :book ) . to_s
98
+ title_number : chapter . os_number ( numbering_options )
86
99
)
87
100
88
101
chapter_para . create_para
89
102
end
90
103
91
- def module_folio ( chapter :)
104
+ def module_folio ( chapter :, numbering_options : )
92
105
# Introduction para
93
106
chapter . pages ( '$.introduction' ) . each do |page |
94
107
intro_para = FolioParaWithNumber . new (
95
108
klass : 'folio-module' ,
96
109
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 )
98
111
)
99
112
100
113
intro_para . create_para
@@ -105,19 +118,19 @@ def module_folio(chapter:)
105
118
module_para = FolioParaWithNumber . new (
106
119
klass : 'folio-module' ,
107
120
title : page . title ,
108
- title_number : " #{ chapter . count_in ( :book ) } . #{ page . count_in ( :chapter ) } "
121
+ title_number : page . os_number ( numbering_options )
109
122
)
110
123
111
124
module_para . create_para
112
125
end
113
126
end
114
127
115
- def eoc_folio ( chapter :, klass :)
128
+ def eoc_folio ( chapter :, klass :, numbering_options : )
116
129
chapter . search ( ' > .os-eoc' ) . each do |eoc_page |
117
130
eoc_para = FolioParaWithNumber . new (
118
131
klass : klass ,
119
132
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 )
121
134
)
122
135
123
136
eoc_para . create_para
0 commit comments