2010-11-06 08:52:58 -07:00
|
|
|
module ContributionHelper
|
2012-08-01 10:34:54 -07:00
|
|
|
def contributed_description(contributed, image = true)
|
2010-11-06 08:52:58 -07:00
|
|
|
case contributed
|
|
|
|
when Item
|
2012-12-29 22:46:36 -08:00
|
|
|
suffix = translate_contributed_description('item_suffix')
|
|
|
|
contributed_item(contributed, image, suffix)
|
2010-11-06 08:52:58 -07:00
|
|
|
when SwfAsset
|
2012-12-29 22:46:36 -08:00
|
|
|
suffix = translate_contributed_description('swf_asset_suffix')
|
|
|
|
contributed_item(contributed.item, image, suffix)
|
2010-11-06 08:52:58 -07:00
|
|
|
when PetType
|
2012-12-29 22:46:36 -08:00
|
|
|
suffix = translate_contributed_description('pet_type_suffix')
|
|
|
|
contributed_pet_type(contributed, image, :after => suffix)
|
2010-11-06 08:52:58 -07:00
|
|
|
when PetState
|
2012-12-29 22:46:36 -08:00
|
|
|
prefix = translate_contributed_description('pet_state_prefix')
|
|
|
|
contributed_pet_type(contributed.pet_type, image, :before => prefix)
|
2010-11-06 08:52:58 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-01 10:47:15 -07:00
|
|
|
def contributed_item(item, image, adverbial)
|
2010-11-15 13:44:57 -08:00
|
|
|
if item
|
|
|
|
output do |html|
|
|
|
|
html << 'the'
|
|
|
|
html << link_to(item.name, item, :class => 'contributed-name')
|
|
|
|
html << adverbial
|
2012-08-01 10:34:54 -07:00
|
|
|
html << image_tag(item.thumbnail_url) if image
|
2010-11-15 13:44:57 -08:00
|
|
|
end
|
|
|
|
else
|
|
|
|
"data for an item that has since been updated"
|
2010-11-06 08:52:58 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
PET_TYPE_IMAGE_FORMAT = 'http://pets.neopets.com/cp/%s/1/3.png'
|
2012-08-01 10:47:15 -07:00
|
|
|
def contributed_pet_type(pet_type, image, options)
|
2010-11-06 08:52:58 -07:00
|
|
|
options[:before] ||= 'the'
|
|
|
|
output do |html|
|
|
|
|
html << options[:before]
|
|
|
|
html << content_tag(:span, pet_type.human_name, :class => 'contributed-name')
|
|
|
|
html << options[:after] if options[:after]
|
2012-08-01 10:34:54 -07:00
|
|
|
html << image_tag(sprintf(PET_TYPE_IMAGE_FORMAT, pet_type.image_hash)) if image
|
2010-11-06 08:52:58 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def output(&block)
|
|
|
|
raw([].tap(&block).join(' '))
|
|
|
|
end
|
2012-12-29 22:46:36 -08:00
|
|
|
|
|
|
|
def translate_contributed_description(key)
|
|
|
|
translate "contributions.contributed_description.#{key}"
|
|
|
|
end
|
2010-11-06 08:52:58 -07:00
|
|
|
end
|