Module: Imgix::Rails::UrlHelper

Included in:
Tag, ViewHelper
Defined in:
lib/imgix/rails/url_helper.rb

Instance Method Summary collapse

Instance Method Details

#ix_image_url(*args) ⇒ Object



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
# File 'lib/imgix/rails/url_helper.rb', line 6

def ix_image_url(*args)
  validate_configuration!

  case args.size
  when 1
    path = args[0]
    source = nil
    options = {}
  when 2
    if args[0].is_a?(String) && args[1].is_a?(Hash)
      source = nil
      path = args[0]
      options = args[1]
    elsif args[0].is_a?(String) && args[1].is_a?(String)
      source = args[0]
      path = args[1]
      options = {}
    else
      raise RuntimeError.new("path and source must be of type String; options must be of type Hash")
    end
  when 3
    source = args[0]
    path = args[1]
    options = args[2]
  else
    raise RuntimeError.new('path missing')
  end

  imgix_client(source).path(path).to_url(options).html_safe
end