Module: Uploadbox::ImgHelper

Defined in:
app/helpers/uploadbox/img_helper.rb

Instance Method Summary collapse

Instance Method Details

#img(source, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/uploadbox/img_helper.rb', line 17

def img(source, options={})
  if source.respond_to?(:url) and source.respond_to?(:width) and source.respond_to?(:height)
    if source.processing?
      data = {
        processing: source.processing?,
        original: source.original_file,
        component: 'ShowImage'
      }
       :div, class: 'uploadbox-image-container uploadbox-processing', style: "width: #{source.width}px; height: #{source.height}px", data: data do
        image_tag(source.url, {width: source.width, height: source.height, style: 'display: none'}.merge(options))
      end
    else
      data = {}
       :div, class: 'uploadbox-image-container', width: source.width, height: source.height, data: data do
        image_tag(source.url, {width: source.width, height: source.height}.merge(options))
      end
    end
  else
    image_tag(source, options)
  end
end

#s3_policyObject



3
4
5
# File 'app/helpers/uploadbox/img_helper.rb', line 3

def s3_policy
  Base64.encode64(policy_data.to_json).gsub("\n", "")
end

#s3_signatureObject



7
8
9
10
11
12
13
14
15
# File 'app/helpers/uploadbox/img_helper.rb', line 7

def s3_signature
  Base64.encode64(
    OpenSSL::HMAC.digest(
      OpenSSL::Digest::Digest.new('sha1'),
      CarrierWave::Uploader::Base.fog_credentials[:aws_secret_access_key],
      s3_policy
    )
  ).gsub("\n", "")
end