tarteaucitron 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tarteaucitron.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Antoine
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,108 @@
1
+ # Tarteaucitron
2
+
3
+ A gem to install tarteaucitron, GeoIP and provide helpers to show social network buttons.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tarteaucitron'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tarteaucitron
20
+
21
+ ## Usage
22
+
23
+ Run the generator to import tarteaucitron and geodat in your public directory
24
+
25
+ ```shell
26
+ rails g tarteaucitron
27
+ ```
28
+
29
+ ## Helpers
30
+
31
+ ### Google analytics
32
+
33
+ Put this in your application layout or elsewhere
34
+
35
+ ```ruby
36
+ <%= tarteaucitron(:google_analytics => "UA-XXXXXX-XX", :google_plus => true) %>
37
+ ```
38
+
39
+ ### Google +
40
+
41
+ You have to enable Google + on the main helper.
42
+ Example :
43
+
44
+ ```ruby
45
+ <%= tarteaucitron(:googleplus => true) %>
46
+ ```
47
+
48
+ Here's its helper
49
+
50
+ ```ruby
51
+ <%= googleplus %>
52
+ ```
53
+
54
+ You can provide a hash of options. Default options are
55
+
56
+ ```ruby
57
+ <%= {size: "small", annotation: "inline", width: "300"} %>
58
+ ```
59
+
60
+ ### Facebook
61
+
62
+ Example :
63
+
64
+ ```ruby
65
+ <%= tarteaucitron(:facebook => true) %>
66
+ ```
67
+
68
+ Here's its helper
69
+
70
+ ```ruby
71
+ <%= facebook %>
72
+ ```
73
+
74
+ You can provide a hash of options. Default options are
75
+
76
+ ```ruby
77
+ <%= {layout: "standard", action: "like", share: "true"} %>
78
+ ```
79
+
80
+ ### Twitter
81
+
82
+ Example :
83
+
84
+ ```ruby
85
+ <%= tarteaucitron(:twitter => {via: "twitter_username", count: "horizontal", dnt: "true"}) %>
86
+ ```
87
+
88
+ Here's its helper
89
+
90
+ ```ruby
91
+ <%= twitter %>
92
+ ```
93
+
94
+ You can provide a hash of options. Default options are
95
+
96
+ ```ruby
97
+ <%= {via: "twitter_username", count: "vertical", dnt: "true"} %>
98
+ ```
99
+
100
+ [See all options on tarteaucitron](https://opt-out.ferank.eu/fr/install/)
101
+
102
+ ## Contributing
103
+
104
+ 1. Fork it ( https://github.com/[my-github-username]/tarteaucitron/fork )
105
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
106
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
107
+ 4. Push to the branch (`git push origin my-new-feature`)
108
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tarteaucitron"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ Description:
2
+ Download tarteaucitron and GeoIP.dat.
3
+
4
+ Example:
5
+ rails generate tarteaucitron
6
+
7
+ This will create in public/tarteaucitron directory:
8
+ lang/tarteaucitron.ru.js
9
+ lang/tarteaucitron.es.js
10
+ lang/tarteaucitron.pt.js
11
+ lang/tarteaucitron.pl.js
12
+ lang/tarteaucitron.de.js
13
+ lang/tarteaucitron.fr.js
14
+ lang/tarteaucitron.it.js
15
+ lang/tarteaucitron.en.js
16
+ README.md
17
+ css/tarteaucitron.css
18
+ tarteaucitron.js
19
+ tarteaucitron.services.js
20
+ LICENSE
21
+ advertising.js
22
+
23
+ It will create GeoIP.dat in db folder
@@ -0,0 +1,42 @@
1
+ class TarteaucitronGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def download_tarteaucitron
5
+ files = %w(
6
+ lang/tarteaucitron.ru.js
7
+ lang/tarteaucitron.es.js
8
+ lang/tarteaucitron.pt.js
9
+ lang/tarteaucitron.pl.js
10
+ lang/tarteaucitron.de.js
11
+ lang/tarteaucitron.fr.js
12
+ lang/tarteaucitron.it.js
13
+ lang/tarteaucitron.en.js
14
+ README.md
15
+ css/tarteaucitron.css
16
+ tarteaucitron.js
17
+ tarteaucitron.services.js
18
+ LICENSE
19
+ advertising.js
20
+ )
21
+
22
+ url = "https://raw.githubusercontent.com/AmauriC/tarteaucitron.js/master/"
23
+
24
+ files.each do |file|
25
+
26
+ get url + file, "public/tarteaucitron/#{file}"
27
+
28
+ end
29
+
30
+ end
31
+
32
+ def download_geocat
33
+
34
+ url = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz"
35
+
36
+ get url, "db/GeoIP.dat.gz"
37
+
38
+ run "gunzip db/GeoIP.dat.gz"
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,2 @@
1
+ #require "tarteaucitron/version"
2
+ require 'tarteaucitron/railtie' if defined?(Rails)
@@ -0,0 +1,8 @@
1
+ require 'tarteaucitron/view_helpers'
2
+ module Tarteaucitron
3
+ class Railtie < Rails::Railtie
4
+ initializer "tarteaucitron.view_helpers" do
5
+ ActionView::Base.send :include, ViewHelpers
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Tarteaucitron
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,77 @@
1
+ module Tarteaucitron
2
+ module ViewHelpers
3
+ def tarteaucitron(options = {})
4
+ options = options.with_indifferent_access
5
+ result = ""
6
+ ip = request.remote_ip
7
+ if ["EU", "--"].include?(GeoIP.new(Rails.root.join('db', 'GeoIP.dat')).country(ip).continent_code)
8
+ result += content_tag("script", '', src: "/tarteaucitron/tarteaucitron.js", type: "text/javascript")
9
+ default = {
10
+ "hashtag"=> "#tarteaucitron",
11
+ "highPrivacy"=> false,
12
+ "orientation"=> "top",
13
+ "adblocker"=> false,
14
+ "showAlertSmall"=> true,
15
+ "cookieslist"=> true,
16
+ "removeCredit"=> false,
17
+ }
18
+ script = "tarteaucitron.init(#{default.to_json});"
19
+ if options.has_key?("google_analytics")
20
+ script += "tarteaucitron.user.gajsUa = '#{options["google_analytics"]}';"
21
+ script += "tarteaucitron.user.gajsMore = function () {};"
22
+ script += "(tarteaucitron.job = tarteaucitron.job || []).push('gajs');"
23
+ end
24
+
25
+ if options.has_key?("facebook")
26
+ script += "(tarteaucitron.job = tarteaucitron.job || []).push('facebook');"
27
+ end
28
+
29
+ if options.has_key?("googleplus")
30
+ script += "(tarteaucitron.job = tarteaucitron.job || []).push('gplus');"
31
+ end
32
+
33
+ if options.has_key?("twitter")
34
+ script += "(tarteaucitron.job = tarteaucitron.job || []).push('twitter');"
35
+ end
36
+
37
+ result += content_tag("script", script.html_safe)
38
+
39
+ result.html_safe
40
+ end
41
+ end
42
+
43
+ def facebook(options = {})
44
+
45
+ default_options = {layout: "standard", action: "like", share: "true"}
46
+ options = default_options.merge(options)
47
+
48
+ content_tag(:div, '', class: "fb-like", data: options).html_safe
49
+
50
+ end
51
+
52
+ def googleplus(options = {})
53
+
54
+ default_options = {size: "small", annotation: "inline", width: "300"}
55
+ options = default_options.merge(options)
56
+
57
+ content_tag(:div, '', class: "g-plusone", data: options).html_safe
58
+
59
+ end
60
+
61
+ def twitter(options = {})
62
+
63
+ result = ""
64
+
65
+ default_options = {via: "twitter_username", count: "vertical", dnt: "true"}
66
+ options = default_options.merge(options)
67
+
68
+ result += content_tag(:span, '', class: "tacTwitter").html_safe
69
+
70
+ result += content_tag(:a,'', href: "https://twitter.com/share", class: "twitter-share-button", data: options).html_safe
71
+
72
+ result.html_safe
73
+
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tarteaucitron/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tarteaucitron"
8
+ spec.version = Tarteaucitron::VERSION
9
+ spec.authors = ["Ouvrages"]
10
+ spec.email = ["contact@ouvrages-web.fr"]
11
+
12
+ spec.summary = %q{A gem to install tarteaucitron, GeoIP and provide helpers to show social network buttons.}
13
+ spec.description = %q{A gem to install tarteaucitron, GeoIP and provide helpers to show social network buttons. }
14
+ spec.homepage = "https://github.com/ouvrages/tarteaucitron"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
24
+ end
25
+
26
+ spec.add_dependency "geoip"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.9"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tarteaucitron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ouvrages
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-04-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: geoip
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.9'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.9'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ description: ! 'A gem to install tarteaucitron, GeoIP and provide helpers to show
63
+ social network buttons. '
64
+ email:
65
+ - contact@ouvrages-web.fr
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - CODE_OF_CONDUCT.md
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - bin/console
77
+ - bin/setup
78
+ - lib/generators/tarteaucitron/USAGE
79
+ - lib/generators/tarteaucitron/tarteaucitron_generator.rb
80
+ - lib/tarteaucitron.rb
81
+ - lib/tarteaucitron/railtie.rb
82
+ - lib/tarteaucitron/version.rb
83
+ - lib/tarteaucitron/view_helpers.rb
84
+ - tarteaucitron.gemspec
85
+ homepage: https://github.com/ouvrages/tarteaucitron
86
+ licenses:
87
+ - MIT
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.23.2
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: A gem to install tarteaucitron, GeoIP and provide helpers to show social
110
+ network buttons.
111
+ test_files: []