Module: Tarteaucitron::ViewHelpers

Defined in:
lib/tarteaucitron/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#facebook(options = {}) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/tarteaucitron/view_helpers.rb', line 43

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



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

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
# 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,
              }
    script = "tarteaucitron.init(#{default.to_json});"
    if options.has_key?("google_analytics")
      script += "tarteaucitron.user.gajsUa = '#{options["google_analytics"]}';"
      script += "tarteaucitron.user.gajsMore = function () {};"
      script += "(tarteaucitron.job = tarteaucitron.job || []).push('gajs');"
    end

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

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

    result.html_safe
  end
end

#twitter(options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/tarteaucitron/view_helpers.rb', line 61

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