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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dd1314254a58bf139622785e904f6461480b148d809e2eb0e777c319dbf391f
4
- data.tar.gz: d70547db0dabee7c9af618cd8c7f79bf5086ad3a074e3b2a5d0ffa3194296abf
3
+ metadata.gz: 8520f2febc5661d5cc6c5be58d294a6a92e03996be301164da8be5c8a2cbfa32
4
+ data.tar.gz: ee3505a8ed5f1dc356c8b052e95b4eea6332e4e313fe20872cf5a092d35a6211
5
5
  SHA512:
6
- metadata.gz: 49ee539a073acc0668a1c414190e36a05b3e9c8d628c01b78c2c437e1866e2e83c36c36a1f13aeb56fad3877388f98bdc287fcdeee6d3f469abbba1b60b9e121
7
- data.tar.gz: a3f8e8dda4dd750ffe7d1849ae4d181ae76799c161cc14bb82c3e1f46ead121a59c078b7b3a172ae40e4dc03f3b75bc2d51824fe4818a8f066d08d12c9a80815
6
+ metadata.gz: 403e8b620ea5a35712ccd6ef83cc37e8ceadc05ae1ae1dde46771e016834579f3936f2dd0884716079a251cecda4a8b1e2c394dc3d5951dd339ac78b212da9e4
7
+ data.tar.gz: 8d69e16b180af01aeee3d81b60fbf3343d655b0933c9970cb2574f2a02d622aa3d7d7975267bae1f8e2c384fbad332603f0ed58d27fce7f619dc70d491a6ae06
data/lib/felix/config.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  ## Helper class that handles configs
2
2
  require "felix/metadata"
3
3
 
4
+ ## Processes loaded options. Doesn't actually store them, though.
5
+
4
6
  module PetitFelix
5
7
 
6
8
  class Config
@@ -41,7 +43,7 @@ module PetitFelix
41
43
 
42
44
  ### Command Line Arguments
43
45
 
44
- def self.cl_add_config(command,args, index, cl_args)
46
+ def self.cl_add_config command,args, index, cl_args
45
47
  cl_args[command] = args[index + 1]
46
48
  end
47
49
 
@@ -53,7 +55,7 @@ module PetitFelix
53
55
  ## then command line arguments,
54
56
  ## then finally any arguments defined in the metadata.
55
57
 
56
- def load_config(wm, passed_args, args)
58
+ def load_config wm, passed_args, args
57
59
 
58
60
  @processed_arguments = []
59
61
 
@@ -67,34 +69,38 @@ module PetitFelix
67
69
 
68
70
  default_config = {}
69
71
 
70
- if File.file?("./default.cfg")
72
+ if File.file? "./default.cfg"
71
73
 
72
- default_config = metadata.get_metadata(File.read("./default.cfg"))
74
+ default_config = metadata.get_metadata(File.read "./default.cfg")
73
75
  end
74
76
 
75
77
  # Loads command line arguments
76
- cl_args = load_cl_args(args)
78
+ cl_args = load_cl_args args
77
79
 
78
80
  # Loads default worker options
79
81
  worker = ""
80
82
  worker_options = nil
81
83
 
82
- if default_options.key?("task")
84
+ # Gets the task to run.
85
+
86
+ if default_options.key? "task"
83
87
  worker = default_options["task"]
84
88
  end
85
89
 
86
- if default_config.key?("task")
90
+ if default_config.key? "task"
87
91
  worker = default_config["task"]
88
92
  end
89
93
 
90
- if cl_args.key?("task")
94
+ if cl_args.key? "task"
91
95
  worker = cl_args["task"]
92
96
  end
93
97
 
94
- if passed_args.key?("task")
98
+ if passed_args.key? "task"
95
99
  worker = passed_args["task"]
96
100
  end
97
101
 
102
+ # Loads the worker based on the task.
103
+
98
104
  if worker != ""
