marlens-jira-api 0.5.0 → 0.5.1

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: 782848ce0d3f51aed25b94ade7e4cabda09106be46fd3803307450f42a9d249c
4
- data.tar.gz: ce6672958668fcf08a45a3dbdceb66ba7a99daf5b2d95e5085b07efc8741581b
3
+ metadata.gz: 4d03091de06691a2493443796b27c4c7205067ba92eb3503cdf0ccb2771b86a6
4
+ data.tar.gz: 0f1c94a08e018b97a171a25a888baabebb301a9427f9f6eccc915e8b222fad7a
5
5
  SHA512:
6
- metadata.gz: b31245df26fe026493a556d6e3b1ab1d9e45be5281705672b631d65b86f85ac91c8ce392064068b913c1c5e0c2096332c4f13533aeffdd59f382f6fd76cf4472
7
- data.tar.gz: 5591a8de6a89de181ef02d0d5e4d7427bb20a6fc36c7d8c888c164f9966f029d30277516bf69b17dcc2bea8444dbbcc4bdb9e7d011fe79d422a2827f90cf9521
6
+ metadata.gz: a47ff4083694ad1406d0248b4ac86afead42c425464c2cfeb0fb61f9d344aed3c8a78172fae723095d02f09ea0cdc9343cfac0d9394388cfa490a646449900bc
7
+ data.tar.gz: 51e132f5fa0b5f3e59fb6ebb35c37d8fd9ec468bab881dbca2fb7bc191cd210a9adc1055ac9173fc1200ab27b05ec49824c1468a9786414a7db6e64b2f8e8c2d
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "base64"
4
4
  require "json"
5
- require "multipart/post"
5
+ require "net/http/post/multipart"
6
6
  require "net/http"
7
7
  require "uri"
8
8
 
@@ -31,6 +31,25 @@ module Marlens
31
31
  }
32
32
  end
33
33
 
34
+ def self.external_media_single(url:, alt:, width:, height:)
35
+ {
36
+ "type" => "mediaSingle",
37
+ "attrs" => { "layout" => "center" },
38
+ "content" => [
39
+ {
40
+ "type" => "media",
41
+ "attrs" => {
42
+ "type" => "external",
43
+ "url" => url,
44
+ "alt" => alt,
45
+ "width" => width,
46
+ "height" => height,
47
+ },
48
+ },
49
+ ],
50
+ }
51
+ end
52
+
34
53
  def self.paragraph(text)
35
54
  new("").send(:paragraph_from_text, text)
36
55
  end
@@ -79,7 +98,7 @@ module Marlens
79
98
  when :heading
80
99
  heading(node)
81
100
  when :paragraph
82
- paragraph(node)
101
+ paragraph_blocks(node)
83
102
  when :code_block
84
103
  code_block(node)
85
104
  when :list
@@ -105,19 +124,23 @@ module Marlens
105
124
  }
106
125
  end
107
126
 
108
- def paragraph(node)
109
- return image_block_for(children(node).first) if single_image_node?(node)
127
+ def paragraph_blocks(node)
128
+ return [image_block_for(children(node).first)] if single_image_node?(node)
129
+
130
+ split_paragraph_around_html_images(node) || [paragraph_from_inline_content(inline_content(node))]
131
+ end
110
132
 
133
+ def paragraph_from_text(text)
111
134
  {
112
135
  "type" => "paragraph",
113
- "content" => inline_content(node),
136
+ "content" => [text_node(text)],
114
137
  }
115
138
  end
116
139
 
117
- def paragraph_from_text(text)
140
+ def paragraph_from_inline_content(content)
118
141
  {
119
142
  "type" => "paragraph",
120
- "content" => [text_node(text)],
143
+ "content" => content,
121
144
  }
122
145
  end
123
146
 
@@ -210,6 +233,43 @@ module Marlens
210
233
  )
211
234
  end
212
235
 
236
+ def split_paragraph_around_html_images(node)
237
+ blocks = []
238
+ pending_content = []
239
+
240
+ children(node).each do |child|
241
+ image_block = inline_html_image_block(child)
242
+
243
+ if image_block.nil?
244
+ append_inline_content(pending_content, render_inline(child, []))
245
+ else
246
+ append_paragraph_block(blocks, pending_content)
247
+ pending_content = []
248
+ blocks << image_block
249
+ end
250
+ end
251
+ return nil if blocks.empty?
252
+
253
+ append_paragraph_block(blocks, pending_content)
254
+ blocks
255
+ end
256
+
257
+ def inline_html_image_block(node)
258
+ return nil unless node.type == :html_inline
259
+
260
+ html_image_block(node)
261
+ end
262
+
263
+ def append_paragraph_block(blocks, content)
264
+ blocks << paragraph_from_inline_content(content) unless content.empty?
265
+ end
266
+
267
+ def append_inline_content(content, inline)
268
+ return if inline.nil?
269
+
270
+ inline.is_a?(Array) ? content.concat(inline.compact) : content << inline
271
+ end
272
+
213
273
  def resolved_image_block(url:, alt: nil, width: nil, height: nil)
214
274
  return nil if url.nil? || url.strip.empty?
215
275
  return fallback_image_paragraph(url, alt) if @image_resolver.nil?
@@ -20,8 +20,8 @@ module Marlens
20
20
  attachment = upload_image_attachment(image.fetch(:url))
21
21
  dimensions = attachment.fetch("dimensions")
22
22
 
23
- MarkdownToAdf.media_single(
24
- id: attachment.fetch("id"),
23
+ MarkdownToAdf.external_media_single(
24
+ url: attachment.fetch("content"),
25
25
  alt: image[:alt].to_s.strip.empty? ? attachment.fetch("filename") : image[:alt],
26
26
  width: image_dimension_value(image[:width], dimensions.fetch("width")),
27
27
  height: image_dimension_value(image[:height], dimensions.fetch("height"))
@@ -55,7 +55,7 @@ module Marlens
55
55
  )
56
56
 
57
57
  return {
58
- "id" => attachment.fetch("id").to_s,
58
+ "content" => attachment.fetch("content").to_s,
59
59
  "filename" => attachment.fetch("filename", filename),
60
60
  "dimensions" => dimensions,
61
61
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Marlens
4
4
  module JiraApi
5
- VERSION = "0.5.0"
5
+ VERSION = "0.5.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marlens-jira-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marlen Brunner