article_json 0.3.8 → 0.4.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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -0
  3. data/README.md +127 -79
  4. data/bin/article_json_export_amp.rb +1 -0
  5. data/bin/{article_json_export_facebook.rb → article_json_export_apple_news.rb} +4 -4
  6. data/bin/article_json_export_html.rb +1 -0
  7. data/bin/article_json_export_plain_text.rb +1 -0
  8. data/bin/article_json_parse_google_doc.rb +1 -0
  9. data/bin/check_google_doc_export.rb +41 -0
  10. data/bin/update_oembed_request-stubs.sh +1 -3
  11. data/bin/update_reference_document.sh +3 -3
  12. data/lib/article_json/article.rb +17 -9
  13. data/lib/article_json/configuration.rb +6 -5
  14. data/lib/article_json/elements/base.rb +0 -1
  15. data/lib/article_json/elements/heading.rb +0 -1
  16. data/lib/article_json/elements/image.rb +0 -1
  17. data/lib/article_json/elements/list.rb +0 -1
  18. data/lib/article_json/elements/paragraph.rb +1 -1
  19. data/lib/article_json/elements/quote.rb +0 -1
  20. data/lib/article_json/elements/text.rb +1 -1
  21. data/lib/article_json/elements/text_box.rb +0 -1
  22. data/lib/article_json/export/amp/custom_element_library_resolver.rb +0 -1
  23. data/lib/article_json/export/amp/elements/embed.rb +43 -31
  24. data/lib/article_json/export/amp/elements/image.rb +7 -5
  25. data/lib/article_json/export/amp/exporter.rb +4 -2
  26. data/lib/article_json/export/apple_news/elements/base.rb +53 -0
  27. data/lib/article_json/export/apple_news/elements/embed.rb +130 -0
  28. data/lib/article_json/export/apple_news/elements/heading.rb +32 -0
  29. data/lib/article_json/export/apple_news/elements/image.rb +59 -0
  30. data/lib/article_json/export/apple_news/elements/list.rb +67 -0
  31. data/lib/article_json/export/apple_news/elements/paragraph.rb +36 -0
  32. data/lib/article_json/export/apple_news/elements/quote.rb +60 -0
  33. data/lib/article_json/export/apple_news/elements/text.rb +55 -0
  34. data/lib/article_json/export/apple_news/elements/text_box.rb +51 -0
  35. data/lib/article_json/export/apple_news/exporter.rb +37 -0
  36. data/lib/article_json/export/common/html/elements/embed.rb +2 -1
  37. data/lib/article_json/export/common/html/elements/image.rb +2 -1
  38. data/lib/article_json/export/common/html/elements/text.rb +2 -0
  39. data/lib/article_json/import/google_doc/html/embedded_parser.rb +1 -0
  40. data/lib/article_json/import/google_doc/html/heading_parser.rb +5 -5
  41. data/lib/article_json/import/google_doc/html/image_parser.rb +18 -2
  42. data/lib/article_json/import/google_doc/html/list_parser.rb +2 -2
  43. data/lib/article_json/import/google_doc/html/node_analyzer.rb +25 -3
  44. data/lib/article_json/import/google_doc/html/parser.rb +7 -1
  45. data/lib/article_json/import/google_doc/html/shared/caption.rb +1 -0
  46. data/lib/article_json/import/google_doc/html/shared/float.rb +2 -0
  47. data/lib/article_json/import/google_doc/html/text_box_parser.rb +2 -1
  48. data/lib/article_json/import/google_doc/html/text_parser.rb +2 -0
  49. data/lib/article_json/utils/additional_element_placer.rb +2 -0
  50. data/lib/article_json/utils/o_embed_resolver/base.rb +14 -4
  51. data/lib/article_json/utils/o_embed_resolver/facebook_video.rb +17 -1
  52. data/lib/article_json/utils/o_embed_resolver/slideshare.rb +2 -2
  53. data/lib/article_json/utils/o_embed_resolver/youtube_video.rb +14 -1
  54. data/lib/article_json/version.rb +1 -1
  55. data/lib/article_json.rb +11 -11
  56. metadata +29 -26
  57. data/lib/article_json/export/facebook_instant_article/elements/base.rb +0 -30
  58. data/lib/article_json/export/facebook_instant_article/elements/embed.rb +0 -44
  59. data/lib/article_json/export/facebook_instant_article/elements/heading.rb +0 -11
  60. data/lib/article_json/export/facebook_instant_article/elements/image.rb +0 -11
  61. data/lib/article_json/export/facebook_instant_article/elements/list.rb +0 -11
  62. data/lib/article_json/export/facebook_instant_article/elements/paragraph.rb +0 -11
  63. data/lib/article_json/export/facebook_instant_article/elements/quote.rb +0 -30
  64. data/lib/article_json/export/facebook_instant_article/elements/text.rb +0 -11
  65. data/lib/article_json/export/facebook_instant_article/elements/text_box.rb +0 -40
  66. data/lib/article_json/export/facebook_instant_article/exporter.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: baf39dbf5fb3f225088927c3ea9f7d58a59a502c6c70da1546829d857760ee6a
