module ApplicationHelper

Public Instance Methods

aws_s3_json(directory) click to toggle source
# File lib/generators/tmatt_cms/templates/helpers/application_helper.rb, line 16
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
flash_tag() click to toggle source
# File lib/generators/tmatt_cms/templates/helpers/application_helper.rb, line 2
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
froala_key() click to toggle source
# File lib/generators/tmatt_cms/templates/helpers/application_helper.rb, line 30
def froala_key
  ENV['FROALA_KEY'];
end

Private Instance Methods

aws_s3_policy(directory) click to toggle source
# File lib/generators/tmatt_cms/templates/helpers/application_helper.rb, line 45
def aws_s3_policy(directory)
  Base64.encode64(aws_s3_policy_data(directory).to_json).gsub("\n", '')
end
aws_s3_policy_data(directory) click to toggle source
# File lib/generators/tmatt_cms/templates/helpers/application_helper.rb, line 49
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
aws_s3_signature(directory) click to toggle source
# File lib/generators/tmatt_cms/templates/helpers/application_helper.rb, line 36
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