impress/app/helpers/items_helper.rb

29 lines
983 B
Ruby
Raw Normal View History

2010-05-15 10:47:46 -07:00
module ItemsHelper
StandardSpeciesImageFormat = 'http://pets.neopets.com/cp/%s/1/1.png'
def standard_species_images(species_list)
2010-06-07 13:08:53 -07:00
pet_types = PetType.random_basic_per_species(species_list.map(&:id))
raw(pet_types.inject('') do |html, pet_type|
src = sprintf(StandardSpeciesImageFormat, pet_type.image_hash)
2010-06-07 13:08:53 -07:00
human_name = pet_type.species.name.humanize
2010-05-16 16:21:36 -07:00
image = image_tag(src, :alt => human_name, :title => human_name)
2010-06-07 13:08:53 -07:00
attributes = {
'data-id' => pet_type.id,
'data-body-id' => pet_type.body_id
}
[:color, :species].each do |pet_type_attribute_name|
pet_type_attribute = pet_type.send(pet_type_attribute_name)
[:id, :name].each do |subattribute_name|
attributes["data-#{pet_type_attribute_name}-#{subattribute_name}"] =
pet_type_attribute.send(subattribute_name)
end
end
html + link_to(
image,
'#',
2010-06-07 13:08:53 -07:00
attributes
)
end)
end
2010-05-15 10:47:46 -07:00
end