Module: Tarteaucitron::ViewHelpers

Defined in:
lib/tarteaucitron/view_helpers.rb

Instance Method Summary collapse

Instance Method Details



84
85
86
87
88
# File 'lib/tarteaucitron/view_helpers.rb', line 84

def cookie_manager_link(text = "Gestion des cookies")

  (:a, h(text), href: "javascript:tarteaucitron.userInterface.openPanel();").html_safe

end

#facebook(options = {}) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/tarteaucitron/view_helpers.rb', line 51

def facebook(options = {})

  default_options = {layout: "standard", action: "like", share: "true"}
  options = default_options.merge(options)

  (:div, '', class: "fb-like", data: options).html_safe

end

#googleplus(options = {}) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/tarteaucitron/view_helpers.rb', line 60

def googleplus(options = {})

  default_options = {size: "small", annotation: "inline", width: "300"}
  options = default_options.merge(options)

  (:div, '', class: "g-plusone", data: options).html_safe

end

#tarteaucitron(options = {}) ⇒ Object



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
# File 'lib/tarteaucitron/view_helpers.rb', line 3

def tarteaucitron(options = {})
  options = options.with_indifferent_access
  result = ""
  ip = request.remote_ip
  if ["EU", "--"].include?(GeoIP.new(Rails.root.join('db', 'GeoIP.dat')).country(ip).continent_code)
    result += ("script", '', src: "/tarteaucitron/tarteaucitron.js", type: "text/javascript")

    default = {
                "hashtag"=> "#tarteaucitron",
                "highPrivacy"=> false,
                "orientation"=> "top",
                "adblocker"=> false,
                "showAlertSmall"=> true,
                "cookieslist"=> true,
                "removeCredit"=> false,
              }

    init_options = default
    
    if options["options"]
      init_options = default.merge(options["options"].with_indifferent_access)
    end

    script = "tarteaucitron.init(#{init_options.to_json});"
    if options["google_analytics"]
      script += "tarteaucitron.user.gajsUa = '#{options["google_analytics"]}';"
      script += "tarteaucitron.user.gajsMore = function () {};"
      script += "(tarteaucitron.job = tarteaucitron.job || []).push('gajs');"
    end

    if options["facebook"]
      script += "(tarteaucitron.job = tarteaucitron.job || []).push('facebook');"
    end

    if options["googleplus"]
      script += "(tarteaucitron.job = tarteaucitron.job || []).push('gplus');"
    end

    if options["twitter"]
      script += "(tarteaucitron.job = tarteaucitron.job || []).push('twitter');"
    end

    result += ("script", script.html_safe)

    result.html_safe
  end
end

#twitter(options = {}) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tarteaucitron/view_helpers.rb', line 69

def twitter(options = {})

  result = ""

  default_options = {via: "twitter_username", count: "vertical", dnt: "true"}
  options = default_options.merge(options)

  result += (:span, '', class: "tacTwitter").html_safe

  result += (:a,'', href: "https://twitter.com/share", class: "twitter-share-button", data: options).html_safe

  result.html_safe

end