Module: Maglev::GetPageSections::TransformTextConcern
- Included in:
- Maglev::GetPageSections
- Defined in:
- app/services/concerns/maglev/get_page_sections/transform_text_concern.rb
Overview
rubocop:disable Style/ClassAndModuleChildren
Instance Method Summary collapse
- #find_link_page_path(link_type_matches, link_id_matches, section_id_matches) ⇒ Object
- #replace_links_in_text(text) ⇒ Object
- #transform_text_content_setting(content, setting) ⇒ Object
Instance Method Details
#find_link_page_path(link_type_matches, link_id_matches, section_id_matches) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/concerns/maglev/get_page_sections/transform_text_concern.rb', line 24 def find_link_page_path(link_type_matches, link_id_matches, section_id_matches) return unless link_type_matches && link_id_matches # rubocop:disable Style/StringHashKeys link = { 'link_type' => link_type_matches[1], 'link_id' => link_id_matches[1] } # rubocop:enable Style/StringHashKeys return unless %w[page static_page].include?(link['link_type']) link['section_id'] = section_id_matches[1] if section_id_matches replace_href_in_link(link)['href'] end |
#replace_links_in_text(text) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/services/concerns/maglev/get_page_sections/transform_text_concern.rb', line 11 def replace_links_in_text(text) text.gsub(/<a([^>]+)>/) do |tag| link_type_matches = tag.match(/maglev-link-type="([^"]+)"/) link_id_matches = tag.match(/maglev-link-id="([^"]+)"/) section_id_matches = tag.match(/maglev-section-id="([^"]+)"/) path = find_link_page_path(link_type_matches, link_id_matches, section_id_matches) tag.gsub!(/href="([^"]+)"/, "href=\"#{path}\"") if path tag end end |
#transform_text_content_setting(content, setting) ⇒ Object
5 6 7 8 9 |
# File 'app/services/concerns/maglev/get_page_sections/transform_text_concern.rb', line 5 def transform_text_content_setting(content, setting) return unless setting.['html'] content['value'] = replace_links_in_text(content['value']) end |