From 647a40be6371e340536c7ba35975a853c30f9a18 Mon Sep 17 00:00:00 2001 From: Christian Bruckmayer Date: Thu, 7 Apr 2016 14:38:36 -0600 Subject: [PATCH 1/5] Prettify sponsors section --- app/models/sponsor.rb | 4 +++- app/views/conference/_sponsors.html.haml | 25 ++++++-------------- spec/views/conference/show.html.haml_spec.rb | 1 - 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index 0981f24a..8b360c6d 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -6,6 +6,8 @@ class Sponsor < ActiveRecord::Base validates_attachment_content_type :logo, content_type: [/jpg/, /jpeg/, /png/, /gif/], - size: { in: 0..500.kilobytes } + size: { in: 0..500.kilobytes }, + presence: true + validates_presence_of :name, :website_url, :sponsorship_level end diff --git a/app/views/conference/_sponsors.html.haml b/app/views/conference/_sponsors.html.haml index 6ce4bc84..22db2916 100644 --- a/app/views/conference/_sponsors.html.haml +++ b/app/views/conference/_sponsors.html.haml @@ -6,28 +6,17 @@ .row .col-md-12 %h2 Sponsors - %p.lead - whom without, - %span.notranslate - = @conference.short_title - wouldn't be possible! - @conference.sponsorship_levels.each do |sponsorship_level| -if sponsorship_level.sponsors.any? + %h4 + = sponsorship_level.title - sponsorship_level.sponsors.each_slice(3) do |slice| - .row.row-centered + .row - slice.each do |sponsor| - .col-md-4.col-sm-4.col-centered.col-top - .thumbnail - - if sponsor.logo.blank? - %h3.text-center - = link_to(sponsor.website_url, title: "#{sponsor.name}") do - = sponsor.name - - else - = link_to(sponsor.website_url, class: 'thumbnail') do - = image_tag sponsor.logo, class: "img-responsive img-sponsor img-sponsor-#{sponsorship_level.position}", title: "#{sponsor.name}" - .caption - -if sponsor.description.present? - = markdown(sponsor.description) + .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}" -if @conference.contact and !@conference.contact.sponsor_email.blank? .row .col-md-12 diff --git a/spec/views/conference/show.html.haml_spec.rb b/spec/views/conference/show.html.haml_spec.rb index 31b1cdea..04951b64 100644 --- a/spec/views/conference/show.html.haml_spec.rb +++ b/spec/views/conference/show.html.haml_spec.rb @@ -58,7 +58,6 @@ describe 'conference/show.html.haml' do it 'renders sponsors partial' do expect(view).to render_template(partial: 'conference/_sponsors') expect(rendered).to match(/example@example.com/) - expect(rendered).to match(/Example sponsor/) expect(rendered).to match(/www.example.com/) expect(rendered).to match(/Lorem Ipsum Dolor/) expect(rendered).to match(/rails.jpg/) From af08d843a85b8b10883fd61e56f7c7330ef8c0da Mon Sep 17 00:00:00 2001 From: Aditya Prakash Date: Wed, 20 Apr 2016 12:13:07 +0530 Subject: [PATCH 2/5] 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 From 8da80f28e2ebad12730b34ca917306a914a4dbab Mon Sep 17 00:00:00 2001 From: Aditya Prakash Date: Wed, 20 Apr 2016 13:35:49 +0530 Subject: [PATCH 3/5] Add pop up modal for sponsor --- app/assets/stylesheets/osem-splash.css.scss | 3 ++- app/views/conference/_sponsors.html.haml | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/osem-splash.css.scss b/app/assets/stylesheets/osem-splash.css.scss index 717c9ab4..d378d223 100644 --- a/app/assets/stylesheets/osem-splash.css.scss +++ b/app/assets/stylesheets/osem-splash.css.scss @@ -89,10 +89,11 @@ } } } - + #sponsors { .img-sponsor { max-height: 100px; + margin: 2% auto; } .img-sponsor-1 { max-height: 200px; diff --git a/app/views/conference/_sponsors.html.haml b/app/views/conference/_sponsors.html.haml index 88a4400b..e50c838a 100644 --- a/app/views/conference/_sponsors.html.haml +++ b/app/views/conference/_sponsors.html.haml @@ -14,8 +14,25 @@ .row - slice.each do |sponsor| .col-md-4.col-sm-4.col-top - = 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}" + %a{ href: '#', data: { toggle: 'modal', target: "#modal_#{sponsor.id}" } } + = image_tag get_logo(sponsor), class: "img-responsive img-sponsor img-sponsor-#{sponsorship_level.position}" + + %div.modal.fade{ id: "modal_#{sponsor.id}" } + .modal-dialog + .modal-content + .modal-header + %button.close{ data: { dismiss: 'modal' } } + x + .modal-title + = sponsor.name + .modal-body.text-center + .logo + = link_to sponsor.website_url, target: '_blank' do + = image_tag get_logo(sponsor), class: "img-responsive img-sponsor img-sponsor-#{sponsorship_level.position}" + .description + = sponsor.description + .modal-footer + = link_to nil, "#{sponsor.website_url}", target: '_blank' -if @conference.contact and !@conference.contact.sponsor_email.blank? .row .col-md-12 From d662ebd25231546d09aa782f344b698d66b247c8 Mon Sep 17 00:00:00 2001 From: Aditya Prakash Date: Thu, 21 Apr 2016 21:22:14 +0530 Subject: [PATCH 4/5] Remove sponsorship level from view and test --- INSTALL.md | 9 ++++++ app/views/conference/_sponsors.html.haml | 9 ++---- spec/helpers/sponsor_helper_spec.rb | 40 ++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 spec/helpers/sponsor_helper_spec.rb diff --git a/INSTALL.md b/INSTALL.md index 9ee16f86..69d4a15f 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -63,6 +63,15 @@ We recommend to run OSEM in production with [mod_passenger](https://www.phusionp and the [apache web-server](https://www.apache.org/). There are tons of guides on how to deploy rails apps on various base operating systems. Check Google ;-) +#### ImageMagick +We use imagemagic for image manipulation of sponsor logo. You can get it from [direct install](http://software.opensuse.org/package/ImageMagick) page of the package or else check out [Download page](http://www.imagemagick.org/script/binary-releases.php) of ImageMagick. + +If you are upgrading your osem instance and would like to resize the exisiting logos, you would need to `reprocess!` the images: +``` +$ rails c +> Sponsor.find_each { |s| s.logo.reprocess! } +``` + #### Use openID In order to use the OpenID feature you need to register your application with the providers (Google and Facebook) and enter their API keys in config/secrets.yml file, changing the existing sample values. diff --git a/app/views/conference/_sponsors.html.haml b/app/views/conference/_sponsors.html.haml index e50c838a..dd202657 100644 --- a/app/views/conference/_sponsors.html.haml +++ b/app/views/conference/_sponsors.html.haml @@ -4,16 +4,14 @@ .container .row - .col-md-12 + .col-md-12.text-center %h2 Sponsors - @conference.sponsorship_levels.each do |sponsorship_level| -if sponsorship_level.sponsors.any? - %h4 - = sponsorship_level.title - sponsorship_level.sponsors.each_slice(3) do |slice| - .row + .row.row-centered - slice.each do |sponsor| - .col-md-4.col-sm-4.col-top + .col-md-4.col-sm-4.col-centered.col-top %a{ href: '#', data: { toggle: 'modal', target: "#modal_#{sponsor.id}" } } = image_tag get_logo(sponsor), class: "img-responsive img-sponsor img-sponsor-#{sponsorship_level.position}" @@ -41,4 +39,3 @@ Want to sponsor #{@conference.short_title}? = link_to("mailto: #{@conference.contact.sponsor_email}?subject=#{@conference.short_title}%20Sponsorship") do Please contact us! - diff --git a/spec/helpers/sponsor_helper_spec.rb b/spec/helpers/sponsor_helper_spec.rb new file mode 100644 index 00000000..492f9df5 --- /dev/null +++ b/spec/helpers/sponsor_helper_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe SponsorsHelper, type: :helper do + let(:sponsor) { create(:sponsor) } + + describe '#get_logo' do + context 'first sponsorship_level' do + before do + first_sponsorship_level = create(:sponsorship_level, position: 1) + sponsor.update_attributes(sponsorship_level: first_sponsorship_level) + end + + it 'returns correct url' do + expect(get_logo(sponsor)).to match %r{.*(\bfirst/rails.jpg\b)} + end + end + + context 'second sponsorship_level' do + before do + second_sponsorship_level = create(:sponsorship_level, position: 2) + sponsor.update_attributes(sponsorship_level: second_sponsorship_level) + end + + it 'returns correct url' do + expect(get_logo(sponsor)).to match %r{.*(\bsecond/rails.jpg\b)} + end + end + + context 'other sponsorship_level' do + before do + other_sponsorship_level = create(:sponsorship_level, position: 3) + sponsor.update_attributes(sponsorship_level: other_sponsorship_level) + end + + it 'returns correct url' do + expect(get_logo(sponsor)).to match %r{.*(\bothers/rails.jpg\b)} + end + end + end +end From d47e9c317dff3e3c7123c6f0249fce3500f3a6e7 Mon Sep 17 00:00:00 2001 From: Aditya Prakash Date: Mon, 25 Apr 2016 17:18:02 +0530 Subject: [PATCH 5/5] Add rake task to reprocess sponsor logos rake logo:reprocess --- INSTALL.md | 5 ++--- lib/tasks/.gitkeep | 0 lib/tasks/logo.rake | 6 ++++++ 3 files changed, 8 insertions(+), 3 deletions(-) delete mode 100644 lib/tasks/.gitkeep create mode 100644 lib/tasks/logo.rake diff --git a/INSTALL.md b/INSTALL.md index 69d4a15f..e86f0662 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -66,10 +66,9 @@ base operating systems. Check Google ;-) #### ImageMagick We use imagemagic for image manipulation of sponsor logo. You can get it from [direct install](http://software.opensuse.org/package/ImageMagick) page of the package or else check out [Download page](http://www.imagemagick.org/script/binary-releases.php) of ImageMagick. -If you are upgrading your osem instance and would like to resize the exisiting logos, you would need to `reprocess!` the images: +If you are upgrading your osem instance and would like to resize the exisiting logos, you would need to `reprocess!` the images. You can do it by running the following rake task: ``` -$ rails c -> Sponsor.find_each { |s| s.logo.reprocess! } +$ rake logo:reprocess ``` #### Use openID diff --git a/lib/tasks/.gitkeep b/lib/tasks/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/tasks/logo.rake b/lib/tasks/logo.rake new file mode 100644 index 00000000..cea95113 --- /dev/null +++ b/lib/tasks/logo.rake @@ -0,0 +1,6 @@ +namespace :logo do + desc 'Resize existing logo of sponsors after change in image manipulation specifications' + task reprocess: :environment do + Sponsor.find_each { |s| s.logo.reprocess! } + end +end