From af08d843a85b8b10883fd61e56f7c7330ef8c0da Mon Sep 17 00:00:00 2001 From: Aditya Prakash Date: Wed, 20 Apr 2016 12:13:07 +0530 Subject: [PATCH] Maintain size of sponsor logos Places logo on a white background if image is smaller than the given constrains. Resizes the logo if image is larger than constrains. Validation of presence of logo was moved cause file field wasn't getting marked as required field ('*' thingy) in form. `- if logo presence` was removed cause logo is mandatory field. --- app/helpers/sponsors_helper.rb | 12 ++++++++++++ app/models/sponsor.rb | 16 ++++++++++++---- app/views/conference/_sponsors.html.haml | 5 ++--- 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 app/helpers/sponsors_helper.rb diff --git a/app/helpers/sponsors_helper.rb b/app/helpers/sponsors_helper.rb new file mode 100644 index 00000000..e827c1fe --- /dev/null +++ b/app/helpers/sponsors_helper.rb @@ -0,0 +1,12 @@ +module SponsorsHelper + # returns the url to be used for logo on basis of sponsorship level position + def get_logo(sponsor) + if sponsor.sponsorship_level.position == 1 + sponsor.logo.url(:first) + elsif sponsor.sponsorship_level.position == 2 + sponsor.logo.url(:second) + else + sponsor.logo.url(:others) + end + end +end diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index 8b360c6d..6b255886 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -2,12 +2,20 @@ class Sponsor < ActiveRecord::Base belongs_to :sponsorship_level belongs_to :conference has_attached_file :logo, - styles: { thumb: '100x100>', large: '300x300>' } + styles: { thumb: '100x100>', + first: '320x180>', + second: '320x150>', + others: '320x120>' }, + # places logo on a white background to maintain size + convert_options: { + first: '-background white -gravity center -extent 320x180', + second: '-background white -gravity center -extent 320x150', + others: '-background white -gravity center -extent 320x120' + } validates_attachment_content_type :logo, content_type: [/jpg/, /jpeg/, /png/, /gif/], - size: { in: 0..500.kilobytes }, - presence: true + size: { in: 0..500.kilobytes } - validates_presence_of :name, :website_url, :sponsorship_level + validates_presence_of :name, :website_url, :sponsorship_level, :logo end diff --git a/app/views/conference/_sponsors.html.haml b/app/views/conference/_sponsors.html.haml index 22db2916..88a4400b 100644 --- a/app/views/conference/_sponsors.html.haml +++ b/app/views/conference/_sponsors.html.haml @@ -14,9 +14,8 @@ .row - slice.each do |sponsor| .col-md-4.col-sm-4.col-top - - if sponsor.logo.present? - = link_to(sponsor.website_url, class: 'thumbnail') do - = image_tag sponsor.logo, class: "img-responsive img-sponsor img-sponsor-#{sponsorship_level.position}", title: "#{sponsor.description}" + = link_to(sponsor.website_url, class: 'thumbnail') do + = image_tag get_logo(sponsor), class: "img-responsive img-sponsor img-sponsor-#{sponsorship_level.position}", title: "#{sponsor.description}" -if @conference.contact and !@conference.contact.sponsor_email.blank? .row .col-md-12