Class: Bookie::Emitters::PDF
- Inherits:
-
Object
- Object
- Bookie::Emitters::PDF
- Includes:
- Prawn::Measurements
- Defined in:
- lib/bookie/emitters.rb
Instance Method Summary collapse
- #build_list(list) ⇒ Object
- #build_paragraph(paragraph) ⇒ Object
- #build_raw_text(raw_text) ⇒ Object
- #build_section_heading(section_text) ⇒ Object
-
#initialize(params) ⇒ PDF
constructor
A new instance of PDF.
- #register_fonts ⇒ Object
- #render(params) ⇒ Object
- #render_header(params) ⇒ Object
Constructor Details
#initialize(params) ⇒ PDF
Returns a new instance of PDF.
113 114 115 116 117 118 119 |
# File 'lib/bookie/emitters.rb', line 113 def initialize(params) @document = new_prawn_document @document.extend(Prawn::Measurements) register_fonts render_header(params) end |
Instance Method Details
#build_list(list) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/bookie/emitters.rb', line 121 def build_list(list) items = list.contents @document.instance_eval do font("serif", :size => 9) do items.each do |li| float { text "•" } indent(in2pt(0.15)) do text li.gsub(/\s+/," "), inline_format: true, leading: 2 end move_down in2pt(0.05) end end move_down in2pt(0.05) end end |
#build_paragraph(paragraph) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/bookie/emitters.rb', line 154 def build_paragraph(paragraph) @document.font("serif", size: 9) do @document.text(paragraph.contents.strip, align: :justify, leading: 2) @document.move_down in2pt(0.1) end end |
#build_raw_text(raw_text) ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'lib/bookie/emitters.rb', line 161 def build_raw_text(raw_text) sanitized_text = raw_text.contents.gsub(" ", Prawn::Text::NBSP).strip @document.font("mono", size: 8) do @document.text sanitized_text @document.move_down in2pt(0.1) end end |
#build_section_heading(section_text) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/bookie/emitters.rb', line 142 def build_section_heading(section_text) @document.move_down in2pt(0.1) @document.float do @document.font("sans", :style => :bold, :size => 14) do @document.text(section_text.contents.strip) end end @document.move_down in2pt(0.3) end |
#register_fonts ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/bookie/emitters.rb', line 191 def register_fonts dejavu_path = File.dirname(__FILE__) + "/../../data/fonts/dejavu" @document.font_families["sans"] = { :normal => "#{dejavu_path}/DejaVuSansCondensed.ttf", :italic => "#{dejavu_path}/DejaVuSansCondensed-Oblique.ttf", :bold => "#{dejavu_path}/DejaVuSansCondensed-Bold.ttf", :bold_italic => "#{dejavu_path}/DejaVuSansCondensed-BoldOblique.ttf" } @document.font_families["mono"] = { :normal => "#{dejavu_path}/DejaVuSansMono.ttf", :italic => "#{dejavu_path}/DejaVuSansMono-Oblique.ttf", :bold => "#{dejavu_path}/DejaVuSansMono-Bold.ttf", :bold_italic => "#{dejavu_path}/DejaVuSansMono-BoldOblique.ttf" } @document.font_families["serif"] = { :normal => "#{dejavu_path}/DejaVuSerif.ttf", :italic => "#{dejavu_path}/DejaVuSerif-Italic.ttf", :bold => "#{dejavu_path}/DejaVuSerif-Bold.ttf", :bold_italic => "#{dejavu_path}/DejaVuSerif-BoldItalic.ttf" } end |
#render(params) ⇒ Object
170 171 172 |
# File 'lib/bookie/emitters.rb', line 170 def render(params) @document.render_file(params[:file]) end |
#render_header(params) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/bookie/emitters.rb', line 174 def render_header(params) @document.instance_eval do font("sans") do text "<b>#{params[:header]}</b>", size: 12, align: :right, inline_format: true stroke_horizontal_rule move_down in2pt(0.1) text "<b>#{params[:title]}</b>", size: 18, align: :right, inline_format: true move_down in2pt(1.25) end end end |