Sha256: 70e99bc8de6313cd4ce58c64b0c0956f2cd8a2ef8b8aed2e11262df7c270a3ca
Contents?: true
Size: 839 Bytes
Versions: 6
Compression:
Stored size: 839 Bytes
Contents
# frozen_string_literal: true module Html2rss module AttributePostProcessors module HtmlTransformers ## # Transformer that converts relative URLs to absolute URLs within specified HTML elements. class TransformUrlsToAbsoluteOnes URL_ELEMENTS_WITH_URL_ATTRIBUTE = { 'a' => :href, 'img' => :src }.freeze def initialize(channel_url) @channel_url = channel_url end ## # Transforms URLs to absolute ones. def call(node_name:, node:, **_env) return unless URL_ELEMENTS_WITH_URL_ATTRIBUTE.key?(node_name) url_attribute = URL_ELEMENTS_WITH_URL_ATTRIBUTE[node_name] url = node[url_attribute] node[url_attribute] = Html2rss::Utils.build_absolute_url_from_relative(url, @channel_url) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems