cookie_law 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +102 -0
- data/Rakefile +1 -0
- data/app/views/cookie_law/_banner.en.html.erb +6 -0
- data/app/views/cookie_law/_banner.it.html.erb +4 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/cookie_law.gemspec +32 -0
- data/lib/cookie_law/configuration.rb +3 -0
- data/lib/cookie_law/engine.rb +4 -0
- data/lib/cookie_law/helper.rb +16 -0
- data/lib/cookie_law/missing_policy_link_exception.rb +2 -0
- data/lib/cookie_law/version.rb +3 -0
- data/lib/cookie_law.rb +48 -0
- data/lib/generators/cookie_law/install_generator.rb +15 -0
- data/lib/generators/cookie_law/templates/_banner.html.erb +6 -0
- data/lib/generators/cookie_law/templates/cookie_law.rb +30 -0
- data/lib/generators/cookie_law/views_generator.rb +19 -0
- data/vendor/assets/javascripts/cookie_law.coffee.erb +53 -0
- data/vendor/assets/javascripts/js.cookie.js +137 -0
- data/vendor/assets/stylesheets/cookie_law.scss +34 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 252c2a5d09529593a2b8a556eb920ea54620702c
|
4
|
+
data.tar.gz: 2fa0aa156e9454a2eb5c575e5c56adc38e6614d5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 88cb7da31b8135331a214d2f6bfb8197e8645dada8a5d7e39fcf2c5a584ac58c016df5b1db10287d01b01f2ff2710752ad16a853e522bc6a5163e44a68a7dc74
|
7
|
+
data.tar.gz: c420ff4307155340aac608a7d6d3929051f2d83169f0217c639d1639af5d402223f4b58246cc7d3efbafbce54f3e95f31587cc68e085fd40a18b17a7b194fd87
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Enrico Carlesso
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# CookieLaw
|
2
|
+
|
3
|
+
CookieLaw aims to help Ruby on Rails developer to deal with European Cookie Policy.
|
4
|
+
|
5
|
+
From June 2015 it is required for every website targeting European users to display a banner and obtain user consent before installing non technical cookies in user's browser.
|
6
|
+
|
7
|
+
To keep it simple, if you use Google Analytics or every other tracking/profiling service which relies on cookies, you must have this banner.
|
8
|
+
|
9
|
+
## Getting Started
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'cookie_law'
|
15
|
+
```
|
16
|
+
|
17
|
+
Run the bundle command to install it.
|
18
|
+
|
19
|
+
After you have installed the gem, you need to run the generator:
|
20
|
+
|
21
|
+
```sh
|
22
|
+
rails generate cookie_law:install
|
23
|
+
```
|
24
|
+
|
25
|
+
The generator will create the initializer file in your rails project,
|
26
|
+
with all configuration options explained. You should take a look at it
|
27
|
+
and you **MUST** provide your *policy link* or `cookie_law` will raise
|
28
|
+
`MissingPolicyLinkException` when you start your server.
|
29
|
+
|
30
|
+
You will need to add two requires in you `application.js` and `application.css` files:
|
31
|
+
|
32
|
+
```javascript
|
33
|
+
// app/assets/javascripts/application.js
|
34
|
+
// ...
|
35
|
+
//= require js.cookie
|
36
|
+
//= require cookie_law
|
37
|
+
```
|
38
|
+
|
39
|
+
and
|
40
|
+
|
41
|
+
```css
|
42
|
+
/* app/assets/javacsripts/application.css
|
43
|
+
* ...
|
44
|
+
*= require cookie_law
|
45
|
+
*/
|
46
|
+
```
|
47
|
+
|
48
|
+
After having configured your initializer and js/css files you can insert the `cookie_law!`
|
49
|
+
helper call in your layout (inside the html body)
|
50
|
+
|
51
|
+
```html
|
52
|
+
<%= cookie_law! %>
|
53
|
+
```
|
54
|
+
|
55
|
+
This will render the default `_banner.<locale>.html.erb` present in this gem.
|
56
|
+
|
57
|
+
When accepting policy with click, `cookie_law` will intercepts every click in the page. If you need to
|
58
|
+
add some exception to this behavior (for example when linking you Privacy Policy) you can add the
|
59
|
+
`.no_cl_accept` class to such links.
|
60
|
+
|
61
|
+
## Javascript events
|
62
|
+
|
63
|
+
`cookie_law` comes with a Javascript library. You should not run any cookie-based profiling tool
|
64
|
+
if the policy is not accepted. To deal with this, `cookie_law` will trigger events in your `document`
|
65
|
+
to allow you to run code in different conditions. Let's see it with an example:
|
66
|
+
|
67
|
+
```javascript
|
68
|
+
$(document).on('cl:ready', function() {
|
69
|
+
// This function will be called only when the users accepts the cookie policy
|
70
|
+
// with one of the allowed method.
|
71
|
+
// Will also be called after every document.ready function if the policy has been accepted.
|
72
|
+
// This is the right place to trigger Google Analytics track page, for example
|
73
|
+
});
|
74
|
+
|
75
|
+
$(document).on('cl:page_change', function() {
|
76
|
+
// If your application uses Turbolinks, this event will be triggered after every
|
77
|
+
// 'page:change' Turbolinks event
|
78
|
+
});
|
79
|
+
```
|
80
|
+
|
81
|
+
## Configuring views
|
82
|
+
|
83
|
+
You can customize the appearance of the banner copying and change the views.
|
84
|
+
Simply run
|
85
|
+
|
86
|
+
```sh
|
87
|
+
rails generate cookie_law:views
|
88
|
+
```
|
89
|
+
|
90
|
+
and you will have the default view copied in your project. You can find the view in `app/views/cookie_laws/_banner.html.erb`.
|
91
|
+
|
92
|
+
## Thanks
|
93
|
+
|
94
|
+
This project uses the awesome [js-cookie](https://github.com/js-cookie/js-cookie).
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
1. Fork it ( https://github.com/[my-github-username]/cookie_law/fork )
|
99
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
100
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
101
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
102
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<% unless policy_accepted? %>
|
2
|
+
<div id="cl_banner">
|
3
|
+
This site uses cookies, even from third part, to send you ads and services that suits your preferences. If you want to know more <%= link_to 'click here', CookieLaw.policy_link, target: '_blank', class: :no_cl_accept %>. Closing this banner, scrolling this page or clicking any link in this page, you agree with cookies usage.
|
4
|
+
<%= link_to 'Close', '#', id: 'cl_close' %>
|
5
|
+
</div>
|
6
|
+
<% end %>
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<div id="cl_banner">
|
2
|
+
Questo sito utilizza cookie, anche di terze parti, per inviarti pubblicità e servizi in linea con le tue preferenze. Se vuoi saperne di più <%= link_to 'clicca qui', CookieLaw.policy_link, target: '_blank', class: :no_cl_accept %>. Chiudendo questo banner, scorrendo questa pagina o cliccando qualunque suo elemento acconsenti all'uso dei cookie.
|
3
|
+
<%= link_to 'Chiudi', '#', id: 'cl_close' %>
|
4
|
+
</div>
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cookie_law"
|
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
|
data/bin/setup
ADDED
data/cookie_law.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cookie_law/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cookie_law"
|
8
|
+
spec.version = CookieLaw::VERSION
|
9
|
+
spec.authors = ["Enrico Carlesso"]
|
10
|
+
spec.email = ["enricocarlesso@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Cookie Law Gem}
|
13
|
+
spec.description = %q{A rails gem to help you to deal with European Cookie Law}
|
14
|
+
spec.homepage = "https://github.com/coders51/cookie_law"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module CookieLaw::Helper
|
2
|
+
# Iniects privacy policy banner and initializes javascript
|
3
|
+
def cookie_law!
|
4
|
+
render 'cookie_law/banner'
|
5
|
+
end
|
6
|
+
|
7
|
+
def policy_accepted?
|
8
|
+
return false unless cookies[CookieLaw.cookie_name].is_a?(String)
|
9
|
+
begin
|
10
|
+
JSON.parse(cookies[CookieLaw.cookie_name])['accepted']
|
11
|
+
rescue JSON::ParserError
|
12
|
+
cookies.delete[CookieLaw.cookie_name]
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/cookie_law.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'cookie_law/version'
|
2
|
+
require 'cookie_law/helper'
|
3
|
+
require 'cookie_law/engine'
|
4
|
+
require 'cookie_law/configuration'
|
5
|
+
require 'cookie_law/missing_policy_link_exception'
|
6
|
+
|
7
|
+
module CookieLaw
|
8
|
+
COOKIE_NAME = 'cl_accepted'
|
9
|
+
DEFAULT_EXPIRATION = 365 # In Days
|
10
|
+
ACCEPT_ON_SCROLL = true
|
11
|
+
ACCEPT_ON_ANY_LINK = true
|
12
|
+
DEFAULT_SCROLL_HEIGHT = 180
|
13
|
+
|
14
|
+
def self.configuration
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.cookie_name
|
23
|
+
configuration.cookie_name || COOKIE_NAME
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.policy_link
|
27
|
+
if configuration.policy_link.nil?
|
28
|
+
raise MissingPolicyLinkException
|
29
|
+
end
|
30
|
+
configuration.policy_link
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.scroll_height
|
34
|
+
configuration.scroll_height || DEFAULT_SCROLL_HEIGHT
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.accept_on_any_link
|
38
|
+
configuration.accept_on_any_link || ACCEPT_ON_ANY_LINK
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.accept_on_scroll
|
42
|
+
configuration.accept_on_scroll || ACCEPT_ON_SCROLL
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
ActiveSupport.on_load(:action_view) do
|
47
|
+
include CookieLaw::Helper
|
48
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module CookieLaw
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
desc 'Creates CookieLaw initializer with default configuration'
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_initializer
|
12
|
+
template 'cookie_law.rb', 'config/initializers/cookie_law.rb'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<% unless policy_accepted? %>
|
2
|
+
<div id="cl_banner">
|
3
|
+
This site uses cookies, even from third part, to send you ads and services that suits your preferences. If you want to know more <%= link_to 'click here', CookieLaw.policy_link, target: '_blank', class: :no_cl_accept %>. Closing this banner, scrolling this page or clicking any link in this page, you agree with cookies usage.
|
4
|
+
<%= link_to 'Close', '#', id: 'cl_close' %>
|
5
|
+
</div>
|
6
|
+
<% end %>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# You can customize CookieLaw configuration with this initializer
|
2
|
+
CookieLaw.configure do |config|
|
3
|
+
# This is the cookie name as it will be stored in the user browser
|
4
|
+
# You should add this to your cookie policy
|
5
|
+
#
|
6
|
+
# config.cookie_name = 'cl_accepted'
|
7
|
+
|
8
|
+
# This defines for how long the cookie will last in user browser
|
9
|
+
# in days. Default value is 365 days
|
10
|
+
#
|
11
|
+
# config.expiration = 365
|
12
|
+
|
13
|
+
# You need to add the link to your privacy policy. There is no
|
14
|
+
# default value and you MUST add your url. This will raise
|
15
|
+
# a MissingPolicyLinkException if not present
|
16
|
+
#
|
17
|
+
# config.policy_link = 'https://www.example.com/cookie_policy.html'
|
18
|
+
|
19
|
+
# You can configure the behavior of policy acceptance.
|
20
|
+
# Accepted methods, besides clicking on Close link on banner,
|
21
|
+
# are via click on links or scroll.
|
22
|
+
# config.accept_on_any_link = true
|
23
|
+
# config.accept_on_scroll = true
|
24
|
+
#
|
25
|
+
# You can also define the minimum scroll span the user has to scroll
|
26
|
+
# for accept via scrolling. Default value is 180
|
27
|
+
#
|
28
|
+
# config.scroll_height = 180
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module CookieLaw
|
4
|
+
class ViewsGenerator < Rails::Generators::Base
|
5
|
+
desc 'Copies CookieLaw views in your project'
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_views
|
12
|
+
view_path = Rails.root.join('app', 'views', 'cookie_law')
|
13
|
+
# unless Dir.exists? view_path
|
14
|
+
# Dir.mkdir view_path
|
15
|
+
# end
|
16
|
+
copy_file '_banner.html.erb', view_path.join('_banner.html.erb')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class @CookieLaw
|
2
|
+
cookieName: '<%= CookieLaw.cookie_name %>'
|
3
|
+
acceptOnScroll: <%= CookieLaw.accept_on_scroll %>
|
4
|
+
acceptOnAnyLink: <%= CookieLaw.accept_on_any_link %>
|
5
|
+
scrollHeight: <%= CookieLaw.scroll_height %>
|
6
|
+
currentCookie: null
|
7
|
+
|
8
|
+
constructor: ->
|
9
|
+
($ document).ready =>
|
10
|
+
if @policyAccepted()
|
11
|
+
@hidePolicy()
|
12
|
+
($ document).trigger 'cl:ready'
|
13
|
+
if typeof Turbolinks isnt 'undefined' and Turbolinks.supported
|
14
|
+
($ document).on 'page:change', ->
|
15
|
+
($ document).trigger 'cl:page_change'
|
16
|
+
else
|
17
|
+
@bindAcceptors()
|
18
|
+
|
19
|
+
bindAcceptors: ->
|
20
|
+
($ document).on 'click', '#cl_close', (e) =>
|
21
|
+
e.preventDefault()
|
22
|
+
@acceptPolicy()
|
23
|
+
|
24
|
+
if @acceptOnScroll
|
25
|
+
($ window).on 'scroll', =>
|
26
|
+
if ($ window).scrollTop() > @scrollHeight
|
27
|
+
@acceptPolicy()
|
28
|
+
if @acceptOnAnyLink
|
29
|
+
($ document).on 'click', "a:not('.no_cl_accept, #cl_close')", @acceptPolicy
|
30
|
+
|
31
|
+
unbindAcceptors: ->
|
32
|
+
if @acceptOnScroll
|
33
|
+
($ window).off 'scroll', @acceptPolicy
|
34
|
+
if @acceptOnAnyLink
|
35
|
+
($ document).off 'click', "a:not('.no_cl_accept, #cl_close')", @acceptPolicy
|
36
|
+
|
37
|
+
policyAccepted: ->
|
38
|
+
@currentCookie = Cookies.getJSON @cookieName
|
39
|
+
@currentCookie? and @currentCookie.accepted is true
|
40
|
+
|
41
|
+
acceptPolicy: (e) =>
|
42
|
+
@unbindAcceptors()
|
43
|
+
|
44
|
+
Cookies.set @cookieName,
|
45
|
+
accepted: true
|
46
|
+
at: new Date()
|
47
|
+
($ document).trigger 'cl:ready'
|
48
|
+
@hidePolicy()
|
49
|
+
|
50
|
+
hidePolicy: ->
|
51
|
+
($ '#cl_banner').hide()
|
52
|
+
|
53
|
+
@_cl_instance = new @CookieLaw()
|
@@ -0,0 +1,137 @@
|
|
1
|
+
/*!
|
2
|
+
* JavaScript Cookie v2.0.0-pre
|
3
|
+
* https://github.com/js-cookie/js-cookie
|
4
|
+
*
|
5
|
+
* Copyright 2006, 2015 Klaus Hartl
|
6
|
+
* Released under the MIT license
|
7
|
+
*/
|
8
|
+
(function (factory) {
|
9
|
+
if (typeof define === 'function' && define.amd) {
|
10
|
+
define(factory);
|
11
|
+
} else if (typeof exports === 'object') {
|
12
|
+
module.exports = factory();
|
13
|
+
} else {
|
14
|
+
var _OldCookies = window.Cookies;
|
15
|
+
var api = window.Cookies = factory(window.jQuery);
|
16
|
+
api.noConflict = function () {
|
17
|
+
window.Cookies = _OldCookies;
|
18
|
+
return api;
|
19
|
+
};
|
20
|
+
}
|
21
|
+
}(function () {
|
22
|
+
function extend () {
|
23
|
+
var i = 0;
|
24
|
+
var result = {};
|
25
|
+
for (; i < arguments.length; i++) {
|
26
|
+
var attributes = arguments[ i ];
|
27
|
+
for (var key in attributes) {
|
28
|
+
result[key] = attributes[key];
|
29
|
+
}
|
30
|
+
}
|
31
|
+
return result;
|
32
|
+
}
|
33
|
+
|
34
|
+
function init (converter) {
|
35
|
+
function api (key, value, attributes) {
|
36
|
+
var result;
|
37
|
+
|
38
|
+
// Write
|
39
|
+
|
40
|
+
if (arguments.length > 1) {
|
41
|
+
attributes = extend({
|
42
|
+
path: '/'
|
43
|
+
}, api.defaults, attributes);
|
44
|
+
|
45
|
+
if (typeof attributes.expires === 'number') {
|
46
|
+
var expires = new Date();
|
47
|
+
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
|
48
|
+
attributes.expires = expires;
|
49
|
+
}
|
50
|
+
|
51
|
+
try {
|
52
|
+
result = JSON.stringify(value);
|
53
|
+
if (/^[\{\[]/.test(result)) {
|
54
|
+
value = result;
|
55
|
+
}
|
56
|
+
} catch (e) {}
|
57
|
+
|
58
|
+
value = encodeURIComponent(String(value));
|
59
|
+
value = value.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
|
60
|
+
|
61
|
+
key = encodeURIComponent(String(key));
|
62
|
+
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
|
63
|
+
key = key.replace(/[\(\)]/g, escape);
|
64
|
+
|
65
|
+
return (document.cookie = [
|
66
|
+
key, '=', value,
|
67
|
+
attributes.expires && '; expires=' + attributes.expires.toUTCString(), // use expires attribute, max-age is not supported by IE
|
68
|
+
attributes.path && '; path=' + attributes.path,
|
69
|
+
attributes.domain && '; domain=' + attributes.domain,
|
70
|
+
attributes.secure && '; secure'
|
71
|
+
].join(''));
|
72
|
+
}
|
73
|
+
|
74
|
+
// Read
|
75
|
+
|
76
|
+
if (!key) {
|
77
|
+
result = {};
|
78
|
+
}
|
79
|
+
|
80
|
+
// To prevent the for loop in the first place assign an empty array
|
81
|
+
// in case there are no cookies at all. Also prevents odd result when
|
82
|
+
// calling "get()"
|
83
|
+
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
84
|
+
var rdecode = /(%[0-9A-Z]{2})+/g;
|
85
|
+
var i = 0;
|
86
|
+
|
87
|
+
for (; i < cookies.length; i++) {
|
88
|
+
var parts = cookies[i].split('=');
|
89
|
+
var name = parts[0].replace(rdecode, decodeURIComponent);
|
90
|
+
var cookie = parts.slice(1).join('=');
|
91
|
+
|
92
|
+
if (cookie.charAt(0) === '"') {
|
93
|
+
cookie = cookie.slice(1, -1);
|
94
|
+
}
|
95
|
+
|
96
|
+
cookie = converter && converter(cookie, name) || cookie.replace(rdecode, decodeURIComponent);
|
97
|
+
|
98
|
+
if (this.json) {
|
99
|
+
try {
|
100
|
+
cookie = JSON.parse(cookie);
|
101
|
+
} catch (e) {}
|
102
|
+
}
|
103
|
+
|
104
|
+
if (key === name) {
|
105
|
+
result = cookie;
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
|
109
|
+
if (!key) {
|
110
|
+
result[name] = cookie;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
return result;
|
115
|
+
}
|
116
|
+
|
117
|
+
api.get = api.set = api;
|
118
|
+
api.getJSON = function () {
|
119
|
+
return api.apply({
|
120
|
+
json: true
|
121
|
+
}, [].slice.call(arguments));
|
122
|
+
};
|
123
|
+
api.defaults = {};
|
124
|
+
|
125
|
+
api.remove = function (key, attributes) {
|
126
|
+
api(key, '', extend(attributes, {
|
127
|
+
expires: -1
|
128
|
+
}));
|
129
|
+
};
|
130
|
+
|
131
|
+
api.withConverter = init;
|
132
|
+
|
133
|
+
return api;
|
134
|
+
}
|
135
|
+
|
136
|
+
return init();
|
137
|
+
}));
|
@@ -0,0 +1,34 @@
|
|
1
|
+
$banner_bg: #000;
|
2
|
+
$banner_text: #fff;
|
3
|
+
$banner_close_button_bg: #fff;
|
4
|
+
$banner_close_button_text: #000;
|
5
|
+
$banner_close_button_border: #f00;
|
6
|
+
|
7
|
+
#cl_banner {
|
8
|
+
position: absolute;
|
9
|
+
top: 0;
|
10
|
+
background-color: $banner_bg;
|
11
|
+
color: $banner_text;
|
12
|
+
width: 100%;
|
13
|
+
padding: 20px;
|
14
|
+
|
15
|
+
a {
|
16
|
+
color: $banner_text;
|
17
|
+
}
|
18
|
+
|
19
|
+
|
20
|
+
#cl_close {
|
21
|
+
float: right;
|
22
|
+
width: 100px;
|
23
|
+
margin-right: 40px;
|
24
|
+
|
25
|
+
padding: 2px 60px;
|
26
|
+
background-color: $banner_close_button_bg;
|
27
|
+
color: $banner_close_button_text;
|
28
|
+
border: 4px solid $banner_close_button_border;
|
29
|
+
text-decoration: none;
|
30
|
+
|
31
|
+
font-size: 28px;
|
32
|
+
line-height: 1.33333;
|
33
|
+
}
|
34
|
+
}
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cookie_law
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Enrico Carlesso
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: A rails gem to help you to deal with European Cookie Law
|
42
|
+
email:
|
43
|
+
- enricocarlesso@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- app/views/cookie_law/_banner.en.html.erb
|
57
|
+
- app/views/cookie_law/_banner.it.html.erb
|
58
|
+
- bin/console
|
59
|
+
- bin/setup
|
60
|
+
- cookie_law.gemspec
|
61
|
+
- lib/cookie_law.rb
|
62
|
+
- lib/cookie_law/configuration.rb
|
63
|
+
- lib/cookie_law/engine.rb
|
64
|
+
- lib/cookie_law/helper.rb
|
65
|
+
- lib/cookie_law/missing_policy_link_exception.rb
|
66
|
+
- lib/cookie_law/version.rb
|
67
|
+
- lib/generators/cookie_law/install_generator.rb
|
68
|
+
- lib/generators/cookie_law/templates/_banner.html.erb
|
69
|
+
- lib/generators/cookie_law/templates/cookie_law.rb
|
70
|
+
- lib/generators/cookie_law/views_generator.rb
|
71
|
+
- vendor/assets/javascripts/cookie_law.coffee.erb
|
72
|
+
- vendor/assets/javascripts/js.cookie.js
|
73
|
+
- vendor/assets/stylesheets/cookie_law.scss
|
74
|
+
homepage: https://github.com/coders51/cookie_law
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata:
|
78
|
+
allowed_push_host: https://rubygems.org
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.5
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Cookie Law Gem
|
99
|
+
test_files: []
|
100
|
+
has_rdoc:
|