docxify 0.1.1 → 0.1.2

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: bc2de5623d8d0605d4aa0ad437c657749e0b39c91c13dc3af0bea385e75dabc3
4
- data.tar.gz: 026160dfca1a977e7a8b7563e4268c363918f2130fe2e89dc0346037013d13ef
3
+ metadata.gz: '02588568aa1d05caf048a8a3b861ffc9b5ec2109817b6931006ce4c36c97adea'
4
+ data.tar.gz: 7f2647fdf663f8fb222c544592c4910ec54aedcdd26cf8fef30a610c7a163d6f
5
5
  SHA512:
6
- metadata.gz: 41d3b81b2ef6e3f90a1cc9a0149b19f93b96f86bb581d0c83a7f739d55cac24bae6337871a70c7278039f46ca50ecd164525d3b2f9631a7e329d1bd2e3a54989
7
- data.tar.gz: eca5c4a3eeb6855546fb7584605fc6579c8cfbe6a31014b1d0dd9896da9c6e15482c34b2638a98c6bca6d6ca887f0f12c076d71018af6f52bcc1421ba03e5ff1
6
+ metadata.gz: bf43c3a7194169d9cb01e0f96a44d3498dffbde8fa7f829dbf8fff1226ea9adffa4f648a06158cc7ad3450203858e2211cf2423f064a683129ef2e23c825353b
7
+ data.tar.gz: b4990b99e150a9f2e3aae3a45873799e91fc850c7180485caa4559ed2eca97d301672bd0181f3e5b703d3c44f32b4c3f6e64c32c36895b0c62a002659f76b83d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.2
4
+
5
+ Features:
6
+
7
+ - "Add 'after' to images and paragraphs to adjust spacing after those elements
8
+
3
9
  ## 0.1.1
4
10
 
5
11
  Features:
data/README.md CHANGED
@@ -23,7 +23,7 @@ gem install docxify
23
23
 
24
24
  @docx.default_styling font: "Serif font here", size: 14, color: "#040404"
25
25
 
26
- @docx.add_paragraph "Title", font: "Something", size: 18, color: "#00000"
26
+ @docx.add_paragraph "Title", font: "Something", size: 18, color: "#00000", after: 18
27
27
  @docx.add_paragraph "Body copy"
28
28
  @docx.add_paragraph "This is <b>bold</b>, <i>Italic</i> and <u>Underlined</u>."
29
29
  @docx.add_paragraph "Text can also contain <a href='foo'>Links</a>."
@@ -37,7 +37,7 @@ gem install docxify
37
37
 
38
38
  @docx.add_divider
39
39
 
40
- @docx.add_image "file_path or data", align: :right, height_cm: 2, width_cm: 4
40
+ @docx.add_image "file_path or data", align: :right, height_cm: 2, width_cm: 4, after: 18
41
41
 
42
42
  @docx.add_page_break
43
43
 
@@ -92,4 +92,4 @@ The `render` method on a `DocXify::Document` will generate a complete `document.
92
92
 
93
93
  ## Contributing
94
94
 
95
- Bug reports and pull requests are welcome on GitHub at <https://github.com/andyjeffries/docxify>.
95
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/foundercatalyst/docxify>.
@@ -8,6 +8,7 @@ module DocXify
8
8
  @file = file
9
9
 
10
10
  @align = options[:align] || :left
11
+ @after = options[:after]
11
12
  @height_cm = options[:height_cm] || 5
12
13
  @width_cm = options[:width_cm] || 5
13
14
  end
@@ -19,20 +20,17 @@ module DocXify
19
20
  def to_s(_container = nil)
20
21
  xml = "<w:p>"
21
22
 
23
+ xml << "<w:pPr>"
22
24
  if @align == :right
23
- xml << <<~XML
24
- <w:pPr>
25
- <w:jc w:val="right"/>
26
- </w:pPr>
27
- XML
25
+ xml << "<w:jc w:val=\"right\"/>"
28
26
  elsif @align == :center
29
- xml << <<~XML
30
- <w:pPr>
31
- <w:jc w:val="center"/>
32
- </w:pPr>
33
- XML
27
+ xml << "<w:jc w:val=\"center\"/>"
34
28
  end
35
29
 
30
+ xml << "<w:spacing w:after=\"#{DocXify.pt2spacing @after}\"/>" if @after
31
+
32
+ xml << "</w:pPr>"
33
+
36
34
  xml << <<~XML
37
35
  <w:r>
38
36
  <w:rPr>
@@ -14,6 +14,7 @@ module DocXify
14
14
  @background = options[:background] if options[:background]
15
15
  @background ||= @document&.background if @document&.background
16
16
  @align = options[:align] || :left
17
+ @after = options[:after]
17
18
  @inline_styling = options.key?(:inline_styling) ? options[:inline_styling] : true
18
19
  @tab_stops_cm = options[:tab_stops_cm] || []
19
20
  @hanging_cm = options[:hanging_cm] || 0
@@ -21,15 +22,16 @@ module DocXify
21
22
 
22
23
  def to_s(_container = nil)
23
24
  nodes = if @inline_styling
24
- parse_simple_html(@text)
25
- else
26
- [@text.gsub("<", "&lt;").gsub(">", "&gt;")]
27
- end
25
+ parse_simple_html(@text)
26
+ else
27
+ [@text.gsub("<", "&lt;").gsub(">", "&gt;")]
28
+ end
28
29
 
29
30
  xml = "<w:p>"
30
31
 
31
32
  xml << "<w:pPr>"
32
33
  xml << "<w:jc w:val=\"#{@align}\"/>" if @align != :left
34
+ xml << "<w:spacing w:after=\"#{DocXify.pt2spacing @after}\"/>" if @after
33
35
 
34
36
  if tab_stops_cm.any?
35
37
  xml << "<w:tabs>"
@@ -1,3 +1,3 @@
1
1
  module DocXify
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
data/lib/docxify.rb CHANGED
@@ -47,6 +47,14 @@ module DocXify
47
47
  (value * 2).to_i
48
48
  end
49
49
 
50
+ # Used for spacing
51
+ def self.pt2spacing(value)
52
+ value = value.to_f
53
+ raise ArgumentError.new("Value must be greater than or equal to 0") if value.negative?
54
+
55
+ (value * 20).to_i
56
+ end
57
+
50
58
  # Used for image sizes
51
59
  def self.cm2emu(value)
52
60
  value = value.to_f
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docxify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
+ - FounderCatalyst Ltd
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2024-08-29 00:00:00.000000000 Z
12
+ date: 2024-09-24 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rubyzip
@@ -27,7 +28,7 @@ dependencies:
27
28
  description: Using a relatively simple DSL, you can generate Word DocX documents from
28
29
  Ruby.
29
30
  email:
30
- - andy@andyjeffries.co.uk
31
+ - andy@foundercatalyst.com
31
32
  executables: []
32
33
  extensions: []
33
34
  extra_rdoc_files: []