Class: Spirit::Render::Processors::BlockImageProcessor

Inherits:
Base
  • Object
show all
Defined in:
lib/spirit/render/processors/block_image_processor.rb

Constant Summary collapse

IMAGE_REGEX =

Paragraphs that only contain images are rendered with Image.

/\A\s*<img[^<>]+>\s*\z/m

Instance Method Summary collapse

Methods inherited from Base

events, inherited, #invoke_callbacks_for, process

Constructor Details

#initialize(*args) ⇒ BlockImageProcessor

Returns a new instance of BlockImageProcessor.



13
14
15
# File 'lib/spirit/render/processors/block_image_processor.rb', line 13

def initialize(*args)
  @image = 0
end

Instance Method Details

#filter(text) ⇒ String

Detects block images and renders them as such.

Returns:

  • (String)

    rendered html



19
20
21
22
23
24
25
26
# File 'lib/spirit/render/processors/block_image_processor.rb', line 19

def filter(text)
  case text
  when IMAGE_REGEX then block_image(text)
  else p(text) end
rescue RenderError => e # fall back to paragraph
  Spirit.logger.warn e.message
  p(text)
end