Module: FillMurray::ViewHelpers

Defined in:
lib/fill_murray/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#fill_murray(options = {}) ⇒ Object



4
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
47
48
49
50
51
52
53
54
# File 'lib/fill_murray/view_helpers.rb', line 4

def fill_murray(options = {})

## dimensions ##
  if !options[:ratio].nil?
    ratio = options[:ratio].split(':')
    # if ratio[0].to_i > 1 and ratio[1].to_i > 1
    if ratio[0].to_i < ratio[1].to_i
      ratio[1] = ratio[1].to_i / ratio[0].to_i
      ratio[0] = 1
      max = 1000 / ratio[1].to_i
      random = Random.new.rand(100...max)
    else
      ratio[0] = ratio[0].to_i / ratio[1].to_i
      ratio[1] = 1
      max = 1000 / ratio[0].to_i
      random = Random.new.rand(100...max)
    end
    # else
    #   random = Random.new.rand(100...1000)
    # end
    options[:width] = ratio[0].to_i * random
    options[:height] = ratio[1].to_i * random
  elsif options[:height].nil? and options[:width].nil?
    options[:width] = Random.new.rand(100...1000)
    options[:height] = Random.new.rand(100...1000)
  elsif options[:height].nil?
    options[:height] = options[:width]
  end

  ## person / subject ##
  case options[:person]
  when "Nick", "Cage", "Nick Cage"
    site = 'http://www.placecage.com'
  when "Steve", "Steven", "Segal", "Steven Segal"
    site = 'http://www.stevensegallery.com'
  else
    site = 'http://www.fillmurray.com'
  end

  ## effects ##
  if options[:grey] == true
    effect = 'g/'
  elsif options[:crazy] == true and site == 'http://www.placecage.com'
    effect = 'c/'
  end

  ## image_tag markup ##
	image_tag "#{site}/#{effect}#{options[:width]}/#{options[:height]}", 
		:alt =>  options[:alt] ? options[:alt] : nil, 
		:class => options[:class] ? options[:class] : nil
end