Class: Prez::Assets::Image

Inherits:
Tagged
  • Object
show all
Defined in:
lib/prez/assets.rb

Instance Attribute Summary

Attributes inherited from Tagged

#contents, #file, #name, #options

Instance Method Summary collapse

Methods inherited from Tagged

#compiled_contents, #dev?, #initialize, #minified_contents, #minify, #to_tag

Constructor Details

This class inherits a constructor from Prez::Assets::Tagged

Instance Method Details

#closeObject



82
83
84
# File 'lib/prez/assets.rb', line 82

def close
  %{" />}
end

#compile(contents) ⇒ Object



105
106
107
# File 'lib/prez/assets.rb', line 105

def compile(contents)
  Prez::DataUri.new(image_type, contents).to_s
end

#extensionObject



60
61
62
# File 'lib/prez/assets.rb', line 60

def extension
  "image"
end

#image_typeObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/prez/assets.rb', line 86

def image_type
  extension = file[/\.([^.]*)$/, 1]

  case extension
  when "gif"
    "image/gif"
  when "jpeg", "jpg"
    "image/jpeg"
  when "png"
    "image/png"
  when "svg"
    "image/svg+xml"
  when "tif", "tiff"
    "image/tiff"
  else
    raise Prez::Error.new("Unknown image extension '#{extension}'")
  end
end

#openObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/prez/assets.rb', line 64

def open
  attributes = []

  if options[:width]
    attributes << %{width="#{options[:width]}"}
  end

  if options[:height]
    attributes << %{height="#{options[:height]}"}
  end

  if options[:style]
    attributes << %{style="#{options[:style]}"}
  end

  %{<img #{attributes.join " "} src="}
end

#self_closing?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/prez/assets.rb', line 56

def self_closing?
  true
end