5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/lorempixel_helper.rb', line 5
def lorempixel_image_tag(size, opts={})
size = "#{size.to_s}" unless size.is_a?(String)
config = {
:alt => (opts[:text] || "A lorempixel image"),
:height => (size.split('x')[1] || size.split('x')[0]),
:width => size.split('x')[0],
:item => opts[:item],
:text => opts[:text].to_s.gsub(/\s+/, "-"),
:title => opts[:text] || "A lorempixel image",
:category => opts[:category],
:type => opts[:type],
:class => opts[:class]
}.merge!(opts)
src = "http://lorempixel.com/#{config[:width]}/#{config[:height]}"
style = 'lorempixel'
style = config[:class] if config[:class]
if config[:type]
src = "http://lorempixel.com/#{config[:type]}/#{config[:width]}/#{config[:height]}"
end
if config[:category]
src += "/#{config[:category]}"
if config[:item]
src += "/#{config[:item]}"
if config[:text]
src += "/#{config[:text]}"
end
elsif config[:text]
src += "/#{config[:text]}"
end
end
image_tag = "<img src='#{src}' alt='#{config[:alt]}' height='#{config[:height]}' width='#{config[:width]}'"
image_tag += " title='#{config[:title]}'"
image_tag += " class='#{style}' />"
return image_tag.html_safe if defined?(Rails)
image_tag
end
|