Module: Formol::PostsHelper

Included in:
TopicsHelper
Defined in:
app/helpers/formol/posts_helper.rb

Instance Method Summary collapse

Instance Method Details

#avatar_for(user) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/formol/posts_helper.rb', line 27

def avatar_for(user)
  img = if user.respond_to?(:avatar_url) && user.avatar_url.present?
    user.avatar_url
  elsif user.respond_to?(:email) && user.email.present?
    require 'digest/md5' unless defined?(Digest::MD5)
    
    email_h = Digest::MD5.hexdigest(user.email.to_s.strip.downcase)
    options = { :s => 100, :d => default_avatar }
    
    "http://www.gravatar.com/avatar/#{email_h}?#{options.to_param}"
  else
    default_avatar
  end
  
  image_tag(img, :alt => user.display_name)
end

#default_avatarObject



44
45
46
47
48
# File 'app/helpers/formol/posts_helper.rb', line 44

def default_avatar
  img = Formol.config.default_avatar
  
  img && URI(img).absolute? ? img : request.protocol + request.host_with_port + path_to_image(img)
end

#display_avatars?(user) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'app/helpers/formol/posts_helper.rb', line 15

def display_avatars?(user)
  return true unless user
  
  user.preference.display_avatars?
end

#display_signatures?(user, post) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'app/helpers/formol/posts_helper.rb', line 21

def display_signatures?(user, post)
  s = post.display_signature? && !post.user.preference.signature.blank?
  
  (s && user ? user.preference.display_signatures? : s)
end

#link_to_last_fives_post_position(post, topic, index) ⇒ Object



9
10
11
12
13
# File 'app/helpers/formol/posts_helper.rb', line 9

def link_to_last_fives_post_position(post, topic, index)
  idx = topic.posts_count - index
  
  return link_to "##{idx}", "#formol_post_#{post.id}"
end

#link_to_post_position(post, index) ⇒ Object



3
4
5
6
7
# File 'app/helpers/formol/posts_helper.rb', line 3

def link_to_post_position(post, index)
  idx = ((params[:page] || 1) - 1) * per_page + index + 1
  
  return link_to "##{idx}", "#formol_post_#{post.id}"
end