article_json 0.3.7 → 0.3.8

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: 2820900cbe5eeba0352a764674bf7dbc1a5a1d2353c0fe5fcacea19799891378
4
- data.tar.gz: 95c0cba7f4896556710fa621ea07576979b98ec62b7975e5ef330883f66b98b1
3
+ metadata.gz: baf39dbf5fb3f225088927c3ea9f7d58a59a502c6c70da1546829d857760ee6a
4
+ data.tar.gz: f9c60e3a2e8aadffda6525eb9acd085ee5ffcc53697cc7fec4a3c204209a571e
5
5
  SHA512:
6
- metadata.gz: 0bd444a45513d39b0499188b7ade246cfde9e215df63b9652dc16435bde2570c51a4ed9cb5124c24a0848b63df3eacd3a2538bcb8ba5829b96b4afc7e5f93ff7
7
- data.tar.gz: 4effc300873b4203bbc4e9594cc49ae871275e3d5c0e92940b10fad380e7c06acd1b42b14b869d00f28385102bb2c7646eca0424f4e9ca4957c7796fa497aaa1
6
+ metadata.gz: 28783003b3b27d4eca2e5141dd59967f0f2ee44f077726bd5935a8e9dfa49fbd482cac67d49f2bc69e66797cb6dff7c67093124887215423117df6bbed8c5840
7
+ data.tar.gz: 0ee51b7975ed3621a99abe34a4d2180c327e3a1a678539aa58ed40171d8bf0cf812c0b1478c49886418fb410eb8634ac3b20c8a00ed881da2edeb5f5e7bc469f
@@ -1,4 +1,11 @@
1
1
  # Changelog
2
+ ## 0.3.8 - 2020/7/31
3
+ - **Improvements:**
4
+ - Add a script to update oembed stubs fixtures.
5
+ - Support for `alt` attribute in images.
6
+
7
+ - **Fix:** Fix a bug when using the `[image-link-to: ]` tag.
8
+
2
9
  ## 0.3.7 - 2019/8/21
3
10
  - **Fix:** Only use https for soundcloud oembed api
4
11
 
data/README.md CHANGED
@@ -53,6 +53,21 @@ $ ./bin/article_json_export_google_doc.rb $DOC_ID \
53
53
  | ./bin/article_json_export_html.rb
