Module: Thredded::UrlsHelper
- Extended by:
- UrlsHelper
- Included in:
- ApplicationController, ApplicationHelper, UrlsHelper
- Defined in:
- app/helpers/thredded/urls_helper.rb
Overview
rubocop:disable Metrics/ModuleLength
Instance Method Summary collapse
-
#delete_post_path(post) ⇒ String
Path to the DELETE endpoint.
-
#edit_post_path(post) ⇒ String
Path to the Edit Post page.
-
#edit_preferences_path(messageboard = nil, params = {}) ⇒ String
The path to the global or messageboard edit preferences page.
-
#edit_preferences_url(messageboard = nil, params = {}) ⇒ String
The URL to the global or messageboard edit preferences page.
- #mark_unread_path(post, _params = {}) ⇒ Object
-
#permalink_path(post) ⇒ String
Post permalink path.
-
#post_path(post, user:, **params) ⇒ String
Path to the topic page with the post anchor.
-
#post_url(post, user:, **params) ⇒ String
URL of the topic page with the post anchor.
- #quote_post_path(post) ⇒ Object
-
#search_path(messageboard = nil) ⇒ String
The path to the global or messageboard search.
-
#send_private_message_path(current_user:, to:, use_existing: true) ⇒ String
A path to a new or existing private message thread for the given users.
-
#topic_path(topic, params = {}) ⇒ String
Path to the latest unread page of the given topic.
- #topic_url(topic, params = {}) ⇒ String
- #unread_topics_path(messageboard: nil, **params) ⇒ Object
-
#user_path(user) ⇒ String
Path to the user as specified by user_path.
Instance Method Details
#delete_post_path(post) ⇒ String
Returns path to the DELETE endpoint.
74 75 76 77 78 79 80 |
# File 'app/helpers/thredded/urls_helper.rb', line 74 def delete_post_path(post) if post.private_topic_post? private_topic_private_post_path(post.postable, post) else (post., post.postable, post) end end |
#edit_post_path(post) ⇒ String
Returns path to the Edit Post page.
64 65 66 67 68 69 70 |
# File 'app/helpers/thredded/urls_helper.rb', line 64 def edit_post_path(post) if post.private_topic_post? edit_private_topic_private_post_path(post.postable, post) else (post., post.postable, post) end end |
#edit_preferences_path(messageboard = nil, params = {}) ⇒ String
Returns the path to the global or messageboard edit preferences page.
96 97 98 |
# File 'app/helpers/thredded/urls_helper.rb', line 96 def edit_preferences_path( = nil, params = {}) edit_preferences_url(, params.merge(only_path: true)) end |
#edit_preferences_url(messageboard = nil, params = {}) ⇒ String
Returns the URL to the global or messageboard edit preferences page.
85 86 87 88 89 90 91 |
# File 'app/helpers/thredded/urls_helper.rb', line 85 def edit_preferences_url( = nil, params = {}) if .try(:persisted?) (, params) else edit_global_preferences_url(params) end end |
#mark_unread_path(post, _params = {}) ⇒ Object
129 130 131 132 133 134 135 |
# File 'app/helpers/thredded/urls_helper.rb', line 129 def mark_unread_path(post, _params = {}) if post.private_topic_post? mark_as_unread_private_post_path(post) else mark_as_unread_post_path(post) end end |
#permalink_path(post) ⇒ String
Returns post permalink path.
139 140 141 142 143 144 145 |
# File 'app/helpers/thredded/urls_helper.rb', line 139 def permalink_path(post) if post.private_topic_post? private_post_permalink_path(post) else post_permalink_path(post) end end |
#post_path(post, user:, **params) ⇒ String
Returns path to the topic page with the post anchor.
58 59 60 |
# File 'app/helpers/thredded/urls_helper.rb', line 58 def post_path(post, user:, **params) post_url(post, **params.merge(user: user, only_path: true)) end |
#post_url(post, user:, **params) ⇒ String
Returns URL of the topic page with the post anchor.
48 49 50 51 52 53 |
# File 'app/helpers/thredded/urls_helper.rb', line 48 def post_url(post, user:, **params) params = params.dup params[:anchor] ||= ActionView::RecordIdentifier.dom_id(post) params[:page] ||= post.private_topic_post? ? post.page : post.page(user: user) topic_url(post.postable, params) end |
#quote_post_path(post) ⇒ Object
121 122 123 124 125 126 127 |
# File 'app/helpers/thredded/urls_helper.rb', line 121 def quote_post_path(post) if post.private_topic_post? quote_private_topic_private_post_path(post.postable, post) else (post., post.postable, post) end end |
#search_path(messageboard = nil) ⇒ String
Returns the path to the global or messageboard search.
113 114 115 116 117 118 119 |
# File 'app/helpers/thredded/urls_helper.rb', line 113 def search_path( = nil) if .try(:persisted?) () else end end |
#send_private_message_path(current_user:, to:, use_existing: true) ⇒ String
Returns a path to a new or existing private message thread for the given users.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/helpers/thredded/urls_helper.rb', line 151 def (current_user:, to:, use_existing: true) existing_topic = use_existing && Thredded::PrivateTopic.has_exact_participants([current_user, to]) .order_recently_posted_first.first if existing_topic page = 1 + (existing_topic.posts_count - 1) / Thredded::PrivatePost.default_per_page Thredded::UrlsHelper.private_topic_path( existing_topic, page: (page if page > 1), autofocus_new_post_content: true, anchor: 'post_content' ) else Thredded::UrlsHelper.new_private_topic_path( private_topic: { user_names: to.send(Thredded.user_name_column), title: [current_user, to].map(&Thredded.user_display_name_method).join(' • ') }, autofocus_new_post_content: true, ) end end |
#topic_path(topic, params = {}) ⇒ String
Returns path to the latest unread page of the given topic.
41 42 43 |
# File 'app/helpers/thredded/urls_helper.rb', line 41 def topic_path(topic, params = {}) topic_url(topic, params.merge(only_path: true)) end |
#topic_url(topic, params = {}) ⇒ String
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/thredded/urls_helper.rb', line 20 def topic_url(topic, params = {}) if params[:page] == 1 params = params.dup params.delete(:page) end if topic.private? private_topic_url( topic.slug, params ) else ( topic..slug, topic.slug, params ) end end |
#unread_topics_path(messageboard: nil, **params) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'app/helpers/thredded/urls_helper.rb', line 102 def unread_topics_path(messageboard: nil, **params) params[:only_path] = true if (, params) else unread_topics_url(params) end end |
#user_path(user) ⇒ String
Returns path to the user as specified by Thredded.user_path.
14 15 16 |
# File 'app/helpers/thredded/urls_helper.rb', line 14 def user_path(user) Thredded.user_path(self, user) end |