Class: HTMLPipeline::TextFilter::ImageFilter

Inherits:
HTMLPipeline::TextFilter show all
Defined in:
lib/html_pipeline/text_filter/image_filter.rb

Overview

HTML Filter that converts image’s url into <img> tag. For example, it will convert

http://example.com/test.jpg

into

<img src="http://example.com/test.jpg" alt=""/>.

Instance Attribute Summary

Attributes inherited from HTMLPipeline::TextFilter

#text

Attributes inherited from Filter

#context, #result

Instance Method Summary collapse

Methods inherited from HTMLPipeline::TextFilter

call, #initialize

Methods inherited from Filter

#base_url, call, #has_ancestor?, #initialize, #needs, #validate

Constructor Details

This class inherits a constructor from HTMLPipeline::TextFilter

Instance Method Details

#call(text, context: {}, result: {}) ⇒ Object



12
13
14
15
16
# File 'lib/html_pipeline/text_filter/image_filter.rb', line 12

def call(text, context: {}, result: {})
  text.gsub(%r{(https|http)?://.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?}i) do |match|
    %(<img src="#{match}" alt=""/>)
  end
end