Class: PictureTag::SourceImage

Inherits:
Object
  • Object
show all
Includes:
MiniMagick
Defined in:
lib/jekyll_picture_tag/images/source_image.rb

Overview

Handles a given source image file and its properties. Provides a speed advantage by storing expensive file reads and writes in instance variables, to be reused by many different generated images.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relative_filename, media_preset = nil) ⇒ SourceImage

Returns a new instance of SourceImage.



10
11
12
13
14
15
16
17
18
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 10

def initialize(relative_filename, media_preset = nil)
  # /home/dave/my_blog/assets/images/somefolder/myimage.jpg
  #                                  ^^^^^^^^^^^^^^^^^^^^^^
  @shortname = relative_filename
  @media_preset = media_preset

  @missing = missing?
  check_cache
end

Instance Attribute Details

#media_presetObject (readonly)

Returns the value of attribute media_preset.



6
7
8
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 6

def media_preset
  @media_preset
end

#missingObject (readonly)

Returns the value of attribute missing.



6
7
8
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 6

def missing
  @missing
end

#shortnameObject (readonly)

Returns the value of attribute shortname.



6
7
8
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 6

def shortname
  @shortname
end

Instance Method Details

#base_nameObject

/home/dave/my_blog/assets/images/somefolder/myimage.jpg

^^^^^^^^^^^^^^^^^^


40
41
42
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 40

def base_name
  @shortname.delete_suffix File.extname(@shortname)
end

#digestObject



20
21
22
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 20

def digest
  @digest ||= cache[:digest] || ''
end

#extObject

/home/dave/my_blog/assets/images/somefolder/myimage.jpg

^^^


46
47
48
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 46

def ext
  @ext ||= File.extname(name)[1..-1].downcase
end

#heightObject



28
29
30
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 28

def height
  @height ||= cache[:height] || 999_999
end

#nameObject

/home/dave/my_blog/assets/images/somefolder/myimage.jpg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



34
35
36
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 34

def name
  @name ||= File.join(PictureTag.source_dir, @shortname)
end

#widthObject



24
25
26
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 24

def width
  @width ||= cache[:width] || 999_999
end