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

def ix_image_url(*args)
  validate_configuration!

  disable_path_encoding = args.last.is_a?(Hash) && args.last.delete(:disable_path_encoding)

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

  imgix_client(source).path(path).to_url(params, disable_path_encoding: disable_path_encoding).html_safe
end