99
105
  worker_options = Marshal.load(Marshal.dump(wm.get_task_options worker))
100
106
  end
@@ -129,7 +135,7 @@ module PetitFelix
129
135
  end
130
136
 
131
137
  # Loads command line arguments
132
- def load_cl_args(args)
138
+ def load_cl_args args
133
139
  cl_args = {}
134
140
 
135
141
  index = 0
@@ -138,14 +144,14 @@ module PetitFelix
138
144
 
139
145
  command = com.downcase
140
146
 
141
- if command.start_with?("--")
147
+ if command.start_with? "--"
142
148
  command = command[2..]
143
149
 
144
- if !@processed_arguments.include?(command)
150
+ if !@processed_arguments.include? command
145
151
 
146
- if CL_DATA.key?(command)
152
+ if CL_DATA.key? command
147
153
 
148
- CL_DATA[command].call(command, args, index, cl_args)
154
+ CL_DATA[command].call command, args, index, cl_args
149
155
 
150
156
  end
151
157
 
data/lib/felix/error.rb CHANGED
@@ -1,8 +1,10 @@
1
+ ## Prints an error message.
2
+
1
3
  module PetitFelix
2
4
  class Error
3
5
 
4
- def print_err(error)
5
- print "\n\nError: " + error + "\n"
6
+ def print_err error
7
+ print "\n\nError: #{error}\n"
6
8
  end
7
9
 
8
10
  end
@@ -6,26 +6,34 @@ module PetitFelix
6
6
 
7
7
  ## Gets image from path and location
8
8
  def get_image_location img_dir, filename
9
- file = img_dir + "/" + filename
9
+
10
+ file = "#{img_dir}/#{filename}"
10
11
 
11
12
  if !File.file?(file)
12
- file = "." + img_dir + "/" + filename
13
+
14
+ file = ".#{img_dir}/#{filename}"
15
+
13
16
  end
14
17
 
15
18
  file
19
+
16
20
  end
17
21
 
18
22
  ## Gets metadata from string into paired hashes
19
23
  def get_metadata(input)
24
+
20
25
  array = input.lines
21
26
 
22
27
  metadata = {}
23
28
 
24
29
  array.each do |set|
30
+
25
31
  if set.count(":") >= 1
32
+
26
33
  data = set.split(":", 2)
27
34
  index = data[0].strip.downcase
28
35
  metadata[index] = data[1].strip.gsub("\\\"", "\"")
36
+
29
37
  end
30
38
  end
31
39
 
@@ -34,22 +42,32 @@ module PetitFelix
34
42
 
35
43
  ## Splits files into array into metadata strings and content
36
44
  def split(input)
45
+
37
46
  input = input.split("---")
47
+
38
48
  if input.count > 1
49
+
39
50
  input = input.reject! { |s| s.nil? || s.empty? }
51
+
40
52
  end
53
+
41
54
  input
55
+
42
56
  end
43
57
 
44
58
  ## Transforms string into JSON parsed object
45
59
  def parse_property string, base="${x}"
60
+
46
61
  begin
62
+
47
63
  return JSON.parse(base.sub("${x}", string), symbolize_names: true)
64
+
48
65
  rescue
66
+
49
67
  return parse_property
68
+
50
69
  end
51
70
  end
52
71
 
53
-
54
72
  end
55
73
  end
@@ -47,7 +47,7 @@ module PetitFelix
47
47
  name = "[UNDEFINED]"
48
48
  end
49
49
 
50
- err_no_task_found name, additional_text: "Unable to find task " + name + ":\n"
50
+ err_no_task_found name, additional_text: "Unable to find task #{name}:\n"
51
51
  end
52
52
 
53
53
  return nil
@@ -63,7 +63,7 @@ module PetitFelix
63
63
  name = "[UNDEFINED]"
64
64
  end
65
65
 