4
- data.tar.gz: f9c60e3a2e8aadffda6525eb9acd085ee5ffcc53697cc7fec4a3c204209a571e
3
+ metadata.gz: 7bf4d22d73f1d9380b282867e7f55ac90aae0cacbf235f26c3aaee678e4adfc5
4
+ data.tar.gz: 250276366fce15b87e51cd62f05d53b90eaff29949c6681b9962b0ccdb127a16
5
5
  SHA512:
6
- metadata.gz: 28783003b3b27d4eca2e5141dd59967f0f2ee44f077726bd5935a8e9dfa49fbd482cac67d49f2bc69e66797cb6dff7c67093124887215423117df6bbed8c5840
7
- data.tar.gz: 0ee51b7975ed3621a99abe34a4d2180c327e3a1a678539aa58ed40171d8bf0cf812c0b1478c49886418fb410eb8634ac3b20c8a00ed881da2edeb5f5e7bc469f
6
+ metadata.gz: 5915080736fd29499a73f73cdb39d5e3f1af1c54da3a6a114be2a546de35f1d7824da407d76eac255e2b38eee00040dc3534a78a702e78eebbc025bab666b82b
7
+ data.tar.gz: fa283f7167ca908145d6c2b2420865e9b08ca91fbe9a417bf20713eda2e02fe10e3664bbbc22e8718c3c5676dbc8ed61861dc15b367089a491ce3cd7991535f8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # Changelog
2
+
3
+ ## 0.5.0 - WIP
4
+
5
+ **Removes**:
6
+ Support for Facebook Instant Articles, as they are no longer supported by Facebook.
7
+
8
+ ## 0.4.0 - 2024/01/17
9
+
10
+ In this fourth release we **added support for Apple News**:
11
+ **New**:
12
+ Support for Apple News Format, specifically the following elements:
13
+
14
+ - text
15
+ - text boxes
16
+ - lists
17
+ - pull quotes
18
+ - image
19
+ - embed objects (posts from X etc.)
20
+ - image captions for images and embed objects
21
+ - video
22
+ Support for Ruby 3.2
23
+
24
+ **Removes**:
25
+ Support for Ruby 2.3
26
+
27
+ **Refactoring**:
28
+
29
+ - Rubocop autocorrections
30
+
31
+ **Fix:**
32
+
33
+ - Fix failing rspec tests
34
+
2
35
  ## 0.3.8 - 2020/7/31
36
+
3
37
  - **Improvements:**
4
38
  - Add a script to update oembed stubs fixtures.
5
39
  - Support for `alt` attribute in images.
@@ -7,65 +41,84 @@
7
41
  - **Fix:** Fix a bug when using the `[image-link-to: ]` tag.
8
42
 
9
43
  ## 0.3.7 - 2019/8/21
44
+
10
45
  - **Fix:** Only use https for soundcloud oembed api
11
46
 
12
47
  ## 0.3.6 - 2019/8/6
48
+
13
49
  - **Improvement** Add tags support in text_box element.
14
50
 
15
51
  ## 0.3.5 - 2018/12/12
52
+
16
53
  - **Improvements** to import and export image links from Google Docs
17
54
  - Import image `href` from caption text using a custom tag
18
55
  - Export the image element href attribute as a link
19
56
 
20
57
  ## 0.3.4 - 2018/5/10
58
+
21
59
  - **Fix:** Only include slug from the soundcloud URL in google doc parser
