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
- #draw(&block) ⇒ 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 141 142 143 144 |
# File 'lib/bookie/emitters.rb', line 121 def build_list(list) items = list.contents draw do font("serif", :size => 9) do items.each do |li| li_text = li.gsub(/\s+/," ") group do float { text "•" } indent(in2pt(0.15)) do text li_text, inline_format: true, leading: 2 end end move_down in2pt(0.05) end end move_down in2pt(0.05) end end |
#build_paragraph(paragraph) ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'lib/bookie/emitters.rb', line 162 def build_paragraph(paragraph) draw do font("serif", size: 9) do text(paragraph.contents.strip, align: :justify, leading: 2) end move_down in2pt(0.1) end end |
#build_raw_text(raw_text) ⇒ Object
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/bookie/emitters.rb', line 171 def build_raw_text(raw_text) sanitized_text = raw_text.contents.gsub(" ", Prawn::Text::NBSP).strip draw do font("mono", size: 8) do text sanitized_text move_down in2pt(0.1) end end end |
#build_section_heading(section_text) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/bookie/emitters.rb', line 146 def build_section_heading(section_text) draw do start_new_page unless cursor > in2pt(0.4) move_down in2pt(0.1) float do font("sans", :style => :bold, :size => 14) do text(section_text.contents.strip) end end move_down in2pt(0.3) end end |
#draw(&block) ⇒ Object
230 231 232 |
# File 'lib/bookie/emitters.rb', line 230 def draw(&block) @document.instance_eval(&block) end |
#register_fonts ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/bookie/emitters.rb', line 203 def register_fonts dejavu_path = File.dirname(__FILE__) + "/../../data/fonts/dejavu" draw do 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" } 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" } 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 end |
#render(params) ⇒ Object
182 183 184 |
# File 'lib/bookie/emitters.rb', line 182 def render(params) @document.render_file(params[:file]) end |
#render_header(params) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/bookie/emitters.rb', line 186 def render_header(params) draw 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 |