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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dd1314254a58bf139622785e904f6461480b148d809e2eb0e777c319dbf391f
4
- data.tar.gz: d70547db0dabee7c9af618cd8c7f79bf5086ad3a074e3b2a5d0ffa3194296abf
3
+ metadata.gz: 43e66d8321092975cf428beebfb0710634396b23b357d349cbb64ea00b86106a
4
+ data.tar.gz: 3b5c0abbd975e5c3acfe58410034dbbcbf835e0e8e8069fffe924a8376b56c6d
5
5
  SHA512:
6
- metadata.gz: 49ee539a073acc0668a1c414190e36a05b3e9c8d628c01b78c2c437e1866e2e83c36c36a1f13aeb56fad3877388f98bdc287fcdeee6d3f469abbba1b60b9e121
7
- data.tar.gz: a3f8e8dda4dd750ffe7d1849ae4d181ae76799c161cc14bb82c3e1f46ead121a59c078b7b3a172ae40e4dc03f3b75bc2d51824fe4818a8f066d08d12c9a80815
6
+ metadata.gz: 044dc388971b643baf04f35ebd6887b1b244e9837d1552b84381bf7418ca83e0c6286569937501906bc6c273be3145855cf2d028f5fad83b080bdab9718dd109
7
+ data.tar.gz: 386d6f9d6a400e06a0400195710b995f42fbc660d498a368af7fe08a8370b58508b0f7429d8cf800dec208a88e9ca3acbddc3100231571fe185f99d15bdb7fc6
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
@@ -11,9 +13,9 @@ module PetitFelix
11
13
 
12
14
  # Global defaults
13
15
  DEFAULT_OPTIONS = {
14
- "image_dir" => "./assets/images",
15
- "input_files" => "./md/*",
16
- "output_dir" => "./output",
16
+ "image_dir" => (File.join("assets","images")),
17
+ "input_files" => (File.join("md","*")),
18
+ "output_dir" => (File.join("output")),
17
19
  "task" => "pdf-single",
18
20
  }
19
21
 
@@ -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,40 @@ module PetitFelix
67
69
 
68
70
  default_config = {}
69
71
 
70
- if File.file?("./default.cfg")
72
+ default_file = File.join("default.cfg")
73
+
74
+ if File.file? default_file
71
75
 
72
- default_config = metadata.get_metadata(File.read("./default.cfg"))
76
+ default_config = metadata.get_metadata(File.read default_file)
73
77
  end
74
78
 
75
79
  # Loads command line arguments
76
- cl_args = load_cl_args(args)
80
+ cl_args = load_cl_args args
77
81
 
78
82
  # Loads default worker options
79
83
  worker = ""
80
84
  worker_options = nil
81
85
 
82
- if default_options.key?("task")
86
+ # Gets the task to run.
87
+
88
+ if default_options.key? "task"
83
89
  worker = default_options["task"]
84
90
  end
85
91
 
86
- if default_config.key?("task")
92
+ if default_config.key? "task"
87
93
  worker = default_config["task"]
88
94
  end
89
95
 
90
- if cl_args.key?("task")
96
+ if cl_args.key? "task"
91
97
  worker = cl_args["task"]
92
98
  end
93
99
 
94
- if passed_args.key?("task")
100
+ if passed_args.key? "task"
95
101
  worker = passed_args["task"]
96
102
  end
97
103
 
104
+ # Loads the worker based on the task.
105
+
98
106
  if worker != ""
99
107
  worker_options = Marshal.load(Marshal.dump(wm.get_task_options worker))
100
108
  end
@@ -129,7 +137,7 @@ module PetitFelix
129
137
  end
130
138
 
131
139
  # Loads command line arguments
132
- def load_cl_args(args)
140
+ def load_cl_args args
133
141
  cl_args = {}
134
142
 
135
143
  index = 0
@@ -138,14 +146,14 @@ module PetitFelix
138
146
 
139
147
  command = com.downcase
