Module: Admin::ImagesHelper

Defined in:
lib/ecrire/app/helpers/admin/images_helper.rb

Instance Method Summary collapse

Instance Method Details

#editor_image_tag(post) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ecrire/app/helpers/admin/images_helper.rb', line 33

def editor_image_tag(post)
  return unless post.header?
   :div, class: %w(image), style: "background-image: url('#{post.header.url}')" do
    button_to "Remove this image",
      admin_post_properties_path(post.id),
      method: :delete,
      remote: true,
      params: {
        property: 'image'
      },
      data: {confirm: 'Are you sure you want to destroy this image?'}
  end
end

#image_form_policy(post) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ecrire/app/helpers/admin/images_helper.rb', line 13

def image_form_policy(post)
  @policy ||= begin
                namespace = [post.id]
                if Rails.application.secrets.s3.has_key?('namespace')
                  namespace.insert 0, Rails.application.secrets.s3['namespace']
                end

                policy = {
                  "expiration" => (Time.now + 10.years).utc.to_s(:iso8601),
                  "conditions" => [
                    {"bucket" => Rails.application.secrets.s3['bucket']},
                    ["starts-with", "$key", "#{namespace.join('/')}/"],
                    ["starts-with", "$Content-Type", ""],
                    {"acl" => "private"}
                  ]
                }
                Base64.encode64(policy.to_json).gsub("\n","")
  end
end

#image_form_signature(policy) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/ecrire/app/helpers/admin/images_helper.rb', line 4

def image_form_signature(policy)
  @signature ||= begin
    key = Rails.application.secrets.s3['secret_key']
    sha = OpenSSL::Digest.new('sha1')
    digest = OpenSSL::HMAC.digest sha, key, policy
    Base64.encode64(digest).gsub("\n", "")
  end
end

#images_config_titleObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ecrire/app/helpers/admin/images_helper.rb', line 47

def images_config_title
  if @s3 && @s3.errors.any?
     :h1, class: %w(error) do
      @s3.errors.messages.values.flatten.to_sentence
    end
  else
     :h1 do
      t('admin.images.helper.title')
    end
  end
end