Module: LabelsHelper

Defined in:
app/helpers/labels_helper.rb

Instance Method Summary collapse

Instance Method Details

#label_code_128_tag(label) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/labels_helper.rb', line 56

def label_code_128_tag(label)
  c = Barby::Code128.new(label.text)

  (
    :span, 

    (
      :span, 
      c.to_svg(xmargin: 0, ymargin: 0).html_safe,
      class: :code128_barcode
    ) +
    (:span, label.text, class: 'code128_text'),
    class: :code128
  )
end


22
23
24
25
26
27
28
29
# File 'app/helpers/labels_helper.rb', line 22

def label_link(label)
  return nil if label.nil?
  if label.label_object_id.blank?
    taxonworks_label_tag(label)
  else
    link_to((:span, label.text), print_labels_task_path(label_id: label.to_param))
  end
end

#label_svg_tag(label) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/labels_helper.rb', line 31

def label_svg_tag(label)
  c = ::RQRCode::QRCode.new(label.text)

  (
    :span, 
    (:span, label.text, class: 'qrcode_text') +
    (
      :span, 
      c.as_svg(
        offset: 0,
        color: '000',
        shape_rendering: 'crispEdges',
        module_size: 1,
        standalone: true,
        viewbox: true,
        svg_attributes: {
          class: :qrcode_svg
        }
      ).to_s.html_safe,
      class: :qrcode_barcode
    ),
    class: :qrcode
  )
end

#taxonworks_label_tag(label) ⇒ Object

!! Note that `label_tag` is a Rails reserved word, so we have to append and make exceptions



10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/labels_helper.rb', line 10

def taxonworks_label_tag(label)
  return nil if label.nil?
  case label.type
  when 'Label::QrCode'
    label_svg_tag(label)
  when 'Label::Code128'
    label_code_128_tag(label)
  else
    (:span, label.text, style: label.style) # TODO: properly reference style
  end
end