class Spirit::Render::Image
Renders a block image with a figure number.
Constants
- IMAGE_TAG
<img …>
Public Class Methods
new(html)
click to toggle source
Creates a new image.
# File lib/spirit/render/templates/image.rb, line 21 def initialize(html) @html = html parse_or_raise end
parse(text)
click to toggle source
Parses the given text for a block image.
# File lib/spirit/render/templates/image.rb, line 16 def self.parse(text) Image.new text end
Public Instance Methods
render(locals={})
click to toggle source
Calls superclass method
# File lib/spirit/render/templates/image.rb, line 26 def render(locals={}) super locals.merge(img: @html, caption: @node['alt']) end
Private Instance Methods
parse_or_raise()
click to toggle source
Parses the given HTML
, or raise {RenderError} if it is invalid.
# File lib/spirit/render/templates/image.rb, line 33 def parse_or_raise frag = Nokogiri::HTML::DocumentFragment.parse(@html.strip) if 1 == frag.children.count and node = frag.children.first and node.is_a? Nokogiri::XML::Element and node.name == IMAGE_TAG @node = node else raise RenderError, 'Not really a block image.' end end