docxify 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 897b2f634b40161a9795499ceb4324d568792267e7e20ac0017c606cf9f42a47
4
- data.tar.gz: 99f727d9d8b1d5063d9c290606911f45bdce092d83ede247fab952a112c72fae
3
+ metadata.gz: '02588568aa1d05caf048a8a3b861ffc9b5ec2109817b6931006ce4c36c97adea'
4
+ data.tar.gz: 7f2647fdf663f8fb222c544592c4910ec54aedcdd26cf8fef30a610c7a163d6f
5
5
  SHA512:
6
- metadata.gz: '051835c221e1d60bf40e9ee2020ad0bb4682d67fcc3beea6f92ba80380ef0177ef7365b24562d1f19294c72fddfb83ddf860409fe835888b3682277aaf79a318'
7
- data.tar.gz: 2f21816e06987a0650c4ab1f5c0628e8eccc77be64fe1bbee35f8a40ed1aede60a95d4bf8fba7bb7ce509feb394c6a1004266541f154a43bc2372a56578b9b17
6
+ metadata.gz: bf43c3a7194169d9cb01e0f96a44d3498dffbde8fa7f829dbf8fff1226ea9adffa4f648a06158cc7ad3450203858e2211cf2423f064a683129ef2e23c825353b
7
+ data.tar.gz: b4990b99e150a9f2e3aae3a45873799e91fc850c7180485caa4559ed2eca97d301672bd0181f3e5b703d3c44f32b4c3f6e64c32c36895b0c62a002659f76b83d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
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
+
9
+ ## 0.1.1
10
+
11
+ Features:
12
+
13
+ - Allow combining bold, italic and underline on a single element (thanks to @b0nn1e for the PR)
14
+
3
15
  ## 0.1.0
4
16
 
5
17
  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
@@ -30,6 +31,7 @@ module DocXify
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>"
@@ -58,9 +60,9 @@ module DocXify
58
60
  <w:sz w:val="#{DocXify.pt2halfpt(@size)}"/>
59
61
  <w:szCs w:val="#{DocXify.pt2halfpt(@size)}"/>
60
62
  #{"<w:highlight w:val=\"yellow\"/>" if @highlight}
61
- #{"<w:b/><w:bCs/>" if node.is_a?(Hash) && node[:tag] == "b"}
62
- #{"<w:i/><w:iCs/>" if node.is_a?(Hash) && node[:tag] == "i"}
63
- #{"<w:u w:val=\"single\"/>" if node.is_a?(Hash) && (node[:tag] == "u" || node[:tag] == "a")}
63
+ #{"<w:b/><w:bCs/>" if node.is_a?(Hash) && node[:tag].match?("b")}
64
+ #{"<w:i/><w:iCs/>" if node.is_a?(Hash) && node[:tag].match?("i")}
65
+ #{"<w:u w:val=\"single\"/>" if node.is_a?(Hash) && (node[:tag].match?("u") || node[:tag] == "a")}
64
66
  #{"<w:rStyle w:val=\"Hyperlink\"/>" if node.is_a?(Hash) && node[:tag] == "a"}
65
67
  </w:rPr>
66
68
  XML
@@ -1,3 +1,3 @@
1
1
  module DocXify
2
- VERSION = "0.1.0".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.0
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: []