From 68d350ddacedf604717f0d1074d7624fa57757c2 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 7 Feb 2018 18:26:19 -0600 Subject: Initial import from BC3 RichText --- lib/active_text/attachables/content_attachment.rb | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/active_text/attachables/content_attachment.rb (limited to 'lib/active_text/attachables/content_attachment.rb') diff --git a/lib/active_text/attachables/content_attachment.rb b/lib/active_text/attachables/content_attachment.rb new file mode 100644 index 0000000000..316d7e304a --- /dev/null +++ b/lib/active_text/attachables/content_attachment.rb @@ -0,0 +1,36 @@ +module ActiveText + module Attachables + class ContentAttachment + include ActiveModel::Model + + def self.from_node(node) + if node["content-type"] + if matches = node["content-type"].match(/vnd\.rubyonrails\.(.+)\.html/) + attachment = new(name: matches[1]) + attachment if attachment.valid? + end + end + end + + attr_accessor :name + validates_inclusion_of :name, in: %w( horizontal-rule ) + + def attachable_plain_text_representation(caption) + case name + when "horizontal-rule" + " ┄ " + else + " " + end + end + + def to_partial_path + "active_text/attachables/content_attachment" + end + + def to_trix_content_attachment_partial_path + "active_text/attachables/content_attachments/#{name.underscore}" + end + end + end +end -- cgit v1.2.3