Module: Dorsale::PrawnHelpers
- Includes:
- ActionView::Helpers::NumberHelper, AllHelpers
- Included in:
- ApplicationPdf
- Defined in:
- app/pdfs/dorsale/prawn_helpers.rb
Instance Method Summary collapse
- #bb(options = {}, &block) ⇒ Object
- #btb(text, options = {}) ⇒ Object
- #draw_debug_bounds! ⇒ Object
- #draw_debug_bounds? ⇒ Boolean
- #get_image(obj) ⇒ Object
- #page_height ⇒ Object
- #page_width ⇒ Object
- #placeholder(method) ⇒ Object
- #t(*args) ⇒ Object
- #tb(text, options = {}) ⇒ Object
Methods included from UsersHelper
#avatar_img, #default_avatar_url
Methods included from ExpenseGun::ApplicationHelper
#expense_states_for_filters_select
Methods included from BillingMachine::ApplicationHelper
#billing_machine_invoices_chart, #billing_machine_payment_status_for_filter_select, #billing_machine_quotation_states_for_filter_select, #billing_machine_quotation_states_for_select, #bm_currency, #quotation_state_classes
Methods included from ContextHelper
#actions_for, #render_dorsale_page
Instance Method Details
#bb(options = {}, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/pdfs/dorsale/prawn_helpers.rb', line 28 def bb( = {}, &block) outer_box_left = .fetch(:left, bounds.left) outer_box_top = .fetch(:top, bounds.top) outer_box_width = .fetch(:width, bounds.width) outer_box_height = .fetch(:height, bounds.height) padding = .fetch(:padding, 0) radius = .fetch(:radius, 0) rectangle = .fetch(:rectangle, false) background = .fetch(:background, false) if rectangle stroke do rounded_rectangle [outer_box_left, outer_box_top], outer_box_width, outer_box_height, radius end end if background previous_fill_color = fill_color fill_color background fill_rounded_rectangle [outer_box_left, outer_box_top], outer_box_width, outer_box_height, radius fill_color previous_fill_color end bounding_box [outer_box_left, outer_box_top], width: outer_box_width, height: outer_box_height do draw_debug_bounds! inner_box_left = bounds.left + padding inner_box_top = bounds.top - padding inner_box_width = bounds.width - (padding * 2) inner_box_height = bounds.height - (padding * 2) bounding_box [inner_box_left, inner_box_top], width: inner_box_width, height: inner_box_height do draw_debug_bounds! block&.call end end end |
#btb(text, options = {}) ⇒ Object
84 85 86 87 88 |
# File 'app/pdfs/dorsale/prawn_helpers.rb', line 84 def btb(text, = {}) bb() do tb(text) end end |
#draw_debug_bounds! ⇒ Object
12 13 14 |
# File 'app/pdfs/dorsale/prawn_helpers.rb', line 12 def draw_debug_bounds! transparent(0.5) { stroke_bounds } if draw_debug_bounds? end |
#draw_debug_bounds? ⇒ Boolean
8 9 10 |
# File 'app/pdfs/dorsale/prawn_helpers.rb', line 8 def draw_debug_bounds? false end |
#get_image(obj) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/pdfs/dorsale/prawn_helpers.rb', line 90 def get_image(obj) return if obj.blank? if ApplicationUploader.storage.to_s.end_with?("File") # Local obj.path elsif ApplicationUploader.storage.to_s.end_with?("Fog") # Amazon S3 URI.parse(obj.url).open else raise NotImplementedError end end |
#page_height ⇒ Object
20 21 22 |
# File 'app/pdfs/dorsale/prawn_helpers.rb', line 20 def page_height page.dimensions[3] end |
#page_width ⇒ Object
24 25 26 |
# File 'app/pdfs/dorsale/prawn_helpers.rb', line 24 def page_width page.dimensions[2] end |
#placeholder(method) ⇒ Object
102 103 104 105 106 |
# File 'app/pdfs/dorsale/prawn_helpers.rb', line 102 def placeholder(method) return unless Rails.env.development? "You can override this text in <b>##{method}</b> method, otherwise it will not be displayed in other environments." end |
#t(*args) ⇒ Object
16 17 18 |
# File 'app/pdfs/dorsale/prawn_helpers.rb', line 16 def t(*args) I18n.t(*args) end |
#tb(text, options = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/pdfs/dorsale/prawn_helpers.rb', line 67 def tb(text, = {}) box_left = [:left] || bounds.left box_top = [:top] || bounds.top box_width = [:width] || bounds.width box_height = [:height] || bounds.height = { :at => [box_left, box_top], :width => box_width, :height => box_height, :overflow => :shrink_to_fit, :inline_format => true, }.merge() text_box(text.to_s, ) end |