article_json 0.3.3 → 0.3.5
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 +5 -5
- data/CHANGELOG.md +8 -0
- data/lib/article_json/elements/image.rb +7 -3
- data/lib/article_json/export/common/html/elements/image.rb +18 -4
- data/lib/article_json/import/google_doc/html/embedded_soundcloud_parser.rb +1 -1
- data/lib/article_json/import/google_doc/html/image_parser.rb +27 -1
- data/lib/article_json/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f34cc736d928d12ee64d0181a15d9b69b2bdfc6c89e76c35ffd79cb6a8acb8d5
|
4
|
+
data.tar.gz: 74c2c855413da0691866fe54d1927b4342bb5409a826807821866613203f3db9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec2b0a1718c9f57dd278ce4e11bcca41a84353b3594be06599204b838701199ecaf5e21bb36921ea68c98c7fa7083d2cd8f939fb7253b07305aa4258bbf47c25
|
7
|
+
data.tar.gz: 381aad7bba231456aa45bf4f512bd2fa788dffa875b1eccf5a77d859cff28d5b061eb3b7a08c0e51b0915a57c9695c8113d07966b313be0d9ca00ad8759f2469
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
# Changelog
|
2
|
+
## 0.3.5 - 2018/12/12
|
3
|
+
- **Improvements** to import and export image links from Google Docs
|
4
|
+
- Import image `href`` from caption text using a custom tag
|
5
|
+
- Export the image element href attribute as a link
|
6
|
+
|
7
|
+
## 0.3.4 - 2018/5/10
|
8
|
+
- **Fix:** Only include slug from the soundcloud URL in google doc parser
|
9
|
+
|
2
10
|
## 0.3.3 - 2018/4/12
|
3
11
|
- Support embedding SoundCloud
|
4
12
|
|
@@ -1,16 +1,18 @@
|
|
1
1
|
module ArticleJSON
|
2
2
|
module Elements
|
3
3
|
class Image < Base
|
4
|
-
attr_reader :source_url, :caption, :float
|
4
|
+
attr_reader :source_url, :caption, :float, :href
|
5
5
|
|
6
6
|
# @param [String] source_url
|
7
7
|
# @param [Array[ArticleJSON::Elements::Text]] caption
|
8
8
|
# @param [Symbol] float
|
9
|
-
|
9
|
+
# @param [String] href
|
10
|
+
def initialize(source_url:, caption:, float: nil, href: nil)
|
10
11
|
@type = :image
|
11
12
|
@source_url = source_url
|
12
13
|
@caption = caption
|
13
14
|
@float = float
|
15
|
+
@href = href
|
14
16
|
end
|
15
17
|
|
16
18
|
# Hash representation of this image element
|
@@ -21,6 +23,7 @@ module ArticleJSON
|
|
21
23
|
source_url: source_url,
|
22
24
|
float: float,
|
23
25
|
caption: caption.map(&:to_h),
|
26
|
+
href: href,
|
24
27
|
}
|
25
28
|
end
|
26
29
|
|
@@ -31,7 +34,8 @@ module ArticleJSON
|
|
31
34
|
new(
|
32
35
|
source_url: hash[:source_url],
|
33
36
|
caption: parse_hash_list(hash[:caption]),
|
34
|
-
float: hash[:float]&.to_sym
|
37
|
+
float: hash[:float]&.to_sym,
|
38
|
+
href: hash[:href]
|
35
39
|
)
|
36
40
|
end
|
37
41
|
end
|
@@ -7,24 +7,38 @@ module ArticleJSON
|
|
7
7
|
include ArticleJSON::Export::Common::HTML::Elements::Shared::Caption
|
8
8
|
include ArticleJSON::Export::Common::HTML::Elements::Shared::Float
|
9
9
|
|
10
|
-
# Generate the `<figure>` node containing the image and caption
|
10
|
+
# Generate the `<figure>` node containing the image and caption or
|
11
|
+
# an `<a>` node containing the `<figure>` node if href is present.
|
11
12
|
# @return [Nokogiri::XML::Element]
|
12
13
|
def export
|
14
|
+
figure_node
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# @return [Nokogiri::XML::NodeSet]
|
20
|
+
def figure_node
|
13
21
|
create_element(:figure, node_opts) do |figure|
|
14
|
-
|
22
|
+
node = @element.href.present? ? href_node : image_node
|
23
|
+
figure.add_child(node)
|
15
24
|
if @element.caption&.any?
|
16
25
|
figure.add_child(caption_node(:figcaption))
|
17
26
|
end
|
18
27
|
end
|
19
28
|
end
|
20
29
|
|
21
|
-
private
|
22
|
-
|
23
30
|
# @return [Nokogiri::XML::NodeSet]
|
24
31
|
def image_node
|
25
32
|
create_element(:img, src: @element.source_url)
|
26
33
|
end
|
27
34
|
|
35
|
+
# @return [Nokogiri::XML::NodeSet]
|
36
|
+
def href_node
|
37
|
+
create_element(:a, href: @element.href) do |a|
|
38
|
+
a.add_child(image_node)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
28
42
|
# @return [Hash]
|
29
43
|
def node_opts
|
30
44
|
return if floating_class.nil?
|
@@ -12,6 +12,7 @@ module ArticleJSON
|
|
12
12
|
def initialize(node:, caption_node:, css_analyzer:)
|
13
13
|
@node = node
|
14
14
|
@caption_node = caption_node
|
15
|
+
@href = href
|
15
16
|
@css_analyzer = css_analyzer
|
16
17
|
|
17
18
|
# Main node indicates the floating behavior
|
@@ -36,17 +37,42 @@ module ArticleJSON
|
|
36
37
|
super if floatable_size?
|
37
38
|
end
|
38
39
|
|
40
|
+
# Extracts an href from the tag [image-link-to: url]) if present
|
41
|
+
# in the caption node.
|
42
|
+
# @return [String]
|
43
|
+
def href
|
44
|
+
return if @caption_node.nil?
|
45
|
+
match = @caption_node.content.strip.match(href_regexp)
|
46
|
+
return if match.nil?
|
47
|
+
remove_image_link_tag
|
48
|
+
match[:url]
|
49
|
+
end
|
50
|
+
|
39
51
|
# @return [ArticleJSON::Elements::Image]
|
40
52
|
def element
|
41
53
|
ArticleJSON::Elements::Image.new(
|
42
54
|
source_url: source_url,
|
43
55
|
float: float,
|
44
|
-
caption: caption
|
56
|
+
caption: caption,
|
57
|
+
href: @href
|
45
58
|
)
|
46
59
|
end
|
47
60
|
|
48
61
|
private
|
49
62
|
|
63
|
+
# Removes the [image-link-to: url] tag from the caption node
|
64
|
+
def remove_image_link_tag
|
65
|
+
@caption_node
|
66
|
+
.children
|
67
|
+
.first
|
68
|
+
.content = @caption_node.content.sub(href_regexp, '').strip
|
69
|
+
end
|
70
|
+
|
71
|
+
# Regular expression to check if there's a [image-link-to: url] tag
|
72
|
+
# @return [Regexp]
|
73
|
+
def href_regexp
|
74
|
+
%r{\[image-link-to:\s+(?<url>.*?)\]}
|
75
|
+
end
|
50
76
|
# Check if the image's width can be determined and is less than 500px
|
51
77
|
# This is about 3/4 of the google document width...
|
52
78
|
# @return [Boolean]
|
data/lib/article_json/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: article_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Sager
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-
|
13
|
+
date: 2018-12-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
230
|
version: '0'
|
231
231
|
requirements: []
|
232
232
|
rubyforge_project:
|
233
|
-
rubygems_version: 2.
|
233
|
+
rubygems_version: 2.7.7
|
234
234
|
signing_key:
|
235
235
|
specification_version: 4
|
236
236
|
summary: JSON Format for News Articles & Ruby Gem
|