Module: Maglev::PagePreviewHelper
- Defined in:
- app/helpers/maglev/page_preview_helper.rb
Instance Method Summary collapse
- #maglev_alt_link(locale, links: nil) ⇒ Object
- #maglev_current_locale?(locale) ⇒ Boolean
- #maglev_rendering_context ⇒ Object
- #maglev_site_link ⇒ Object
- #render_maglev_alternate_links(links: nil, x_default_locale: nil) ⇒ Object
-
#render_maglev_section(type, site: nil, theme: nil, page: nil, page_sections: nil) ⇒ Object
rubocop:enable Rails/OutputSafety.
-
#render_maglev_sections(site: nil, theme: nil, page: nil, page_sections: nil) ⇒ Object
rubocop:disable Rails/OutputSafety.
- #rendering_maglev_page? ⇒ Boolean
Instance Method Details
#maglev_alt_link(locale, links: nil) ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/helpers/maglev/page_preview_helper.rb', line 44 def maglev_alt_link(locale, links: nil) links ||= maglev_page_fullpaths link = links[locale.to_sym] return nil if link.nil? "#{request.base_url}#{link}" end |
#maglev_current_locale?(locale) ⇒ Boolean
56 57 58 |
# File 'app/helpers/maglev/page_preview_helper.rb', line 56 def maglev_current_locale?(locale) locale.to_sym == maglev_content_locale end |
#maglev_rendering_context ⇒ Object
60 61 62 63 64 65 66 |
# File 'app/helpers/maglev/page_preview_helper.rb', line 60 def maglev_rendering_context { templates_root_path: maglev_sections_path, rendering_mode: maglev_rendering_mode, config: maglev_config } end |
#maglev_site_link ⇒ Object
52 53 54 |
# File 'app/helpers/maglev/page_preview_helper.rb', line 52 def maglev_site_link maglev_site_root_fullpath end |
#render_maglev_alternate_links(links: nil, x_default_locale: nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/maglev/page_preview_helper.rb', line 30 def render_maglev_alternate_links(links: nil, x_default_locale: nil) links ||= maglev_page_fullpaths x_default_locale ||= maglev_site.default_locale_prefix.to_sym return '' if links.blank? || links.size < 2 safe_join( [tag.link(rel: 'alternate', hreflang: 'x-default', href: maglev_alt_link(x_default_locale))] + links.map do |(locale, _link)| tag.link(rel: 'alternate', hreflang: locale, href: maglev_alt_link(locale)) end ) end |
#render_maglev_section(type, site: nil, theme: nil, page: nil, page_sections: nil) ⇒ Object
rubocop:enable Rails/OutputSafety
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/maglev/page_preview_helper.rb', line 17 def render_maglev_section(type, site: nil, theme: nil, page: nil, page_sections: nil) sections = (page_sections || maglev_page_sections).find_all do |section| (section['type'] || section[:type]).start_with?(type.to_s) end render_maglev_sections( site: site, theme: theme, page: page, page_sections: sections ) end |
#render_maglev_sections(site: nil, theme: nil, page: nil, page_sections: nil) ⇒ Object
rubocop:disable Rails/OutputSafety
6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/maglev/page_preview_helper.rb', line 6 def render_maglev_sections(site: nil, theme: nil, page: nil, page_sections: nil) PageComponent.new( site: site || maglev_site, theme: theme || maglev_theme, page: page || maglev_page, page_sections: page_sections || maglev_page_sections, context: maglev_rendering_context ).tap { |component| component.view_context = self }.render.html_safe end |
#rendering_maglev_page? ⇒ Boolean
68 69 70 |
# File 'app/helpers/maglev/page_preview_helper.rb', line 68 def rendering_maglev_page? controller.class.module_parent.to_s == 'Maglev' end |