Class: Sablon::Content::Image

Inherits:
Struct
  • Object
show all
Defined in:
lib/sablon/content.rb

Overview

Handles reading image data and inserting it into the document

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, attributes = {}) ⇒ Image

Returns a new instance of Image.



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/sablon/content.rb', line 186

def initialize(source, attributes = {})
  attributes = Hash[attributes.map { |k, v| [k.to_s, v] }]
  # If the source object is readable, use it as such otherwise open
  # and read the content
  if source.respond_to?(:read)
    name, img_data = process_readable(source, attributes)
  else
    name = File.basename(source)
    img_data = IO.binread(source)
  end
  #
  super name, img_data
  @attributes = attributes
  # rId's are separate for each XML file but I want to be able
  # to reuse the actual image file itself.
  @rid_by_file = {}
end

Instance Attribute Details

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



176
177
178
# File 'lib/sablon/content.rb', line 176

def data
  @data
end

#local_ridObject

Returns the value of attribute local_rid

Returns:

  • (Object)

    the current value of local_rid



176
177
178
# File 'lib/sablon/content.rb', line 176

def local_rid
  @local_rid
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



176
177
178
# File 'lib/sablon/content.rb', line 176

def name
  @name
end

#rid_by_fileObject (readonly)

Returns the value of attribute rid_by_file.



177
178
179
# File 'lib/sablon/content.rb', line 177

def rid_by_file
  @rid_by_file
end

Class Method Details

.idObject



179
# File 'lib/sablon/content.rb', line 179

def self.id; :image end

.wraps?(value) ⇒ Boolean

Returns:

  • (Boolean)


180
# File 'lib/sablon/content.rb', line 180

def self.wraps?(value) false end

Instance Method Details

#append_to(paragraph, display_node, env) ⇒ Object



204
# File 'lib/sablon/content.rb', line 204

def append_to(paragraph, display_node, env) end

#inspectObject



182
183
184
# File 'lib/sablon/content.rb', line 182

def inspect
  "#<Image #{name}:#{@rid_by_file}>"
end