Module: TopicsHelper

Defined in:
app/helpers/topics_helper.rb

Instance Method Summary collapse

Instance Method Details

#markdown(text) ⇒ Object


3
4
5
# File 'app/helpers/topics_helper.rb', line 3

def markdown(text)
  sanitize_markdown(MarkdownTopicConverter.format(text))
end

#render_topic_created_at(topic) ⇒ Object


72
73
74
# File 'app/helpers/topics_helper.rb', line 72

def render_topic_created_at(topic)
  timeago(topic.created_at, class: 'published')
end

#render_topic_last_be_replied_time(topic) ⇒ Object


76
77
78
# File 'app/helpers/topics_helper.rb', line 76

def render_topic_last_be_replied_time(topic)
  timeago(topic.replied_at)
end

#render_topic_last_reply_time(topic) ⇒ Object


68
69
70
# File 'app/helpers/topics_helper.rb', line 68

def render_topic_last_reply_time(topic)
  l((topic.replied_at || topic.created_at), format: :short)
end

#render_topic_node_select_tag(topic) ⇒ Object


80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/topics_helper.rb', line 80

def render_topic_node_select_tag(topic)
  return if topic.blank?
  opts = {
    'data-width' => '140px',
    'data-live-search' => 'true',
    class: 'show-menu-arrow'
  }
  grouped_collection_select :topic, :node_id, Section.all, :sorted_nodes, :name, :id, :name,
                            { value: topic.node_id, prompt: '选择节点' }, opts
end

#topic_excellent_tag(topic) ⇒ Object


63
64
65
66
# File 'app/helpers/topics_helper.rb', line 63

def topic_excellent_tag(topic)
  return '' unless topic.excellent?
  (:i, '', title: '精华帖', class: 'fa fa-diamond')
end

#topic_favorite_tag(topic, opts = {}) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/topics_helper.rb', line 16

def topic_favorite_tag(topic, opts = {})
  return '' if current_user.blank?
  opts[:class] ||= ""
  class_name = ''
  link_title = '收藏'
  if current_user && current_user.favorite_topic_ids.include?(topic.id)
    class_name = 'active'
    link_title = '取消收藏'
  end

  icon = raw(('i', '', class: 'fa fa-bookmark'))
  if opts[:class].present?
    class_name += ' ' + opts[:class]
  end

  link_to(raw("#{icon} 收藏"), '#', title: link_title, class: "bookmark #{class_name}", 'data-id' => topic.id)
end

#topic_follow_tag(topic, opts = {}) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/topics_helper.rb', line 34

def topic_follow_tag(topic, opts = {})
  return '' if current_user.blank?
  return '' if topic.blank?
  return '' if owner?(topic)
  opts[:class] ||= ""
  class_name = 'follow'
  followed = false
  if topic.follower_ids.include?(current_user.id)
    class_name = 'follow active'
    followed = true
  end
  if opts[:class].present?
    class_name += ' ' + opts[:class]
  end
  icon = ('i', '', class: 'fa fa-eye')
  link_to(raw("#{icon} 关注"), '#', 'data-id' => topic.id, class: class_name)
end

#topic_title_tag(topic, opts = {}) ⇒ Object


52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/topics_helper.rb', line 52

def topic_title_tag(topic, opts = {})
  return t('topics.topic_was_deleted') if topic.blank?
  if opts[:reply]
    index = topic.floor_of_reply(opts[:reply])
    path = main_app.topic_path(topic, anchor: "reply#{index}")
  else
    path = main_app.topic_path(topic)
  end
  link_to(topic.title, path, title: topic.title)
end

#topic_use_readed_text(state) ⇒ Object


7
8
9
10
11
12
13
14
# File 'app/helpers/topics_helper.rb', line 7

def topic_use_readed_text(state)
  case state
  when true
    t('topics.have_no_new_reply')
  else
    t('topics.has_new_replies')
  end
end