Implement Unified Embeds for Jsitor URLs (#16250)

* Complete implementation and add specs

* update regex
This commit is contained in:
Arit Amana 2022-01-21 14:40:14 -05:00 committed by GitHub
parent 2522b924e6
commit 659806b754
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -1,7 +1,7 @@
class JsitorTag < LiquidTagBase
PARTIAL = "liquids/jsitor".freeze
URL_REGEXP = %r{\A(https|http)://jsitor\.com/embed/\w+[-?a-zA-Z&]*\Z}
ID_REGEXP = /\A[\w&?-]+\Z/
REGISTRY_REGEXP = %r{\A(https|http)://jsitor\.com/embed/[\w\-?&]+\Z}
ID_REGEXP = /\A[\w\-?&]+\Z/
def initialize(_tag_name, link, _parse_context)
super
@ -26,7 +26,7 @@ class JsitorTag < LiquidTagBase
end
def validate_link(link)
return link if URL_REGEXP.match link
return link if REGISTRY_REGEXP.match link
return "https://jsitor.com/embed/#{link}" if ID_REGEXP.match link
jsitor_error
@ -38,3 +38,5 @@ class JsitorTag < LiquidTagBase
end
Liquid::Template.register_tag("jsitor", JsitorTag)
UnifiedEmbed.register(JsitorTag, regexp: JsitorTag::REGISTRY_REGEXP)

View file

@ -116,6 +116,11 @@ RSpec.describe UnifiedEmbed::Registry do
.to eq(JsFiddleTag)
end
it "returns JsitorTag for a jsitor url" do
expect(described_class.find_liquid_tag_for(link: "https://jsitor.com/embed/B7FQ5tHbY"))
.to eq(JsitorTag)
end
it "returns Forem Link for a forem url" do
expect(described_class.find_liquid_tag_for(link: URL.url + article.path))
.to eq(LinkTag)