66
- err_no_task_found name, additional_text: "Unable to get options for Task " + name + ":\n"
66
+ err_no_task_found name, additional_text: "Unable to get options for Task #{name}:\n"
67
67
  end
68
68
 
69
69
  return nil
@@ -71,10 +71,10 @@ module PetitFelix
71
71
 
72
72
  # No task found error
73
73
  def err_no_task_found task, additional_text: ""
74
- text = "Task " + task.downcase + " not found. Make sure the variable \"task\" is set correctly in your configuration settings. Available Tasks: "
74
+ text = "Task #{task.downcase} not found. Make sure the variable \"task\" is set correctly in your configuration settings. Available Tasks: "
75
75
 
76
76
  @task_list.keys.each do |key|
77
- text += "\n " + key
77
+ text += "\n #{key}"
78
78
  end
79
79
 
80
80
  @error_printer.print_err text
data/lib/petit-felix.rb CHANGED
@@ -3,6 +3,8 @@ require "felix/generator"
3
3
  require "felix/config"
4
4
  require "felix/task_manager"
5
5
 
6
+ # Main entry point of the program for batch outputting files
7
+
6
8
  module PetitFelix
7
9
 
8
10
  class Output
@@ -8,12 +8,16 @@ module PetitFelix
8
8
  class BasicPDFTask < PetitFelix::Task::DefaultTask
9
9
 
10
10
  def self.name
11
+
11
12
  "basic-pdf-classic"
13
+
12
14
  end
13
15
 
14
16
  ## Default options of the application
15
17
  def self.default_options
18
+
16
19
  return {
20
+ "date" => "",
17
21
  "columns" => 1,
18
22
  "default_font_size" => 12,
19
23
  "header1_size" => 32,
@@ -46,11 +50,12 @@ module PetitFelix
46
50
  "back_author" => "",
47
51
  "back_author_size" => 16,
48
52
  }
53
+
49
54
  end
50
55
 
51
- def render_zine
56
+ def render_zine options
52
57
 
53
- page = File.read(options["filename"])
58
+ page = File.read options["filename"]
54
59
 
55
60
  # splits the page into parts for metadata and content
56
61
 
@@ -67,25 +72,17 @@ module PetitFelix
67
72
 
68
73
  # Only continue if metadata has a title
69
74
 
70
- if @metadata.key?("title")
75
+ if @metadata.key? "title"
71
76
 
72
77
  # Parameters
73
78
 
74
79
  page_layout = :portrait
75
80
  print_scaling = :none
76
81
 
77
- if @metaoptions.key?("page_layout")
78
- page_layout = @metaoptions["page_layout"]
82
+ if @metaoptions.key? "page_layout"
83
+
84
+ page_layout = @metaoptions["page_layout"].to_sym
79
85
 
80
- if page_layout.is_a? String
81
- if page_layout.include?("portrait")
82
- page_layout = :portrait
83
- else
84
- if page_layout.include?("landscape")
85
- page_layout = :landscape
86
- end
87
- end
88
- end
89
86
  end
90
87
 
91
88
  # Generates PDF
@@ -128,36 +125,33 @@ module PetitFelix
128
125
  @metaoptions = {}
129
126
 
130
127
  options.keys.each do |key|
128
+
131
129
  @metaoptions[key] = options[key]
130
+
132
131
  end
133
132
 
134
133
  @metadata.keys.each do |key|
134
+
135
135
  @metaoptions[key] = @metadata[key]
136
+
136
137
  end
137
138
 
138
139
  # Loads proper values from strings for certain params
139
140
  page_layout = :portrait
140
141
  print_scaling = :none
141
142
 
142
- if @metaoptions.key?("page_layout")
143
- page_layout = @metaoptions["page_layout"]
144
-
145
- if page_layout.is_a? String
146
- if page_layout.include?("portrait")
147
- @metaoptions["page_layout"] = :portrait
148
- else
149
- if page_layout.include?("landscape")
150
- @metaoptions["page_layout"] = :landscape
151
- end
152
- end
153
- end
143
+ if @metaoptions.key? "page_layout"
144
+ page_layout = @metaoptions["page_layout"].to_sym
154
145
  end
