50 lines
1.5 KiB
Ruby
50 lines
1.5 KiB
Ruby
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 && 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-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'), 'public']
|
|
elsif screenshot.hidden
|
|
[(icon('eye-closed', class: 'icon') + ' Hidden'), 'hidden']
|
|
elsif !screenshot.approved
|
|
[(icon('hourglass', class: 'icon') + ' Unapproved'), 'unapproved']
|
|
end
|
|
end
|
|
end
|