Skip to content

Commit

Permalink
FIX: better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
lis2 committed Jul 14, 2020
1 parent 9fba73a commit 920c320
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -75,7 +75,7 @@ Adding Support for a new URL
----------------------------

1. Check if the site supports [oEmbed](http://oembed.com/) or [Open Graph](https://developers.facebook.com/docs/opengraph/).
If it does, you can probably get away with just allowlisting the URL in `Onebox::Engine::AllowlistedGenericOnebox` (see: [Allowlisted Generic Onebox caveats](#user-content-allowlisted-generic-onebox-caveats)).
If it does, you can probably get away with just allowing the URL in `Onebox::Engine::AllowlistedGenericOnebox` (see: [Allowlisted Generic Onebox caveats](#user-content-allowlisted-generic-onebox-caveats)).
If the site does not support open standards, you can create a new engine.

2. Create new onebox engine
Expand Down
18 changes: 9 additions & 9 deletions lib/onebox/engine/allowlisted_generic_onebox.rb
Expand Up @@ -9,15 +9,15 @@ class AllowlistedGenericOnebox
include StandardEmbed
include LayoutSupport

def self.allowlist=(list)
@allowlist = list
def self.allowed_domains=(list)
@allowed_domains = list
end

def self.allowlist
@allowlist ||= default_allowlist.dup
def self.allowed_domains
@allowed_domains ||= default_allowed_domains.dup
end

def self.default_allowlist
def self.default_allowed_domains
%w(
23hq.com
500px.com
Expand Down Expand Up @@ -176,13 +176,13 @@ def self.probable_wordpress(uri)
!!(uri.path =~ /\d{4}\/\d{2}\//)
end

def self.twitter_label_allowlist
def self.allowed_twitter_labels
['brand', 'price', 'usd', 'cad', 'reading time', 'likes']
end

def self.===(other)
other.kind_of?(URI) ?
host_matches(other, allowlist) || probable_wordpress(other) || probable_discourse(other) :
host_matches(other, allowed_domains) || probable_wordpress(other) || probable_discourse(other) :
super
end

Expand Down Expand Up @@ -233,11 +233,11 @@ def data
end

# Twitter labels
if !Onebox::Helpers.blank?(d[:label1]) && !Onebox::Helpers.blank?(d[:data1]) && !!AllowlistedGenericOnebox.twitter_label_allowlist.find { |l| d[:label1] =~ /#{l}/i }
if !Onebox::Helpers.blank?(d[:label1]) && !Onebox::Helpers.blank?(d[:data1]) && !!AllowlistedGenericOnebox.allowed_twitter_labels.find { |l| d[:label1] =~ /#{l}/i }
d[:label_1] = Onebox::Helpers.truncate(d[:label1])
d[:data_1] = Onebox::Helpers.truncate(d[:data1])
end
if !Onebox::Helpers.blank?(d[:label2]) && !Onebox::Helpers.blank?(d[:data2]) && !!AllowlistedGenericOnebox.twitter_label_allowlist.find { |l| d[:label2] =~ /#{l}/i }
if !Onebox::Helpers.blank?(d[:label2]) && !Onebox::Helpers.blank?(d[:data2]) && !!AllowlistedGenericOnebox.allowed_twitter_labels.find { |l| d[:label2] =~ /#{l}/i }
unless Onebox::Helpers.blank?(d[:label_1])
d[:label_2] = Onebox::Helpers.truncate(d[:label2])
d[:data_2] = Onebox::Helpers.truncate(d[:data2])
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb
Expand Up @@ -6,7 +6,7 @@

describe ".===" do
before do
described_class.allowlist = %w(eviltrout.com discourse.org)
described_class.allowed_domains = %w(eviltrout.com discourse.org)
end

it "matches an entire domain" do
Expand Down Expand Up @@ -154,7 +154,7 @@ def generic_html
let(:redirect_link) { 'http://www.dailymail.co.uk/news/article-479146/Brutality-justice-The-truth-tarred-feathered-drug-dealer.html' }

before do
described_class.allowlist = %w(dailymail.co.uk discourse.org)
described_class.allowed_domains = %w(dailymail.co.uk discourse.org)
FakeWeb.register_uri(
:get,
original_link,
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox_spec.rb
Expand Up @@ -24,7 +24,7 @@ def expect_templates_to_not_match(text)

describe 'has_matcher?' do
before do
Onebox::Engine::AllowlistedGenericOnebox.allowlist = %w(youtube.com)
Onebox::Engine::AllowlistedGenericOnebox.allowed_domains = %w(youtube.com)
end

it "has no matcher for a made up url" do
Expand Down

0 comments on commit 920c320

Please sign in to comment.