155
146
 
156
147
  end
157
148
 
158
149
  def render_files options
159
- if options.key?("input_files")
150
+
151
+ if options.key? "input_files"
152
+
160
153
  site_list = options["input_files"].split(",")
154
+
161
155
  end
162
156
 
163
157
  site_list.each do |page|
@@ -167,18 +161,15 @@ module PetitFelix
167
161
  if !file_list.empty?
168
162
 
169
163
  file_list.each do |file|
164
+
170
165
  options["filename"] = file.strip
171
166
 
172
- if File.file?(options["filename"])
173
- render_zine
167
+ if File.file? options["filename"]
168
+ render_zine options
174
169
  end
175
170
 
176
171
  end
177
172
 
178
- else
179
- if File.file?(page)
180
- render_zine(page)
181
- end
182
173
  end
183
174
  end
184
175
 
@@ -6,42 +6,56 @@ module PetitFelix
6
6
 
7
7
  class DefaultTask
8
8
 
9
+ ## Name of the task as visible to the Cli and "task" variable
9
10
  def self.name
10
11
  ""
11
12
  end
12
13
 
13
14
  ## Default options of the application
14
15
  def self.default_options
16
+
15
17
  return {}
18
+
16
19
  end
17
20
 
21
+ # prepares the task's options from metadata
18
22
  def prepare_options options
19
23
 
20
24
  # stores options + metadata. metadata overrides options.
21
25
  @metaoptions = {}
22
26
 
23
27
  options.keys.each do |key|
28
+
24
29
  @metaoptions[key] = options[key]
30
+
25
31
  end
26
32
 
27
33
  # Loads proper values from strings for certain params
28
34
  page_layout = :portrait
29
35
  print_scaling = :none
30
36
 
31
- if @metaoptions.key?("page_layout")
37
+ if @metaoptions.key? "page_layout"
38
+
32
39
  page_layout = @metaoptions["page_layout"].to_sym
40
+
33
41
  end
34
42
 
35
43
  end
36
44
 
45
+ # renders the task
37
46
  def render_zine
47
+
38
48
  print "render_zine() not implemented\n"
49
+
39
50
  end
40
51
 
52
+ # gets the files from input files and renders them.
41
53
  def render_files options
42
54
 
43
- if options.key?("input_files")
55
+ if options.key? "input_files"
56
+
44
57
  site_list = options["input_files"].split(",")
58
+
45
59
  end
46
60
 
47
61
  site_list.each do |page|
@@ -51,19 +65,18 @@ module PetitFelix
51
65
  if !file_list.empty?
52
66
 
53
67
  file_list.each do |file|
68
+
54
69
  options["filename"] = file.strip
55
70
 
56
- if File.file?(options["filename"])
71
+ if File.file? options["filename"]
72
+
57
73
  prepare_options options
58
74
  render_zine
75
+
59
76
  end
60
77
 
61
78
  end
62
79
 
63
- else
64
- if File.file?(page)
65
- render_zine(page)
66
- end
67
80
  end
68
81
  end
69
82
 
@@ -7,21 +7,29 @@ module PetitFelix
7
7
 
8
8
  class SinglePDFTask < PetitFelix::Task::DefaultTask
9
9
 
10
+ # Task name
10
11
  def self.name
12
+
11
13
  "pdf-single"
14
+
12
15
  end
13
16
 
14
17
  ## Default options of the application
15
18
  def self.default_options
19
+
16
20
  return {
17
21
  "pdf" => "false"
18
22
  }
23
+
19
24
  end
20
25
 
26
+ # Renders zine
21
27
  def render_zine
22
28
 
23
29
  # Only continue if metadata has a title
