Files
once-campfire/lib/rails_ext/actiontext_opengraph_embeds.rb
Kevin McConnell df76a227dc Hello world
First open source release of Campfire 🎉
2025-08-21 09:31:59 +01:00

45 lines
1018 B
Ruby

class ActionText::Attachment::OpengraphEmbed
include ActiveModel::Model
OPENGRAPH_EMBED_CONTENT_TYPE = "application/vnd.actiontext.opengraph-embed"
class << self
def from_node(node)
if node["content-type"]
if matches = node["content-type"].match(OPENGRAPH_EMBED_CONTENT_TYPE)
attachment = new(attributes_from_node(node))
attachment if attachment.valid?
end
end
end
private
def attributes_from_node(node)
{
href: node["href"],
url: node["url"],
filename: node["filename"],
description: node["caption"]
}
end
end
attr_accessor :href, :url, :filename, :description
def attachable_content_type
OPENGRAPH_EMBED_CONTENT_TYPE
end
def attachable_plain_text_representation(caption)
""
end
def to_partial_path
"action_text/attachables/opengraph_embed"
end
def to_trix_content_attachment_partial_path
"action_text/attachables/opengraph_embed"
end
end