class Mobiledoc::HTMLRenderer
Constants
- VERSION
Attributes
state[RW]
Public Class Methods
new(options={})
click to toggle source
# File lib/mobiledoc_html_renderer.rb, line 12 def initialize(options={}) cards = options[:cards] || [] validate_cards(cards) atoms = options[:atoms] || [] validate_atoms(atoms) card_options = options[:card_options] || {} unknown_card_handler = options[:unknown_card_handler] || UnknownCard unknown_atom_handler = options[:unknown_atom_handler] || UnknownAtom self.state = { cards: cards, atoms: atoms, card_options: card_options, unknown_card_handler: unknown_card_handler, unknown_atom_handler: unknown_atom_handler } end
Public Instance Methods
render(mobiledoc)
click to toggle source
# File lib/mobiledoc_html_renderer.rb, line 65 def render(mobiledoc) version = mobiledoc['version'] case version when '0.2.0' Renderer_0_2.new(mobiledoc, state).render when '0.3.0', '0.3.1', '0.3.2', nil Renderer_0_3.new(mobiledoc, state).render else raise Mobiledoc::Error.new(%Q[Unexpected Mobiledoc version "#{version}"]) end end
validate_atoms(atoms)
click to toggle source
# File lib/mobiledoc_html_renderer.rb, line 49 def validate_atoms(atoms) unless atoms.is_a?(Array) raise Mobiledoc::Error.new("`atoms` must be passed as an array") end atoms.each do |atom| unless atom.type == 'html' raise Mobiledoc::Error.new(%Q[Atom "#{atom.name}" must be of type "html", was "#{atom.type}"]) end unless atom.respond_to?(:render) raise Mobiledoc::Error.new(%Q[Atom "#{atom.name}" must define \`render\`]) end end end
validate_cards(cards)
click to toggle source
# File lib/mobiledoc_html_renderer.rb, line 33 def validate_cards(cards) unless cards.is_a?(Array) raise Mobiledoc::Error.new("`cards` must be passed as an array") end cards.each do |card| unless card.type == 'html' raise Mobiledoc::Error.new(%Q[Card "#{card.name}" must be of type "html", was "#{card.type}"]) end unless card.respond_to?(:render) raise Mobiledoc::Error.new(%Q[Card "#{card.name}" must define \`render\`]) end end end