Sha256: 909184058a7c4cd1713168404d84ce92f2ab11d0e0f23b17610056bfaa2ff325
Contents?: true
Size: 1.29 KB
Versions: 2
Compression:
Stored size: 1.29 KB
Contents
module Hydra::PersonalizationHelperBehavior DEFAULT_USER_ATTRIBUTES = ['full_name', 'affiliation', 'photo'] # Helper methods to retrieve information from the user attributes # # == get_full_name_from_login # # Given a login, returns a string concatenating first_name and last_name # # == get_affiliation_from_login # # Given a login, returns a string # # == get_photo_from_login # # Given a login, returns a string representing either a path or a url pointing to an image file DEFAULT_USER_ATTRIBUTES.each do |m| class_eval <<-EOC def #{m}_from_login login get_user_attribute(login, '#{m}') end EOC end # Creates an image tag with the user#photo attribute as the source # @param [string] login the login of the user # @return an html image tag or an empty string def user_photo_tag login path = photo_from_login login path == "" ? "" : image_tag(path) end private # Retrieves an attribute from the user # @param [string] login the login of the user # @param [string] attribute the name of the attribute: out of the box values are first_name, last_name, full_name, affiliation, and photo def get_user_attribute login, attribute user = User.find_by_login(login) user.nil? ? "" : user.send(attribute.to_sym) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hydra-head-4.0.3 | app/helpers/hydra/personalization_helper_behavior.rb |
hydra-head-4.0.2 | app/helpers/hydra/personalization_helper_behavior.rb |