Class: Html2rss::Selectors::PostProcessors::HtmlTransformers::WrapImgInA
- Inherits:
-
Object
- Object
- Html2rss::Selectors::PostProcessors::HtmlTransformers::WrapImgInA
- Defined in:
- lib/html2rss/selectors/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
-
#already_wrapped?(node) ⇒ Boolean
Whether the image is already wrapped in a link.
-
#call(node_name:, node:, **_env) ⇒ nil
Wraps <img> tags into <a> tags that link to ‘img.src`.
-
#should_process?(node_name) ⇒ Boolean
Whether this transformer should run for the node.
Instance Method Details
#already_wrapped?(node) ⇒ Boolean
Returns whether the image is already wrapped in a link.
32 33 34 |
# File 'lib/html2rss/selectors/post_processors/html_transformers/wrap_img_in_a.rb', line 32 def already_wrapped?(node) node.parent.name == 'a' end |
#call(node_name:, node:, **_env) ⇒ nil
Wraps <img> tags into <a> tags that link to ‘img.src`.
18 19 20 21 22 |
# File 'lib/html2rss/selectors/post_processors/html_transformers/wrap_img_in_a.rb', line 18 def call(node_name:, node:, **_env) return unless should_process?(node_name) wrap_image_in_anchor(node) unless already_wrapped?(node) end |
#should_process?(node_name) ⇒ Boolean
Returns whether this transformer should run for the node.
26 27 28 |
# File 'lib/html2rss/selectors/post_processors/html_transformers/wrap_img_in_a.rb', line 26 def should_process?(node_name) node_name == 'img' end |