Sha256: 282795d20d1fd098c5d66274f593058ca5ccaa48f1a6b8e8112050e8842a7d4a

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

module ApplicationHelper
  def flash_tag
    return '' if flash.blank?
    html = ''
    flash.each do |name, msg|
      if msg.is_a?(String)
        html << "<div class='action-alert alert alert-#{name} text-center m-c'>"
        html << "<button type='button' class='close action-alert-close'>&times;</button>"
        html << "#{msg}"
        html << '</div>'
      end
    end
    raw html
  end

  def aws_s3_json(directory)
    aws_s3_hash = {
        bucket: ENV['AWS_S3_BUCKET'],
        region: ENV['AWS_S3_REGION'],
        key_start: "#{ENV['AWS_S3_KEY_START']}#{directory}",
        acl: ENV['AWS_S3_ACL'],
        access_id: ENV['AWS_S3_ACCESS_ID'],
        signature: aws_s3_signature(directory),
        policy: aws_s3_policy(directory),
    }

    @aws_s3_json = aws_s3_hash.to_json
  end

  def froala_key
    ENV['FROALA_KEY'];
  end

  private

  def aws_s3_signature(directory)
    Base64.encode64(
        OpenSSL::HMAC.digest(
            OpenSSL::Digest.new('sha1'),
            ENV['AWS_S3_SECRET_KEY'], aws_s3_policy(directory)
        )
    ).gsub("\n", '')
  end

  def aws_s3_policy(directory)
    Base64.encode64(aws_s3_policy_data(directory).to_json).gsub("\n", '')
  end

  def aws_s3_policy_data(directory)
    {
        expiration: 10.hours.from_now.utc.iso8601,
        conditions: [
            ['starts-with', '$key', "#{ENV['AWS_S3_KEY_START']}#{directory}"],
            %w(starts-with $x-requested-with xhr),
            ['content-length-range', 0, 20.megabytes],
            ['starts-with', '$content-type', ''],
            {bucket: ENV['AWS_S3_BUCKET']},
            {acl: ENV['AWS_S3_ACL']},
            {success_action_status: '201'}
        ]
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tmatt_cms-0.1.9 lib/generators/tmatt_cms/templates/helpers/application_helper.rb