Module: RailsSiteEngine::ApplicationHelper
- Defined in:
- app/helpers/rails_site_engine/application_helper.rb
Instance Method Summary collapse
- #app_stylesheet_link_tag ⇒ Object
- #brand_label ⇒ Object
- #branding_logo_text ⇒ Object
- #canonical_url ⇒ Object
- #contact_channels ⇒ Object
- #contact_page_path ⇒ Object
- #engine_stylesheet_link_tag ⇒ Object
- #footer_nav_items ⇒ Object
- #local_business_json_ld_tag ⇒ Object
- #nav_link_options(item, data: nil) ⇒ Object
- #page_description ⇒ Object
- #page_lead(page = current_page) ⇒ Object
- #page_title ⇒ Object
- #page_title_visible?(page = current_page) ⇒ Boolean
- #primary_cta ⇒ Object
- #primary_nav_items ⇒ Object
- #render_section(section, page:, index:) ⇒ Object
- #resolve_link_href(link_config) ⇒ Object
- #section_heading_tag(section:, page:, index:) ⇒ Object
- #seo_meta_tags ⇒ Object
- #site_language ⇒ Object
- #site_name ⇒ Object
Instance Method Details
#app_stylesheet_link_tag ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 138 def app_stylesheet_link_tag return nil unless Rails.application.respond_to?(:assets) && Rails.application.assets&.respond_to?(:resolver) candidates = { "app.css" => "app", "application.css" => "application" } logical_name = candidates.find { |asset_name, _| Rails.application.assets.resolver.resolve(asset_name).present? }&.last return nil if logical_name.blank? stylesheet_link_tag logical_name end |
#brand_label ⇒ Object
19 20 21 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 19 def brand_label branding_logo_text || site_name end |
#branding_logo_text ⇒ Object
15 16 17 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 15 def branding_logo_text site_config.dig("branding", "logo_text").to_s.strip.presence end |
#canonical_url ⇒ Object
80 81 82 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 80 def canonical_url "#{request.base_url}#{request.path}" end |
#contact_channels ⇒ Object
58 59 60 61 62 63 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 58 def contact_channels { phone: site_config.dig("contact", "phone").to_s.strip.presence, email: site_config.dig("contact", "email").to_s.strip.presence }.compact end |
#contact_page_path ⇒ Object
164 165 166 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 164 def contact_page_path content_store.path_for_page(content_store.contact_page_id) || "/contact" end |
#engine_stylesheet_link_tag ⇒ Object
134 135 136 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 134 def engine_stylesheet_link_tag stylesheet_link_tag "rails_site_engine/engine" end |
#footer_nav_items ⇒ Object
27 28 29 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 27 def ("footer") end |
#local_business_json_ld_tag ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 112 def local_business_json_ld_tag phone = site_config.dig("contact", "phone").to_s.strip.presence email = site_config.dig("contact", "email").to_s.strip.presence return nil if phone.blank? && email.blank? json_ld = { "@context" => "https://schema.org", "@type" => "LocalBusiness", "name" => site_name, "url" => site_base_url || request.base_url } json_ld["telephone"] = phone if phone.present? json_ld["email"] = email if email.present? content_tag( :script, json_escape(json_ld.to_json).html_safe, type: "application/ld+json" ) end |
#nav_link_options(item, data: nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 31 def (item, data: nil) = { class: ("menu-active" if item[:active]), target: (item[:external] ? "_blank" : nil), rel: (item[:external] ? "noopener noreferrer" : nil) }.compact [:"aria-current"] = "page" if item[:active] [:data] = data if data.present? end |
#page_description ⇒ Object
75 76 77 78 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 75 def page_description current_page&.description.to_s.strip.presence || site_config.dig("seo", "default_description").to_s.strip.presence end |
#page_lead(page = current_page) ⇒ Object
172 173 174 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 172 def page_lead(page = current_page) page&.lead.to_s.strip.presence end |
#page_title ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 65 def page_title current_title = current_page&.title.to_s.strip.presence default_title = seo_default_title return default_title if current_title.blank? return current_title if default_title.blank? || current_title == default_title "#{current_title} | #{default_title}" end |
#page_title_visible?(page = current_page) ⇒ Boolean
168 169 170 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 168 def page_title_visible?(page = current_page) page.present? && page.show_title && page.title.present? end |
#primary_cta ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 43 def primary_cta cta = site_config.dig("branding", "primary_cta") return nil unless cta.is_a?(Hash) label = cta["label"].to_s.strip href = resolve_link_href(cta) return nil if label.blank? || href.blank? { label: label, href: href, external: external_link?(href) } end |
#primary_nav_items ⇒ Object
23 24 25 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 23 def primary_nav_items ("primary") end |
#render_section(section, page:, index:) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 183 def render_section(section, page:, index:) section = section.is_a?(Hash) ? section : {} type = section["type"].to_s partial = "rails_site_engine/sections/#{type}" heading_tag = section_heading_tag(section: section, page: page, index: index) render partial:, locals: { section: section, page: page, heading_tag: heading_tag } rescue ActionView::MissingTemplate Rails.logger.warn("rails_site_engine: unknown section type=#{type.inspect}") return "".html_safe unless Rails.env.development? render partial: "rails_site_engine/sections/unknown", locals: { section: section } end |
#resolve_link_href(link_config) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 152 def resolve_link_href(link_config) return nil unless link_config.is_a?(Hash) page_id = link_config["page"].to_s.strip.presence || link_config[:page].to_s.strip.presence if page_id.present? path = content_store.path_for_page(page_id) return path if path.present? end link_config["href"].to_s.strip.presence || link_config[:href].to_s.strip.presence end |
#section_heading_tag(section:, page:, index:) ⇒ Object
176 177 178 179 180 181 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 176 def section_heading_tag(section:, page:, index:) section_type = section["type"].to_s.strip return "h1" if section_type == "hero" && index.to_i.zero? && !page.show_title "h2" end |
#seo_meta_tags ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 84 def = [] description = page_description og_image = page_og_image << tag.(name: "description", content: description) if description.present? << tag.link(rel: "canonical", href: canonical_url) << tag.(property: "og:title", content: page_title) << tag.(property: "og:description", content: description) if description.present? << tag.(property: "og:type", content: "website") << tag.(property: "og:url", content: canonical_url) << tag.(property: "og:image", content: og_image) if og_image.present? << tag.(name: "twitter:card", content: og_image.present? ? "summary_large_image" : "summary") << tag.(name: "twitter:title", content: current_page&.twitter_title.to_s.strip.presence || page_title) twitter_description = current_page&.twitter_description.to_s.strip.presence || description << tag.(name: "twitter:description", content: twitter_description) if twitter_description.present? << tag.(name: "twitter:image", content: og_image) if og_image.present? twitter_handle = site_config.dig("seo", "twitter_handle").to_s.strip.presence << tag.(name: "twitter:site", content: twitter_handle) if twitter_handle.present? safe_join(.compact, "\n") end |
#site_language ⇒ Object
5 6 7 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 5 def site_language I18n.locale.to_s end |
#site_name ⇒ Object
9 10 11 12 13 |
# File 'app/helpers/rails_site_engine/application_helper.rb', line 9 def site_name site_config.dig("site", "name").to_s.strip.presence || branding_logo_text || "Website" end |