Module: Spree::PageHelper
- Defined in:
- app/helpers/spree/page_helper.rb
Instance Method Summary collapse
- #page_builder_link_to(link, options = {}, &block) ⇒ Object
- #render_page(page = nil, variables = {}) ⇒ Object
- #render_section(section, variables = {}, lazy_allowed: true) ⇒ Object
Instance Method Details
#page_builder_link_to(link, options = {}, &block) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/spree/page_helper.rb', line 57 def page_builder_link_to(link, = {}, &block) if link.present? link_to(spree_storefront_resource_url(link.linkable || link), .except(:label)) do block.present? ? block.call : [:label] end else block&.call&.html_safe end end |
#render_page(page = nil, variables = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'app/helpers/spree/page_helper.rb', line 3 def render_page(page = nil, variables = {}) page ||= current_page sections = current_page_preview.present? ? current_page_preview.sections : page.sections sections_html = sections.includes(:links, { asset_attachment: :blob }, { blocks: [:rich_text_text, :links] }).map do |section| render_section(section, variables) end.join.html_safe "<main class='page-contents'>#{sections_html}</main>".html_safe end |
#render_section(section, variables = {}, lazy_allowed: true) ⇒ Object
14 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 |
# File 'app/helpers/spree/page_helper.rb', line 14 def render_section(section, variables = {}, lazy_allowed: true) return '' if section.blank? variables[:section] = section variables[:loaded] = true css_id = "section-#{section.id}" css_class = "section-#{section.class.name.demodulize.underscore.dasherize}" if page_builder_enabled? turbo_frame_tag(css_id, class: css_class) do content_tag(:div, data: { editor_id: css_id, editor_name: section.name, editor_link: spree.edit_admin_page_section_path(section) } ) do render('/' + section.to_partial_path, **variables) end end elsif section.lazy? && lazy_allowed variables[:loaded] = false variables[:url_options] = { locale: I18n.locale } path = section.lazy_path(variables) turbo_frame_tag(css_id, src: path, loading: 'eager', class: css_class) do render('/' + section.to_partial_path, **variables) end else content_tag(:div, id: css_id, class: css_class) do render('/' + section.to_partial_path, **variables) end end rescue ActionView::MissingTemplate, ActionView::Template::Error => e raise e unless Rails.env.production? Rails.error.report(e, context: { section_id: section.id }, source: 'spree.storefront') '' end |