From f1cff3883d90933dc42a38d59d74db374dd9d66b Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Sun, 1 Nov 2020 23:24:07 +0100 Subject: [PATCH] small_img() helper added --- app/helpers/packages_helper.rb | 18 ++++++++++++ app/views/packages/_grid_thumbnail.slim | 38 ++++++++++++++++--------- app/views/packages/_medium_image.slim | 14 --------- app/views/welcome/home.slim | 4 +-- 4 files changed, 45 insertions(+), 29 deletions(-) delete mode 100644 app/views/packages/_medium_image.slim diff --git a/app/helpers/packages_helper.rb b/app/helpers/packages_helper.rb index a246fd2..66e4a09 100644 --- a/app/helpers/packages_helper.rb +++ b/app/helpers/packages_helper.rb @@ -32,6 +32,24 @@ module PackagesHelper str.join(' ∙ ') end + def small_img(screenshot, cls: 'thumbnail') + if screenshot && screenshot.simage(:small) + image = screenshot.simage(:small) + image_tag( + image.url, + width: image.width, + height: image.height, + alt: screenshot.caption, + class: cls + ) + else + image_tag( + '/images/dummy/no-screenshots-available.svg', + width: 220, + height: 220 * 3 / 4 + ) + end + end # Show filled/empty star icons from FontAwesome # depending on the rating (1-5) diff --git a/app/views/packages/_grid_thumbnail.slim b/app/views/packages/_grid_thumbnail.slim index dd9281d..ef3fc51 100644 --- a/app/views/packages/_grid_thumbnail.slim +++ b/app/views/packages/_grid_thumbnail.slim @@ -1,15 +1,27 @@ // TODO: Handle packages with multiple screenshots a.black href=package_path(name: pkg.name) - div.grid-thumbnail - - if pkg.screenshots_approved.any? - // TODO: smarter selection of the most useful screenshot instead of taking the first one - - screenshot = pkg.screenshots.first - /= image_tag(screenshot.image.variant(resize_to_limit: [160,120]), alt: screenshot.caption, class: 'thumbnail') - = image_tag(screenshot.simage_url(:small), alt: screenshot.caption, class: 'thumbnail') - - else - img.screenshot.thumbnail src="/images/dummy/no-screenshots-upload-one.svg" - div - .pkgname - = pkg.name - .pkgdescription - = pkg.description + / div.grid-thumbnail + / - if pkg.screenshots_approved.any? + / // TODO: smarter selection of the most useful screenshot instead of taking the first one + / - screenshot = pkg.screenshots.first + / = small_img(screenshot) + / - else + / img.screenshot.thumbnail src="/images/dummy/no-screenshots-upload-one.svg" + / div + / .pkgname + / = pkg.name + / .pkgdescription + / = pkg.description + + .image + = small_img(pkg.screenshots.first, cls: '') + .text.pkgname + = pkg.name + .text + = pkg.description + + / .card.callout + / .card-divider = pkg.name + / = small_img(pkg.screenshots.first, cls: 'float-center') + / .card-section + / = pkg.description diff --git a/app/views/packages/_medium_image.slim b/app/views/packages/_medium_image.slim deleted file mode 100644 index 22e2292..0000000 --- a/app/views/packages/_medium_image.slim +++ /dev/null @@ -1,14 +0,0 @@ -/ Show image in medium size with zoom option and caption below -a href =url_for(screenshot.simage_url(:large)) rel='fancybox-thumb' title=screenshot.caption data-fancybox='gallery' data-caption=screenshot_caption(screenshot) - .image-with-zoom-icon - = image_tag(url_for(screenshot.simage_url(:medium)), alt: screenshot.caption, class: 'thumbnail') - - .magnifying-glass-icon - i.fa.fa-search - -.imgcaption - = screenshot.description - -/ Display management buttons for admins only -- if user_signed_in? and current_user.is_admin? - = render(partial: 'admin_dropdown', locals: {screenshot: screenshot}) diff --git a/app/views/welcome/home.slim b/app/views/welcome/home.slim index da829ea..b066319 100644 --- a/app/views/welcome/home.slim +++ b/app/views/welcome/home.slim @@ -30,7 +30,7 @@ h2 Newest upload .thumb-height a href=package_path(@newest_upload.package.name) - = image_tag(@newest_upload.image.variant(resize_to_limit: [160,120]), alt: @newest_upload.caption) + = small_img(@newest_upload) p strong =@newest_upload.package.name @@ -41,7 +41,7 @@ .thumb-height - if @most_popular_package a href=package_path(@most_popular_package.name) - = image_tag(@most_popular_package.screenshots.first.image.variant(resize_to_limit: [160,120])) + = small_img(@most_popular_package.screenshots.first) - else 'No uploaded screenshots yet. p