Module: Thredded::ApplicationHelper
- Includes:
- IconHelper, NavHelper, RenderHelper, UrlsHelper
- Included in:
- DatabaseSeeder
- Defined in:
- app/helpers/thredded/application_helper.rb
Constant Summary
Constants included from NavHelper
NavHelper::USER_NAV_MODERATION_PAGES, NavHelper::USER_NAV_PREFERENCES_PAGES, NavHelper::USER_NAV_PRIVATE_TOPICS_PAGES, NavHelper::USER_NAV_UNREAD_TOPICS
Instance Method Summary collapse
- #global_nav_icons_count ⇒ Object
- #paginate(collection, args = {}) ⇒ Object
- #posts_pending_moderation_count ⇒ Object
- #render_posts(posts, partial: 'thredded/posts/post', content_partial: 'thredded/posts/content', locals: {}) ⇒ Object
- #thredded_container_classes ⇒ Object
- #thredded_container_data ⇒ Object
-
#thredded_page(&block) ⇒ Object
Render the page container with the supplied block as content.
-
#time_ago(datetime, default: '-', html_options: {}) ⇒ String
Html_safe datetime presentation.
- #topic_css_classes(topic) ⇒ Array<String>
- #topic_follow_reason_text(follow_reason) ⇒ Object
-
#user_link(user) ⇒ String
Html_safe link to the user.
-
#user_mention(user) ⇒ String
Wrapped @mention string.
-
#view_hooks ⇒ AllViewHooks
View hooks configuration.
Methods included from IconHelper
#define_svg_icons, #inline_svg_once, #shared_inline_svg
Methods included from RenderHelper
#render_collection_to_strings_with_cache
Methods included from NavHelper
#current_page_moderation?, #current_page_preferences?, #current_page_private_topics?, #current_page_unread_topics?, #nav_back_path
Methods included from UrlsHelper
#delete_post_path, #edit_post_path, #edit_preferences_path, #edit_preferences_url, #mark_unread_path, #permalink_path, #post_path, #post_url, #quote_post_path, #search_path, #send_private_message_path, #topic_path, #topic_url, #unread_topics_path, #user_path
Instance Method Details
#global_nav_icons_count ⇒ Object
33 34 35 36 37 38 |
# File 'app/helpers/thredded/application_helper.rb', line 33 def global_nav_icons_count result = 1 # Notification Settings result += 1 if Thredded.private_messaging_enabled result += 1 if thredded_moderator? result end |
#paginate(collection, args = {}) ⇒ Object
94 95 96 |
# File 'app/helpers/thredded/application_helper.rb', line 94 def paginate(collection, args = {}) super(collection, **args.reverse_merge(views_prefix: 'thredded')) end |
#posts_pending_moderation_count ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'app/helpers/thredded/application_helper.rb', line 120 def posts_pending_moderation_count @posts_pending_moderation_count ||= begin scope = Thredded::Post.pending_moderation = thredded_current_user. unless == Thredded::Messageboard.all scope = scope.where(messageboard_id: .pluck(:id)) end scope.count end end |
#render_posts(posts, partial: 'thredded/posts/post', content_partial: 'thredded/posts/content', locals: {}) ⇒ Object
86 87 88 89 90 91 92 |
# File 'app/helpers/thredded/application_helper.rb', line 86 def render_posts(posts, partial: 'thredded/posts/post', content_partial: 'thredded/posts/content', locals: {}) posts_with_contents = render_collection_to_strings_with_cache( partial: content_partial, collection: posts, as: :post, expires_in: 1.week, locals: { options: { users_provider: ::Thredded::UsersProviderWithCache.new } } ) render partial: partial, collection: posts_with_contents, as: :post_and_content, locals: locals end |
#thredded_container_classes ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/thredded/application_helper.rb', line 23 def thredded_container_classes [ 'thredded--main-container', content_for(:thredded_page_id), "thredded--global-nav-icons-#{global_nav_icons_count}", ('thredded--is-moderator' if thredded_moderator?), ('thredded--private-messaging-enabled' if Thredded.private_messaging_enabled), ].compact end |
#thredded_container_data ⇒ Object
15 16 17 18 19 20 21 |
# File 'app/helpers/thredded/application_helper.rb', line 15 def thredded_container_data { 'thredded-locale' => I18n.locale, '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.
41 42 43 44 45 46 |
# File 'app/helpers/thredded/application_helper.rb', line 41 def thredded_page(&block) # enable the host app to easily check whether a thredded view is being rendered: content_for :thredded, true content_for :thredded_page_content, &block render partial: 'thredded/shared/page' end |
#time_ago(datetime, default: '-', html_options: {}) ⇒ String
Returns html_safe datetime presentation.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/thredded/application_helper.rb', line 68 def time_ago(datetime, default: '-', html_options: {}) return content_tag :time, default if datetime.nil? = .dup is_current_year = datetime.year == Time.current.year if datetime > 4.days.ago content = t 'thredded.time_ago', time: time_ago_in_words(datetime) ['data-time-ago'] = true unless .key?('data-time-ago') else content = I18n.l(datetime.to_date, format: (is_current_year ? :short : :long)) end [:title] = I18n.l(datetime) unless .key?(:title) time_tag datetime, content, end |
#topic_css_classes(topic) ⇒ Array<String>
100 101 102 103 104 105 106 |
# File 'app/helpers/thredded/application_helper.rb', line 100 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
109 110 111 112 113 114 115 116 117 118 |
# File 'app/helpers/thredded/application_helper.rb', line 109 def topic_follow_reason_text(follow_reason) if follow_reason # rubocop:disable Layout/LineLength # i18n-tasks-use t('thredded.topics.following.manual') t('thredded.topics.following.posted') t('thredded.topics.following.mentioned') t('thredded.topics.following.auto') # rubocop:enable Layout/LineLength t("thredded.topics.following.#{follow_reason}") else t('thredded.topics.not_following') end end |
#user_link(user) ⇒ String
Returns html_safe link to the user.
50 51 52 |
# File 'app/helpers/thredded/application_helper.rb', line 50 def user_link(user) render partial: 'thredded/users/link', locals: { user: user } end |
#user_mention(user) ⇒ String
Returns wrapped @mention string.
56 57 58 59 60 61 62 63 |
# File 'app/helpers/thredded/application_helper.rb', line 56 def user_mention(user) username = user.send(Thredded.user_name_column) if username.include?(' ') %(@"#{username}") else "@#{username}" end end |
#view_hooks ⇒ AllViewHooks
Returns View hooks configuration.
11 12 13 |
# File 'app/helpers/thredded/application_helper.rb', line 11 def view_hooks @view_hooks ||= Thredded.view_hooks end |