Module: TipjarHelper

Defined in:
app/helpers/tipjar_helper.rb

Instance Method Summary collapse

Instance Method Details

#tip_jar(options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
66
67
68
# File 'app/helpers/tipjar_helper.rb', line 2

def tip_jar(options = {})
  # Extract all options with sensible defaults
  payment_link = options[:payment_link] || options[:link]
  payment_links = options[:payment_links]
  use_modal = options[:use_modal] || false
  
  # Button configuration
  message = options[:message] || options[:button_text] || "Tip Jar"
  icon = options[:icon] || :jar
  position = options[:position] || :bottom_right
  color = options[:color] || "#3b82f6"
  text_color = options[:text_color] || "#ffffff"
  pulse = options[:pulse] || false
  z_index = options[:z_index] || 1000
  custom_class = options[:class] || ""
  
  # Modal configuration (if using modal)
  modal_title = options[:modal_title] || "Support my work"
  modal_description = options[:modal_description] || "Your support helps me continue creating and maintaining this project."
  theme = options[:theme] || :light
  custom_amounts = options[:custom_amounts] || [
    { amount: 5, label: "$5", default: false },
    { amount: 10, label: "$10", default: true },
    { amount: 25, label: "$25", default: false },
    { amount: 50, label: "$50", default: false }
  ]
  
  # Ensure color has # prefix
  color = "##{color}" unless color.start_with?('#')
  text_color = "##{text_color}" unless text_color.start_with?('#')
  
  # If payment_links is provided or use_modal is true, use modal mode
  if payment_links || use_modal
    # Modal mode
    tipjar_modal_button(
      payment_links: payment_links || { default: payment_link },
      position: position,
      icon: icon,
      theme: theme,
      button_text: message,
      modal_title: modal_title,
      modal_description: modal_description,
      custom_amounts: custom_amounts,
      button_class: custom_class,
      z_index: z_index,
      color: color,
      text_color: text_color,
      pulse: pulse
    )
  elsif payment_link
    # Simple direct link mode
    tipjar_simple_button(
      payment_link: payment_link,
      message: message,
      icon: icon,
      position: position,
      color: color,
      text_color: text_color,
      pulse: pulse,
      z_index: z_index,
      custom_class: custom_class
    )
  else
    # No payment method specified
    raise ArgumentError, "You must provide either :payment_link or :payment_links option to tip_jar helper"
  end
end