article_json 0.4.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -1
- data/README.md +30 -18
- data/bin/update_reference_document.sh +0 -4
- data/lib/article_json/article.rb +0 -12
- data/lib/article_json/configuration.rb +4 -4
- data/lib/article_json/elements/heading.rb +0 -1
- data/lib/article_json/elements/image.rb +0 -1
- data/lib/article_json/elements/list.rb +0 -1
- data/lib/article_json/elements/paragraph.rb +1 -1
- data/lib/article_json/elements/quote.rb +0 -1
- data/lib/article_json/elements/text.rb +1 -1
- data/lib/article_json/elements/text_box.rb +0 -1
- data/lib/article_json/export/amp/custom_element_library_resolver.rb +0 -1
- data/lib/article_json/export/amp/elements/embed.rb +42 -30
- data/lib/article_json/export/amp/elements/image.rb +7 -5
- data/lib/article_json/export/amp/exporter.rb +4 -2
- data/lib/article_json/export/apple_news/elements/embed.rb +1 -1
- data/lib/article_json/export/apple_news/elements/image.rb +2 -1
- data/lib/article_json/export/apple_news/elements/paragraph.rb +1 -1
- data/lib/article_json/export/apple_news/elements/text.rb +15 -2
- data/lib/article_json/export/apple_news/exporter.rb +1 -1
- data/lib/article_json/export/common/html/elements/embed.rb +2 -1
- data/lib/article_json/export/common/html/elements/image.rb +2 -1
- data/lib/article_json/export/common/html/elements/text.rb +2 -0
- data/lib/article_json/import/google_doc/html/embedded_parser.rb +1 -0
- data/lib/article_json/import/google_doc/html/heading_parser.rb +5 -5
- data/lib/article_json/import/google_doc/html/image_parser.rb +2 -0
- data/lib/article_json/import/google_doc/html/list_parser.rb +2 -2
- data/lib/article_json/import/google_doc/html/node_analyzer.rb +14 -2
- data/lib/article_json/import/google_doc/html/parser.rb +1 -0
- data/lib/article_json/import/google_doc/html/shared/caption.rb +1 -0
- data/lib/article_json/import/google_doc/html/shared/float.rb +2 -0
- data/lib/article_json/import/google_doc/html/text_box_parser.rb +2 -1
- data/lib/article_json/import/google_doc/html/text_parser.rb +2 -0
- data/lib/article_json/utils/additional_element_placer.rb +2 -0
- data/lib/article_json/utils/o_embed_resolver/base.rb +14 -4
- data/lib/article_json/utils/o_embed_resolver/facebook_video.rb +1 -1
- data/lib/article_json/utils/o_embed_resolver/slideshare.rb +2 -2
- data/lib/article_json/utils/o_embed_resolver/youtube_video.rb +13 -0
- data/lib/article_json/version.rb +1 -1
- data/lib/article_json.rb +0 -11
- metadata +3 -18
- data/bin/article_json_export_facebook.rb +0 -16
- data/lib/article_json/export/facebook_instant_article/elements/base.rb +0 -30
- data/lib/article_json/export/facebook_instant_article/elements/embed.rb +0 -44
- data/lib/article_json/export/facebook_instant_article/elements/heading.rb +0 -11
- data/lib/article_json/export/facebook_instant_article/elements/image.rb +0 -11
- data/lib/article_json/export/facebook_instant_article/elements/list.rb +0 -11
- data/lib/article_json/export/facebook_instant_article/elements/paragraph.rb +0 -11
- data/lib/article_json/export/facebook_instant_article/elements/quote.rb +0 -30
- data/lib/article_json/export/facebook_instant_article/elements/text.rb +0 -11
- data/lib/article_json/export/facebook_instant_article/elements/text_box.rb +0 -40
- 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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7bf4d22d73f1d9380b282867e7f55ac90aae0cacbf235f26c3aaee678e4adfc5
|
|
4
|
+
data.tar.gz: 250276366fce15b87e51cd62f05d53b90eaff29949c6681b9962b0ccdb127a16
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5915080736fd29499a73f73cdb39d5e3f1af1c54da3a6a114be2a546de35f1d7824da407d76eac255e2b38eee00040dc3534a78a702e78eebbc025bab666b82b
|
|
7
|
+
data.tar.gz: fa283f7167ca908145d6c2b2420865e9b08ca91fbe9a417bf20713eda2e02fe10e3664bbbc22e8718c3c5676dbc8ed61861dc15b367089a491ce3cd7991535f8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
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
|
+
|
|
2
8
|
## 0.4.0 - 2024/01/17
|
|
9
|
+
|
|
3
10
|
In this fourth release we **added support for Apple News**:
|
|
4
11
|
**New**:
|
|
5
12
|
Support for Apple News Format, specifically the following elements:
|
|
13
|
+
|
|
6
14
|
- text
|
|
7
15
|
- text boxes
|
|
8
16
|
- lists
|
|
@@ -17,13 +25,15 @@ Support for Ruby 3.2
|
|
|
17
25
|
Support for Ruby 2.3
|
|
18
26
|
|
|
19
27
|
**Refactoring**:
|
|
28
|
+
|
|
20
29
|
- Rubocop autocorrections
|
|
21
30
|
|
|
22
31
|
**Fix:**
|
|
23
|
-
- Fix failing rspec tests
|
|
24
32
|
|
|
33
|
+
- Fix failing rspec tests
|
|
25
34
|
|
|
26
35
|
## 0.3.8 - 2020/7/31
|
|
36
|
+
|
|
27
37
|
- **Improvements:**
|
|
28
38
|
- Add a script to update oembed stubs fixtures.
|
|
29
39
|
- Support for `alt` attribute in images.
|
|
@@ -31,65 +41,84 @@ Support for Ruby 2.3
|
|
|
31
41
|
- **Fix:** Fix a bug when using the `[image-link-to: ]` tag.
|
|
32
42
|
|
|
33
43
|
## 0.3.7 - 2019/8/21
|
|
44
|
+
|
|
34
45
|
- **Fix:** Only use https for soundcloud oembed api
|
|
35
46
|
|
|
36
47
|
## 0.3.6 - 2019/8/6
|
|
48
|
+
|
|
37
49
|
- **Improvement** Add tags support in text_box element.
|
|
38
50
|
|
|
39
51
|
## 0.3.5 - 2018/12/12
|
|
52
|
+
|
|
40
53
|
- **Improvements** to import and export image links from Google Docs
|
|
41
54
|
- Import image `href` from caption text using a custom tag
|
|
42
55
|
- Export the image element href attribute as a link
|
|
43
56
|
|
|
44
57
|
## 0.3.4 - 2018/5/10
|
|
58
|
+
|
|
45
59
|
- **Fix:** Only include slug from the soundcloud URL in google doc parser
|
|
46
60
|
|
|
47
61
|
## 0.3.3 - 2018/4/12
|
|
62
|
+
|
|
48
63
|
- Support embedding SoundCloud
|
|
49
64
|
|
|
50
65
|
## 0.3.2 - 2017/12/06
|
|
66
|
+
|
|
51
67
|
- Another **fix** to prevent `nil` elements when placing additional elements on articles that end with empty paragraphs
|
|
52
68
|
|
|
53
69
|
## 0.3.1 - 2017/11/29
|
|
70
|
+
|
|
54
71
|
- **Fix:** prevent `nil` elements when placing additional element on empty articles
|
|
55
72
|
|
|
56
73
|
## 0.3.0 - 2017/11/21
|
|
74
|
+
|
|
57
75
|
In this third bigger release we **added support**:
|
|
76
|
+
|
|
58
77
|
- For exporting articles in the Facebook Instant Article format
|
|
59
78
|
- For exporting articles in a plain text format
|
|
60
79
|
- To all exporters for `caption` elements that are an empty array
|
|
61
80
|
- For `[no-caption]` text in _Google Documents_ below elements (like images or embed URLs), this now returns empty caption for element
|
|
62
81
|
|
|
63
82
|
**Improvements** were done regarding additional element placement:
|
|
83
|
+
|
|
64
84
|
- Rework algorithm to place additional elements to better support placing a single element
|
|
65
85
|
- Improve behavior of multiple calls to `Article#place_additional_elements`
|
|
66
86
|
|
|
67
87
|
One potentially **breaking change** was added:
|
|
88
|
+
|
|
68
89
|
- Remove deprecated `#register_html_element_exporter`, use `#register_element_exporters` instead
|
|
69
90
|
|
|
70
91
|
**Fixes**:
|
|
92
|
+
|
|
71
93
|
- Fix AMP export of Twitter tweets
|
|
72
94
|
|
|
73
95
|
## 0.2.1 - 2017/11/08
|
|
96
|
+
|
|
74
97
|
**Fix**: Handle non-successful OEmbed responses by rendering message
|
|
75
98
|
|
|
76
99
|
## 0.2.0 - 2017/11/03
|
|
100
|
+
|
|
77
101
|
In this second release we **added support** to:
|
|
102
|
+
|
|
78
103
|
- Export AMP along with required libraries for AMP rendering
|
|
79
104
|
- Configure custom HTML and AMP element exporters
|
|
80
105
|
- Resolve oembed elements in HTML export
|
|
81
106
|
|
|
82
107
|
One potentially **breaking change** was added:
|
|
108
|
+
|
|
83
109
|
- Export quotes as `<div>` instead of `<aside>`
|
|
84
110
|
|
|
85
111
|
**Fixes**:
|
|
112
|
+
|
|
86
113
|
- Support Vimeo videos with old flash player URLs
|
|
87
114
|
- Make Google Parser more fault tolerant
|
|
88
115
|
- Respect linebreaks when importing Google Docs
|
|
89
116
|
- Export linebreaks in JSON to `<br>` tags in HTML / AMP
|
|
90
117
|
|
|
91
118
|
## 0.1.0 - 2017/09/20
|
|
119
|
+
|
|
92
120
|
This is the very first release, with the following functionality:
|
|
121
|
+
|
|
93
122
|
- article-json format that supports several basic elements; like headings,
|
|
94
123
|
paragraphs, images or lists
|
|
95
124
|
- Resolving of embedded elements like videos or tweets via OEmbed standard
|
data/README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# article_json
|
|
2
|
+
|
|
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.
|
|
3
4
|
|
|
4
5
|
It takes an article from a Google Doc and creates a JSON version of it.
|
|
5
6
|
|
|
6
7
|
From there it can export the article:
|
|
8
|
+
|
|
7
9
|
- as HTML
|
|
8
10
|
- as AMP
|
|
9
11
|
- as Apple News Format (ANF)
|
|
10
|
-
- as Facebook Instant Article HTML
|
|
11
12
|
- as plain text
|
|
12
13
|
- as JSON
|
|
13
14
|
|
|
@@ -16,6 +17,7 @@ It also provides functionalities to parse content from Google Document HTML expo
|
|
|
16
17
|
---
|
|
17
18
|
|
|
18
19
|
## Status
|
|
20
|
+
|
|
19
21
|
[](https://badge.fury.io/rb/article_json)
|
|
20
22
|
[](https://github.com/Devex/article_json/actions/workflows/check-google-doc.yml)
|
|
21
23
|
[](https://github.com/Devex/article_json/actions/workflows/rspec.yml)
|
|
@@ -23,10 +25,12 @@ It also provides functionalities to parse content from Google Document HTML expo
|
|
|
23
25
|
[](https://coveralls.io/github/Devex/article_json?branch=master)
|
|
24
26
|
|
|
25
27
|
## Usage
|
|
28
|
+
|
|
26
29
|
First, install the gem with `gem install article_json` or add it to your Gemfile
|
|
27
30
|
via `gem 'article_json'`.
|
|
28
31
|
|
|
29
32
|
### Ruby
|
|
33
|
+
|
|
30
34
|
```ruby
|
|
31
35
|
require 'article_json'
|
|
32
36
|
|
|
@@ -50,9 +54,6 @@ puts article.amp_exporter.amp_libraries
|
|
|
50
54
|
# export article as Apple News Format (ANF)
|
|
51
55
|
puts article.to_apple_news
|
|
52
56
|
|
|
53
|
-
# export article as Facebook Instant Article HTML
|
|
54
|
-
puts article.to_facebook_instant_article
|
|
55
|
-
|
|
56
57
|
# export article as plain text
|
|
57
58
|
puts article.to_plain_text
|
|
58
59
|
|
|
@@ -61,7 +62,8 @@ puts article.to_json
|
|
|
61
62
|
```
|
|
62
63
|
|
|
63
64
|
### CLI
|
|
64
|
-
|
|
65
|
+
|
|
66
|
+
To load, parse and export the latest (amp / apple news / html) version of the reference document, run the following:
|
|
65
67
|
|
|
66
68
|
```bash
|
|
67
69
|
$ export DOC_ID=1E4lncZE2jDkbE34eDyYQmXKA9O26BHUiwguz4S9qyE8
|
|
@@ -71,11 +73,11 @@ $ ./bin/article_json_export_google_doc.rb $DOC_ID \
|
|
|
71
73
|
## OR
|
|
72
74
|
# | ./bin/article_json_export_amp.rb
|
|
73
75
|
# | ./bin/article_json_export_apple_news.rb
|
|
74
|
-
# | ./bin/article_json_export_facebook.rb
|
|
75
76
|
# | ./bin/article_json_export_plain_text.rb
|
|
76
77
|
```
|
|
77
78
|
|
|
78
79
|
Alternatively, you can concatenate your command line commands, like so:
|
|
80
|
+
|
|
79
81
|
```bash
|
|
80
82
|
$ ./bin/article_json_export_google_doc.rb $DOC_ID > test_ref_doc.html
|
|
81
83
|
$ cat test_ref_doc.html | bin/article_json_parse_google_doc.rb > \
|
|
@@ -84,10 +86,10 @@ $ cat test_ref_doc_parsed_apple.json | bin/article_json_export_apple_news.rb > \
|
|
|
84
86
|
test_ref_doc_exported_apple.json
|
|
85
87
|
```
|
|
86
88
|
|
|
87
|
-
You can also update _all_ the different exported versions of the reference document _(amp, apple_news,
|
|
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:
|
|
88
90
|
|
|
89
91
|
```
|
|
90
|
-
|
|
92
|
+
./bin/update_reference_document.sh
|
|
91
93
|
```
|
|
92
94
|
|
|
93
95
|
When running the tests, we use some fixtures to mock the responses for oembed requests, but these may change over time.
|
|
@@ -95,10 +97,11 @@ When running the tests, we use some fixtures to mock the responses for oembed re
|
|
|
95
97
|
To update them, run:
|
|
96
98
|
|
|
97
99
|
```
|
|
98
|
-
|
|
100
|
+
./bin/update_oembed_request-stubs.sh
|
|
99
101
|
```
|
|
100
102
|
|
|
101
103
|
### Configuration
|
|
104
|
+
|
|
102
105
|
Some configuration options allow a more tailored usage of the `article_json` gem.
|
|
103
106
|
|
|
104
107
|
The following code snippet gives an example for every available setting:
|
|
@@ -128,17 +131,17 @@ ArticleJSON.configure do |config|
|
|
|
128
131
|
image: ArticleJSON::Export::HTML::Elements::ScaledImage
|
|
129
132
|
)
|
|
130
133
|
|
|
131
|
-
# It works the same way for custom AMP,
|
|
132
|
-
# exporters:
|
|
134
|
+
# It works the same way for custom AMP, Apple News, or PlainText exporters:
|
|
133
135
|
config.register_element_exporters(
|
|
134
|
-
:amp, # Or change this for `:
|
|
136
|
+
:amp, # Or change this for `:apple_news` or `:plain_text`
|
|
135
137
|
image: ArticleJSON::Export::AMP::Elements::ScaledImage
|
|
136
138
|
)
|
|
137
139
|
end
|
|
138
140
|
```
|
|
139
141
|
|
|
140
142
|
### Facebook Oembed
|
|
141
|
-
|
|
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).
|
|
142
145
|
|
|
143
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:
|
|
144
147
|
|
|
@@ -153,13 +156,17 @@ end
|
|
|
153
156
|
Find more info about the access token [here](https://developers.facebook.com/docs/plugins/oembed#access-tokens).
|
|
154
157
|
|
|
155
158
|
## Format
|
|
159
|
+
|
|
156
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.
|
|
157
161
|
|
|
158
162
|
## Import
|
|
163
|
+
|
|
159
164
|
### Google Document Parser
|
|
165
|
+
|
|
160
166
|
This [reference document](https://docs.google.com/document/d/1E4lncZE2jDkbE34eDyYQmXKA9O26BHUiwguz4S9qyE8/editusp=sharing) contains all the supported formatting along with some descriptions.
|
|
161
167
|
|
|
162
168
|
## Add custom elements
|
|
169
|
+
|
|
163
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.
|
|
164
171
|
|
|
165
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.
|
|
@@ -174,6 +181,7 @@ If the objects you pass in are instances of elements defined within this gem (e.
|
|
|
174
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).
|
|
175
182
|
|
|
176
183
|
Example using only existing elements:
|
|
184
|
+
|
|
177
185
|
```ruby
|
|
178
186
|
# Create your article instance as you normally do
|
|
179
187
|
article = ArticleJSON::Article.from_hash(parsed_json)
|
|
@@ -209,6 +217,7 @@ article.to_html # this will now include the custom elements
|
|
|
209
217
|
```
|
|
210
218
|
|
|
211
219
|
Example with custom advertisement elements:
|
|
220
|
+
|
|
212
221
|
```ruby
|
|
213
222
|
# Define your custom element class
|
|
214
223
|
class MyAdvertisement
|
|
@@ -253,10 +262,13 @@ article.to_html
|
|
|
253
262
|
```
|
|
254
263
|
|
|
255
264
|
## Export
|
|
265
|
+
|
|
256
266
|
### HTML
|
|
267
|
+
|
|
257
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).
|
|
258
269
|
|
|
259
270
|
### AMP
|
|
271
|
+
|
|
260
272
|
The AMP exporter generates an AMP HTML representation of the elements.
|
|
261
273
|
|
|
262
274
|
AMP uses [custom HTML tags](https://www.ampproject.org/docs/reference/components), some of which require additional Javascript libraries.
|
|
@@ -265,17 +277,14 @@ If you have an `article` (see code example in _Usage_ section), you can get a li
|
|
|
265
277
|
|
|
266
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).
|
|
267
279
|
|
|
268
|
-
### Facebook Instant Articles
|
|
269
|
-
The `FacebookInstantArticle` exporter generates a custom HTML string for a list of elements. An example of the Facebook Instant Article export for the parsed reference document can be found [here](https://github.com/Devex/article_json/blob/master/spec/fixtures/reference_document_exported.html).
|
|
270
|
-
|
|
271
|
-
To learn more about the Facebook Instant Article HTML format see have a look at the [Facebook Developer Documentation](https://developers.facebook.com/docs/instant-articles/guides/format-overview).
|
|
272
|
-
|
|
273
280
|
### Plain Text
|
|
281
|
+
|
|
274
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.
|
|
275
283
|
|
|
276
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).
|
|
277
285
|
|
|
278
286
|
Usage:
|
|
287
|
+
|
|
279
288
|
```ruby
|
|
280
289
|
# Create your article instance as you normally do
|
|
281
290
|
article = ArticleJSON::Article.from_hash(parsed_json)
|
|
@@ -285,6 +294,7 @@ article.to_plain_text
|
|
|
285
294
|
```
|
|
286
295
|
|
|
287
296
|
## Contributing
|
|
297
|
+
|
|
288
298
|
- Fork this repository
|
|
289
299
|
- Implement your feature or fix including tests
|
|
290
300
|
- Update the [change log](CHANGELOG.md)
|
|
@@ -297,9 +307,11 @@ See the
|
|
|
297
307
|
[list of contributors](https://github.com/Devex/article_json/contributors).
|
|
298
308
|
|
|
299
309
|
## Tests
|
|
310
|
+
|
|
300
311
|
For the whole test suite, run `bundle exec rspec`.
|
|
301
312
|
|
|
302
313
|
For individual tests, run `bundle exec rspec spec/article_json/version_spec.rb`.
|
|
303
314
|
|
|
304
315
|
## License
|
|
316
|
+
|
|
305
317
|
MIT License, see the [license file](LICENSE).
|
|
@@ -8,7 +8,6 @@ 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"
|
|
12
11
|
APPLE_NEWS_EXPORT_FILE="spec/fixtures/reference_document_exported.apple_news.json"
|
|
13
12
|
PLAIN_TEXT_EXPORT_FILE="spec/fixtures/reference_document_exported.txt"
|
|
14
13
|
|
|
@@ -24,9 +23,6 @@ PLAIN_TEXT_EXPORT_FILE="spec/fixtures/reference_document_exported.txt"
|
|
|
24
23
|
# convert the JSON export to AMP
|
|
25
24
|
./bin/article_json_export_amp.rb < ${JSON_FILE} > ${AMP_EXPORT_FILE}
|
|
26
25
|
|
|
27
|
-
# convert the JSON export to Facebook Instant Article
|
|
28
|
-
./bin/article_json_export_facebook.rb < ${JSON_FILE} > ${FACEBOOK_EXPORT_FILE}
|
|
29
|
-
|
|
30
26
|
# convert the JSON export to Apple News
|
|
31
27
|
./bin/article_json_export_apple_news.rb < ${JSON_FILE} > ${APPLE_NEWS_EXPORT_FILE}
|
|
32
28
|
|
data/lib/article_json/article.rb
CHANGED
|
@@ -74,18 +74,6 @@ module ArticleJSON
|
|
|
74
74
|
apple_news_exporter.to_json
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
# Exporter instance for FacebookInstantArticle
|
|
78
|
-
# @return [ArticleJSON::Export::FacebookInstantArticle::Exporter]
|
|
79
|
-
def facebook_instant_article_exporter
|
|
80
|
-
ArticleJSON::Export::FacebookInstantArticle::Exporter.new(elements)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# FacebookInstantArticle export of the article
|
|
84
|
-
# @return [String]
|
|
85
|
-
def to_facebook_instant_article
|
|
86
|
-
facebook_instant_article_exporter.html
|
|
87
|
-
end
|
|
88
|
-
|
|
89
77
|
# Exporter instance for plain text
|
|
90
78
|
# @return [ArticleJSON::Export::PlainText::Exporter]
|
|
91
79
|
def plain_text_exporter
|
|
@@ -31,7 +31,7 @@ module ArticleJSON
|
|
|
31
31
|
# @param [Symbol] exporter
|
|
32
32
|
# @param [Hash[Symbol => Class]] type_class_mapping
|
|
33
33
|
def register_element_exporters(exporter, type_class_mapping)
|
|
34
|
-
valid_exporters = %i(html amp
|
|
34
|
+
valid_exporters = %i(html amp apple_news plain_text)
|
|
35
35
|
unless valid_exporters.include?(exporter)
|
|
36
36
|
raise ArgumentError, '`exporter` needs to be one of ' \
|
|
37
37
|
"#{valid_exporters} but is `#{exporter.inspect}`"
|
|
@@ -39,8 +39,9 @@ module ArticleJSON
|
|
|
39
39
|
if !type_class_mapping.is_a?(Hash) ||
|
|
40
40
|
type_class_mapping.keys.any? { |key| !key.is_a? Symbol } ||
|
|
41
41
|
type_class_mapping.values.any? { |value| !value.is_a? Class }
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
|
|
43
|
+
raise ArgumentError, '`type_class_mapping` has to be a Hash with ' \
|
|
44
|
+
'symbolized keys and classes as values but is ' \
|
|
44
45
|
"`#{type_class_mapping.inspect}`"
|
|
45
46
|
end
|
|
46
47
|
|
|
@@ -57,4 +58,3 @@ module ArticleJSON
|
|
|
57
58
|
end
|
|
58
59
|
end
|
|
59
60
|
end
|
|
60
|
-
|
|
@@ -42,18 +42,22 @@ module ArticleJSON
|
|
|
42
42
|
|
|
43
43
|
# @return [Nokogiri::XML::Element]
|
|
44
44
|
def youtube_node
|
|
45
|
-
create_element(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
create_element(
|
|
46
|
+
'amp-youtube',
|
|
47
|
+
'data-videoid' => @element.embed_id,
|
|
48
|
+
width: default_width,
|
|
49
|
+
height: default_height
|
|
50
|
+
)
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
# @return [Nokogiri::XML::Element]
|
|
52
54
|
def vimeo_node
|
|
53
|
-
create_element(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
create_element(
|
|
56
|
+
'amp-vimeo',
|
|
57
|
+
'data-videoid' => @element.embed_id,
|
|
58
|
+
width: default_width,
|
|
59
|
+
height: default_height
|
|
60
|
+
)
|
|
57
61
|
end
|
|
58
62
|
|
|
59
63
|
# @return [Nokogiri::XML::Element]
|
|
@@ -61,42 +65,50 @@ module ArticleJSON
|
|
|
61
65
|
# The embed_id of a tweet is stored as "<handle>/<tweet_id>" but
|
|
62
66
|
# the `amp-twitter` tag only takes the `tweet_id` part
|
|
63
67
|
tweet_id = @element.embed_id.split('/').last
|
|
64
|
-
create_element(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
create_element(
|
|
69
|
+
'amp-twitter',
|
|
70
|
+
'data-tweetid': tweet_id,
|
|
71
|
+
width: default_width,
|
|
72
|
+
height: default_height
|
|
73
|
+
)
|
|
68
74
|
end
|
|
69
75
|
|
|
70
76
|
# @return [Nokogiri::XML::Element]
|
|
71
77
|
def facebook_node
|
|
72
78
|
url = "#{@element.oembed_data[:author_url]}/videos/#{@element.embed_id}"
|
|
73
|
-
create_element(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
create_element(
|
|
80
|
+
'amp-facebook',
|
|
81
|
+
'data-embedded-as' => 'video',
|
|
82
|
+
'data-href' => url,
|
|
83
|
+
width: default_width,
|
|
84
|
+
height: default_height
|
|
85
|
+
)
|
|
78
86
|
end
|
|
79
87
|
|
|
80
88
|
def soundcloud_node
|
|
81
89
|
src = Nokogiri::HTML(@element.oembed_data[:html])
|
|
82
|
-
|
|
83
|
-
track_id = src.match(
|
|
84
|
-
create_element(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
.xpath('//iframe/@src').first.value
|
|
91
|
+
track_id = src.match(%r{tracks%2F(\d+)})[1]
|
|
92
|
+
create_element(
|
|
93
|
+
'amp-soundcloud',
|
|
94
|
+
layout: 'fixed-height',
|
|
95
|
+
'data-trackid': track_id,
|
|
96
|
+
'data-visual': true,
|
|
97
|
+
width: 'auto',
|
|
98
|
+
height: default_height
|
|
99
|
+
)
|
|
90
100
|
end
|
|
91
101
|
|
|
92
102
|
# @return [Nokogiri::XML::Element]
|
|
93
103
|
def iframe_node
|
|
94
104
|
node = Nokogiri::HTML(@element.oembed_data[:html]).xpath('//iframe')
|
|
95
|
-
create_element(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
create_element(
|
|
106
|
+
'amp-iframe',
|
|
107
|
+
src: node.attribute('src').value,
|
|
108
|
+
width: node.attribute('width').value,
|
|
109
|
+
height: node.attribute('height').value,
|
|
110
|
+
frameborder: '0'
|
|
111
|
+
)
|
|
100
112
|
end
|
|
101
113
|
|
|
102
114
|
# @return [String]
|
|
@@ -9,11 +9,13 @@ module ArticleJSON
|
|
|
9
9
|
|
|
10
10
|
# @return [Nokogiri::HTML::NodeSet]
|
|
11
11
|
def image_node
|
|
12
|
-
create_element(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
create_element(
|
|
13
|
+
'amp-img',
|
|
14
|
+
src: @element.source_url,
|
|
15
|
+
width: default_width,
|
|
16
|
+
height: default_height,
|
|
17
|
+
layout: :responsive
|
|
18
|
+
)
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def default_width
|
|
@@ -8,10 +8,11 @@ module ArticleJSON
|
|
|
8
8
|
# @return [Array[Symbol]]
|
|
9
9
|
def custom_element_tags
|
|
10
10
|
return @custom_element_tags if defined? @custom_element_tags
|
|
11
|
+
|
|
11
12
|
@custom_element_tags =
|
|
12
13
|
element_exporters
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
.flat_map { |element| element.custom_element_tags }
|
|
15
|
+
.uniq
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
# Return an array with all the javascript libraries needed for some
|
|
@@ -19,6 +20,7 @@ module ArticleJSON
|
|
|
19
20
|
# @return [Array<String>]
|
|
20
21
|
def amp_libraries
|
|
21
22
|
return @amp_libraries if defined? @amp_libraries
|
|
23
|
+
|
|
22
24
|
@amp_libraries =
|
|
23
25
|
CustomElementLibraryResolver.new(custom_element_tags).script_tags
|
|
24
26
|
end
|
|
@@ -10,6 +10,7 @@ module ArticleJSON
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
private
|
|
13
|
+
|
|
13
14
|
# Image
|
|
14
15
|
# @return [Hash]
|
|
15
16
|
def image
|
|
@@ -48,7 +49,7 @@ module ArticleJSON
|
|
|
48
49
|
def text
|
|
49
50
|
@element.caption.map do |child_element|
|
|
50
51
|
text_exporter.new(child_element)
|
|
51
|
-
|
|
52
|
+
.export
|
|
52
53
|
end.join
|
|
53
54
|
end
|
|
54
55
|
end
|
|
@@ -6,8 +6,21 @@ module ArticleJSON
|
|
|
6
6
|
include ArticleJSON::Export::Common::HTML::Elements::Base
|
|
7
7
|
include ArticleJSON::Export::Common::HTML::Elements::Text
|
|
8
8
|
|
|
9
|
-
UNSUPPORTED_HTML_TAGS = %w[
|
|
10
|
-
|
|
9
|
+
UNSUPPORTED_HTML_TAGS = %w[
|
|
10
|
+
title
|
|
11
|
+
meta
|
|
12
|
+
script
|
|
13
|
+
noscript
|
|
14
|
+
style
|
|
15
|
+
link
|
|
16
|
+
applet
|
|
17
|
+
object
|
|
18
|
+
iframe
|
|
19
|
+
noframes
|
|
20
|
+
form
|
|
21
|
+
select
|
|
22
|
+
option
|
|
23
|
+
optgroup
|
|
11
24
|
].freeze
|
|
12
25
|
|
|
13
26
|
# A Nokogiri object is returned with`super`, which is is then
|