• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

foodcoops / foodsoft / 21521827700

30 Jan 2026 03:53PM UTC coverage: 42.78% (-24.3%) from 67.127%
21521827700

Pull #1269

github

lentschi
Remove GitHub deploy workflow
Pull Request #1269: Remove GitHub deploy workflow

3087 of 7216 relevant lines covered (42.78%)

11.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.85
/lib/render_pdf.rb
1
require 'prawn/measurement_extensions'
1✔
2

3
class RotatedCell < Prawn::Table::Cell::Text
1✔
4
  def initialize(pdf, text, options = {})
1✔
5
    options[:content] = text
×
6
    options[:valign] = :center
×
7
    options[:align] = :center
×
8
    options[:rotate_around] = :center
×
9
    @rotation = -options[:rotate] || 0
×
10
    super(pdf, [0, pdf.cursor], options)
×
11
  end
12

13
  def tan_rotation
1✔
14
    Math.tan(Math::PI * @rotation / 180)
×
15
  end
16

17
  def skew
1✔
18
    (height + (border_top_width / 2.0) + (border_bottom_width / 2.0)) / tan_rotation
×
19
  end
20

21
  def styled_width_of(_text)
1✔
22
    options = @text_options.reject { |k| k == :style }
×
23
    with_font { (@pdf.height_of(@content, options) + padding_top + padding_bottom) / tan_rotation }
×
24
  end
25

26
  def natural_content_height
1✔
27
    options = @text_options.reject { |k| k == :style }
×
28
    with_font { (@pdf.width_of(@content, options) + padding_top + padding_bottom) * tan_rotation }
×
29
  end
30

31
  def draw_borders(point)
1✔
32
    @pdf.mask(:line_width, :stroke_color) do
×
33
      x, y = point
×
34
      from = [[x - skew, y + (border_top_width / 2.0)],
×
35
              to = [x, y - height - (border_bottom_width / 2.0)]]
×
36

37
      @pdf.line_width = @border_widths[3]
×
38
      @pdf.stroke_color = @border_colors[3]
×
39
      @pdf.stroke_line(from, to)
×
40
      @pdf.undash
×
41
    end
42
  end
43

44
  def draw_content
1✔
45
    with_font do
×
46
      with_text_color do
×
47
        text_box(width: spanned_content_width + FPTolerance + skew,
×
48
                 height: spanned_content_height + FPTolerance,
49
                 at: [1 - skew, @pdf.cursor]).render
50
      end
51
    end
52
  end
53
end
54

55
class RenderPdf < Prawn::Document
1✔
56
  include ActionView::Helpers::NumberHelper
1✔
57
  include ApplicationHelper
1✔
58

59
  TOP_MARGIN = 36
1✔
60
  BOTTOM_MARGIN = 23
1✔
61
  HEADER_SPACE = 9
1✔
62
  FOOTER_SPACE = 3
1✔
63
  HEADER_FONT_SIZE = 16
1✔
64
  FOOTER_FONT_SIZE = 8
1✔
65
  DEFAULT_FONT = 'OpenSans'
1✔
66

67
  def initialize(options = {})
1✔
68
    options[:font_size] ||= FoodsoftConfig[:pdf_font_size].try(:to_f) || 12
×
69
    options[:page_size] ||= FoodsoftConfig[:pdf_page_size] || 'A4'
×
70
    options[:skip_page_creation] = true
×
71
    @options = options
×
72
    @first_page = true
×
73

74
    super
×
75

76
    # Use ttf for better utf-8 compability
77
    font_families.update(
×
78
      'OpenSans' => {
79
        bold: font_path('OpenSans-Bold.ttf'),
80
        italic: font_path('OpenSans-Italic.ttf'),
81
        bold_italic: font_path('OpenSans-BoldItalic.ttf'),
82
        normal: font_path('OpenSans-Regular.ttf')
83
      }
84
    )
85

86
    header = options[:title] || title
×
87
    footer = I18n.l(Time.now, format: :long)
×
88

89
    header_size = 0
×
90
    header_size = height_of(header, size: HEADER_FONT_SIZE, font: DEFAULT_FONT) + HEADER_SPACE if header
×
91
    footer_size = height_of(footer, size: FOOTER_FONT_SIZE, font: DEFAULT_FONT) + FOOTER_SPACE
×
92

93
    start_new_page(top_margin: TOP_MARGIN + header_size, bottom_margin: BOTTOM_MARGIN + footer_size)
×
94

95
    font DEFAULT_FONT
×
96

97
    repeat :all, dynamic: true do
×
98
      bounding_box [bounds.left, bounds.top + header_size], width: bounds.width, height: header_size do
×
99
        text header, size: HEADER_FONT_SIZE, align: :center, overflow: :shrink_to_fit if header
×
100
      end
101
      font_size FOOTER_FONT_SIZE do
×
102
        bounding_box [bounds.left, bounds.bottom - FOOTER_SPACE], width: bounds.width, height: footer_size do
×
103
          text footer, align: :left, valign: :bottom
×
104
        end
105
        bounding_box [bounds.left, bounds.bottom - FOOTER_SPACE], width: bounds.width, height: footer_size do
×
106
          text I18n.t('lib.render_pdf.page', number: page_number, count: page_count), align: :right, valign: :bottom
×
107
        end
108
      end
109
    end
110
  end
111

112
  def title
1✔
113
    nil
×
114
  end
115

116
  def to_pdf
1✔
117
    body # Add content, which is defined in subclasses
×
118
    render # Render pdf
×
119
  end
120

121
  # @todo avoid underscore instead of unicode whitespace in pdf :/
122
  def number_to_currency(number, options = {})
1✔
123
    super.gsub("\u202f", ' ') if number
×
124
  end
125

126
  def font_size(points = nil, &)
1✔
127
    points *= @options[:font_size] / 12 if points
×
128
    super
×
129
  end
130

131
  # add pagebreak or vertical whitespace, depending on configuration
132
  def down_or_page(space = 10)
1✔
133
    if @first_page
×
134
      @first_page = false
×
135
      return
×
136
    end
137
    if pdf_add_page_breaks?
×
138
      start_new_page
×
139
    else
140
      move_down space
×
141
    end
142
  end
143

144
  protected
1✔
145

146
  def fontsize(size)
1✔
147
    size
×
148
  end
149

150
  # return whether pagebreak or vertical whitespace is used for breaks
151
  def pdf_add_page_breaks?(docid = nil)
1✔
152
    docid ||= self.class.name.underscore
×
153
    cfg = FoodsoftConfig[:pdf_add_page_breaks]
×
154
    case cfg
×
155
    when Array
156
      cfg.index(docid.to_s).any?
×
157
    when Hash
158
      cfg[docid.to_s]
×
159
    else
160
      cfg
×
161
    end
162
  end
163

164
  def font_path(name)
1✔
165
    Rails.root.join('vendor', 'assets', 'fonts', name)
×
166
  end
167
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc