Class: PictureTag::ImgURI

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll_picture_tag/img_uri.rb

Overview

Represents a link to an image. We use the File library rather than the URI library to build these because it doesn’t like relative URIs.

Just give it a filename, and pass source_image: true if it’s not a generated image. Call to_s on it to get the link.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, source_image: false) ⇒ ImgURI

Returns a new instance of ImgURI.



11
12
13
14
# File 'lib/jekyll_picture_tag/img_uri.rb', line 11

def initialize(filename, source_image: false)
  @source_image = source_image
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



10
11
12
# File 'lib/jekyll_picture_tag/img_uri.rb', line 10

def filename
  @filename
end

#source_imageObject (readonly)

Returns the value of attribute source_image.



10
11
12
# File 'lib/jekyll_picture_tag/img_uri.rb', line 10

def source_image
  @source_image
end

Instance Method Details

#to_sObject

| domain | baseurl | directory | filename



18
19
20
21
22
# File 'lib/jekyll_picture_tag/img_uri.rb', line 18

def to_s
  Addressable::URI.escape(
    File.join(domain, baseurl, directory, @filename)
  )
end