140
148
 
141
- if command.start_with?("--")
149
+ if command.start_with? "--"
142
150
  command = command[2..]
143
151
 
144
- if !@processed_arguments.include?(command)
152
+ if !@processed_arguments.include? command
145
153
 
146
- if CL_DATA.key?(command)
154
+ if CL_DATA.key? command
147
155
 
148
- CL_DATA[command].call(command, args, index, cl_args)
156
+ CL_DATA[command].call command, args, index, cl_args
149
157
 
150
158
  end
151
159
 
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
data/lib/felix/file.rb ADDED
@@ -0,0 +1,28 @@
1
+
2
+ module PetitFelix
3
+ class FileManager
4
+
5
+ def file_from_string string
6
+ file_split = file_array_from_string string
7
+
8
+ if file_split.count > 0
9
+ string = File.join(file_split)
10
+ end
11
+
12
+ return string
13
+ end
14
+
15
+ def file_array_from_string string
16
+ file_split = []
17
+
18
+ if string.include? "/"
19
+ file_split = string.split("/")
20
+ elsif string.include? "\\"
21
+ file_split = string.split("\\")
22
+ end
23
+
24
+ return file_split
25
+ end
26
+
27
+ end
28
+ end
@@ -6,26 +6,26 @@ 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
10
-
11
- if !File.file?(file)
12
- file = "." + img_dir + "/" + filename
13
- end
14
-
15
- file
9
+
10
+ return File.join(img_dir,filename)
11
+
16
12
  end
17
13
 
18
14
  ## Gets metadata from string into paired hashes
19
15
  def get_metadata(input)
16
+
20
17
  array = input.lines
21
18
 
22
19
  metadata = {}
23
20
 
24
21
  array.each do |set|
22
+
25
23
  if set.count(":") >= 1
24
+
26
25
  data = set.split(":", 2)
27
26
  index = data[0].strip.downcase
28
27
  metadata[index] = data[1].strip.gsub("\\\"", "\"")
28
+
29
29
  end
30
30
  end
31
31
 
@@ -34,22 +34,32 @@ module PetitFelix
34
34
 
35
35
  ## Splits files into array into metadata strings and content
36
36
  def split(input)
37
+
37
38
  input = input.split("---")
39
+
38
40
  if input.count > 1
41
+
39
42
  input = input.reject! { |s| s.nil? || s.empty? }
43
+
40
44
  end
45
+
41
46
  input
47
+
42
48
  end
43
49
 
44
50
  ## Transforms string into JSON parsed object
45
51
  def parse_property string, base="${x}"
52
+
46
53
  begin
54
+
47
55
  return JSON.parse(base.sub("${x}", string), symbolize_names: true)
56
+
48
57
  rescue
58
+
49
59
  return parse_property
60
+
50
61
  end
51
62
  end
52
63
 
53
-
54
64
  end
55
65
  end
@@ -14,9 +14,11 @@ module PetitFelix
14
14
  @error_printer = PetitFelix::Error.new
15
15
  @task_list = {}
16
16
 
17
- load_task "task/template_pdf_task.rb"
18
- load_task "task/pdf_single_task.rb"
19
- load_task "task/basic_pdf_classic_task.rb"
17
+ File.join("..","task","template_pdf_task.rb")
18
+
19
+ load_task File.join(File.dirname(__FILE__),"..","task","template_pdf_task.rb")
20
+ load_task File.join(File.dirname(__FILE__),"..","task","pdf_single_task.rb")
21
+ load_task File.join(File.dirname(__FILE__),"..","task","basic_pdf_classic_task.rb")
20
22
 
21
23
  task_list = PetitFelix::Task.constants.select {|c| PetitFelix::Task.const_get(c).is_a? Class}
22
24
 
@@ -47,7 +49,7 @@ module PetitFelix
47
49
  name = "[UNDEFINED]"
48
50
  end
49
51
 
