class Spirit::Render::Processors::BlockImageProcessor

Constants

IMAGE_REGEX

Paragraphs that only contain images are rendered with {Spirit::Render::Image}.

Public Class Methods

new(*args) click to toggle source
# File lib/spirit/render/processors/block_image_processor.rb, line 13
def initialize(*args)
  @image = 0
end

Public Instance Methods

filter(text) click to toggle source

Detects block images and renders them as such. @return [String] rendered html

# 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

Private Instance Methods

block_image(text) click to toggle source

Prepares a block image. Raises {RenderError} if the given text does not contain a valid image block. @param [String] text markdown text @return [String] rendered HTML

# File lib/spirit/render/processors/block_image_processor.rb, line 34
def block_image(text)
  Image.parse(text).render(index: @image += 1)
end
p(text) click to toggle source

Wraps the given text with paragraph tags. @param [String] text paragraph text @return [String] rendered html

# File lib/spirit/render/processors/block_image_processor.rb, line 41
def p(text)
  '<p>' + text + '</p>'
end