class Proforma::PrawnRenderer
This main class to use as a Proforma
renderer.
Constants
- EXTENSION
- RENDERERS
- VERSION
Attributes
options[R]
pdf[R]
renderers[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/proforma/prawn_renderer.rb, line 46 def initialize(options = {}) @options = Util::Options.make(options) clear end
Public Instance Methods
render(prototype)
click to toggle source
# File lib/proforma/prawn_renderer.rb, line 52 def render(prototype) clear render_children(prototype.children) Proforma::Document.new( contents: pdf.render, extension: EXTENSION, title: prototype.title ) end
Private Instance Methods
clear()
click to toggle source
# File lib/proforma/prawn_renderer.rb, line 68 def clear @pdf = fresh_pdf @renderers = RENDERERS.each_with_object({}) do |(model_class, renderer_class), hash| hash[model_class] = renderer_class.new(pdf, options) end end
fresh_pdf()
click to toggle source
# File lib/proforma/prawn_renderer.rb, line 76 def fresh_pdf Prawn::Document.new.tap do |p| options.fonts.each do |font| p.font_families.update(font.prawn_config) end p.font(options.font_name) end end
render_children(children)
click to toggle source
# File lib/proforma/prawn_renderer.rb, line 86 def render_children(children) children.each do |child| raise ArgumentError, "Cannot render: #{child.class.name}" unless renderable?(child) renderer(child).render(child) end end
renderable?(child)
click to toggle source
# File lib/proforma/prawn_renderer.rb, line 94 def renderable?(child) renderers.key?(child.class) end
renderer(child)
click to toggle source
# File lib/proforma/prawn_renderer.rb, line 98 def renderer(child) renderers[child.class] end