Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module MaRuKu::Out::Prawn
def to_prawn(pdf)
@pdf = pdf
@pdf.font_size = 11
array_to_prawn(@children)
end
def array_to_prawn(children)
children.each do |c|
send("to_prawn_#{c.node_type}", c)
end
end
def to_prawn_paragraph(para)
@pdf.text para.children.join("\n")
@pdf.text ' '
end
def to_prawn_entity(entity)
puts "Didn't write entity to pdf"
p entity
end
# TODO find a less ghetto way to do leading-trailing margins
def to_prawn_header(header)
size = { 1 => 16, 2 => 14 }[header.level]
@pdf.text header.children.join("\n"), :size => size, :style => :bold
@pdf.text ' '
end
def to_prawn_div(div)
if div.attributes[:class] == "signature"
signature_name = div.children.map.join(" ")
@pdf.instance_eval do
text ' ', :size => 30
stroke_horizontal_line 0, 200
stroke_horizontal_line 250, 300
text ' ', :size => 4
text signature_name
draw_text "Date", :at => [250, y - bounds.absolute_bottom + 5]
text ' ', :size => 20
stroke_horizontal_line 0, 200
text ' ', :size => 4
text signature_name + " (Print)"
end
else
puts "Didn't write div to pdf: #{div.inspect}"
end
end
end
MaRuKu::MDElement.send(:include, MaRuKu::Out::Prawn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment