1
0
Fork 0
forked from OpenNeo/impress
impress/app/helpers/contribution_helper.rb

45 lines
1.3 KiB
Ruby
Raw Normal View History

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-08-01 10:34:54 -07:00
contributed_item(contributed, image, 'for the first time')
2010-11-06 08:52:58 -07:00
when SwfAsset
2012-08-01 10:34:54 -07:00
contributed_item(contributed.item, image, 'on a new body type')
2010-11-06 08:52:58 -07:00
when PetType
2012-08-01 10:34:54 -07:00
contributed_pet_type(contributed, image, :after => 'for the first time')
2010-11-06 08:52:58 -07:00
when PetState
2012-08-01 10:34:54 -07:00
contributed_pet_type(contributed.pet_type, image, :before => 'a new pose for')
2010-11-06 08:52:58 -07:00
end
end
2012-08-01 10:34:54 -07:00
def contributed_item(item, image = true, 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:34:54 -07:00
def contributed_pet_type(pet_type, image = true, 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
end