petit-felix 0.1.5 → 0.1.7

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.
@@ -0,0 +1,90 @@
1
+ ## Error handling stuff for TemplatePDFWriter
2
+
3
+ module PetitFelix
4
+ module Worker
5
+
6
+ class TemplatePDFWriter < PetitFelix::Worker::DefaultPDFWriter
7
+
8
+ # error count: 16
9
+
10
+ ERROR_CODES = [
11
+ "OK",
12
+ "Malformed command list.",
13
+ "No command defined. Use \"com\" or \"command\" to define commands.",
14
+ "Command not found.",
15
+ "Stack overflow.",
16
+ "Template ID \"{{arg}}\" not found.",
17
+ "Template method \"{{arg}}\" not found.",
18
+ "\"{{arg}}\" argument not defined.",
19
+ "Expression \"{{arg}}\" does not result in boolean result.",
20
+ "Expression \"{{arg}}\" cannot be evaluated.",
21
+ "File \"{{arg}}\" not found.",
22
+ "Not a valid position.",
23
+ "\"at\" (Array) argument not defined.",
24
+ "\"{{arg}}\" is not an array.",
25
+ "Image \"{{arg}}\" not found.",
26
+ "Template file \"{{arg}}\" not found.",
27
+ "\"template\" option not defined. No template file can be loaded."
28
+ ]
29
+
30
+ ## Error display
31
+
32
+ def error_replace_string error
33
+
34
+ @error_param.keys.each do |key|
35
+
36
+ error = error.gsub "{{#{key}}}", @error_param[key]
37
+
38
+ end
39
+
40
+ error
41
+ end
42
+
43
+ def print_error error_code, line
44
+
45
+ if error_code > -1 && error_code < ERROR_CODES.count
46
+
47
+ @error_printer.print_err "Error reading template. #{error_replace_string( ERROR_CODES[error_code])}"
48
+
49
+ else
50
+
51
+ @error_printer.print_err "Error reading template. General template processing error occured."
52
+
53
+ end
54
+
55
+ print "Error code: #{error_code}"
56
+
57
+ print "\n\n"
58
+ print "Processing markdown file: #{@metaoptions["filename"]}"
59
+ print "\n\n"
60
+
61
+ stack_rv = @command_stack.reverse
62
+
63
+ if line >= 0 && !stack_rv.empty?
64
+
65
+ print "\n\nCurrent line:\n"
66
+ print stack_rv[0][line]
67
+
68
+ print "\n\nCurrent Stack:"
69
+ test_arr = *(0..[19,@command_stack.count-1].min)
70
+ test_arr.each do | i |
71
+
72
+ command_obj = stack_rv[i]
73
+
74
+ line_edit = command_obj[0..@counter_stack[i]+1]
75
+
76
+ print "\n"
77
+ print "Line: #{line_edit.count}: "
78
+ print line_edit[-1]
79
+
80
+ end
81
+ end
82
+
83
+ print "\n"
84
+
85
+ return error_code
86
+ end
87
+
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,64 @@
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
+ args_has_file :normal, font
12
+ args_has_file :bold, font
13
+ args_has_file :italic, font
14
+ args_has_file :bold_italic, font
15
+
16
+ if font.key?(:normal)
17
+
18
+ if font.key?(:italic)
19
+
20
+ font[:italic] = font[:normal]
21
+
22
+ end
23
+
24
+ if font.key?(:bold)
25
+
26
+ font[:bold] = font[:normal]
27
+
28
+ end
29
+
30
+ if font.key?(:bold_italic)
31
+
32
+ font[:bold_italic] = font[:normal]
33
+
34
+ end
35
+
36
+ font.keys.each do |key|
37
+
38
+ font[key] = replace_variable font[key]
39
+
40
+ end
41
+
42
+ font_families.update(font_name => font)
43
+
44
+ end
45
+
46
+ end
47
+
48
+ def add_fonts
49
+
50
+ font_families.clear
51
+
52
+ fonts = Marshal.load(Marshal.dump(@fonts))
53
+
54
+ fonts.keys.each do |font|
55
+
56
+ add_font fonts[font], font.to_s
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -225,7 +225,7 @@ module PetitFelix
225
225
 
226
226
  def com_image args, obj
227
227
 
228
- validate = args_has_string :file, args
228
+ validate = args_has_file :file, args
229
229
 
230
230
  if validate != 0
231
231
  return validate
@@ -857,9 +857,9 @@ module PetitFelix
857
857
  end
858
858
 
859
859
  result = false
860
-
860
+
861
861
  if ["true","false"].include? args[:exp].strip
862
- if args[:exp] == true
862
+ if args[:exp] == "true"
863
863
  result = true
864
864
  else
865
865
  result = false
@@ -925,7 +925,7 @@ module PetitFelix
925
925
  # clears the current markdown file
926
926
  com_clear_markdown args, obj
927
927
 
928
- validate = args_has_string :file, args
928
+ validate = args_has_file :file, args
929
929
 
930
930
  if validate != 0
931
931
  return validate
