Module: MaRuKu::Out::Prawn
- Defined in:
- lib/legal_beagle/to_prawn.rb
Instance Method Summary collapse
- #array_to_prawn(children) ⇒ Object
- #entity_table ⇒ Object
- #li_text(li) ⇒ Object
- #to_pdf_string(children) ⇒ Object
- #to_prawn(pdf) ⇒ Object
- #to_prawn_div(div) ⇒ Object
-
#to_prawn_header(header) ⇒ Object
TODO find a less ghetto way to do leading-trailing margins.
- #to_prawn_ol(ol) ⇒ Object
- #to_prawn_ol_span(li, i) ⇒ Object
- #to_prawn_paragraph(para) ⇒ Object
- #to_prawn_string_emphasis(em) ⇒ Object
- #to_prawn_string_entity(entity) ⇒ Object
- #to_prawn_string_im_image(image) ⇒ Object
- #to_prawn_string_paragraph(para) ⇒ Object
- #to_prawn_string_strong(strong) ⇒ Object
- #to_prawn_ul(ul) ⇒ Object
- #to_prawn_ul_span(li) ⇒ Object
Instance Method Details
#array_to_prawn(children) ⇒ Object
11 12 13 14 15 |
# File 'lib/legal_beagle/to_prawn.rb', line 11 def array_to_prawn(children) children.each do |c| send("to_prawn_#{c.node_type}", c) end end |
#entity_table ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/legal_beagle/to_prawn.rb', line 78 def entity_table @table ||= { "lsquo" => "‘", "rsquo" => "’", "ldquo" => "“", "rdquo" => "”" } end |
#li_text(li) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/legal_beagle/to_prawn.rb', line 31 def li_text(li) if li.children.empty? li.to_html else to_pdf_string(li.children) end end |
#to_pdf_string(children) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/legal_beagle/to_prawn.rb', line 53 def to_pdf_string(children) children.inject("") do |t, c| if c.is_a? String t + c else t + send("to_prawn_string_#{c.node_type}", c) end end end |
#to_prawn(pdf) ⇒ Object
6 7 8 9 |
# File 'lib/legal_beagle/to_prawn.rb', line 6 def to_prawn(pdf) @pdf = pdf array_to_prawn(@children) end |
#to_prawn_div(div) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/legal_beagle/to_prawn.rb', line 105 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 |
#to_prawn_header(header) ⇒ Object
TODO find a less ghetto way to do leading-trailing margins
99 100 101 102 103 |
# File 'lib/legal_beagle/to_prawn.rb', line 99 def to_prawn_header(header) size = { 1 => 16, 2 => 12 }[header.level] @pdf.text header.children.join("\n"), :size => size, :style => :bold @pdf.text ' ' end |
#to_prawn_ol(ol) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/legal_beagle/to_prawn.rb', line 17 def to_prawn_ol(ol) ol.children.each_with_index do |c, i| to_prawn_ol_span(c, i) end @pdf.text ' ' end |
#to_prawn_ol_span(li, i) ⇒ Object
39 40 41 |
# File 'lib/legal_beagle/to_prawn.rb', line 39 def to_prawn_ol_span(li, i) @pdf.text " #{i+1}. " + li_text(li), :indent_paragraphs => 20 end |
#to_prawn_paragraph(para) ⇒ Object
47 48 49 50 51 |
# File 'lib/legal_beagle/to_prawn.rb', line 47 def to_prawn_paragraph(para) text = to_pdf_string(para.children) @pdf.text text, :inline_format => true @pdf.text ' ' end |
#to_prawn_string_emphasis(em) ⇒ Object
63 64 65 |
# File 'lib/legal_beagle/to_prawn.rb', line 63 def to_prawn_string_emphasis(em) "<em>#{to_pdf_string(em.children)}</em>" end |
#to_prawn_string_entity(entity) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/legal_beagle/to_prawn.rb', line 91 def to_prawn_string_entity(entity) name = entity.entity_name typographic = entity_table[name] raise "I don't know how to make a typographic #{name}" unless typographic typographic end |
#to_prawn_string_im_image(image) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/legal_beagle/to_prawn.rb', line 71 def to_prawn_string_im_image(image) = {} [:width] = image.children.first.to_i if image.children.first @pdf.image image.url, "" end |
#to_prawn_string_paragraph(para) ⇒ Object
87 88 89 |
# File 'lib/legal_beagle/to_prawn.rb', line 87 def to_prawn_string_paragraph(para) para.to_html end |
#to_prawn_string_strong(strong) ⇒ Object
67 68 69 |
# File 'lib/legal_beagle/to_prawn.rb', line 67 def to_prawn_string_strong(strong) "<strong>#{to_pdf_string(strong.children)}</strong>" end |
#to_prawn_ul(ul) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/legal_beagle/to_prawn.rb', line 24 def to_prawn_ul(ul) ul.children.each do |c| to_prawn_ul_span(c) end @pdf.text ' ' end |
#to_prawn_ul_span(li) ⇒ Object
43 44 45 |
# File 'lib/legal_beagle/to_prawn.rb', line 43 def to_prawn_ul_span(li) @pdf.text " • " + li_text(li), :indent_paragraphs => 20 end |