Skip to content

Commit

Permalink
Complete work on Facebook Instant Article exporter
Browse files Browse the repository at this point in the history
Therefore, add convenience methods to `ArticleJSON::Article` class and
update README.md and CHANGELOG.md accordingly.
  • Loading branch information
nicolas-fricke committed Nov 21, 2017
1 parent 3be44e0 commit a9b4057
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## WIP
- Start work on Facebook Instant Article exporter
- Add an exporter for Facebook Instant Articles
- Add support to exporters for `caption` elements that are an empty array
- GDoc Importer: Support `[no-caption]` text, returns empty caption for element
- Fix AMP export of Twitter tweets
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ puts article.to_amp
# get javascript libraries needed for the AMP article
puts article.amp_exporter.amp_libraries

# export article as Facebook Instant Article HTML
puts article.to_facebook_instant_article

# export article as plain text
puts article.to_plain_text

# export article as JSON
puts article.to_json
```
Expand Down Expand Up @@ -77,9 +83,10 @@ ArticleJSON.configure do |config|
image: ArticleJSON::Export::HTML::Elements::ScaledImage
)

# It works the same way for custom AMP exporters:
# It works the same way for custom AMP, FacebookInstantArticle, or
# PlainText exporters:
config.register_element_exporters(
:amp,
:amp, # Or change this for `:facebook_instant_article` or `:plain_text`
image: ArticleJSON::Export::AMP::Elements::ScaledImage
)
end
Expand Down Expand Up @@ -201,6 +208,15 @@ 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).

### Facebook Instant Articles
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).

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).

### Plain Text
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.
Expand Down
12 changes: 12 additions & 0 deletions lib/article_json/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ def to_amp
amp_exporter.html
end

# Exporter instance for FacebookInstantArticle
# @return [ArticleJSON::Export::FacebookInstantArticle::Exporter]
def facebook_instant_article_exporter
ArticleJSON::Export::FacebookInstantArticle::Exporter.new(elements)
end

# FacebookInstantArticle export of the article
# @return [String]
def to_facebook_instant_article
facebook_instant_article_exporter.html
end

# Exporter instance for plain text
# @return [ArticleJSON::Export::PlainText::Exporter]
def plain_text_exporter
Expand Down
11 changes: 11 additions & 0 deletions spec/article_json/article_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@
it { should eq '<p>Foo Bar</p>' }
end

describe '#facebook_instant_article_exporter' do
subject { article.facebook_instant_article_exporter }
it { should be_a ArticleJSON::Export::FacebookInstantArticle::Exporter }
end

describe '#to_facebook_instant_article' do
subject { article.to_facebook_instant_article }
it { should be_a String }
it { should eq '<p>Foo Bar</p>' }
end

describe '#plain_text_exporter' do
subject { article.plain_text_exporter }
it { should be_a ArticleJSON::Export::PlainText::Exporter }
Expand Down

0 comments on commit a9b4057

Please sign in to comment.