Module: Postnhost::PublicPagesHelper
- Defined in:
- app/helpers/postnhost/public_pages_helper.rb
Instance Method Summary collapse
-
#current_path_without_locale ⇒ Object
Language switcher helpers.
- #default_language_options ⇒ Object
- #document_lang ⇒ Object
- #language_author_path(author_slug, language) ⇒ Object
- #language_author_url(author_slug, language) ⇒ Object
- #language_category_path(category_slug, language) ⇒ Object
-
#language_root_path(language) ⇒ Object
Language-aware navigation helpers for public pages.
- #language_search_path(language) ⇒ Object
- #language_search_url(language) ⇒ Object
- #language_static_page_path(page_slug, language) ⇒ Object
- #localized_language_options(primary) ⇒ Object
- #localized_path(language) ⇒ Object
- #paginated_public_page? ⇒ Boolean
-
#public_article_show_page? ⇒ Boolean
Public layout language switcher helpers.
- #public_articles_index_heading ⇒ Object
- #public_articles_index_title ⇒ Object
- #public_blog_heading ⇒ Object
- #public_blog_index_title ⇒ Object
- #public_blog_index_url ⇒ Object
- #public_category_description(category) ⇒ Object
- #public_category_heading(category) ⇒ Object
- #public_category_index_url(category) ⇒ Object
- #public_category_title(category) ⇒ Object
-
#public_page_number ⇒ Object
Public page metadata helpers.
- #public_search_endpoint? ⇒ Boolean
- #public_search_heading ⇒ Object
- #public_search_page? ⇒ Boolean
- #public_search_query ⇒ Object
- #public_search_title ⇒ Object
- #public_search_trigger_url ⇒ Object
- #public_static_page_show_page? ⇒ Boolean
- #public_template_preview_path(path) ⇒ Object
- #show_article_variant_language_switcher? ⇒ Boolean
- #show_other_languages_switcher? ⇒ Boolean
- #show_page_variant_language_switcher? ⇒ Boolean
- #show_public_blog_subtitle? ⇒ Boolean
- #show_public_category_description?(category) ⇒ Boolean
Instance Method Details
#current_path_without_locale ⇒ Object
Language switcher helpers
10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 10 def current_path_without_locale base_path = request.path_info.to_s base_path = "/" if base_path.blank? locale = params[:locale].presence stripped_path = locale.present? ? base_path.sub(%r{\A/#{Regexp.escape(locale)}(?=/|$)}, "") : base_path stripped_path.presence || "/" end |
#default_language_options ⇒ Object
282 283 284 285 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 282 def [[@current_language.name, localized_path(@current_language)]] + @other_languages.to_a.map { |language| [language.name, localized_path(language)] } end |
#document_lang ⇒ Object
3 4 5 6 7 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 3 def document_lang return content_for(:lang) if content_for?(:lang) @current_language&.html_lang.presence || I18n.locale.to_s.presence || "en" end |
#language_author_path(author_slug, language) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 91 def (, language) return unless return postnhost.() unless language if language.default postnhost.() else postnhost.(language.html_lang, ) end end |
#language_author_url(author_slug, language) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 102 def (, language) return unless return postnhost.() unless language if language.default postnhost.() else postnhost.(language.html_lang, ) end end |
#language_category_path(category_slug, language) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 71 def language_category_path(category_slug, language) return postnhost.public_category_path(category_slug) unless language if language.default postnhost.public_category_path(category_slug) else postnhost.localized_public_category_path(language.html_lang, category_slug) end end |
#language_root_path(language) ⇒ Object
Language-aware navigation helpers for public pages
41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 41 def language_root_path(language) return postnhost.root_path unless language if language.default postnhost.root_path else postnhost.localized_root_path(locale: language.html_lang) end end |
#language_search_path(language) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 51 def language_search_path(language) return postnhost.public_search_path unless language if language.default postnhost.public_search_path else postnhost.localized_public_search_path(language.html_lang) end end |
#language_search_url(language) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 61 def language_search_url(language) return postnhost.public_search_url unless language if language.default postnhost.public_search_url else postnhost.localized_public_search_url(language.html_lang) end end |
#language_static_page_path(page_slug, language) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 81 def language_static_page_path(page_slug, language) return postnhost.public_static_page_path(slug: page_slug) unless language if language.default postnhost.public_static_page_path(slug: page_slug) else postnhost.localized_public_static_page_path(locale: language.html_lang, slug: page_slug) end end |
#localized_language_options(primary) ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 265 def (primary) = [[@current_language.name, localized_path(@current_language)]] primary_language = primary.is_a?(Postnhost::Snapshot::Article) ? @primary_language : primary&.language << [primary_language.name, localized_path(primary_language)] if primary_language.present? && primary_language != @current_language return if @available_variants.blank? @available_variants.each do |variant| next if variant.language == @current_language << [variant.language.name, localized_path(variant.language)] end .uniq { |(_, path)| path } end |
#localized_path(language) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 20 def localized_path(language) base_path = current_path_without_locale base_path = "/" if base_path.empty? locale_path = if language.default base_path else base_path == "/" ? "/#{language.html_lang}" : "/#{language.html_lang}#{base_path}" end public_template_preview_path("#{request.script_name}#{locale_path}") end |
#paginated_public_page? ⇒ Boolean
118 119 120 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 118 def paginated_public_page? public_page_number > 1 end |
#public_article_show_page? ⇒ Boolean
Public layout language switcher helpers
231 232 233 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 231 def public_article_show_page? controller_name == "articles" && action_name == "show" end |
#public_articles_index_heading ⇒ Object
161 162 163 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 161 def public_articles_index_heading public_search_page? ? public_search_heading : public_blog_heading end |
#public_articles_index_title ⇒ Object
154 155 156 157 158 159 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 154 def public_articles_index_title return public_search_title if public_search_page? return t("postnhost.public.search.submit") if public_search_endpoint? public_blog_index_title end |
#public_blog_heading ⇒ Object
177 178 179 180 181 182 183 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 177 def public_blog_heading if paginated_public_page? t("postnhost.public.blog.page_title", page: public_page_number) else t("postnhost.public.site.blog_tagline") end end |
#public_blog_index_title ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 122 def public_blog_index_title if paginated_public_page? t( "postnhost.public.site.blog_meta_title_paginated", page: public_page_number, blog_meta_title: t("postnhost.public.site.blog_meta_title") ) else t("postnhost.public.site.blog_meta_title") end end |
#public_blog_index_url ⇒ Object
169 170 171 172 173 174 175 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 169 def public_blog_index_url if public_search_endpoint? paginated_public_page? ? language_search_url(@current_language) : request.original_url else paginated_public_page? ? postnhost.root_url : request.original_url end end |
#public_category_description(category) ⇒ Object
222 223 224 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 222 def public_category_description(category) (category, @current_language) end |
#public_category_heading(category) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 210 def public_category_heading(category) if paginated_public_page? t( "postnhost.public.category.page_heading", page: public_page_number, category: localized_category_name(category, @current_language) ) else localized_category_name(category, @current_language) end end |
#public_category_index_url(category) ⇒ Object
204 205 206 207 208 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 204 def public_category_index_url(category) return postnhost.public_category_url(category.slug) if @localized_category_fallback paginated_public_page? ? postnhost.public_category_url(category.slug) : request.original_url end |
#public_category_title(category) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 189 def public_category_title(category) if paginated_public_page? t( "postnhost.public.category.page_title", page: public_page_number, category: localized_category_name(category, @current_language) ) else t( "postnhost.public.category.title", category: localized_category_name(category, @current_language) ) end end |
#public_page_number ⇒ Object
Public page metadata helpers
114 115 116 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 114 def public_page_number params[:page].to_i end |
#public_search_endpoint? ⇒ Boolean
138 139 140 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 138 def public_search_endpoint? controller_name == "articles" && action_name == "search" end |
#public_search_heading ⇒ Object
150 151 152 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 150 def public_search_heading t("postnhost.public.search.heading", query: public_search_query) end |
#public_search_page? ⇒ Boolean
142 143 144 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 142 def public_search_page? public_search_query.present? end |
#public_search_query ⇒ Object
134 135 136 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 134 def public_search_query @search_query.presence || params[:s].to_s.strip.presence end |
#public_search_title ⇒ Object
146 147 148 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 146 def public_search_title t("postnhost.public.search.title", query: public_search_query) end |
#public_search_trigger_url ⇒ Object
165 166 167 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 165 def public_search_trigger_url language_search_path(@current_language) end |
#public_static_page_show_page? ⇒ Boolean
235 236 237 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 235 def public_static_page_show_page? controller_name == "static_pages" && action_name == "show" end |
#public_template_preview_path(path) ⇒ Object
33 34 35 36 37 38 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 33 def public_template_preview_path(path) previewing_template = respond_to?(:user_signed_in?, true) && user_signed_in? && params[:preview_template].present? return path unless previewing_template "#{path}?preview_template=#{ERB::Util.url_encode(params[:preview_template])}" end |
#show_article_variant_language_switcher? ⇒ Boolean
239 240 241 242 243 244 245 246 247 248 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 239 def show_article_variant_language_switcher? return false unless public_article_show_page? return false if @available_variants.nil? if @available_variants.respond_to?(:exists?) @available_variants.offset(1).exists? || (@article.present? && @available_variants.exists?) else @available_variants.size > 1 || (@article.present? && @available_variants.any?) end end |
#show_other_languages_switcher? ⇒ Boolean
261 262 263 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 261 def show_other_languages_switcher? !public_article_show_page? && !public_static_page_show_page? && @other_languages&.any? end |
#show_page_variant_language_switcher? ⇒ Boolean
250 251 252 253 254 255 256 257 258 259 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 250 def show_page_variant_language_switcher? return false unless public_static_page_show_page? return false if @available_variants.nil? if @available_variants.respond_to?(:exists?) @available_variants.offset(1).exists? || (@page.present? && @available_variants.exists?) else @available_variants.size > 1 || (@page.present? && @available_variants.any?) end end |
#show_public_blog_subtitle? ⇒ Boolean
185 186 187 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 185 def show_public_blog_subtitle? !paginated_public_page? && !public_search_page? && !public_search_endpoint? end |
#show_public_category_description?(category) ⇒ Boolean
226 227 228 |
# File 'app/helpers/postnhost/public_pages_helper.rb', line 226 def show_public_category_description?(category) public_category_description(category).present? && !paginated_public_page? end |