Module: Dorsale::PrawnHelpers

Includes:
ActionView::Helpers::NumberHelper, AllHelpers
Included in:
ApplicationPdf
Defined in:
app/pdfs/dorsale/prawn_helpers.rb

Instance Method Summary collapse

Methods included from UsersHelper

#avatar_img, #default_avatar_url

Methods included from ExpenseGun::ApplicationHelper

#expense_states_for_filters_select

Methods included from Flyboy::ApplicationHelper

#flyboy_reminder_type_units_for_select, #flyboy_reminder_types_for_select, #flyboy_status_for_filters_select, #flyboy_tasks_owners_for_filters_select, #flyboy_tasks_owners_for_select, #flyboy_tasks_tags_for_filters_select, #flyboy_tasks_tags_for_select, #show_tasks_summary, #task_term_values_for_select, #tasks_for

Methods included from CustomerVault::ApplicationHelper

#customer_vault_activity_types_for_select, #customer_vault_event_actions_for_filter_select, #customer_vault_event_contact_types_for_filter_select, #customer_vault_link_form_path, #customer_vault_origins_for_select, #customer_vault_tag_list, #new_event_for, #person_address_blank?, #person_related_people_blank?, #person_social_blank?, #person_types_for_filter_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 Alexandrie::AttachmentsHelper

#attachments_for

Methods included from CommentsHelper

#comments_for, #new_comment_for, #truncate_comment_text, #truncate_comments_in_this_page?

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(options = {}, &block)
  outer_box_left   = options.fetch(:left, bounds.left)
  outer_box_top    = options.fetch(:top, bounds.top)
  outer_box_width  = options.fetch(:width, bounds.width)
  outer_box_height = options.fetch(:height, bounds.height)
  padding          = options.fetch(:padding, 0)
  radius           = options.fetch(:radius, 0)
  rectangle        = options.fetch(:rectangle, false)
  background       = options.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, options = {})
  bb(options) 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

Returns:

  • (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_heightObject



20
21
22
# File 'app/pdfs/dorsale/prawn_helpers.rb', line 20

def page_height
  page.dimensions[3]
end

#page_widthObject



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, options = {})
  box_left   = options[:left]   || bounds.left
  box_top    = options[:top]    || bounds.top
  box_width  = options[:width]  || bounds.width
  box_height = options[:height] || bounds.height

  options = {
    :at            => [box_left, box_top],
    :width         => box_width,
    :height        => box_height,
    :overflow      => :shrink_to_fit,
    :inline_format => true,
  }.merge(options)

  text_box(text.to_s, options)
end