Class: Mill::Resource::Image

Inherits:
Mill::Resource show all
Includes:
HTMLHelpers
Defined in:
lib/mill/resources/image.rb

Constant Summary collapse

FileTypes =
%w{
  image/gif
  image/jpeg
  image/png
  image/tiff
  image/vnd.microsoft.icon
  image/svg+xml
}

Constants included from HTMLHelpers

HTMLHelpers::LinkElementsXPath

Instance Attribute Summary collapse

Attributes inherited from Mill::Resource

#content, #date, #input_file, #node, #output_file, #path, #public, #site

Instance Method Summary collapse

Methods included from HTMLHelpers

#check_errors, #find_link_elements, #google_analytics, #html_document, #html_fragment, #link_if, #parse_html, #parse_html_fragment, #replace_element

Methods inherited from Mill::Resource

#absolute_uri, #build, #change_frequency, #children, #final_content, #initialize, #parent, #public?, #redirect?, #save, #siblings, #tag_uri, #text?, #uri

Constructor Details

This class inherits a constructor from Mill::Resource

Instance Attribute Details

#heightObject

Returns the value of attribute height.



19
20
21
# File 'lib/mill/resources/image.rb', line 19

def height
  @height
end

#widthObject

Returns the value of attribute width.



18
19
20
# File 'lib/mill/resources/image.rb', line 18

def width
  @width
end

Instance Method Details

#img_htmlObject



34
35
36
37
38
39
40
41
42
# File 'lib/mill/resources/image.rb', line 34

def img_html
  html_fragment do |html|
    html.img(
      src: uri,
      alt: @title,
      height: @height,
      width: @width)
  end
end

#inspectObject



21
22
23
24
25
26
# File 'lib/mill/resources/image.rb', line 21

def inspect
  super + ", width: %p, height: %p" % [
    @width,
    @height,
  ]
end

#loadObject



28
29
30
31
32
# File 'lib/mill/resources/image.rb', line 28

def load
  info = ImageSize.path(@input_file.to_s)
  @width, @height = *info.size
  super
end