class Rodolfo::Renderer
Requires a filesystem folder path which should contain
-
schema.json to perform the validation
-
data.json as example data (for testing purposes only and valid example)
-
template.rb the pdf generator itself
It renders the the given template validating the data against that json schema
Attributes
data[R]
validation_errors[R]
Public Class Methods
new(path, data, strict = false)
click to toggle source
# File lib/rodolfo/renderer.rb, line 23 def initialize(path, data, strict = false) @path = Pathname.new(path).absolute? ? path : File.join(Dir.pwd, path) @data = data schema_path = File.join(@path, 'schema.json') @schema = JSONSchema.new schema_path, strict end
Public Instance Methods
json_schema()
click to toggle source
Get the recipe json schema
# File lib/rodolfo/renderer.rb, line 31 def json_schema @schema.to_s end
pdf_meta()
click to toggle source
# File lib/rodolfo/renderer.rb, line 40 def pdf_meta { CreationDate: Time.now.iso8601, JsonSchema: @schema.to_h, Payload: validated_data, Renderer: "Rodolfo v#{VERSION}" } end
render()
click to toggle source
Render the template
# File lib/rodolfo/renderer.rb, line 48 def render require File.join @path, 'template' Rodolfo::Template.new(validated_data, info: pdf_meta).render rescue NoMethodError msg = 'Missing or incorrect data, template can\'t be rendered' raise RenderError, [msg] end
validated_data()
click to toggle source
Validates the data against the json schema
# File lib/rodolfo/renderer.rb, line 36 def validated_data @schema.validate(@data) end