aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_text/attachables/remote_image.rb
diff options
context:
space:
mode:
authorSam Stephenson <sam@37signals.com>2018-02-07 18:26:19 -0600
committerSam Stephenson <sam@37signals.com>2018-02-07 18:26:19 -0600
commit68d350ddacedf604717f0d1074d7624fa57757c2 (patch)
treea01852130448e37368ed2fd4af7e930e6c2cd0f2 /lib/active_text/attachables/remote_image.rb
parente22ba227a694b8426e69dbce640c5b0e4f39f574 (diff)
downloadrails-68d350ddacedf604717f0d1074d7624fa57757c2.tar.gz
rails-68d350ddacedf604717f0d1074d7624fa57757c2.tar.bz2
rails-68d350ddacedf604717f0d1074d7624fa57757c2.zip
Initial import from BC3 RichText
Diffstat (limited to 'lib/active_text/attachables/remote_image.rb')
-rw-r--r--lib/active_text/attachables/remote_image.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/active_text/attachables/remote_image.rb b/lib/active_text/attachables/remote_image.rb
new file mode 100644
index 0000000000..0624b5564d
--- /dev/null
+++ b/lib/active_text/attachables/remote_image.rb
@@ -0,0 +1,44 @@
+module ActiveText
+ module Attachables
+ class RemoteImage
+ extend ActiveModel::Naming
+
+ class << self
+ def from_node(node)
+ if node["url"] && content_type_is_image?(node["content-type"])
+ new(attributes_from_node(node))
+ end
+ end
+
+ private
+ def content_type_is_image?(content_type)
+ content_type.to_s =~ /^image(\/.+|$)/
+ end
+
+ def attributes_from_node(node)
+ { url: node["url"],
+ content_type: node["content-type"],
+ width: node["width"],
+ height: node["height"] }
+ end
+ end
+
+ attr_reader :url, :content_type, :width, :height
+
+ def initialize(attributes = {})
+ @url = attributes[:url]
+ @content_type = attributes[:content_type]
+ @width = attributes[:width]
+ @height = attributes[:height]
+ end
+
+ def attachable_plain_text_representation(caption)
+ "[#{caption || "Image"}]"
+ end
+
+ def to_partial_path
+ "active_text/attachables/remote_image"
+ end
+ end
+ end
+end