Class: Html2rss::AttributePostProcessors::HtmlTransformers::WrapImgInA

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/attribute_post_processors/html_transformers/wrap_img_in_a.rb

Overview

Transformer that wraps <img> tags into <a> tags linking to ‘img.src`.

Instance Method Summary collapse

Instance Method Details

#already_wrapped?(node_name, node) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/html2rss/attribute_post_processors/html_transformers/wrap_img_in_a.rb', line 21

def already_wrapped?(node_name, node)
  node_name == 'img' && node.parent.name != 'a'
end

#call(node_name:, node:, **_env) ⇒ nil

Wraps <img> tags into <a> tags that link to ‘img.src`.

Parameters:

  • node_name (String)
  • node (Nokogiri::XML::Node)

Returns:

  • (nil)


15
16
17
18
19
# File 'lib/html2rss/attribute_post_processors/html_transformers/wrap_img_in_a.rb', line 15

def call(node_name:, node:, **_env)
  return unless already_wrapped?(node_name, node)

  wrap_image_in_anchor(node)
end