Class: HTML::Pipeline::ImageFilter

Inherits:
TextFilter show all
Defined in:
lib/html/pipeline/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 TextFilter

#text

Attributes inherited from Filter

#context, #result

Instance Method Summary collapse

Methods inherited from TextFilter

#initialize

Methods inherited from Filter

#base_url, call, #current_user, #doc, #has_ancestor?, #html, #initialize, #needs, #parse_html, #repository, to_document, to_html, #validate

Constructor Details

This class inherits a constructor from HTML::Pipeline::TextFilter

Instance Method Details

#callObject


12
13
14
15
16
# File 'lib/html/pipeline/image_filter.rb', line 12

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