54
54
  ```
55
55
 
56
+ You can also update all the different exported versions of the reference
57
+ document (html, json, amp, facebook instant article and plain txt) by
58
+ running the following command:
59
+
60
+ ```
61
+ $ ./bin/update_reference_document.sh
62
+ ```
63
+
64
+ When running the tests, we use some fixtures to mock the responses for oembed
65
+ request, but these may change over time. To update them, run:
66
+
67
+ ```
68
+ $ ./bin/update_oembed_request-stubs.sh
69
+ ```
70
+
56
71
  ### Configuration
57
72
  There are some configuration options that allow a more tailored usage of the
58
73
  `article_json` gem. The following code snippet gives an example for every
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
4
+ #
5
+ # Simple script to read a JSON document and export it to AMP.
6
+ #
7
+ # Usage:
8
+ #
9
+ # ./bin/article_json_export_amp.rb < my_document.json
10
+ #
11
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
12
+
13
+ require_relative '../lib/article_json'
14
+ puts ArticleJSON::Article.from_json(ARGF.read).to_amp
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
4
+ #
5
+ # Simple script to read a JSON document and export it to Facebook Instant
6
+ # Article.
7
+ #
8
+ # Usage:
9
+ #
10
+ # ./bin/article_json_export_facebook.rb < my_document.json
11
+ #
12
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
13
+
14
+ require_relative '../lib/article_json'
15
+ puts ArticleJSON::Article.from_json(ARGF.read).to_facebook_instant_article
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
4
+ #
5
+ # Simple script to read a JSON document and export it to plain text.
6
+ #
7
+ # Usage:
8
+ #
9
+ # ./bin/article_json_export_plain_text.rb < my_document.json
10
+ #
11
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
12
+
13
+ require_relative '../lib/article_json'
14
+ puts ArticleJSON::Article.from_json(ARGF.read).to_plain_text
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env sh
2
+
3
+ curl -X GET "https://vimeo.com/api/oembed.json?url=https://vimeo.com/42315417" | jq > spec/fixtures/vimeo_video_oembed.json
4
+
5
+ curl -X GET "http://www.youtube.com/oembed?format=json&url=https://www.youtube.com/watch?v=_ZG8HBuDjgc" | jq > spec/fixtures/youtube_video_oembed.json
6
+
7
+ curl -X GET "https://www.slideshare.net/api/oembed/2?format=json&url=https://www.slideshare.net/Devex/the-best-global-development-quotes-of-2012" | jq > spec/fixtures/slideshare_oembed.json
8
+
9
+ curl -X GET "https://api.twitter.com/1/statuses/oembed.json?align=center&url=https://twitter.com/d3v3x/status/554608639030599681" | jq > spec/fixtures/tweet_oembed.json
10
+
11
+ curl -X GET 'https://soundcloud.com/oembed?format=json&url=https://soundcloud.com/rich-the-kid/plug-walk-1' | jq > spec/fixtures/soundcloud_oembed.json
12
+
13
+ curl -X GET 'https://www.facebook.com/plugins/video/oembed.json?url=https://www.facebook.com/facebook/videos/1814600831891266' | jq > spec/fixtures/facebook_video_oembed.json
@@ -7,6 +7,9 @@ DOC_ID="1E4lncZE2jDkbE34eDyYQmXKA9O26BHUiwguz4S9qyE8"
7
7
  SOURCE_HTML_FILE="spec/fixtures/reference_document.html"
8
8
  JSON_FILE="spec/fixtures/reference_document_parsed.json"
9
9
  HTML_EXPORT_FILE="spec/fixtures/reference_document_exported.html"
10
+ AMP_EXPORT_FILE="spec/fixtures/reference_document_exported.amp.html"
11
+ FACEBOOK_EXPORT_FILE="spec/fixtures/reference_document_exported.facebook.html"
12
+ PLAIN_TEXT_EXPORT_FILE="spec/fixtures/reference_document_exported.txt"
10
13
 
11
14
  # export the google doc to HTML
12
15
  ./bin/article_json_export_google_doc.rb ${DOC_ID} > ${SOURCE_HTML_FILE}
@@ -16,3 +19,12 @@ HTML_EXPORT_FILE="spec/fixtures/reference_document_exported.html"
16
19
 
17
20
  # convert the JSON export to HTML
18
21
  ./bin/article_json_export_html.rb < ${JSON_FILE} > ${HTML_EXPORT_FILE}
22
+
23
+ # convert the JSON export to AMP
24
+ ./bin/article_json_export_amp.rb < ${JSON_FILE} > ${AMP_EXPORT_FILE}
25
+
26
+ # convert the JSON export to Facebook Instant Article
27
+ ./bin/article_json_export_facebook.rb < ${JSON_FILE} > ${FACEBOOK_EXPORT_FILE}
28
+
29
+ # convert the JSON export to plain text
30
+ ./bin/article_json_export_plain_text.rb < ${JSON_FILE} > ${PLAIN_TEXT_EXPORT_FILE}
@@ -1,18 +1,20 @@
1
1
  module ArticleJSON
2
2
  module Elements
3
3
  class Image < Base
4
- attr_reader :source_url, :caption, :float, :href
4
+ attr_reader :source_url, :caption, :float, :href, :alt
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
+ # @param [String] alt
11
+ def initialize(source_url:, caption:, float: nil, href: nil, alt: nil)
11
12
  @type = :image
12
13
  @source_url = source_url
13
14
  @caption = caption
14
15
  @float = float
15
16
  @href = href
17
+ @alt = alt
16
18
  end
17
19
 
18
20
  # Hash representation of this image element
@@ -24,6 +26,7 @@ module ArticleJSON
24
26
  float: float,
25
27
  caption: caption.map(&:to_h),
26
28
  href: href,
29
+ alt: alt,
27
30
  }
28
31
  end
29
32
 
@@ -35,7 +38,8 @@ module ArticleJSON
35
38
  source_url: hash[:source_url],
36
39
  caption: parse_hash_list(hash[:caption]),
37
40
  float: hash[:float]&.to_sym,
38
- href: hash[:href]
41
+ href: hash[:href],
42
+ alt: hash[:alt]
39
43
  )
40
44
  end
41
45
  end
@@ -29,7 +29,7 @@ module ArticleJSON
29
29
 
30
30
  # @return [Nokogiri::XML::NodeSet]
31
31
  def image_node
32
- create_element(:img, src: @element.source_url)
32
+ create_element(:img, src: @element.source_url, alt: @element.alt)
33
33
  end
34
34
 
35
35
  # @return [Nokogiri::XML::NodeSet]
@@ -19,6 +19,12 @@ module ArticleJSON
19
19
  @float_node = @node
20
20
  end
21
21
 
22
+ # The value of the image's `alt` attribute
23
+ # @return [String]
24
+ def alt
25
+ image_node.attribute('alt')&.value || ''
26
+ end
27
+
22
28
  # The value of the image's `src` attribute
23
29
  # @return [String]
24
30
  def source_url
@@ -54,7 +60,8 @@ module ArticleJSON
54
60
  source_url: source_url,
55
61
  float: float,
56
62
  caption: caption,
57
- href: @href
63
+ href: @href,
64
+ alt: alt
58
65
  )
59
66
  end
60
67
 
@@ -1,3 +1,3 @@
1
1
  module ArticleJSON
2
- VERSION = '0.3.7'
2
+ VERSION = '0.3.8'
3
3
  end
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.7
4
+ version: 0.3.8
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: 2019-08-21 00:00:00.000000000 Z
13
+ date: 2020-07-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -111,9 +111,13 @@ files:
111
111
  - CODE_OF_CONDUCT.md
112
112
  - LICENSE
113
113
  - README.md
114
+ - bin/article_json_export_amp.rb
115
+ - bin/article_json_export_facebook.rb
114
116
  - bin/article_json_export_google_doc.rb
115
117
  - bin/article_json_export_html.rb
118
+ - bin/article_json_export_plain_text.rb
116
119
  - bin/article_json_parse_google_doc.rb
120
+ - bin/update_oembed_request-stubs.sh
117
121
  - bin/update_reference_document.sh
118
122
  - lib/article_json.rb
119
123
  - lib/article_json/article.rb
@@ -229,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
233
  - !ruby/object:Gem::Version
230
234
  version: '0'
231
235
  requirements: []
232
- rubygems_version: 3.0.4
236
+ rubygems_version: 3.0.8
233
237
  signing_key:
234
238
  specification_version: 4
235
239
  summary: JSON Format for News Articles & Ruby Gem