Class: ActionText::AttachmentGallery
- Inherits:
-
Object
- Object
- ActionText::AttachmentGallery
- Includes:
- ActiveModel::Model
- Defined in:
- lib/action_text/attachment_gallery.rb
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Class Method Summary collapse
- .find_attachment_gallery_nodes(content) ⇒ Object
- .fragment_by_canonicalizing_attachment_galleries(content) ⇒ Object
- .fragment_by_replacing_attachment_gallery_nodes(content) ⇒ Object
- .from_node(node) ⇒ Object
Instance Method Summary collapse
- #attachments ⇒ Object
-
#initialize(node) ⇒ AttachmentGallery
constructor
A new instance of AttachmentGallery.
- #inspect ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(node) ⇒ AttachmentGallery
Returns a new instance of AttachmentGallery.
41 42 43 |
# File 'lib/action_text/attachment_gallery.rb', line 41 def initialize(node) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
39 40 41 |
# File 'lib/action_text/attachment_gallery.rb', line 39 def node @node end |
Class Method Details
.find_attachment_gallery_nodes(content) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/action_text/attachment_gallery.rb', line 22 def (content) Fragment.wrap(content).find_all(SELECTOR).select do |node| node.children.all? do |child| if child.text? child.text =~ /\A(\n|\ )*\z/ else child.matches? ATTACHMENT_SELECTOR end end end end |
.fragment_by_canonicalizing_attachment_galleries(content) ⇒ Object
8 9 10 11 12 |
# File 'lib/action_text/attachment_gallery.rb', line 8 def (content) (content) do |node| "<#{TAG_NAME}>#{node.inner_html}</#{TAG_NAME}>" end end |
.fragment_by_replacing_attachment_gallery_nodes(content) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/action_text/attachment_gallery.rb', line 14 def (content) Fragment.wrap(content).update do |source| (source).each do |node| node.replace(yield(node).to_s) end end end |
.from_node(node) ⇒ Object
34 35 36 |
# File 'lib/action_text/attachment_gallery.rb', line 34 def from_node(node) new(node) end |
Instance Method Details
#attachments ⇒ Object
45 46 47 48 49 |
# File 'lib/action_text/attachment_gallery.rb', line 45 def @attachments ||= node.css(ATTACHMENT_SELECTOR).map do |node| ActionText::Attachment.from_node(node).with_full_attributes end end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/action_text/attachment_gallery.rb', line 55 def inspect "#<#{self.class.name} size=#{size.inspect}>" end |
#size ⇒ Object
51 52 53 |
# File 'lib/action_text/attachment_gallery.rb', line 51 def size .size end |