@@ -0,0 +1,231 @@
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_file arg_name, args
39
+
40
+ if !args.key? arg_name
41
+ # text not defined
42
+ @error_param["arg"] = arg_name.to_s
43
+ return 7
44
+ end
45
+
46
+ file = replace_variable args[arg_name].to_s
47
+
48
+
49
+
50
+ args[arg_name] = file
51
+
52
+ return 0
53
+
54
+ end
55
+
56
+ def args_has_int arg_name, args
57
+
58
+ if !args.key? arg_name
59
+
60
+ # text not defined
61
+ @error_param["arg"] = arg_name.to_s
62
+ return 7
63
+
64
+ end
65
+
66
+ if args[arg_name].instance_of? String
67
+
68
+ begin
69
+
70
+ args[arg_name] = Eqn::Calculator.calc(replace_variable args[arg_name]).to_i
71
+ rescue
72
+
73
+ @error_param["arg"] = replace_variable args[arg_name]
74
+ return 9
75
+ end
76
+ end
77
+
78
+ return 0
79
+ end
80
+
81
+ def args_has_float arg_name, args
82
+
83
+ if !args.key? arg_name
84
+ # text not defined
85
+ @error_param["arg"] = arg_name.to_s
86
+ return 7
87
+
88
+ end
89
+
90
+ begin
91
+
92
+ args[arg_name] = Eqn::Calculator.calc(replace_variable args[arg_name]).to_f
93
+
94
+ rescue
95
+
96
+ @error_param["arg"] = replace_variable args[arg_name]
97
+ return 9
98
+
99
+ end
100
+
101
+ return 0
102
+
103
+ end
104
+
105
+ def args_has_arr arg_name, args, type, options = {}
106
+
107
+ if !args.key? arg_name
108
+ # text not defined
109
+ @error_param["arg"] = arg_name.to_s
110
+ return 7
111
+
112
+ end
113
+
114
+ if args[arg_name].instance_of? String
115
+
116
+ begin
117
+
118
+ set_variables
119
+
120
+ test = replace_variable args[arg_name]
121
+
122
+ args[arg_name] = JSON.parse(test)
123
+
124
+ rescue => error
125
+
126
+ print "\nError parsing array: #{args[arg_name]}\n"
127
+ print error
128
+
129
+ end
130
+
131
+ end
132
+
133
+ if args[arg_name].instance_of? Array
134
+
135
+ if type == :float
136
+
137
+ args[arg_name].map! {|item| Eqn::Calculator.calc(replace_variable item.to_s).to_f }
138
+ elsif type == :int
139
+
140
+ args[arg_name].map! {|item| Eqn::Calculator.calc(replace_variable item.to_s).to_i }
141
+ elsif type == :hash
142
+
143
+ args[arg_name].map! {|item| args_correct_hash item, options[:second_type] }
144
+ else
145
+
146
+ args[arg_name].map! {|item| replace_variable item.to_s }
147
+ end
148
+
149
+ end
150
+
151
+ return 0
152
+
153
+ end
154
+
155
+ def args_correct_hash hash, type
156
+
157
+ hash.transform_keys!(&:to_sym)
158
+
159
+ hash.keys.each do |key|
160
+
161
+ if type == :int
162
+
163
+ begin
164
+
165
+ hash[key] = Eqn::Calculator.calc(replace_variable hash[key].to_s).to_i
166
+
167
+ rescue
168
+
169
+ @error_param["arg"] = replace_variable hash[key]
170
+ return 9
171
+
172
+ end
173
+
174
+ elsif type == :float
175
+
176
+ begin
177
+
178
+ hash[key] = Eqn::Calculator.calc(replace_variable hash[key].to_s).to_f
179
+ rescue
180
+
181
+ @error_param["arg"] = replace_variable hash[key]
182
+ return 9
183
+
184
+ end
185
+
186
+ else
187
+
188
+ hash[key] = replace_variable hash[key].to_s
189
+ end
190
+
191
+ end
192
+
193
+ hash
194
+
195
+ end
196
+
197
+ def args_correct_values args
198
+
199
+ args_has_int :width, args
200
+ args_has_int :height, args
201
+
202
+ SYMBOLIZE.each do |symbol|
203
+
204
+ if args.key? symbol
205
+
206
+ args[symbol] = args[symbol].to_sym
207
+
208
+ end
209
+ end
210
+
211
+ if args.key? :position
212
+
213
+ if ["left","center","right"].include? args[:position]
214
+
215
+ args[:position] = args[:position].to_sym
216
+
217
+ else
218
+
219
+ args[:position] = args[:position].to_i
220
+
221
+ end
222
+
223
+ end
224
+
225
+ args
226
+
227
+ end
228
+
229
+ end
230
+ end
231
+ 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.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - PunishedFelix
@@ -67,6 +67,7 @@ extra_rdoc_files: []
67
67
  files:
68
68
  - lib/felix/config.rb
69
69
  - lib/felix/error.rb
70
+ - lib/felix/file.rb
70
71
  - lib/felix/generator.rb
71
72
  - lib/felix/metadata.rb
72
73
  - lib/felix/task_manager.rb
@@ -80,8 +81,11 @@ files:
80
81
  - lib/worker/pdf_writer.rb
81
82
  - lib/worker/pdf_writer/bounding_box.rb
82
83
  - lib/worker/pdf_writer/column_box.rb
83
- - lib/worker/template_pdf_calls.rb
84
84
  - lib/worker/template_pdf_writer.rb
85
+ - lib/worker/templater/error.rb
86
+ - lib/worker/templater/font.rb
87
+ - lib/worker/templater/methods.rb
88
+ - lib/worker/templater/validation.rb
85
89
  - templates/zine-single.json
86
90
  homepage: https://github.com/badgernested/petit-felix
87
91
  licenses: