Class: Prez::Assets::Image
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
Instance Method Details
#close ⇒ Object
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
|
#extension ⇒ Object
60
61
62
|
# File 'lib/prez/assets.rb', line 60
def extension
"image"
end
|
#image_type ⇒ Object
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
|
#open ⇒ Object
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
56
57
58
|
# File 'lib/prez/assets.rb', line 56
def self_closing?
true
end
|