Module: Palapala::Helper

Defined in:
lib/palapala/helper.rb

Class Method Summary collapse

Class Method Details


13
14
15
# File 'lib/palapala/helper.rb', line 13

def self.footer(left: "", center: "", right: "", margin: "1cm", font_family: "Arial")
  self.header(left:, center:, right:, margin:, font_family:)
end

.header(left: "", center: "", right: "", margin: "1cm", font_family: "Arial") ⇒ Object


3
4
5
6
7
8
9
10
11
# File 'lib/palapala/helper.rb', line 3

def self.header(left: "", center: "", right: "", margin: "1cm", font_family: "Arial")
  <<~HTML
    <div style="display: flex; justify-content: space-between; width: 100%; margin-left: #{margin}; margin-right: #{margin}; font-family: #{font_family}">
      <div style="text-align: left; flex: 1;">#{left}</div>
      <div style="text-align: center; flex: 1;">#{center}</div>
      <div style="text-align: right; flex: 1;">#{right}</div>
  </div>
  HTML
end

.hf_template(from:) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/palapala/helper.rb', line 41

def self.hf_template(from:)
  return if from.nil?
  style = <<~HTML.freeze
    <style>
      #header, #footer {
        font-size: 10pt;
        display: flex;
        justify-content: center;
      }
    </style>
  HTML
  style + from
end

.page_number(style: nil) ⇒ Object


17
18
19
20
21
22
# File 'lib/palapala/helper.rb', line 17

def self.page_number(style: nil)
  style_attr = style.nil? ? "" : "style='#{style}'"
  <<~HTML
    <span class="pageNumber" #{style_attr}></span>/<span class="totalPages"></span>
  HTML
end

.watermark(watermark, angle: "-15deg", color: "rgba(25,25,25,0.25)", font_size: "72pt") ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/palapala/helper.rb', line 24

def self.watermark(watermark, angle: "-15deg", color: "rgba(25,25,25,0.25)", font_size: "72pt")
  <<~HTML
    <style>
      .palapala_pdf_watermark {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) rotate(#{angle});
        font-size: #{font_size};
        color: #{color};
        z-index: 9999;
      }
    </style>
    <span class="palapala_pdf_watermark">#{watermark}</span>
  HTML
end