Class: Deface::Actions::SurroundContents

Inherits:
SurroundAction show all
Defined in:
lib/deface/actions/surround_contents.rb

Instance Attribute Summary

Attributes inherited from ElementAction

#source_element

Instance Method Summary collapse

Methods inherited from SurroundAction

#original_placeholders, #source_element

Methods inherited from ElementAction

#initialize

Methods inherited from Action

#initialize, to_sym

Constructor Details

This class inherits a constructor from Deface::Actions::ElementAction

Instance Method Details

#execute(target_range) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/deface/actions/surround_contents.rb', line 4

def execute(target_range)
  if target_range.length == 1
    target_element = target_range.first
    original_placeholders.each do |placeholder|
      placeholder.replace target_element.clone(1).children
    end
    target_element.children.remove
    target_element.add_child(source_element)
  else
    original_placeholders.each do |placeholder|
      start = target_range[1].clone(1)
      placeholder.replace start

      target_range[2...-1].each do |element|
        element = element.clone(1)
        start.after(element)
        start = element
      end
    end
    target_range.first.after(source_element)
    target_range[1...-1].map(&:remove)
  end
end

#range_compatible?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/deface/actions/surround_contents.rb', line 28

def range_compatible?
  true
end