Class: ActionMosaico::AttachmentGallery
- Inherits:
-
Object
- Object
- ActionMosaico::AttachmentGallery
- Includes:
- ActiveModel::Model
- Defined in:
- lib/action_mosaico/attachment_gallery.rb
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Class Method Summary collapse
- .attachment_selector ⇒ Object
- .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
- .selector ⇒ 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.
52 53 54 |
# File 'lib/action_mosaico/attachment_gallery.rb', line 52 def initialize(node) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
50 51 52 |
# File 'lib/action_mosaico/attachment_gallery.rb', line 50 def node @node end |
Class Method Details
.attachment_selector ⇒ Object
41 42 43 |
# File 'lib/action_mosaico/attachment_gallery.rb', line 41 def "#{ActionMosaico::Attachment.tag_name}[presentation=gallery]" end |
.find_attachment_gallery_nodes(content) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/action_mosaico/attachment_gallery.rb', line 25 def (content) Fragment.wrap(content).find_all(selector).select do |node| node.children.all? do |child| if child.text? /\A(\n|\ )*\z/.match?(child.text) else child.matches? end end end end |
.fragment_by_canonicalizing_attachment_galleries(content) ⇒ Object
11 12 13 14 15 |
# File 'lib/action_mosaico/attachment_gallery.rb', line 11 def (content) (content) do |node| "<#{TAG_NAME}>#{node.inner_html}</#{TAG_NAME}>" end end |
.fragment_by_replacing_attachment_gallery_nodes(content) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/action_mosaico/attachment_gallery.rb', line 17 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
37 38 39 |
# File 'lib/action_mosaico/attachment_gallery.rb', line 37 def from_node(node) new(node) end |
.selector ⇒ Object
45 46 47 |
# File 'lib/action_mosaico/attachment_gallery.rb', line 45 def selector "#{TAG_NAME}:has(#{} + #{})" end |
Instance Method Details
#attachments ⇒ Object
56 57 58 59 60 |
# File 'lib/action_mosaico/attachment_gallery.rb', line 56 def @attachments ||= node.css(ActionMosaico::AttachmentGallery.).map do |node| ActionMosaico::Attachment.from_node(node).with_full_attributes end end |
#inspect ⇒ Object
66 67 68 |
# File 'lib/action_mosaico/attachment_gallery.rb', line 66 def inspect "#<#{self.class.name} size=#{size.inspect}>" end |
#size ⇒ Object
62 63 64 |
# File 'lib/action_mosaico/attachment_gallery.rb', line 62 def size .size end |