22
60
 
23
61
  ## 0.3.3 - 2018/4/12
62
+
24
63
  - Support embedding SoundCloud
25
64
 
26
65
  ## 0.3.2 - 2017/12/06
66
+
27
67
  - Another **fix** to prevent `nil` elements when placing additional elements on articles that end with empty paragraphs
28
68
 
29
69
  ## 0.3.1 - 2017/11/29
70
+
30
71
  - **Fix:** prevent `nil` elements when placing additional element on empty articles
31
72
 
32
73
  ## 0.3.0 - 2017/11/21
74
+
33
75
  In this third bigger release we **added support**:
76
+
34
77
  - For exporting articles in the Facebook Instant Article format
35
78
  - For exporting articles in a plain text format
36
79
  - To all exporters for `caption` elements that are an empty array
37
80
  - For `[no-caption]` text in _Google Documents_ below elements (like images or embed URLs), this now returns empty caption for element
38
81
 
39
82
  **Improvements** were done regarding additional element placement:
83
+
40
84
  - Rework algorithm to place additional elements to better support placing a single element
41
85
  - Improve behavior of multiple calls to `Article#place_additional_elements`
42
86
 
43
87
  One potentially **breaking change** was added:
88
+
44
89
  - Remove deprecated `#register_html_element_exporter`, use `#register_element_exporters` instead
45
90
 
46
91
  **Fixes**:
92
+
47
93
  - Fix AMP export of Twitter tweets
48
94
 
49
95
  ## 0.2.1 - 2017/11/08
96
+
50
97
  **Fix**: Handle non-successful OEmbed responses by rendering message
51
98
 
52
99
  ## 0.2.0 - 2017/11/03
100
+
53
101
  In this second release we **added support** to:
102
+
54
103
  - Export AMP along with required libraries for AMP rendering
55
104
  - Configure custom HTML and AMP element exporters
56
105
  - Resolve oembed elements in HTML export
57
106
 
58
107
  One potentially **breaking change** was added:
108
+
59
109
  - Export quotes as `<div>` instead of `<aside>`
60
110
 
61
111
  **Fixes**:
112
+
62
113
  - Support Vimeo videos with old flash player URLs
63
114
  - Make Google Parser more fault tolerant
64
115
  - Respect linebreaks when importing Google Docs
65
116
  - Export linebreaks in JSON to `<br>` tags in HTML / AMP
66
117
 
67
118
  ## 0.1.0 - 2017/09/20
119
+
68
120
  This is the very first release, with the following functionality:
121
+
69
122
  - article-json format that supports several basic elements; like headings,
70
123
  paragraphs, images or lists
71
124
  - Resolving of embedded elements like videos or tweets via OEmbed standard
data/README.md CHANGED
@@ -1,17 +1,36 @@
1
1
  # article_json
2
- JSON Format for News Articles & Ruby Gem.
2
+
3
+ The `article_json` gem is a Ruby library designed to simplify the conversion and manipulation of structured articles in various formats, allowing easy importing, manipulation and export of content across different platforms and environments.
4
+
5
+ It takes an article from a Google Doc and creates a JSON version of it.
6
+
7
+ From there it can export the article:
8
+
9
+ - as HTML
10
+ - as AMP
11
+ - as Apple News Format (ANF)
12
+ - as plain text
13
+ - as JSON
14
+
15
+ It also provides functionalities to parse content from Google Document HTML exports and initialize articles from JSON strings or already parsed JSON.
16
+
17
+ ---
3
18
 
4
19
  ## Status
