Module: EffectivePagesHelper
- Defined in:
- app/helpers/effective_pages_helper.rb
Instance Method Summary collapse
- #application_root_to_effective_pages_slug ⇒ Object
- #effective_pages_body_classes ⇒ Object
- #effective_pages_canonical_url ⇒ Object
- #effective_pages_google_analytics ⇒ Object
- #effective_pages_header_tags ⇒ Object
- #effective_pages_meta_description ⇒ Object
- #effective_pages_og_type ⇒ Object
- #effective_pages_page_title ⇒ Object
- #effective_pages_site_title ⇒ Object
Instance Method Details
#application_root_to_effective_pages_slug ⇒ Object
100 101 102 |
# File 'app/helpers/effective_pages_helper.rb', line 100 def application_root_to_effective_pages_slug Rails.application.routes.routes.find { |r| r.name == 'root' && r.defaults[:controller] == 'Effective::Pages' && r.defaults[:action] == 'show' }.defaults[:id] rescue nil end |
#effective_pages_body_classes ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/effective_pages_helper.rb', line 5 def effective_pages_body_classes [ params[:controller].to_s.parameterize, params[:action], (user_signed_in? ? 'signed-in' : 'not-signed-in'), (@page.template if @page && @page.respond_to?(:template)), @body_classes ].compact.join(' ') end |
#effective_pages_canonical_url ⇒ Object
79 80 81 82 83 84 85 |
# File 'app/helpers/effective_pages_helper.rb', line 79 def effective_pages_canonical_url unless @canonical_url.present? || EffectivePages.silence_missing_canonical_url_warnings Rails.logger.error("WARNING: (effective_pages) Expected @canonical_url to be present. Please assign a @canonical_url variable in your controller action.") end @canonical_url end |
#effective_pages_google_analytics ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'app/helpers/effective_pages_helper.rb', line 91 def effective_pages_google_analytics return unless Rails.env.production? code = EffectivePages.google_analytics_code return unless code.present? render('layouts/google_analytics', code: code) end |
#effective_pages_header_tags ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/effective_pages_helper.rb', line 15 def = [ content_tag(:title, effective_pages_site_title), tag(:meta, name: 'description', content: ), tag(:meta, property: 'og:site_name', content: EffectivePages.site_title.to_s), tag(:meta, property: 'og:title', content: effective_pages_page_title), tag(:meta, property: 'og:url', content: request.original_url), tag(:meta, property: 'og:type', content: effective_pages_og_type), tag(:meta, property: 'og:description', content: ), tag(:meta, itemprop: 'name', content: effective_pages_page_title), tag(:meta, itemprop: 'url', content: request.original_url), tag(:meta, itemprop: 'description', content: ), tag(:meta, name: 'twitter:title', content: effective_pages_page_title), tag(:meta, name: 'twitter:url', content: request.original_url), tag(:meta, name: 'twitter:card', content: 'summary'), tag(:meta, name: 'twitter:description', content: ), ] if EffectivePages.site_og_image.present? image_url = asset_url(EffectivePages.site_og_image) += [ tag(:meta, property: 'og:image', content: image_url), tag(:meta, itemprop: 'thumbnailUrl', content: image_url), tag(:meta, itemprop: 'image', content: image_url), tag(:meta, name: 'twitter:image', content: image_url), ] if EffectivePages.site_og_image_width.present? << tag(:meta, property: 'og:image:width', content: EffectivePages.site_og_image_width) end if EffectivePages.site_og_image_height.present? << tag(:meta, property: 'og:image:height', content: EffectivePages.site_og_image_height) end end if effective_pages_canonical_url.present? << tag(:link, rel: 'canonical', href: effective_pages_canonical_url) end .compact.join("\n").html_safe end |
#effective_pages_meta_description ⇒ Object
71 72 73 74 75 76 77 |
# File 'app/helpers/effective_pages_helper.rb', line 71 def unless @meta_description.present? || EffectivePages. Rails.logger.error("WARNING: (effective_pages) Expected @meta_description to be present. Please assign a @meta_description variable in your controller action.") end truncate((@meta_description || EffectivePages.).to_s, length: 150) end |
#effective_pages_og_type ⇒ Object
87 88 89 |
# File 'app/helpers/effective_pages_helper.rb', line 87 def effective_pages_og_type @effective_pages_og_type || 'website' end |
#effective_pages_page_title ⇒ Object
59 60 61 62 63 64 65 |
# File 'app/helpers/effective_pages_helper.rb', line 59 def effective_pages_page_title unless @page_title.present? || EffectivePages.silence_missing_page_title_warnings Rails.logger.error("WARNING: (effective_pages) Expected @page_title to be present. Please assign a @page_title variable in your controller action.") end (@page_title || "#{params[:controller].try(:titleize)} #{params[:action].try(:titleize)}") end |
#effective_pages_site_title ⇒ Object
67 68 69 |
# File 'app/helpers/effective_pages_helper.rb', line 67 def effective_pages_site_title effective_pages_page_title + (@site_title_suffix || EffectivePages.site_title_suffix).to_s end |