Module: LoremImageWare::Helpers

Defined in:
lib/lorem-image-ware.rb

Instance Method Summary collapse

Instance Method Details

#default_lorem_image_heightObject



28
29
30
# File 'lib/lorem-image-ware.rb', line 28

def default_lorem_image_height
  200
end

#default_lorem_image_widthObject



32
33
34
# File 'lib/lorem-image-ware.rb', line 32

def default_lorem_image_width
  400
end

#lorem_image_path(options = {}) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/lorem-image-ware.rb', line 36

def lorem_image_path(options = {})
  height = options.fetch(:height, default_lorem_image_height)
  width  = options.fetch(:width, default_lorem_image_width)
  type   = options.fetch(:type, "abstract")

  "#{lorem_image_root}/image/#{width}/#{height}/#{type}?r=#{rand(99)}"
end

#lorem_image_rootObject



24
25
26
# File 'lib/lorem-image-ware.rb', line 24

def lorem_image_root
  "/lorem"
end

#lorem_image_tag(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/lorem-image-ware.rb', line 44

def lorem_image_tag(options = {})
  height     = options.fetch(:height, default_lorem_image_height)
  width      = options.fetch(:width, default_lorem_image_width)
  html_class = [options[:class], "lorem-image"].compact.join(" ")

  html = %Q{<img src="#{lorem_image_path(options)}"}
  html += %Q{ class="#{html_class}" width="#{width}" height="#{height}"}
  html += %Q{ style="height: #{height}px; width: #{width}px;" />}
end