20
+
5
21
  [![Gem Version](https://badge.fury.io/rb/article_json.svg)](https://badge.fury.io/rb/article_json)
6
- [![Build Status](https://travis-ci.org/Devex/article_json.svg)](https://travis-ci.org/Devex/article_json)
7
- [![Code Climate](https://codeclimate.com/github/Devex/article_json/badges/gpa.svg)](https://codeclimate.com/github/Devex/article_json)
22
+ [![Check Google Doc](https://github.com/Devex/article_json/workflows/Check%20Google%20Doc/badge.svg)](https://github.com/Devex/article_json/actions/workflows/check-google-doc.yml)
23
+ [![RSpec](https://github.com/Devex/article_json/workflows/rspec/badge.svg)](https://github.com/Devex/article_json/actions/workflows/rspec.yml)
24
+ [![Code Climate](https://codeclimate.com/github/Devex/article_json/badges/gpa.svg)](https://codeclimate.com/github/Devex/article_json?event=push)
8
25
  [![Coverage Status](https://coveralls.io/repos/github/Devex/article_json/badge.svg?branch=master)](https://coveralls.io/github/Devex/article_json?branch=master)
9
26
 
10
27
  ## Usage
28
+
11
29
  First, install the gem with `gem install article_json` or add it to your Gemfile
12
30
  via `gem 'article_json'`.
13
31
 
14
32
  ### Ruby
33
+
15
34
  ```ruby
16
35
  require 'article_json'
17
36
 
@@ -32,8 +51,8 @@ puts article.to_amp
32
51
  # get javascript libraries needed for the AMP article
33
52
  puts article.amp_exporter.amp_libraries
34
53
 
35
- # export article as Facebook Instant Article HTML
36
- puts article.to_facebook_instant_article
54
+ # export article as Apple News Format (ANF)
55
+ puts article.to_apple_news
37
56
 
38
57
  # export article as plain text
39
58
  puts article.to_plain_text
@@ -43,35 +62,49 @@ puts article.to_json
43
62
  ```
44
63
 
45
64
  ### CLI
46
- To load, parse and html-export the latest version of the reference document,
47
- run the following:
48
65
 
49
- ```
66
+ To load, parse and export the latest (amp / apple news / html) version of the reference document, run the following:
67
+
68
+ ```bash
50
69
  $ export DOC_ID=1E4lncZE2jDkbE34eDyYQmXKA9O26BHUiwguz4S9qyE8
51
70
  $ ./bin/article_json_export_google_doc.rb $DOC_ID \
52
71
  | ./bin/article_json_parse_google_doc.rb \
53
72
  | ./bin/article_json_export_html.rb
73
+ ## OR
74
+ # | ./bin/article_json_export_amp.rb
75
+ # | ./bin/article_json_export_apple_news.rb
76
+ # | ./bin/article_json_export_plain_text.rb
77
+ ```
78
+
79
+ Alternatively, you can concatenate your command line commands, like so:
80
+
81
+ ```bash
82
+ $ ./bin/article_json_export_google_doc.rb $DOC_ID > test_ref_doc.html
83
+ $ cat test_ref_doc.html | bin/article_json_parse_google_doc.rb > \
84
+ test_ref_doc_parsed_apple.json
85
+ $ cat test_ref_doc_parsed_apple.json | bin/article_json_export_apple_news.rb > \
86
+ test_ref_doc_exported_apple.json
54
87
  ```
55
88
 
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:
89
+ You can also update _all_ the different exported versions of the reference document _(amp, apple_news, google_doc, html and plain_text)_ by running the following command:
59
90
 
60
91
  ```
61
- $ ./bin/update_reference_document.sh
92
+ ./bin/update_reference_document.sh
62
93
  ```
63
94
 
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:
95
+ When running the tests, we use some fixtures to mock the responses for oembed requests, but these may change over time.
96
+
97
+ To update them, run:
66
98
 
67
99
  ```
68
- $ ./bin/update_oembed_request-stubs.sh
100
+ ./bin/update_oembed_request-stubs.sh
69
101
  ```
70
102
 
71
103
  ### Configuration
72
- There are some configuration options that allow a more tailored usage of the
73
- `article_json` gem. The following code snippet gives an example for every
74
- available setting:
104
+
105
+ Some configuration options allow a more tailored usage of the `article_json` gem.
106
+
107
+ The following code snippet gives an example for every available setting:
75
108
 
76
109
  ```ruby
77
110
  ArticleJSON.configure do |config|
@@ -84,95 +117,116 @@ ArticleJSON.configure do |config|
84
117
  :html,
85
118
  advertisement: ArticleJSON::Export::HTML::Elements::Advertisement
86
119
  )
87
-
120
+
88
121
  # You can also overwrite existing exporters:
89
122
  config.register_element_exporters(
90
123
  :html,
91
124
  image: ArticleJSON::Export::HTML::Elements::ScaledImage
92
125
  )
93
-
126
+
94
127
  # And you can define multiple custom exporters:
95
128
  config.register_element_exporters(
96
129
  :html,
97
130
  advertisement: ArticleJSON::Export::HTML::Elements::Advertisement,
98
131
  image: ArticleJSON::Export::HTML::Elements::ScaledImage
99
132
  )
100
-
101
- # It works the same way for custom AMP, FacebookInstantArticle, or
102
- # PlainText exporters:
133
+
134
+ # It works the same way for custom AMP, Apple News, or PlainText exporters:
103
135
  config.register_element_exporters(
104
- :amp, # Or change this for `:facebook_instant_article` or `:plain_text`
136
+ :amp, # Or change this for `:apple_news` or `:plain_text`
105
137
  image: ArticleJSON::Export::AMP::Elements::ScaledImage
106
- )
138
+ )
107
139
  end
108
- ```
140
+ ```
141
+
142
+ ### Facebook Oembed
143
+
144
+ Facebook deprecated its public endpoints for embeddable Facebook content in 2020 (See <https://developers.facebook.com/docs/plugins/oembed-legacy> for more info).
145
+
146
+ You now need to use a Facebook token to access the new oembed endpoints. You can configure the gem to use this token so:
147
+
148
+ ``` ruby
149
+ ArticleJSON.configure do |config|
150
+ # 'token' being the combination of the app-id and the access token joined
151
+ # with the pipe symbol (`|`)
152
+ config.facebook_token = 'token'
153
+ end
154
+ ```
155
+
156
+ Find more info about the access token [here](https://developers.facebook.com/docs/plugins/oembed#access-tokens).
109
157
 
110
158
  ## Format
111
- A full example of the format can be found in the test fixtures:
112
- [Parsed Reference Document](https://github.com/Devex/article_json/blob/master/spec/fixtures/reference_document_parsed.json)
159
+
160
+ A [full example of the format](https://github.com/Devex/article_json/blob/master/spec/fixtures/reference_document_parsed.json) can be found in the test fixtures.
113
161
 
114
162
  ## Import
163
+
115
164
  ### Google Document Parser
116
- This [Reference Document](https://docs.google.com/document/d/1E4lncZE2jDkbE34eDyYQmXKA9O26BHUiwguz4S9qyE8/edit?usp=sharing)
117
- lists contains all supported formatting along with some descriptions.
165
+
166
+ This [reference document](https://docs.google.com/document/d/1E4lncZE2jDkbE34eDyYQmXKA9O26BHUiwguz4S9qyE8/editusp=sharing) contains all the supported formatting along with some descriptions.
118
167
 
119
168
  ## Add custom elements
120
- Sometimes you might want to place additional elements into the article, like e.g. advertisements.
121
- `article_json` supports this via `article.place_additional_elements` which accepts an array of elements that you can define in your own code.
122
- Each element that is added this way will directly get placed in between paragraphs of the article.
123
- The method ensures that an additional element is never added before or after any node other than paragraphs (e.g. an image).
124
- The elements are added in the order you pass them into the method.
125
- If the article should not have enough spaces to place all the provided elements, they will be placed after the last element in the article.
126
-
127
- You can pass any type of element into this method.
128
- If the objects you pass in are instances of elements defined within this gem (e.g. `ArticleJSON::Elements::Image`), you won't have to do anything else to get them rendered.
169
+
170
+ Sometimes you might want to place additional elements into the article, like e.g. advertisements. `article_json` supports this via `article.place_additional_elements`, which accepts an array of elements that you can define in your code.
171
+
172
+ Each element that is added this way will directly get placed in between paragraphs of the article. The method ensures that an additional element is never added before or after any node other than paragraphs (e.g. an image). The elements are added in the order you pass them into the method.
173
+
174
+ If the article does not have enough space to place all the provided elements, they will be placed after the last
175
+ element in the article.
176
+
177
+ You can pass any type of element into this method.
178
+
179
+ If the objects you pass in are instances of elements defined within this gem (e.g. `ArticleJSON::Elements::Image`), you won't have to do anything else to render them.
180
+
129
181
  If you pass in an instance of a custom class (e.g. `MyAdvertisement`), make sure to register an exporter for this type (check the _Configuration_ section for more details).
130
182
 
131
183
  Example using only existing elements:
184
+
132
185
  ```ruby
133
186
  # Create your article instance as you normally do
134
187
  article = ArticleJSON::Article.from_hash(parsed_json)
135
188
 
136
189
  # Within your code, create additional elements you would like to add
137
- image_advertisement =
138
- ArticleJSON::Elements::Image.new(source_url: 'https://robohash.org/great-ad',
190
+ image_advertisement =
191
+ ArticleJSON::Elements::Image.new(source_url: 'https://robohash.org/great-ad',
139
192
  caption: ArticleJSON::Elements::Text.new(
140
193
  content: 'Buy more robots!',
141
194
  href: '/robot-sale'
142
195
  ))
143
- text_box_similar_articles =
196
+ text_box_similar_articles =
144
197
  ArticleJSON::Elements::TextBox.new(content: [
145
- ArticleJSON::Elements::Heading.new(level: 3, content: 'Read more...'),
198
+ ArticleJSON::Elements::Heading.new(level: 3, content: 'Read more...'),
146
199
  ArticleJSON::Elements::List.new(content: [
147
200
  ArticleJSON::Elements::Paragraph(content: [
148
- ArticleJSON::Elements::Text.new(content: 'Very similar article',
201
+ ArticleJSON::Elements::Text.new(content: 'Very similar article',
149
202
  href: '/news/123'),
150
203
  ]),
151
204
  ArticleJSON::Elements::Paragraph(content: [
152
- ArticleJSON::Elements::Text.new(content: 'Great article!',
205
+ ArticleJSON::Elements::Text.new(content: 'Great article!',
153
206
  href: '/news/42'),
154
207
  ]),
155
- ]),
208
+ ]),
156
209
  ])
157
210
 
158
211
  # Add these elements to the article
159
- article.place_additional_elements([image_advertisement,
212
+ article.place_additional_elements([image_advertisement,
160
213
  text_box_similar_articles])
161
-
162
- # Export the article to the different formats as you would normally do
214
+
215
+ # Export the article to the different formats as you would normally do
163
216
  article.to_html # this will now include the custom elements
164
- ```
217
+ ```
165
218
 
166
219
  Example with custom advertisement elements:
220
+
167
221
  ```ruby
168
222
  # Define your custom element class
169
223
  class MyAdvertisement
170
224
  attr_reader :url
171
-
225
+
172
226
  def initialize(url:)
173
227
  @url = url
174
228
  end
175
-
229
+
176
230
  def type
177
231
  :my_advertisement
178
232
  end
@@ -180,9 +234,9 @@ end
180
234
 
181
235
  # Define an exporter for your class, we only use HTML in this example but this
182
236
  # would work similarly for AMP or other formats
183
- class MyAdvertisementExporter <
184
- ArticleJSON::Export::HTML::Elements::Base
185
-
237
+ class MyAdvertisementExporter <
238
+ ArticleJSON::Export::HTML::Elements::Base
239
+
186
240
  # Needs to implement the `#export` method
187
241
  def export
188
242
  create_element(:iframe, src: @element.url)
@@ -208,62 +262,56 @@ article.to_html
208
262
  ```
209
263
 
210
264
  ## Export
265
+
211
266
  ### HTML
212
- The HTML exporter generates a HTML string for a list of elements. An example of
213
- the HTML export for the parsed reference document can be found
214
- [here](https://github.com/Devex/article_json/blob/master/spec/fixtures/reference_document_exported.html).
267
+
268
+ The HTML exporter generates an HTML string for a list of elements. An example of the HTML export for the parsed reference document can be found [here](https://github.com/Devex/article_json/blob/master/spec/fixtures/reference_document_exported.html).
215
269
 
216
270
  ### AMP
217
- The AMP exporter generates an AMP HTML representation of the elements.
218
271
 
219
- AMP uses [custom HTML tags](https://www.ampproject.org/docs/reference/components), some of which require additional Javascript libraries.
220
- If you have an `article` (see code example in _Usage_ section), you can get a list of the custom tags required by this article by calling `article.amp_exporter.custom_element_tags` and by calling `article.amp_exporter.amp_libraries` you get a list of `<script>` tags that can directly be included on your page to render the AMP article.
272
+ The AMP exporter generates an AMP HTML representation of the elements.
221
273
 
222
- An example of
223
- the AMP HTML export for the parsed reference document can be found
224
- [here](https://github.com/Devex/article_json/blob/master/spec/fixtures/reference_document_exported.amp.html).
274
+ AMP uses [custom HTML tags](https://www.ampproject.org/docs/reference/components), some of which require additional Javascript libraries.
225
275
 
226
- ### Facebook Instant Articles
227
- The `FacebookInstantArticle` exporter generates a custom HTML string for a list
228
- of elements. An example of the Facebook Instant Article export for the parsed
229
- reference document can be found
230
- [here](https://github.com/Devex/article_json/blob/master/spec/fixtures/reference_document_exported.html).
276
+ If you have an `article` (see code example in _Usage_ section), you can get a list of the custom tags required by this article by calling `article.amp_exporter.custom_element_tags` and calling `article.amp_exporter.amp_libraries` gives a list of `<script>` tags that can directly be included on your page to render the AMP article.
231
277
 
232
- To learn more about the Facebook Instant Article HTML format see have a look at
233
- the [Facebook Developer Documentation](https://developers.facebook.com/docs/instant-articles/guides/format-overview).
278
+ An example of the AMP HTML export for the parsed reference document can be found [here](https://github.com/Devex/article_json/blob/master/spec/fixtures/reference_document_exported.amp.html).
234
279
 
235
280
  ### Plain Text
236
- As the name suggests, this exporter generates a plain text version of the article.
237
- Rich text elements like images, embeds or even text boxes are not being rendered.
238
281
 
239
- The reference document rendered as plain text can be found
240
- [here](https://github.com/Devex/article_json/blob/master/spec/fixtures/reference_document_exported.txt).
282
+ As the name suggests, this exporter generates a plain text version of the article. Rich text elements like images, embeds or even text boxes are not being rendered.
283
+
284
+ The reference document rendered as plain text can be found [here](https://github.com/Devex/article_json/blob/master/spec/fixtures/reference_document_exported.txt).
241
285
 
242
286
  Usage:
287
+
243
288
  ```ruby
244
289
  # Create your article instance as you normally do
245
290
  article = ArticleJSON::Article.from_hash(parsed_json)
246
291
 
247
292
  # Then simply call `#to_plain_text` on it
248
- article.to_plain_text
293
+ article.to_plain_text
249
294
  ```
250
295
 
251
296
  ## Contributing
297
+
252
298
  - Fork this repository
253
- - Implement your feature or fix including Tests
299
+ - Implement your feature or fix including tests
254
300
  - Update the [change log](CHANGELOG.md)
255
301
  - Commit your changes with a meaningful commit message
256
302
  - Create a pull request
257
303
 
258
304
  Thank you!
259
305
 
260
- See the
306
+ See the
261
307
  [list of contributors](https://github.com/Devex/article_json/contributors).
262
308
 
263
- ### Tests
309
+ ## Tests
310
+
264
311
  For the whole test suite, run `bundle exec rspec`.
265
312
 
266
313
  For individual tests, run `bundle exec rspec spec/article_json/version_spec.rb`.
267
314
 
268
315
  ## License
316
+
269
317
  MIT License, see the [license file](LICENSE).
@@ -10,5 +10,6 @@
10
10
  #
11
11
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
12
12
 
13
+ require 'bundler/setup'
13
14
  require_relative '../lib/article_json'
14
15
  puts ArticleJSON::Article.from_json(ARGF.read).to_amp
@@ -2,14 +2,14 @@
2
2
 
3
3
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
4
4
  #
5
- # Simple script to read a JSON document and export it to Facebook Instant
6
- # Article.
5
+ # Simple script to read a JSON document and export it to Apple News.
7
6
  #
8
7
  # Usage:
9
8
  #
10
- # ./bin/article_json_export_facebook.rb < my_document.json
9
+ # ./bin/article_json_export_apple_news.rb < my_document.json
11
10
  #
12
11
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
13
12
 
13
+ require 'bundler/setup'
14
14
  require_relative '../lib/article_json'
15
- puts ArticleJSON::Article.from_json(ARGF.read).to_facebook_instant_article
15
+ puts ArticleJSON::Article.from_json(ARGF.read).to_apple_news
@@ -10,5 +10,6 @@
10
10
  #
11
11
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
12
12
 
13
+ require 'bundler/setup'
13
14
  require_relative '../lib/article_json'
14
15
  puts ArticleJSON::Article.from_json(ARGF.read).to_html
@@ -10,5 +10,6 @@
10
10
  #
11
11
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
12
12
 
13
+ require 'bundler/setup'
13
14
  require_relative '../lib/article_json'
14
15
  puts ArticleJSON::Article.from_json(ARGF.read).to_plain_text
@@ -10,5 +10,6 @@
10
10
  #
11
11
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
12
12
 
13
+ require 'bundler/setup'
13
14
  require_relative '../lib/article_json'
14
15
  puts ArticleJSON::Article.from_google_doc_html((ARGF.read)).to_json
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
4
+ #
5
+ # Script to check that google doc export works as expected.
6
+ #
7
+ # Usage:
8
+ #
9
+ # ./bin/check_google_doc_export.rb
10
+ #
11
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
12
+
13
+ require 'bundler/setup'
14
+ require 'net/http'
15
+ require 'uri'
16
+ require_relative '../lib/article_json'
17
+
18
+ doc_id = '1E4lncZE2jDkbE34eDyYQmXKA9O26BHUiwguz4S9qyE8'
19
+ url =
20
+ "https://docs.google.com/feeds/download/documents/export/Export?id=#{doc_id}&exportFormat=html"
21
+ parsed_exported_doc = JSON.parse(
22
+ ArticleJSON::Article
23
+ .from_google_doc_html(Net::HTTP.get(URI.parse(url)))
24
+ .to_json
25
+ )
26
+ parsed_expected_doc = JSON.parse(File.read('spec/fixtures/reference_document_parsed.json'))
27
+
28
+ # `source_url` (for hosted images) is dynamic, so we need to remove it from the comparison`
29
+ def nullify_source_url(hash)
30
+ hash['content'].each { |element| element['source_url'] = nil if element['source_url'] }
31
+ hash
32
+ end
33
+
34
+ parsed_exported_doc = nullify_source_url(parsed_exported_doc)
35
+ parsed_expected_doc = nullify_source_url(parsed_expected_doc)
36
+
37
+ if parsed_exported_doc != parsed_expected_doc
38
+ raise StandardError, "Google doc export doesn't work as expected"
39
+ end
40
+
41
+ puts 'Google doc export worked as expected'
@@ -2,12 +2,10 @@
2
2
 
3
3
  curl -X GET "https://vimeo.com/api/oembed.json?url=https://vimeo.com/42315417" | jq > spec/fixtures/vimeo_video_oembed.json
4
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
5
+ curl -X GET "https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/watch?v=_ZG8HBuDjgc" | jq > spec/fixtures/youtube_video_oembed.json
6
6
 
7
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
8
 
9
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
10
 
11
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
@@ -8,7 +8,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
10
  AMP_EXPORT_FILE="spec/fixtures/reference_document_exported.amp.html"
11
- FACEBOOK_EXPORT_FILE="spec/fixtures/reference_document_exported.facebook.html"
11
+ APPLE_NEWS_EXPORT_FILE="spec/fixtures/reference_document_exported.apple_news.json"
12
12
  PLAIN_TEXT_EXPORT_FILE="spec/fixtures/reference_document_exported.txt"
13
13
 
14
14
  # export the google doc to HTML
@@ -23,8 +23,8 @@ PLAIN_TEXT_EXPORT_FILE="spec/fixtures/reference_document_exported.txt"
23
23
  # convert the JSON export to AMP
24
24
  ./bin/article_json_export_amp.rb < ${JSON_FILE} > ${AMP_EXPORT_FILE}
25
25
 
26
- # convert the JSON export to Facebook Instant Article
27
- ./bin/article_json_export_facebook.rb < ${JSON_FILE} > ${FACEBOOK_EXPORT_FILE}
26
+ # convert the JSON export to Apple News
27
+ ./bin/article_json_export_apple_news.rb < ${JSON_FILE} > ${APPLE_NEWS_EXPORT_FILE}
28
28
 
29
29
  # convert the JSON export to plain text
30
30
  ./bin/article_json_export_plain_text.rb < ${JSON_FILE} > ${PLAIN_TEXT_EXPORT_FILE}