Module: Maglev::GetPageSections::TransformLinkConcern
- Included in:
- Maglev::GetPageSections
- Defined in:
- app/services/concerns/maglev/get_page_sections/transform_link_concern.rb
Overview
rubocop:disable Style/ClassAndModuleChildren
Instance Method Summary collapse
- #get_fullpath_from_link(link) ⇒ Object
- #replace_href_in_link(link) ⇒ Object
- #transform_link_content_setting(content, _setting) ⇒ Object
Instance Method Details
#get_fullpath_from_link(link) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/concerns/maglev/get_page_sections/transform_link_concern.rb', line 22 def get_fullpath_from_link(link) is_static_page = link['link_type'] == 'static_page' page_id = link['link_id'] # since the static pages don't have a preview version, we need the raw url if is_static_page page = fetch_static_pages.call.find { |static_page| static_page.id == page_id } page&.path else get_page_fullpath.call(page: page_id, locale: locale) end end |
#replace_href_in_link(link) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'app/services/concerns/maglev/get_page_sections/transform_link_concern.rb', line 11 def replace_href_in_link(link) path = get_fullpath_from_link(link) if path anchor = link['section_id'] link['href'] = anchor.present? ? "#{path}#section-#{anchor}" : path end link end |
#transform_link_content_setting(content, _setting) ⇒ Object
5 6 7 8 9 |
# File 'app/services/concerns/maglev/get_page_sections/transform_link_concern.rb', line 5 def transform_link_content_setting(content, _setting) return unless content['value'].is_a?(Hash) && %w[page static_page].include?(content.dig('value', 'link_type')) content['value'] = replace_href_in_link(content['value']) end |