Module: Account::ReferralsHelper

Defined in:
app/helpers/account/referrals_helper.rb

Instance Method Summary collapse

Instance Method Details

#essay_page_entries_info(collection, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/account/referrals_helper.rb', line 46

def essay_page_entries_info(collection, options = {})
  entry_name = options[:entry_name] || collection.entry_name
  entry_name = entry_name.pluralize unless collection.total_count == 1

  if collection.total_pages < 2
    t('helpers.page_entries_info.one_page.display_entries', entry_name: entry_name, count: collection.total_count)
  else
    client_offset = (collection.current_page.to_i - 1) * options[:per_page].to_i

    first = client_offset + 1
    last = collection.last_page? ? collection.total_count : client_offset + collection.limit_value
    t('helpers.page_entries_info.more_pages.display_entries', entry_name: entry_name, first: first, last: last, total: collection.total_count)
  end.html_safe
end


40
41
42
43
44
# File 'app/helpers/account/referrals_helper.rb', line 40

def invite_link
  return unless @member&.registered?

  @invite_link ||= new_order_url(discount: @member.referral_code)
end

#social_provider_class(name) ⇒ Object



31
32
33
34
35
36
37
38
# File 'app/helpers/account/referrals_helper.rb', line 31

def social_provider_class(name)
  case name.to_s
  when 'facebook' then 'fb'
  when 'twitter' then 'twit'
  when 'google' then 'gplus'
  else name
  end
end

#social_share(url, options = {}) ⇒ Object



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
# File 'app/helpers/account/referrals_helper.rb', line 5

def social_share(url, options = {})
  options.reverse_merge!(
    description: '',
    image: '',
    links: [:facebook, :twitter, :linkedin]
  )

  options[:twitter] ||= options[:description]

  links = options.delete(:links) || TranslationCms::SOCIAL_LINKS.keys
  # analytics = { utm_medium: 'share', utm_campaign: 'Info' }

  links.each do |name|
    break unless TranslationCms::SOCIAL_LINKS.key?(name)

    submit_url = TranslationCms::SOCIAL_LINKS[name].dup
    options[:url] = url.to_s

    options.each do |key, value|
      submit_url.gsub!("{{#{key}}}", Rack::Utils.escape(value))
    end

    yield submit_url.html_safe, name
  end
end