aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_text/attachables/remote_image.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-04-13 16:23:04 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-04-13 16:23:04 -0700
commitf1d74871e7f00e8bbde3501a759487ac8cc4c3fc (patch)
tree2f1fa680bd1e6a356256fdc59cab5a6af8d74da7 /lib/action_text/attachables/remote_image.rb
parent3bc244abc1800c7617cbfbbe1dd2597053a638c9 (diff)
downloadrails-f1d74871e7f00e8bbde3501a759487ac8cc4c3fc.tar.gz
rails-f1d74871e7f00e8bbde3501a759487ac8cc4c3fc.tar.bz2
rails-f1d74871e7f00e8bbde3501a759487ac8cc4c3fc.zip
Rename from Active Text to Action Text
This is more like Action View than Active Model.
Diffstat (limited to 'lib/action_text/attachables/remote_image.rb')
-rw-r--r--lib/action_text/attachables/remote_image.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/action_text/attachables/remote_image.rb b/lib/action_text/attachables/remote_image.rb
new file mode 100644
index 0000000000..2333427371
--- /dev/null
+++ b/lib/action_text/attachables/remote_image.rb
@@ -0,0 +1,44 @@
+module ActionText
+ 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
+ "action_text/attachables/remote_image"
+ end
+ end
+ end
+end