2010-11-06 08:52:58 -07:00
|
|
|
module ContributionHelper
|
2013-02-12 09:45:54 -08:00
|
|
|
def contributed_description(contributed, show_image = true)
|
2010-11-06 08:52:58 -07:00
|
|
|
case contributed
|
|
|
|
when Item
|
2013-02-12 09:45:54 -08:00
|
|
|
contributed_item('item', contributed, show_image)
|
2010-11-06 08:52:58 -07:00
|
|
|
when SwfAsset
|
2013-02-12 09:45:54 -08:00
|
|
|
contributed_item('swf_asset', contributed.item, show_image)
|
2010-11-06 08:52:58 -07:00
|
|
|
when PetType
|
2013-02-12 09:45:54 -08:00
|
|
|
contributed_pet_type('pet_type', contributed, show_image)
|
2010-11-06 08:52:58 -07:00
|
|
|
when PetState
|
2013-02-12 09:45:54 -08:00
|
|
|
contributed_pet_type('pet_state', contributed.pet_type, show_image)
|
2010-11-06 08:52:58 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-12 09:45:54 -08:00
|
|
|
def contributed_item(main_key, item, show_image)
|
2010-11-15 13:44:57 -08:00
|
|
|
if item
|
2013-02-12 09:45:54 -08:00
|
|
|
link = link_to(item.name, item, :class => 'contributed-name')
|
|
|
|
description = translate('contributions.contributed_description.parents.item.present_html',
|
|
|
|
:item_link => link)
|
|
|
|
output = translate("contributions.contributed_description.main.#{main_key}_html",
|
|
|
|
:item_description => description)
|
2023-11-11 08:24:08 -08:00
|
|
|
output << image_tag(item.thumbnail_url) if show_image
|
2013-02-12 09:45:54 -08:00
|
|
|
output
|
2010-11-15 13:44:57 -08:00
|
|
|
else
|
2013-02-12 09:45:54 -08:00
|
|
|
translate('contributions.contributed_description.parents.item.blank')
|
2010-11-06 08:52:58 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-25 15:16:46 -07:00
|
|
|
PET_TYPE_IMAGE_FORMAT = 'https://pets.neopets.com/cp/%s/1/3.png'
|
2013-02-12 09:45:54 -08:00
|
|
|
def contributed_pet_type(main_key, pet_type, show_image)
|
|
|
|
span = content_tag(:span, pet_type.human_name, :class => 'contributed-name')
|
|
|
|
description = translate('contributions.contributed_description.parents.pet_type_html',
|
|
|
|
:pet_type_name => span)
|
|
|
|
output = translate("contributions.contributed_description.main.#{main_key}_html",
|
|
|
|
:pet_type_description => description)
|
|
|
|
output << image_tag(sprintf(PET_TYPE_IMAGE_FORMAT, pet_type.image_hash)) if show_image
|
|
|
|
output
|
2010-11-06 08:52:58 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def output(&block)
|
|
|
|
raw([].tap(&block).join(' '))
|
|
|
|
end
|
2012-12-29 22:46:36 -08:00
|
|
|
|
2013-02-12 09:45:54 -08:00
|
|
|
def translate_contributed_suffix(key)
|
|
|
|
translate "contributions.contributed_description.suffix.#{key}"
|
2012-12-29 22:46:36 -08:00
|
|
|
end
|
2010-11-06 08:52:58 -07:00
|
|
|
end
|