petit-felix 0.1.5 → 0.1.6
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 +20 -14
- data/lib/felix/error.rb +4 -2
- data/lib/felix/metadata.rb +21 -3
- data/lib/felix/task_manager.rb +4 -4
- data/lib/petit-felix.rb +2 -0
- data/lib/task/basic_pdf_classic_task.rb +24 -33
- data/lib/task/default_task.rb +20 -7
- data/lib/task/pdf_single_task.rb +9 -4
- data/lib/task/template_pdf_task.rb +4 -3
- data/lib/version.rb +3 -1
- data/lib/worker/basic_pdf_writer_classic.rb +4 -4
- data/lib/worker/pdf_writer.rb +30 -70
- data/lib/worker/template_pdf_writer.rb +59 -261
- data/lib/worker/templater/error.rb +90 -0
- data/lib/worker/templater/font.rb +59 -0
- data/lib/worker/{template_pdf_calls.rb → templater/methods.rb} +2 -2
- data/lib/worker/templater/validation.rb +213 -0
- metadata +5 -2
@@ -0,0 +1,59 @@
|
|
1
|
+
## font handling stuff for TemplatePDFWriter
|
2
|
+
|
3
|
+
module PetitFelix
|
4
|
+
module Worker
|
5
|
+
|
6
|
+
class TemplatePDFWriter < PetitFelix::Worker::DefaultPDFWriter
|
7
|
+
|
8
|
+
# Adds a font to the pdf document
|
9
|
+
def add_font font, font_name
|
10
|
+
|
11
|
+
if font.key?(:normal)
|
12
|
+
|
13
|
+
if font.key?(:italic)
|
14
|
+
|
15
|
+
font[:italic] = font[:normal]
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
if font.key?(:bold)
|
20
|
+
|
21
|
+
font[:bold] = font[:normal]
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
if font.key?(:bold_italic)
|
26
|
+
|
27
|
+
font[:bold_italic] = font[:normal]
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
font.keys.each do |key|
|
32
|
+
|
33
|
+
font[key] = replace_variable font[key]
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
font_families.update(font_name => font)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_fonts
|
44
|
+
|
45
|
+
font_families.clear
|
46
|
+
|
47
|
+
fonts = Marshal.load(Marshal.dump(@fonts))
|
48
|
+
|
49
|
+
fonts.keys.each do |font|
|
50
|
+
|
51
|
+
add_font fonts[font], font.to_s
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
## validation stuff for TemplatePDFWriter
|
2
|
+
|
3
|
+
module PetitFelix
|
4
|
+
module Worker
|
5
|
+
|
6
|
+
class TemplatePDFWriter < PetitFelix::Worker::DefaultPDFWriter
|
7
|
+
|
8
|
+
SYMBOLIZE = [
|
9
|
+
:align,
|
10
|
+
:odd_align,
|
11
|
+
:even_align,
|
12
|
+
:valign,
|
13
|
+
:odd_valign,
|
14
|
+
:even_valign,
|
15
|
+
:direction,
|
16
|
+
:mode,
|
17
|
+
:style,
|
18
|
+
:overflow,
|
19
|
+
:rotate_around
|
20
|
+
]
|
21
|
+
|
22
|
+
## variable validation methods
|
23
|
+
|
24
|
+
def args_has_string arg_name, args
|
25
|
+
|
26
|
+
if !args.key? arg_name
|
27
|
+
# text not defined
|
28
|
+
@error_param["arg"] = arg_name.to_s
|
29
|
+
return 7
|
30
|
+
end
|
31
|
+
|
32
|
+
args[arg_name] = replace_variable args[arg_name].to_s
|
33
|
+
|
34
|
+
return 0
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def args_has_int arg_name, args
|
39
|
+
|
40
|
+
if !args.key? arg_name
|
41
|
+
|
42
|
+
# text not defined
|
43
|
+
@error_param["arg"] = arg_name.to_s
|
44
|
+
return 7
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
if args[arg_name].instance_of? String
|
49
|
+
|
50
|
+
begin
|
51
|
+
|
52
|
+
args[arg_name] = Eqn::Calculator.calc(replace_variable args[arg_name]).to_i
|
53
|
+
rescue
|
54
|
+
|
55
|
+
@error_param["arg"] = replace_variable args[arg_name]
|
56
|
+
return 9
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
return 0
|
61
|
+
end
|
62
|
+
|
63
|
+
def args_has_float arg_name, args
|
64
|
+
|
65
|
+
if !args.key? arg_name
|
66
|
+
# text not defined
|
67
|
+
@error_param["arg"] = arg_name.to_s
|
68
|
+
return 7
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
begin
|
73
|
+
|
74
|
+
args[arg_name] = Eqn::Calculator.calc(replace_variable args[arg_name]).to_f
|
75
|
+
|
76
|
+
rescue
|
77
|
+
|
78
|
+
@error_param["arg"] = replace_variable args[arg_name]
|
79
|
+
return 9
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
return 0
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
def args_has_arr arg_name, args, type, options = {}
|
88
|
+
|
89
|
+
if !args.key? arg_name
|
90
|
+
# text not defined
|
91
|
+
@error_param["arg"] = arg_name.to_s
|
92
|
+
return 7
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
if args[arg_name].instance_of? String
|
97
|
+
|
98
|
+
begin
|
99
|
+
|
100
|
+
set_variables
|
101
|
+
|
102
|
+
test = replace_variable args[arg_name]
|
103
|
+
|
104
|
+
args[arg_name] = JSON.parse(test)
|
105
|
+
|
106
|
+
rescue => error
|
107
|
+
|
108
|
+
print "\nError parsing array: #{args[arg_name]}\n"
|
109
|
+
print error
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
if args[arg_name].instance_of? Array
|
116
|
+
|
117
|
+
if type == :float
|
118
|
+
|
119
|
+
args[arg_name].map! {|item| Eqn::Calculator.calc(replace_variable item.to_s).to_f }
|
120
|
+
elsif type == :int
|
121
|
+
|
122
|
+
args[arg_name].map! {|item| Eqn::Calculator.calc(replace_variable item.to_s).to_i }
|
123
|
+
elsif type == :hash
|
124
|
+
|
125
|
+
args[arg_name].map! {|item| args_correct_hash item, options[:second_type] }
|
126
|
+
else
|
127
|
+
|
128
|
+
args[arg_name].map! {|item| replace_variable item.to_s }
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
return 0
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
def args_correct_hash hash, type
|
138
|
+
|
139
|
+
hash.transform_keys!(&:to_sym)
|
140
|
+
|
141
|
+
hash.keys.each do |key|
|
142
|
+
|
143
|
+
if type == :int
|
144
|
+
|
145
|
+
begin
|
146
|
+
|
147
|
+
hash[key] = Eqn::Calculator.calc(replace_variable hash[key].to_s).to_i
|
148
|
+
|
149
|
+
rescue
|
150
|
+
|
151
|
+
@error_param["arg"] = replace_variable hash[key]
|
152
|
+
return 9
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
elsif type == :float
|
157
|
+
|
158
|
+
begin
|
159
|
+
|
160
|
+
hash[key] = Eqn::Calculator.calc(replace_variable hash[key].to_s).to_f
|
161
|
+
rescue
|
162
|
+
|
163
|
+
@error_param["arg"] = replace_variable hash[key]
|
164
|
+
return 9
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
else
|
169
|
+
|
170
|
+
hash[key] = replace_variable hash[key].to_s
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
hash
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
def args_correct_values args
|
180
|
+
|
181
|
+
args_has_int :width, args
|
182
|
+
args_has_int :height, args
|
183
|
+
|
184
|
+
SYMBOLIZE.each do |symbol|
|
185
|
+
|
186
|
+
if args.key? symbol
|
187
|
+
|
188
|
+
args[symbol] = args[symbol].to_sym
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
if args.key? :position
|
194
|
+
|
195
|
+
if ["left","center","right"].include? args[:position]
|
196
|
+
|
197
|
+
args[:position] = args[:position].to_sym
|
198
|
+
|
199
|
+
else
|
200
|
+
|
201
|
+
args[:position] = args[:position].to_i
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
args
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: petit-felix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PunishedFelix
|
@@ -80,8 +80,11 @@ files:
|
|
80
80
|
- lib/worker/pdf_writer.rb
|
81
81
|
- lib/worker/pdf_writer/bounding_box.rb
|
82
82
|
- lib/worker/pdf_writer/column_box.rb
|
83
|
-
- lib/worker/template_pdf_calls.rb
|
84
83
|
- lib/worker/template_pdf_writer.rb
|
84
|
+
- lib/worker/templater/error.rb
|
85
|
+
- lib/worker/templater/font.rb
|
86
|
+
- lib/worker/templater/methods.rb
|
87
|
+
- lib/worker/templater/validation.rb
|
85
88
|
- templates/zine-single.json
|
86
89
|
homepage: https://github.com/badgernested/petit-felix
|
87
90
|
licenses:
|