Implement Unified Embeds for Jsitor URLs (#16250)
* Complete implementation and add specs * update regex
This commit is contained in:
parent
2522b924e6
commit
659806b754
2 changed files with 10 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue