diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2018-04-13 16:23:04 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2018-04-13 16:23:04 -0700 |
commit | f1d74871e7f00e8bbde3501a759487ac8cc4c3fc (patch) | |
tree | 2f1fa680bd1e6a356256fdc59cab5a6af8d74da7 /lib/action_text/attachables/content_attachment.rb | |
parent | 3bc244abc1800c7617cbfbbe1dd2597053a638c9 (diff) | |
download | rails-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/content_attachment.rb')
-rw-r--r-- | lib/action_text/attachables/content_attachment.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/action_text/attachables/content_attachment.rb b/lib/action_text/attachables/content_attachment.rb new file mode 100644 index 0000000000..3ebd734786 --- /dev/null +++ b/lib/action_text/attachables/content_attachment.rb @@ -0,0 +1,36 @@ +module ActionText + 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 + "action_text/attachables/content_attachment" + end + + def to_trix_content_attachment_partial_path + "action_text/attachables/content_attachments/#{name.underscore}" + end + end + end +end |