50
- err_no_task_found name, additional_text: "Unable to find task " + name + ":\n"
52
+ err_no_task_found name, additional_text: "Unable to find task #{name}:\n"
51
53
  end
52
54
 
53
55
  return nil
@@ -63,7 +65,7 @@ module PetitFelix
63
65
  name = "[UNDEFINED]"
64
66
  end
65
67
 
66
- err_no_task_found name, additional_text: "Unable to get options for Task " + name + ":\n"
68
+ err_no_task_found name, additional_text: "Unable to get options for Task #{name}:\n"
67
69
  end
68
70
 
69
71
  return nil
@@ -71,10 +73,10 @@ module PetitFelix
71
73
 
72
74
  # No task found error
73
75
  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: "
76
+ text = "Task #{task.downcase} not found. Make sure the variable \"task\" is set correctly in your configuration settings. Available Tasks: "
75
77
 
76
78
  @task_list.keys.each do |key|
77
- text += "\n " + key
79
+ text += "\n #{key}"
78
80
  end
79
81
 
80
82
  @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
 
@@ -35,9 +43,9 @@ module PetitFelix
35
43
  metadata = @metaoptions.merge(metadata_helper.get_metadata(page_data[0]))
36
44
 
37
45
  # Always forces you to use this template
38
- @metaoptions["template"] = File.dirname(__FILE__) + "/../../templates/zine-single.json"
46
+ @metaoptions["template"] = File.join(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
- "template" => "./templates/test.json",
18
- "output_file" => "./output/test.pdf"
20
+ "template" => (File.join(File.dirname(__FILE__),"..","..","templates","test.json")),
21
+ "output_file" => (File.join("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.7"
6
8
  end
7
9
  end
@@ -2,6 +2,7 @@ require "prawn"
2
2
  require 'fileutils'
3
3
  require "prawndown-ext"
4
4
  require "felix/metadata"
5
+ require "felix/file"
5
6
  require "worker/pdf_writer"
6
7
 
7
8
  module PetitFelix
@@ -52,8 +53,15 @@ module PetitFelix
52
53
  end
53
54
 
54
55
  def output
55
- FileUtils.mkdir_p @options["output_dir"]
56
- render_file(@options["output_dir"] + "/" + @options["title"].gsub(/[^\w\s]/, '').tr(" ", "_") + '.pdf')
56
+ fileedit = PetitFelix::FileManager.new
57
+
58
+ file_output = fileedit.file_array_from_string(@options["output_dir"]) + [@options["output_file"]]
59
+
60
+ file = File.join(file_output)
61
+
62
+ FileUtils.mkdir_p File.dirname(file)
63
+
64
+ render_file(file)
57
65
  end
58
66
 
59
67
  # Draws page numbering
@@ -67,7 +75,7 @@ module PetitFelix
67
75
 
68
76
  font_size(@options["paginator_size"].to_i)
69
77
 
70
- string = @options["title"] + ": " ' <page>'
78
+ string = "#{@options["title"]}: <page>"
71
79
 
72
80
  page_start_count = @options["paginator_start_count"].to_i
73
81
  page_start = @options["paginator_start"].to_i
@@ -263,7 +271,7 @@ module PetitFelix
263
271
  bounding_box([50, cursor],
264
272
  width: bounds.width - 100,
265
273
  height: 30) do
266
- text_box("Original Publication: " + @options["date"],#.strftime('%e %B, %Y'),
274
+ text_box("Original Publication: #{@options["date"]}",#.strftime('%e %B, %Y'),
267
275
  align: :center)
268
276
  #transparent(0.5) { stroke_bounds }
269
277
  end
@@ -325,7 +333,7 @@ module PetitFelix
325
333
  rescue
326
334
  if @options.key?("markdown_margin_array")
327
335
  print "\n"
328
- print "Note: unable to parse argument " + @options["markdown_margin_array"]
336
+ print "Note: unable to parse argument #{@options["markdown_margin_array"]}"
329
337
  end
330
338
  end
331
339