prawndown-ext 0.1.10 → 0.1.12

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: 01be81f1ee2b7abfc146e5965bd1c70cf70c4194070ca69c6be11c51bb492a84
4
- data.tar.gz: 63a75b0bdffb9d985b45895201e6b4edd9e3f76d2da934be413153331409858d
3
+ metadata.gz: 6abd3d5ad775ed05ac8dfbe1fc68283104e63bd64aeadb6254bf31759db1b959
4
+ data.tar.gz: 555e53c35fbd8380eaaa434d024f0d084efdd222e1a7f1376f50bffbe162abc9
5
5
  SHA512:
6
- metadata.gz: 356e6b501c171868581103a98614f4ac5ffc1975712833d06ad818c67155e093b9468bc1c8f8810d261b70a3c1dc2191a0d65554c15887cef99f08bd2a25e206
7
- data.tar.gz: 9bc56bc6ce9444aa13e63b0c4d4471d2f66ffbbc22a1d82c3d475c7c3d6dc38fd02df746ac3d789d64e72b3450ee01769f9c9c8f13f6528ba300c312212890a8
6
+ metadata.gz: c7e6004fe66a36371094bd33532664f17250ad7a877f09fa4b1ed1ec12b810987e79738d1179e50db014c010637d07deb1aba0edcce11ef32cf72887993c6a04
7
+ data.tar.gz: bf13a1d81efc3d6239d93b37bf002558cbe7fd5d24571dc3b1691fbf2ed23eb69e1511283131adee052ce6507231f98e59d569738d2f35612c02081d80ff3277
@@ -98,7 +98,7 @@ module PrawndownExt
98
98
 
99
99
  def replace_options text
100
100
  # remove nil options if it doesnt exist
101
-
101
+
102
102
  DELETE_NAMES.each do |option|
103
103
  if @options.key?(option)
104
104
  if @options[option].nil?
@@ -106,6 +106,7 @@ module PrawndownExt
106
106
  @options.delete(option)
107
107
  end
108
108
  end
109
+
109
110
  end
110
111
 
111
112
  # remove quote spacing if it doesnt exist
@@ -115,9 +116,7 @@ module PrawndownExt
115
116
  end
116
117
 
117
118
  DEFAULT_OPTIONS.keys.each do |replacer|
118
- if @options.key?(replacer)
119
- text = text.gsub(replacer.upcase, @options[replacer].to_s)
120
- end
119
+ text = text.gsub(replacer.upcase, @options[replacer].to_s)
121
120
  end
122
121
 
123
122
  text
@@ -2,6 +2,6 @@
2
2
 
3
3
  module PrawndownExt
4
4
  module Ext
5
- VERSION = "0.1.10"
5
+ VERSION = "0.1.12"
6
6
  end
7
7
  end
data/lib/prawndown-ext.rb CHANGED
@@ -37,7 +37,9 @@ module PrawndownExt
37
37
  args["margin"] = 0
38
38
  end
39
39
 
40
- pdf.pad args["margin"] do
40
+ half_margin = (args["margin"] * 0.5).floor
41
+
42
+ pdf.pad half_margin do
41
43
  pdf.indent args["margin"], args["margin"] do
42
44
  pdf.text args["text"], inline_format: true, leading: options[args["command"] + "_line_spacing"].to_f
43
45
  end
@@ -52,6 +54,25 @@ module PrawndownExt
52
54
  end
53
55
  end
54
56
 
57
+ width = nil
58
+ height = nil
59
+
60
+ if options.key?("image_width")
61
+ width = options["image_width"].to_i
62
+ end
63
+
64
+ if options.key?("image_height")
65
+ height = options["image_height"].to_i
66
+ end
67
+
68
+ if width.nil? && height.nil?
69
+ width = pdf.bounds.width
70
+ end
71
+
72
+ if !width.nil?
73
+ width = [pdf.bounds.width, width].min
74
+ end
75
+
55
76
  if args["path"][0] == "/"
56
77
  args["path"] = args["path"][1..-1]
57
78
  end
@@ -63,14 +84,32 @@ module PrawndownExt
63
84
  end
64
85
 
65
86
  if File.extname(file) != ".gif"
66
- pdf.image(file,
67
- width: pdf.bounds.width,
68
- position: :center)
87
+ if !(height.nil? && width.nil?)
88
+
89
+ if height.nil? && !width.nil?
90
+ pdf.image(file,
91
+ width: [pdf.bounds.width, width].min,
92
+ position: :center)
93
+ elsif !height.nil? && width.nil?
94
+ pdf.image(file,
95
+ height: height,
96
+ position: :center)
97
+ else
98
+ pdf.image(file,
99
+ width: [pdf.bounds.width, width].min,
100
+ height: height,
101
+ position: :center)
102
+ end
103
+ end
69
104
  end
70
105
  end
71
106
 
72
107
  def self.cl_newline args, pdf, options
73
- pdf.start_new_page()
108
+ if pdf.bounds.instance_of? Prawn::Document::ColumnBox
109
+ pdf.bounds.move_past_bottom
110
+ else
111
+ pdf.start_new_page
112
+ end
74
113
  end
75
114
 
76
115
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawndown-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - PunishedFelix