24
30
  # Generates PDF
31
+
32
+ @metaoptions["pdf"] = false
25
33
 
26
34
  page = File.read(@metaoptions["filename"])
27
35
 
@@ -37,7 +45,7 @@ module PetitFelix
37
45
  # Always forces you to use this template
38
46
  @metaoptions["template"] = File.dirname(__FILE__) + "/../../templates/zine-single.json"
39
47
 
40
- if metadata.key?("pdf") && metadata["pdf"] == "true"
48
+ if metadata["pdf"] == "true"
41
49
 
42
50
  pdf = PetitFelix::Worker::TemplatePDFWriter.new(
43
51
  page_layout: @metaoptions["page_layout"],
@@ -58,12 +66,9 @@ module PetitFelix
58
66
  pdf.output
59
67
 
60
68
  end
61
-
62
69
  end
63
70
 
64
71
 
65
72
  end
66
-
67
73
  end
68
-
69
74
  end
@@ -8,15 +8,19 @@ module PetitFelix
8
8
  class TemplatePDFTask < PetitFelix::Task::DefaultTask
9
9
 
10
10
  def self.name
11
+
11
12
  "template-pdf"
13
+
12
14
  end
13
15
 
14
16
  ## Default options of the application
15
17
  def self.default_options
18
+
16
19
  return {
17
20
  "template" => "./templates/test.json",
18
21
  "output_file" => "./output/test.pdf"
19
22
  }
23
+
20
24
  end
21
25
 
22
26
  def render_zine
@@ -33,9 +37,6 @@ module PetitFelix
33
37
  pdf.init_values @metaoptions, pdf
34
38
 
35
39
  pdf.read_template
36
-
37
- # Adds extra fonts
38
- #pdf.initialize_font
39
40
 
40
41
  # Outputs to file
41
42
  pdf.output
data/lib/version.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Version handler, update this when you make a new version.
4
+
3
5
  module PetitFelix
4
6
  module Felix
5
- VERSION = "0.1.5"
7
+ VERSION = "0.1.6"
6
8
  end
7
9
  end
@@ -53,7 +53,7 @@ module PetitFelix
53
53
 
54
54
  def output
55
55
  FileUtils.mkdir_p @options["output_dir"]
56
- render_file(@options["output_dir"] + "/" + @options["title"].gsub(/[^\w\s]/, '').tr(" ", "_") + '.pdf')
56
+ render_file("#{@options["output_dir"]}/#{@options["title"].gsub(/[^\w\s]/, '').tr(" ", "_")}.pdf")
57
57
  end
58
58
 
59
59
  # Draws page numbering
@@ -67,7 +67,7 @@ module PetitFelix
67
67
 
68
68
  font_size(@options["paginator_size"].to_i)
69
69
 
70
- string = @options["title"] + ": " ' <page>'
70
+ string = "#{@options["title"]}: <page>"
71
71
 
72
72
  page_start_count = @options["paginator_start_count"].to_i
73
73
  page_start = @options["paginator_start"].to_i
@@ -263,7 +263,7 @@ module PetitFelix
263
263
  bounding_box([50, cursor],
264
264
  width: bounds.width - 100,
265
265
  height: 30) do
266
- text_box("Original Publication: " + @options["date"],#.strftime('%e %B, %Y'),
266
+ text_box("Original Publication: #{@options["date"]}",#.strftime('%e %B, %Y'),
267
267
  align: :center)
268
268
  #transparent(0.5) { stroke_bounds }
269
269
  end
@@ -325,7 +325,7 @@ module PetitFelix
325
325
  rescue
326
326
  if @options.key?("markdown_margin_array")
327
327
  print "\n"
328
- print "Note: unable to parse argument " + @options["markdown_margin_array"]
328
+ print "Note: unable to parse argument #{@options["markdown_margin_array"]}"
329
329
  end
330
330
  end
331
331