Module: Thredded::ApplicationHelper
- Includes:
- UrlsHelper
- Defined in:
- app/helpers/thredded/application_helper.rb
Instance Method Summary
collapse
Methods included from UrlsHelper
#delete_post_path, #edit_post_path, #edit_preferences_path, #edit_preferences_url, #post_path, #post_url, #search_path, #topic_path, #topic_url, #user_path
Instance Method Details
#moderatable_messageboards_ids ⇒ Object
93
94
95
96
|
# File 'app/helpers/thredded/application_helper.rb', line 93
def moderatable_messageboards_ids
@moderatable_messageboards_ids ||=
thredded_current_user.thredded_can_moderate_messageboards.pluck(:id)
end
|
#paginate(collection, args = {}) ⇒ Object
55
56
57
|
# File 'app/helpers/thredded/application_helper.rb', line 55
def paginate(collection, args = {})
super(collection, args.reverse_merge(views_prefix: 'thredded'))
end
|
#posts_pending_moderation_count ⇒ Object
98
99
100
101
|
# File 'app/helpers/thredded/application_helper.rb', line 98
def posts_pending_moderation_count
@posts_pending_moderation_count ||=
Thredded::Post.where(messageboard_id: moderatable_messageboards_ids).pending_moderation.count
end
|
#thredded_container_classes ⇒ Object
13
14
15
16
17
|
# File 'app/helpers/thredded/application_helper.rb', line 13
def thredded_container_classes
['thredded--main-container', content_for(:thredded_page_id)].tap do |classes|
classes << 'thredded--is-moderator' if moderatable_messageboards_ids
end
end
|
#thredded_container_data ⇒ Object
6
7
8
9
10
11
|
# File 'app/helpers/thredded/application_helper.rb', line 6
def thredded_container_data
{
'thredded-page-id' => content_for(:thredded_page_id),
'thredded-root-url' => thredded.root_path
}
end
|
#thredded_page(&block) ⇒ Object
Render the page container with the supplied block as content.
20
21
22
23
24
25
|
# File 'app/helpers/thredded/application_helper.rb', line 20
def thredded_page(&block)
content_for :thredded, true
content_for :thredded_page_content, &block
render partial: 'thredded/shared/page'
end
|
#time_ago(datetime, default: '-') ⇒ String
Returns html_safe datetime presentation.
47
48
49
50
51
52
53
|
# File 'app/helpers/thredded/application_helper.rb', line 47
def time_ago(datetime, default: '-')
timeago_tag datetime,
lang: I18n.locale.to_s.downcase,
format: -> (t, _opts) { t.year == Time.current.year ? :short : :long },
nojs: true,
default: default
end
|
#topic_css_classes(topic) ⇒ Array<String>
61
62
63
64
65
66
67
|
# File 'app/helpers/thredded/application_helper.rb', line 61
def topic_css_classes(topic)
[
*topic.states.map { |s| "thredded--topic-#{s}" },
*(topic.categories.map { |c| "thredded--topic-category-#{c.name}" } if topic.respond_to?(:categories)),
*('thredded--private-topic' if topic.is_a?(Thredded::PrivateTopicView))
]
end
|
#topic_follow_reason_text(follow_reason) ⇒ Object
70
71
72
73
74
75
76
77
78
79
|
# File 'app/helpers/thredded/application_helper.rb', line 70
def topic_follow_reason_text(follow_reason)
if follow_reason
t("thredded.topics.following.#{follow_reason}")
else
t('thredded.topics.not_following')
end
end
|
#unread_private_topics_count ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/helpers/thredded/application_helper.rb', line 81
def unread_private_topics_count
@unread_private_topics_count ||=
if signed_in?
Thredded::PrivateTopic
.for_user(thredded_current_user)
.unread(thredded_current_user)
.count
else
0
end
end
|
#user_link(user) ⇒ String
Returns html_safe link to the user.
29
30
31
|
# File 'app/helpers/thredded/application_helper.rb', line 29
def user_link(user)
render partial: 'thredded/users/link', locals: { user: user }
end
|
#user_mention(user) ⇒ String
Returns wrapped @mention string.
35
36
37
38
39
40
41
42
|
# File 'app/helpers/thredded/application_helper.rb', line 35
def user_mention(user)
username = user.send(Thredded.user_name_column)
if username.include?(' ')
%(@"#{username}")
else
"@#{username}"
end
end
|