class HTML::Pipeline::ImageLinkFilter
Constants
- IGNORE_PARENTS
Public Instance Methods
apply_filter(content)
click to toggle source
# File lib/html/pipeline/image_link/filter.rb, line 21 def apply_filter(content) protocols = https_only? ? %w[https] : %w[https http] content.gsub(/#{Regexp.union(protocols)}:\/\/.+\.#{Regexp.union(image_extensions)}(\?\S+)?/i) do |match| %(<a href="#{match}"><img src="#{match}" alt=""></a>) end end
call()
click to toggle source
# File lib/html/pipeline/image_link/filter.rb, line 8 def call doc.xpath('.//text()').each do |node| next if has_ancestor?(node, IGNORE_PARENTS) content = node.to_html html = apply_filter(content) next if html == content node.replace(html) end doc end
Private Instance Methods
https_only?()
click to toggle source
# File lib/html/pipeline/image_link/filter.rb, line 30 def https_only? @context.key?(:https_only) ? @context[:https_only] : true end
image_extensions()
click to toggle source
# File lib/html/pipeline/image_link/filter.rb, line 34 def image_extensions @context[:image_extensions] || %w[jpg jpeg bmp gif png] end