Module: UsersHelper

Includes:
LetterAvatar::AvatarHelper
Defined in:
app/helpers/users_helper.rb

Instance Method Summary collapse

Instance Method Details

#block_node_tag(node) ⇒ Object


98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/helpers/users_helper.rb', line 98

def block_node_tag(node)
  return '' if current_user.blank?
  return '' if node.blank?
  blocked = current_user.blocked_node_ids.include?(node.id)
  class_names = 'btn btn-default btn-sm button-block-node'
  icon = '<i class="fa fa-eye-slash"></i>'
  if blocked
    link_to raw("#{icon} <span>取消屏蔽</span>"), '#', title: '忽略后,社区首页列表将不会显示这里的内容。', 'data-id' => node.id, class: "#{class_names} active"
  else
    link_to raw("#{icon} <span>忽略节点</span>"), '#', title: '', 'data-id' => node.id, class: class_names
  end
end

#block_user_tag(user) ⇒ Object


111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/helpers/users_helper.rb', line 111

def block_user_tag(user)
  return '' if current_user.blank?
  return '' if user.blank?
  return '' if current_user.id == user.id
  blocked = current_user.blocked_user_ids.include?(user.id)
  class_names = 'button-block-user btn btn-default btn-block'
  icon = '<i class="fa fa-eye-slash"></i>'
  if blocked
    link_to raw("#{icon} <span>取消屏蔽</span>"), '#', title: '忽略后,社区首页列表将不会显示此用户发布的内容。', 'data-id' => user., class: "#{class_names} active"
  else
    link_to raw("#{icon} <span>屏蔽</span>"), '#', title: '', 'data-id' => user., class: class_names
  end
end

#follow_user_tag(user, opts = {}) ⇒ Object


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'app/helpers/users_helper.rb', line 125

def follow_user_tag(user, opts = {})
  return '' if current_user.blank?
  return '' if user.blank?
  return '' if current_user.id == user.id
  followed = current_user.followed?(user)
  opts[:class] ||= 'btn btn-primary btn-block'
  class_names = "button-follow-user #{opts[:class]}"
  icon = '<i class="fa fa-user"></i>'
   = user..downcase
  if followed
    link_to raw("#{icon} <span>取消关注</span>"), '#', 'data-id' => , class: "#{class_names} active"
  else
    link_to raw("#{icon} <span>关注</span>"), '#', title: '', 'data-id' => , class: class_names
  end
end

#render_user_github_url(user) ⇒ Object


75
76
77
# File 'app/helpers/users_helper.rb', line 75

def render_user_github_url(user)
  link_to(user.github_url, user.github_url, target: '_blank', rel: 'nofollow')
end

#render_user_join_time(user) ⇒ Object


67
68
69
# File 'app/helpers/users_helper.rb', line 67

def render_user_join_time(user)
  I18n.l(user.created_at.to_date, format: :long)
end

#render_user_level_tag(user) ⇒ Object


84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/helpers/users_helper.rb', line 84

def render_user_level_tag(user)
  return '' if user.blank?
  level_class = case user.level
                when 'admin' then 'label-danger'
                when 'vip' then 'label-success'
                when 'hr' then 'label-success'
                when 'blocked' then 'label-warning'
                when 'newbie' then 'label-default'
                else 'label-info'
                end

  (:span, user.level_name, class: "label #{level_class} role")
end

#render_user_personal_website(user) ⇒ Object


79
80
81
82
# File 'app/helpers/users_helper.rb', line 79

def render_user_personal_website(user)
  website = user.website[%r{^https?://}] ? user.website : 'http://' + user.website
  link_to(website, website, target: '_blank', class: 'url', rel: 'nofollow')
end

#render_user_tagline(user) ⇒ Object


71
72
73
# File 'app/helpers/users_helper.rb', line 71

def render_user_tagline(user)
  user.tagline
end

#user_avatar_size_name_for_2x(size) ⇒ Object


33
34
35
36
37
38
39
40
41
# File 'app/helpers/users_helper.rb', line 33

def user_avatar_size_name_for_2x(size)
  case size
  when :normal then :large
  when :small then :normal
  when :large then :big
  when :big then :big
  else size
  end
end

#user_avatar_tag(user, size = :normal, opts = {}) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/users_helper.rb', line 43

def user_avatar_tag(user, size = :normal, opts = {})
  link = opts[:link].nil? ? true : opts[:link]

  width = user_avatar_width_for_size(size)
  img_class = "media-object avatar-#{width}"

  if user.blank?
    # hash = Digest::MD5.hexdigest("") => d41d8cd98f00b204e9800998ecf8427e
    return image_tag("avatar/#{size}.png", class: img_class)
  end

  if user.avatar?
    img = image_tag(user.avatar.url(user_avatar_size_name_for_2x(size)), class: img_class)
  else
    img = image_tag(user.letter_avatar_url(width * 2), class: img_class)
  end

  if link
    link_to(raw(img), user_path(user))
  else
    raw img
  end
end

#user_avatar_width_for_size(size) ⇒ Object


23
24
25
26
27
28
29
30
31
# File 'app/helpers/users_helper.rb', line 23

def user_avatar_width_for_size(size)
  case size
  when :normal then 48
  when :small then 16
  when :large then 96
  when :big then 120
  else size
  end
end

#user_name_tag(user, options = {}) ⇒ Object

生成用户 login 的链接,user 参数可接受 user 对象或者 字符串的 login


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/users_helper.rb', line 6

def user_name_tag(user, options = {})
  return '匿名'.freeze if user.blank?

  if user.is_a? String
     = user
    name = 
  else
     = user.
    name = user.name
  end

  name ||= 
  options['data-name'.freeze] = name

  link_to(, main_app.user_path(), options)
end