Class: ActionText::Attachables::ContentAttachment

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
actiontext/lib/action_text/attachables/content_attachment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveModel::Model

#initialize, #persisted?

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Methods included from ActiveModel::Conversion

#to_key, #to_model, #to_param

Methods included from ActiveModel::Validations

#errors, #initialize_dup, #invalid?, #valid?, #validate!, #validates_with

Methods included from ActiveModel::AttributeAssignment

#assign_attributes

Instance Attribute Details

#nameObject

Returns the value of attribute name


17
18
19
# File 'actiontext/lib/action_text/attachables/content_attachment.rb', line 17

def name
  @name
end

Class Method Details

.from_node(node) ⇒ Object


8
9
10
11
12
13
14
15
# File 'actiontext/lib/action_text/attachables/content_attachment.rb', line 8

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

Instance Method Details

#attachable_plain_text_representation(caption) ⇒ Object


20
21
22
23
24
25
26
27
# File 'actiontext/lib/action_text/attachables/content_attachment.rb', line 20

def attachable_plain_text_representation(caption)
  case name
  when "horizontal-rule"
    ""
  else
    " "
  end
end

#to_partial_pathObject


29
30
31
# File 'actiontext/lib/action_text/attachables/content_attachment.rb', line 29

def to_partial_path
  "action_text/attachables/content_attachment"
end

#to_trix_content_attachment_partial_pathObject


33
34
35
# File 'actiontext/lib/action_text/attachables/content_attachment.rb', line 33

def to_trix_content_attachment_partial_path
  "action_text/attachables/content_attachments/#{name.underscore}"
end