petit-felix 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/felix/config.rb +6 -19
- data/lib/task/template_pdf_task.rb +2 -2
- data/lib/version.rb +1 -1
- data/lib/worker/pdf_writer/bounding_box.rb +3 -1
- data/lib/worker/pdf_writer.rb +121 -1
- data/lib/worker/template_pdf_writer.rb +1 -1
- data/lib/worker/templater/methods.rb +77 -8
- data/templates/zine-single.json +26 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d2e8b23995447848c4ca2a9aa1fc32d714d13c103474af97b4de7b15a9b909e
|
4
|
+
data.tar.gz: 7ce09991565bb9129a30f9ed51024d669b41077b8462e1343ab40091f7471f18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 001ade81df3dc72cb4672cea3c295cda649d47a8a55d55290a3e141c68b38faf338a0f6e7f9875aefd1e1ab7f6fb3c58807626fc14bbfa5ac09b8e661718a780
|
7
|
+
data.tar.gz: 86c720c74ecd9181c6b6527187af8511241cb50d67760c8a454142476fce8ab9ae1aaacab0527daece7522be9bc0f4830d8f58ecda3edae5f8ecb6bec76a1772
|
data/lib/felix/config.rb
CHANGED
@@ -21,29 +21,12 @@ module PetitFelix
|
|
21
21
|
|
22
22
|
## Hash for custom command line argument calls
|
23
23
|
CL_DATA = {
|
24
|
-
|
25
|
-
"default_font_size" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args).to_i },
|
26
|
-
"header1_size" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args).to_i },
|
27
|
-
"header2_size" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args).to_i },
|
28
|
-
"header3_size" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args).to_i },
|
29
|
-
"header4_size" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args).to_i },
|
30
|
-
"header5_size" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args).to_i },
|
31
|
-
"header6_size" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args).to_i },
|
32
|
-
"margin" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args).to_i },
|
33
|
-
"font_normal" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args) },
|
34
|
-
"font_italic" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args) },
|
35
|
-
"font_bold" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args) },
|
36
|
-
"font_bold_italic" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args) },
|
37
|
-
"page_layout" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args) },
|
38
|
-
"input_files" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args) },
|
39
|
-
"image_dir" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args) },
|
40
|
-
"task" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args) },
|
41
|
-
"template" => -> (command, args, index, cl_args) { cl_add_config(command, args, index, cl_args) },
|
24
|
+
|
42
25
|
}
|
43
26
|
|
44
27
|
### Command Line Arguments
|
45
28
|
|
46
|
-
def
|
29
|
+
def cl_add_config command, args, index, cl_args
|
47
30
|
cl_args[command] = args[index + 1]
|
48
31
|
end
|
49
32
|
|
@@ -155,6 +138,10 @@ module PetitFelix
|
|
155
138
|
|
156
139
|
CL_DATA[command].call command, args, index, cl_args
|
157
140
|
|
141
|
+
else
|
142
|
+
|
143
|
+
cl_add_config command, args, index, cl_args
|
144
|
+
|
158
145
|
end
|
159
146
|
|
160
147
|
@processed_arguments << command
|
@@ -18,7 +18,7 @@ module PetitFelix
|
|
18
18
|
|
19
19
|
return {
|
20
20
|
"template" => (File.join(File.dirname(__FILE__),"..","..","templates","test.json")),
|
21
|
-
"output_file" =>
|
21
|
+
"output_file" => "test.pdf"
|
22
22
|
}
|
23
23
|
|
24
24
|
end
|
@@ -31,7 +31,7 @@ module PetitFelix
|
|
31
31
|
pdf = PetitFelix::Worker::TemplatePDFWriter.new(
|
32
32
|
page_layout: @metaoptions["page_layout"],
|
33
33
|
print_scaling: @metaoptions["print_scaling"])
|
34
|
-
|
34
|
+
|
35
35
|
pdf.set_options @metaoptions
|
36
36
|
|
37
37
|
pdf.init_values @metaoptions, pdf
|
data/lib/version.rb
CHANGED
data/lib/worker/pdf_writer.rb
CHANGED
@@ -12,6 +12,14 @@ module PetitFelix
|
|
12
12
|
|
13
13
|
class DefaultPDFWriter < Prawn::Document
|
14
14
|
|
15
|
+
def alternates_pages
|
16
|
+
return @alternates_pages
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_alternate_pages
|
20
|
+
@alternates_pages = true
|
21
|
+
end
|
22
|
+
|
15
23
|
# Initializes fonts
|
16
24
|
def initialize_font
|
17
25
|
|
@@ -82,7 +90,8 @@ module PetitFelix
|
|
82
90
|
end
|
83
91
|
|
84
92
|
def set_options metaoptions
|
85
|
-
|
93
|
+
@alternates_pages = false
|
94
|
+
|
86
95
|
@options = metaoptions
|
87
96
|
|
88
97
|
end
|
@@ -99,6 +108,117 @@ module PetitFelix
|
|
99
108
|
render_file(file)
|
100
109
|
|
101
110
|
end
|
111
|
+
|
112
|
+
# Copies the contents of a page.
|
113
|
+
def copy_page index=@page_number-1
|
114
|
+
|
115
|
+
return false if index.abs > (state.pages.count - 1)
|
116
|
+
|
117
|
+
# deep copies the page data
|
118
|
+
@page_data = copy_page_data index
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
# Returns the page data copied
|
123
|
+
def copy_page_data index
|
124
|
+
return false if index.abs > (state.pages.count - 1)
|
125
|
+
|
126
|
+
# deep copies the page data
|
127
|
+
return Marshal.load(Marshal.dump(state.store.pages.data[:Kids][index]))
|
128
|
+
end
|
129
|
+
|
130
|
+
# Pastes (overwrites) the content of a page.
|
131
|
+
def paste_page index=@page_number-1
|
132
|
+
|
133
|
+
return false if index.abs > (state.pages.count - 1)
|
134
|
+
|
135
|
+
if !@page_data.nil?
|
136
|
+
|
137
|
+
state.store.pages.data[:Kids][index] = @page_data
|
138
|
+
|
139
|
+
# deep copies the page data so its not referencing the same object constantly
|
140
|
+
@page_data = Marshal.load(Marshal.dump(@page_data))
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
# Clears copied page data.
|
147
|
+
def clear_copied_page
|
148
|
+
|
149
|
+
@page_data = nil
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
# Reorganizes the pages in the given order.
|
154
|
+
|
155
|
+
def reorder_pages pages
|
156
|
+
|
157
|
+
if pages.count != state.pages.count
|
158
|
+
|
159
|
+
return false
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
initial_content = []
|
164
|
+
|
165
|
+
state.store.pages.data[:Kids].each_with_index {
|
166
|
+
|item,index|
|
167
|
+
initial_content.append(state.store.pages.data[:Kids][index])
|
168
|
+
}
|
169
|
+
|
170
|
+
index = 0
|
171
|
+
|
172
|
+
while index < initial_content.count
|
173
|
+
|
174
|
+
return false if pages[index].abs > (state.pages.count - 1)
|
175
|
+
|
176
|
+
state.store.pages.data[:Kids][index] = initial_content[pages[index]]
|
177
|
+
index +=1
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
# Orders the pages properly so they can be printed 2 on a page for stapling
|
184
|
+
def reorder_pages_for_2_page
|
185
|
+
|
186
|
+
pages = []
|
187
|
+
pairs = []
|
188
|
+
|
189
|
+
# first test if page count is odd.
|
190
|
+
# if its odd add an extra page before the back cover
|
191
|
+
|
192
|
+
if state.pages.count % 2 == 1
|
193
|
+
go_to_page(-2)
|
194
|
+
start_new_page
|
195
|
+
|
196
|
+
go_to_page(state.pages.count)
|
197
|
+
end
|
198
|
+
|
199
|
+
# Now that its even do the algorithm
|
200
|
+
center = (state.pages.count / 2) - 1
|
201
|
+
center_other = center + 1
|
202
|
+
|
203
|
+
while center >= 0
|
204
|
+
|
205
|
+
pairs.unshift [center, center_other]
|
206
|
+
|
207
|
+
center -= 1
|
208
|
+
center_other += 1
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
pairs.each do |item|
|
213
|
+
|
214
|
+
pages.append item[0]
|
215
|
+
pages.append item[1]
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
reorder_pages pages
|
220
|
+
|
221
|
+
end
|
102
222
|
|
103
223
|
end
|
104
224
|
end
|
@@ -13,6 +13,9 @@ module PetitFelix
|
|
13
13
|
# List of executable commands
|
14
14
|
|
15
15
|
COMMAND = {
|
16
|
+
## Comment this one out when releasing
|
17
|
+
#:test => -> (obj, args) { obj.com_test args, obj },
|
18
|
+
|
16
19
|
:print => -> (obj, args) { obj.com_print args, obj },
|
17
20
|
:call => -> (obj, args) { obj.com_call args, obj },
|
18
21
|
:if => -> (obj, args) { obj.com_if args, obj },
|
@@ -32,6 +35,8 @@ module PetitFelix
|
|
32
35
|
:move_down => -> (obj, args) { obj.com_move_down args, obj },
|
33
36
|
:move_to => -> (obj, args) { obj.com_move_to args, obj },
|
34
37
|
:move_cursor_to => -> (obj, args) { obj.com_move_cursor_to args, obj },
|
38
|
+
:copy_page => -> (obj, args) { obj.com_copy_page args, obj },
|
39
|
+
:paste_page => -> (obj, args) { obj.com_paste_page args, obj },
|
35
40
|
:delete_page => -> (obj, args) { obj.com_delete_page args, obj },
|
36
41
|
:start_new_page => -> (obj, args) { obj.com_start_new_page args, obj },
|
37
42
|
:draw_text => -> (obj, args) { obj.com_draw_text args, obj },
|
@@ -53,8 +58,21 @@ module PetitFelix
|
|
53
58
|
:span => -> (obj, args) { obj.com_span args, obj },
|
54
59
|
:translate => -> (obj, args) { obj.com_translate args, obj },
|
55
60
|
:transparent => -> (obj, args) { obj.com_transparent args, obj },
|
61
|
+
|
62
|
+
# special custom functions
|
63
|
+
:alternate_pages => -> (obj, args) { obj.com_alternate_pages args, obj },
|
64
|
+
:set_alternate_pages => -> (obj, args) { obj.com_set_alternate_pages args, obj },
|
56
65
|
}
|
57
66
|
|
67
|
+
## Debug test command
|
68
|
+
|
69
|
+
def com_test args, obj
|
70
|
+
#obj.reorder_pages [3,2,0,1]
|
71
|
+
obj.reorder_pages_for_2_page
|
72
|
+
|
73
|
+
return 0
|
74
|
+
end
|
75
|
+
|
58
76
|
# Prawn commands
|
59
77
|
|
60
78
|
def com_bounding_box args, obj
|
@@ -141,6 +159,33 @@ module PetitFelix
|
|
141
159
|
return 0
|
142
160
|
end
|
143
161
|
|
162
|
+
def com_copy_page args, obj
|
163
|
+
args_has_int :val, args
|
164
|
+
|
165
|
+
if args.key?(:val)
|
166
|
+
obj.copy_page args[:val]
|
167
|
+
else
|
168
|
+
obj.copy_page
|
169
|
+
end
|
170
|
+
|
171
|
+
return 0
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
def com_paste_page args, obj
|
176
|
+
|
177
|
+
args_has_int :val, args
|
178
|
+
|
179
|
+
if args.key?(:val)
|
180
|
+
obj.paste_page args[:val]
|
181
|
+
else
|
182
|
+
obj.paste_page
|
183
|
+
end
|
184
|
+
|
185
|
+
return 0
|
186
|
+
|
187
|
+
end
|
188
|
+
|
144
189
|
def com_delete_page args, obj
|
145
190
|
validate = args_has_int :val, args
|
146
191
|
|
@@ -430,8 +475,6 @@ module PetitFelix
|
|
430
475
|
args_has_int :page_start, args
|
431
476
|
args_has_int :page_finish, args
|
432
477
|
|
433
|
-
odd_options[:start_count_at] += 1
|
434
|
-
|
435
478
|
if !args.key?(:page_start)
|
436
479
|
@variables["paginator_start"] = @metaoptions["paginator_start"]
|
437
480
|
else
|
@@ -440,13 +483,26 @@ module PetitFelix
|
|
440
483
|
|
441
484
|
@variables["paginator_end"] = args[:page_finish]
|
442
485
|
|
443
|
-
if
|
444
|
-
|
445
|
-
|
446
|
-
|
486
|
+
if obj.alternates_pages
|
487
|
+
even_options[:start_count_at] = ((obj.page_count - 1) * 0.5).floor
|
488
|
+
|
489
|
+
even_options[:page_filter] = ->(pg) { pg > @variables["paginator_start"] && (pg < @variables["paginator_end"] || @variables["paginator_end"] <= -1) && pg > obj.page_count * 0.5 }
|
490
|
+
|
491
|
+
odd_options[:page_filter] = ->(pg) { pg > @variables["paginator_start"] && (pg < @variables["paginator_end"] || @variables["paginator_end"] <= -1) && pg <= obj.page_count * 0.5 }
|
492
|
+
|
447
493
|
else
|
448
|
-
|
449
|
-
odd_options[:
|
494
|
+
|
495
|
+
odd_options[:start_count_at] += 1
|
496
|
+
|
497
|
+
if @metaoptions["paginator_switch"]
|
498
|
+
odd_options[:page_filter] = ->(pg) { pg > @variables["paginator_start"] && (pg < @variables["paginator_end"] || @variables["paginator_end"] <= -1) && pg % 2 == 1 }
|
499
|
+
even_options[:page_filter] = ->(pg) { pg > @variables["paginator_start"] && (pg < @variables["paginator_end"] || @variables["paginator_end"] <= -1) && pg % 2 == 0 }
|
500
|
+
|
501
|
+
else
|
502
|
+
even_options[:page_filter] = ->(pg) { pg > @variables["paginator_start"] && (pg < @variables["paginator_end"] || @variables["paginator_end"] <= -1) && pg % 2 == 1 }
|
503
|
+
odd_options[:page_filter] = ->(pg) { pg > @variables["paginator_start"] && (pg < @variables["paginator_end"] || @variables["paginator_end"] <= -1) && pg % 2 == 0 }
|
504
|
+
|
505
|
+
end
|
450
506
|
|
451
507
|
end
|
452
508
|
|
@@ -1067,6 +1123,19 @@ module PetitFelix
|
|
1067
1123
|
return 0
|
1068
1124
|
end
|
1069
1125
|
|
1126
|
+
def com_alternate_pages args, obj
|
1127
|
+
#obj.reorder_pages [3,2,0,1]
|
1128
|
+
obj.reorder_pages_for_2_page
|
1129
|
+
|
1130
|
+
return 0
|
1131
|
+
end
|
1132
|
+
|
1133
|
+
def com_set_alternate_pages args, obj
|
1134
|
+
obj.set_alternate_pages
|
1135
|
+
|
1136
|
+
return 0
|
1137
|
+
end
|
1138
|
+
|
1070
1139
|
end
|
1071
1140
|
end
|
1072
1141
|
end
|
data/templates/zine-single.json
CHANGED
@@ -189,6 +189,7 @@
|
|
189
189
|
|
190
190
|
"default_font_size" : 12,
|
191
191
|
"columns" : 1,
|
192
|
+
"alternate_output" : false,
|
192
193
|
|
193
194
|
"front_cover" : false,
|
194
195
|
"front_extra_page" : true,
|
@@ -723,8 +724,26 @@
|
|
723
724
|
}
|
724
725
|
],
|
725
726
|
|
727
|
+
"alternate_output" : [
|
728
|
+
{
|
729
|
+
"cmd" : "alternate_pages"
|
730
|
+
}
|
731
|
+
],
|
732
|
+
|
733
|
+
"set_alternate_output" : [
|
734
|
+
{
|
735
|
+
"cmd" : "set_alternate_pages"
|
736
|
+
}
|
737
|
+
],
|
726
738
|
|
727
739
|
"main": [
|
740
|
+
{
|
741
|
+
"cmd" : "if",
|
742
|
+
"args" : {
|
743
|
+
"exp" : "${alternate_output}",
|
744
|
+
"func" : "set_alternate_output"
|
745
|
+
}
|
746
|
+
},
|
728
747
|
{
|
729
748
|
"cmd": "set",
|
730
749
|
"args": {
|
@@ -768,6 +787,13 @@
|
|
768
787
|
"args": {
|
769
788
|
"func": "paginator"
|
770
789
|
}
|
790
|
+
},
|
791
|
+
{
|
792
|
+
"cmd" : "if",
|
793
|
+
"args" : {
|
794
|
+
"exp" : "${alternate_output}",
|
795
|
+
"func" : "alternate_output"
|
796
|
+
}
|
771
797
|
}
|
772
798
|
]
|
773
799
|
}
|