Class: Sablon::Processor::Document::ImageBlock

Inherits:
ParagraphBlock show all
Defined in:
lib/sablon/processor/document/blocks.rb

Instance Attribute Summary

Attributes inherited from Block

#end_field, #start_field

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Block

#body, enclosed_by, #end_node, #initialize, parent, parent_selector, #process, #remove_control_elements, #start_node

Constructor Details

This class inherits a constructor from Sablon::Processor::Document::Block

Class Method Details

.encloses?(start_field, end_field) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/sablon/processor/document/blocks.rb', line 90

def self.encloses?(start_field, end_field)
  start_field.expression.start_with?('@')
end

Instance Method Details

#replace(image) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/sablon/processor/document/blocks.rb', line 94

def replace(image)
  # we need to include the start and end nodes incase the image is
  # inline with the merge fields
  nodes = [start_node] + body + [end_node]
  #
  if image
    nodes.each do |node|
      pic_prop = node.at_xpath('.//pic:cNvPr', pic: 'http://schemas.openxmlformats.org/drawingml/2006/picture')
      pic_prop.attributes['name'].value = image.name if pic_prop
      blip = node.at_xpath('.//a:blip', a: 'http://schemas.openxmlformats.org/drawingml/2006/main')
      blip.attributes['embed'].value = image.local_rid if blip
    end
  end
  #
  start_field.remove
  end_field.remove
end