Sha256: b5075b1bb69304795ac9e0520bc31475d5c9d22e46fefd7106c8f9ae7c4900d4

Contents?: true

Size: 1.28 KB

Versions: 22

Compression:

Stored size: 1.28 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] 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

22 entries across 22 versions & 1 rubygems

Version Path
hydra-head-4.0.1 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-4.0.0 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-4.0.0.rc6 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-4.0.0.rc5 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-4.0.0.rc4 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-4.0.0.rc3 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-4.0.0.rc2 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.3.0 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.2.2 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.2.1 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.2.0 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.2.0.pre3 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.2.0.pre2 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.2.0.pre1 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.1.5 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.1.4 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.1.3 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.1.2 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.1.1 app/helpers/hydra/personalization_helper_behavior.rb
hydra-head-3.1.0 app/helpers/hydra/personalization_helper_behavior.rb