petit-felix 0.1.9 → 0.1.10
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/task/template_pdf_task.rb +1 -1
- data/lib/version.rb +1 -1
- data/lib/worker/pdf_writer.rb +111 -0
- data/lib/worker/template_pdf_writer.rb +1 -1
- data/lib/worker/templater/methods.rb +51 -0
- data/templates/zine-single.json +13 -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: 2709ae62f534f69b2f394dfb49ca307fd6602ffcbdae735803abf565dc0da54c
|
4
|
+
data.tar.gz: c1beb16e7c071dba1f13dc43c7e19912fa09715bc28b05423af6c2ede3740a2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0f453504b5a168de33733685603a6a29fe19c4226cbd023f9446fef141e927afde08392677c07610c600abed939c16fb1154161f955ef9ce297a28f49b65223
|
7
|
+
data.tar.gz: 20dc63d0e0d917ecccb81adfe85ad8d181a06522c1dea4ac8865437a599c77d1ca11e00af13af9439a4a61fcfbcaed0334d48120190dae584db7d60cd8d21457
|
data/lib/version.rb
CHANGED
data/lib/worker/pdf_writer.rb
CHANGED
@@ -99,6 +99,117 @@ module PetitFelix
|
|
99
99
|
render_file(file)
|
100
100
|
|
101
101
|
end
|
102
|
+
|
103
|
+
# Copies the contents of a page.
|
104
|
+
def copy_page index=@page_number-1
|
105
|
+
|
106
|
+
return false if index.abs > (state.pages.count - 1)
|
107
|
+
|
108
|
+
# deep copies the page data
|
109
|
+
@page_data = copy_page_data index
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
# Returns the page data copied
|
114
|
+
def copy_page_data index
|
115
|
+
return false if index.abs > (state.pages.count - 1)
|
116
|
+
|
117
|
+
# deep copies the page data
|
118
|
+
return Marshal.load(Marshal.dump(state.store.pages.data[:Kids][index]))
|
119
|
+
end
|
120
|
+
|
121
|
+
# Pastes (overwrites) the content of a page.
|
122
|
+
def paste_page index=@page_number-1
|
123
|
+
|
124
|
+
return false if index.abs > (state.pages.count - 1)
|
125
|
+
|
126
|
+
if !@page_data.nil?
|
127
|
+
|
128
|
+
state.store.pages.data[:Kids][index] = @page_data
|
129
|
+
|
130
|
+
# deep copies the page data so its not referencing the same object constantly
|
131
|
+
@page_data = Marshal.load(Marshal.dump(@page_data))
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
# Clears copied page data.
|
138
|
+
def clear_copied_page
|
139
|
+
|
140
|
+
@page_data = nil
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
# Reorganizes the pages in the given order.
|
145
|
+
|
146
|
+
def reorder_pages pages
|
147
|
+
|
148
|
+
if pages.count != state.pages.count
|
149
|
+
|
150
|
+
return false
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
initial_content = []
|
155
|
+
|
156
|
+
state.store.pages.data[:Kids].each_with_index {
|
157
|
+
|item,index|
|
158
|
+
initial_content.append(state.store.pages.data[:Kids][index])
|
159
|
+
}
|
160
|
+
|
161
|
+
index = 0
|
162
|
+
|
163
|
+
while index < initial_content.count
|
164
|
+
|
165
|
+
return false if pages[index].abs > (state.pages.count - 1)
|
166
|
+
|
167
|
+
state.store.pages.data[:Kids][index] = initial_content[pages[index]]
|
168
|
+
index +=1
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
# Orders the pages properly so they can be printed 2 on a page for stapling
|
175
|
+
def reorder_pages_for_2_page
|
176
|
+
|
177
|
+
pages = []
|
178
|
+
pairs = []
|
179
|
+
|
180
|
+
# first test if page count is odd.
|
181
|
+
# if its odd add an extra page before the back cover
|
182
|
+
|
183
|
+
if state.pages.count % 2 == 1
|
184
|
+
go_to_page(-2)
|
185
|
+
start_new_page
|
186
|
+
|
187
|
+
go_to_page(state.pages.count)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Now that its even do the algorithm
|
191
|
+
center = (state.pages.count / 2) - 1
|
192
|
+
center_other = center + 1
|
193
|
+
|
194
|
+
while center >= 0
|
195
|
+
|
196
|
+
pairs.unshift [center, center_other]
|
197
|
+
|
198
|
+
center -= 1
|
199
|
+
center_other += 1
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
pairs.each do |item|
|
204
|
+
|
205
|
+
pages.append item[0]
|
206
|
+
pages.append item[1]
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
reorder_pages pages
|
211
|
+
|
212
|
+
end
|
102
213
|
|
103
214
|
end
|
104
215
|
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,20 @@ 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 },
|
56
64
|
}
|
57
65
|
|
66
|
+
## Debug test command
|
67
|
+
|
68
|
+
def com_test args, obj
|
69
|
+
#obj.reorder_pages [3,2,0,1]
|
70
|
+
obj.reorder_pages_for_2_page
|
71
|
+
|
72
|
+
return 0
|
73
|
+
end
|
74
|
+
|
58
75
|
# Prawn commands
|
59
76
|
|
60
77
|
def com_bounding_box args, obj
|
@@ -141,6 +158,33 @@ module PetitFelix
|
|
141
158
|
return 0
|
142
159
|
end
|
143
160
|
|
161
|
+
def com_copy_page args, obj
|
162
|
+
args_has_int :val, args
|
163
|
+
|
164
|
+
if args.key?(:val)
|
165
|
+
obj.copy_page args[:val]
|
166
|
+
else
|
167
|
+
obj.copy_page
|
168
|
+
end
|
169
|
+
|
170
|
+
return 0
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
def com_paste_page args, obj
|
175
|
+
|
176
|
+
args_has_int :val, args
|
177
|
+
|
178
|
+
if args.key?(:val)
|
179
|
+
obj.paste_page args[:val]
|
180
|
+
else
|
181
|
+
obj.paste_page
|
182
|
+
end
|
183
|
+
|
184
|
+
return 0
|
185
|
+
|
186
|
+
end
|
187
|
+
|
144
188
|
def com_delete_page args, obj
|
145
189
|
validate = args_has_int :val, args
|
146
190
|
|
@@ -1067,6 +1111,13 @@ module PetitFelix
|
|
1067
1111
|
return 0
|
1068
1112
|
end
|
1069
1113
|
|
1114
|
+
def com_alternate_pages args, obj
|
1115
|
+
#obj.reorder_pages [3,2,0,1]
|
1116
|
+
obj.reorder_pages_for_2_page
|
1117
|
+
|
1118
|
+
return 0
|
1119
|
+
end
|
1120
|
+
|
1070
1121
|
end
|
1071
1122
|
end
|
1072
1123
|
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,6 +724,11 @@
|
|
723
724
|
}
|
724
725
|
],
|
725
726
|
|
727
|
+
"alternate_output" : [
|
728
|
+
{
|
729
|
+
"cmd" : "alternate_pages"
|
730
|
+
}
|
731
|
+
],
|
726
732
|
|
727
733
|
"main": [
|
728
734
|
{
|
@@ -768,6 +774,13 @@
|
|
768
774
|
"args": {
|
769
775
|
"func": "paginator"
|
770
776
|
}
|
777
|
+
},
|
778
|
+
{
|
779
|
+
"cmd" : "if",
|
780
|
+
"args" : {
|
781
|
+
"exp" : "${alternate_output}",
|
782
|
+
"func" : "alternate_output"
|
783
|
+
}
|
771
784
|
}
|
772
785
|
]
|
773
786
|
}
|