module PackagesHelper # Return the description and/or the version of the package def screenshot_caption(screenshot) str = [] str << screenshot.description if screenshot.description.present? if screenshot.version.present? str << "#{screenshot.package.name} version #{screenshot.version}" end str << "uploaded #{time_ago_in_words(screenshot.created_at)} ago" str.join(' ∙ ') end def small_img(screenshot, cls: 'thumbnail') if screenshot&.simage(:small) image = screenshot.simage(:small) # image = screenshot_image_path(name: screenshot.package.name) image_tag( small_image_with_id_path(name: screenshot.package.name, screenshot_id: screenshot.id), width: image.width, height: image.height, alt: screenshot.caption, class: cls ) else image_tag( '/images/dummy/no-screenshots-upload-one.svg', width: 220, height: 220 * 3 / 4 ) end end # Show filled/empty star icons from FontAwesome # depending on the rating (1-5) # def star_rating(rating) # filled_stars = fa_icon('star') * rating # empty_stars = fa_icon('star-o') * (5-rating) # (filled_stars+empty_stars).html_safe # end # Return a readable status of a screenshot and a matching CSS color class def status(screenshot) if screenshot.approved && !screenshot.hidden ["#{icon('eye', class: 'icon')} Public".html_safe, 'public'] elsif screenshot.hidden ["#{icon('eye-closed', class: 'icon')} Hidden".html_safe, 'hidden'] elsif !screenshot.approved ["#{icon('hourglass', class: 'icon')} Unapproved".html_safe, 'unapproved'] end end end