Class: ActionText::Content
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Serialization
|
|
Inherits: | Object |
Defined in: | actiontext/lib/action_text/content.rb |
Rendering
- Attributes & Methods
- .default_renderer rw
- #render readonly
Class Method Summary
Instance Attribute Summary
- #fragment readonly
- #html_safe readonly
Instance Method Summary
- #==(other)
- #append_attachables(attachables)
- #as_json
- #attachables
- #attachment_galleries
- #attachments
- #blank? ⇒ Boolean
- #empty? ⇒ Boolean
- #gallery_attachments
- #inspect
- #links
- #present? ⇒ Boolean
- #render_attachment_galleries(&block)
- #render_attachments(**options, &block)
- #to_html
- #to_plain_text
- #to_rendered_html_with_layout
- #to_s
- #to_trix_html
Serialization
- Included
Constructor Details
.new(content = nil, options = {}) ⇒ Content
# File 'actiontext/lib/action_text/content.rb', line 19
def initialize(content = nil, = {}) .with_defaults! canonicalize: true if [:canonicalize] @fragment = self.class.fragment_by_canonicalizing_content(content) else @fragment = ActionText::Fragment.wrap(content) end end
Class Attribute Details
.default_renderer (rw)
[ GitHub ]# File 'actiontext/lib/action_text/rendering.rb', line 11
cattr_accessor :default_renderer, instance_accessor: false
Class Method Details
.fragment_by_canonicalizing_content(content)
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 12
def fragment_by_canonicalizing_content(content) fragment = ActionText::Attachment. (content) fragment = ActionText::AttachmentGallery. (fragment) fragment end
Instance Attribute Details
#fragment (readonly)
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 7
attr_reader :fragment
#html_safe (readonly)
[ GitHub ]#render (readonly)
[ GitHub ]# File 'actiontext/lib/action_text/rendering.rb', line 13
delegate :render, to: :class
Instance Method Details
#==(other)
[ GitHub ]#append_attachables(attachables)
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 55
def append_attachables(attachables) = ActionText::Attachment.from_attachables(attachables) self.class.new([self.to_s.presence, * ].compact.join("\n")) end
#as_json
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 94
def as_json(*) to_html end
#attachables
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 49
def attachables @attachables ||= .map do |node| ActionText::Attachable.from_node(node) end end
#attachment_galleries
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 39
def @attachment_galleries ||= .map do |node| (node) end end
#attachments
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 33
def @attachments ||= .map do |node| (node) end end
#blank? ⇒ Boolean
#empty? ⇒ Boolean
#gallery_attachments
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 45
def @gallery_attachments ||= .flat_map(&: ) end
#inspect
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 98
def inspect "#<#{self.class.name} #{to_s.truncate(25).inspect}>" end
#links
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 29
def links @links ||= fragment.find_all("a[href]").map { |a| a["href"] }.uniq end
#present? ⇒ Boolean
#render_attachment_galleries(&block)
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 67
def (&block) content = ActionText::AttachmentGallery. (fragment) do |node| block.call( (node)) end self.class.new(content, canonicalize: false) end
#render_attachments(**options, &block)
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 60
def (**, &block) content = fragment.replace(ActionText::Attachment::SELECTOR) do |node| block.call( (node, ** )) end self.class.new(content, canonicalize: false) end
#to_html
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 82
def to_html fragment.to_html end
#to_plain_text
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 74
def to_plain_text (with_full_attributes: false, &:to_plain_text).fragment.to_plain_text end
#to_rendered_html_with_layout
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 86
def to_rendered_html_with_layout render partial: "action_text/content/layout", formats: :html, locals: { content: self } end
#to_s
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 90
def to_s to_rendered_html_with_layout end
#to_trix_html
[ GitHub ]# File 'actiontext/lib/action_text/content.rb', line 78
def to_trix_html (&: ).to_html end