cookie_alert 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +131 -0
  4. data/Rakefile +29 -0
  5. data/app/assets/javascripts/cookie_alert.js +12 -0
  6. data/app/assets/stylesheets/cookie_alert.css +49 -0
  7. data/app/controllers/cookie_alert/application_controller.rb +4 -0
  8. data/app/controllers/cookie_alert/cookies_controller.rb +42 -0
  9. data/app/helpers/cookie_alert/application_helper.rb +4 -0
  10. data/app/helpers/cookie_alert/cookie_alert_helper.rb +4 -0
  11. data/app/views/cookie_alert/cookies/_no_response.html +0 -0
  12. data/app/views/cookie_alert/cookies/_primary_alert.html.erb +13 -0
  13. data/app/views/cookie_alert/cookies/_secondary_alert.html.erb +14 -0
  14. data/app/views/cookie_alert/cookies/cookie_accepted.js.erb +1 -0
  15. data/app/views/layouts/cookie_alert/application.html.erb +14 -0
  16. data/config/routes.rb +7 -0
  17. data/lib/cookie_alert/engine.rb +5 -0
  18. data/lib/cookie_alert/version.rb +3 -0
  19. data/lib/cookie_alert.rb +182 -0
  20. data/lib/generators/cookie_alert/install_generator.rb +42 -0
  21. data/lib/generators/cookie_alert/templates/_primary_alert.html.erb +13 -0
  22. data/lib/generators/cookie_alert/templates/_secondary_alert.html.erb +12 -0
  23. data/lib/generators/cookie_alert/templates/cookie_accepted.js.erb +1 -0
  24. data/lib/generators/cookie_alert/templates/cookie_alert.css +49 -0
  25. data/lib/generators/cookie_alert/templates/cookie_alert.js +12 -0
  26. data/lib/generators/cookie_alert/templates/cookie_alert.rb +155 -0
  27. data/lib/generators/cookie_alert/uninstall_generator.rb +40 -0
  28. data/lib/tasks/cookie_alert_tasks.rake +4 -0
  29. metadata +156 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26b7e0e151fa04f5c9f12a93f55b6db5e5d70d55
4
+ data.tar.gz: 67d5ba720210c7fb2acc5e0b776d4476078c3258
5
+ SHA512:
6
+ metadata.gz: 16ab513f44550d71195b7c11e125919f54859a9ac39adefd2bd737455836c1c4deb58aec0ef04aedb5351bb967e18ed3e92b7dff43476341d6fe66a60633206b
7
+ data.tar.gz: ef3cefdd51c9e5709736e949c0d5fceace4f1303ce809518dc5feeb77efc139f7b2fef9ae31baa76a819faf57e3b15774c283e6975de484fedc0ea0524c07dad
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 KatanaCode Ltd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # CookieAlert (beta)
2
+
3
+ CookieAlert will add an alert to your webpage informing your visitor that your website uses Cookies. It can be configured to display the Alert for a fixed
4
+ number of views, or display it constantly until the visitor 'accepts' the alert. It:
5
+
6
+ * Will work 'straight out the box' without any additional configuration
7
+ * Is fully customisable, including views, javascript response and number of displays.
8
+ * Aims to be a simple way to address the [EU Cookie Law](http://www.ico.org.uk/for_organisations/privacy_and_electronic_communications/the_guide/cookies) requiring websites to notify their visitors that they use Cookies.
9
+
10
+ ## Install
11
+
12
+ 1. Update `Gemfile` to add
13
+
14
+ ```Ruby
15
+ gem "cookie_alert"
16
+ ```
17
+
18
+
19
+ 2. Run bundle
20
+
21
+ ```bash
22
+ bundle install
23
+ ```
24
+
25
+ 3. Install the configuration & view files
26
+
27
+ ```bash
28
+ rails g cookie_alert:install
29
+ ```
30
+ 4. Update your `app/helpers/application_helper.rb` file to include the CookieAlert module:
31
+
32
+ ```Ruby
33
+ include CookieAlert
34
+ ```
35
+
36
+ 5. Update your `config/routes.rb` file to add the CookieAlert route:
37
+
38
+ ```Ruby
39
+ mount CookieAlert::Engine => "/cookie-alert"
40
+ ```
41
+
42
+ 6. Update your Asset Manifest files to add the JavaScript and CSS files:
43
+
44
+ * in application.js add
45
+
46
+ ```Ruby
47
+ //= require cookie_alert
48
+ ```
49
+
50
+ * in application.css add
51
+
52
+ ```Ruby
53
+ *= require cookie_alert
54
+ ```
55
+
56
+ ## Uninstall
57
+
58
+ To remove the installed files run `rails g cookie_alert:uninstall`
59
+
60
+ ## Displaying Alerts
61
+
62
+
63
+ To display the Cookie Alerts, simply call the following method from your layout `<%= display_cookie_alert %>`
64
+
65
+ ## How It Works
66
+
67
+ When a visitor first comes to your site CookieAlert will set an encrypted Cookie that keeps track of how many pages the visitor has viewed and display a
68
+ Primary Alert notifying the visitor that your site uses Cookies. By default this Primary Alert is a large banner fixed at the foot of the screen.
69
+
70
+ After the Primary Alert has been displayed a number of times (5 by default) it is replaced by a Secondary Alert. By default this is a smaller box fixed to
71
+ the bottom-left of the screen which transforms back to the the large banner when moused-over.
72
+
73
+ The visitor can click a link to 'hide the banner', thereby accepting the notice, and the Alerts will no longer be displayed for the remainder of the session.
74
+
75
+
76
+ ## Configuration
77
+
78
+ CookieAlert can be configured to:
79
+
80
+ * Display a Primary Alert message until the visitor clicks the 'accept' link.
81
+ * Display a Primary Alert message which, after a number of views, changes to a Secondary Alert message until the visitor clicks the 'accept' link.
82
+ * Display a Primary Alert message then, after a number of views, stop showing any alert messages at all.
83
+
84
+ Please [check the WIKI](https://github.com/KatanaCode/cookie_alert/wiki) for a full list of the configuration options available.
85
+
86
+ ## JavaScript
87
+
88
+ The default Alerts use JQuery to allow a server-side response and to add effects. You can easily change this to use a different JavaScript framework
89
+ (or none at all!). [Check the WIKI](https://github.com/KatanaCode/cookie_alert/wiki) to see how.
90
+
91
+ ## IMPORTANT
92
+
93
+ If you are using CookieAlert to address the [EU Cookie Law](http://www.ico.org.uk/for_organisations/privacy_and_electronic_communications/the_guide/cookies),
94
+ then within the Alert message you should also include a link to a Cookie Policy page where your visitors can view a description of the cookies used by
95
+ your site. See [KatanaCode.com](http://katanacode.com) for an example.
96
+
97
+ Note that CookieAlert is designed to allow you to display alerts - **the content and wording of the alert is entirely your own responsibility**.
98
+ KatanaCode do not warrant in any way that the default message, operation or usage of this Gem will make you compliant with the EU Cookie Law.
99
+ It is up to you to ensure compliance!
100
+
101
+ All we can say is that we use it ourselves.
102
+
103
+ ## Issues
104
+
105
+ If you discover a problem with CookieAlert, please let us know about it.
106
+
107
+ **Remember** to search the [issues list](https://github.com/KatanaCode/cookie_alert/issues) first in case your issue has already been raised
108
+ by another Githuber
109
+
110
+ ## Documentation
111
+
112
+ Full documentation is available here: http://rubydoc.info/gems/cookie_alert
113
+
114
+ ## Contributing
115
+
116
+ You're welcome to contribute to CookieAlert. Please consult the [contribution guidelines](https://github.com/KatanaCode/cookie_alert/wiki/Contributing)
117
+ for more info.
118
+
119
+ ## Legal Stuff
120
+
121
+ Copyright 2013 [Katana Code Ltd.](http://katanacode.com)
122
+
123
+ See MIT-LICENSE for full details.
124
+
125
+ ## Credits
126
+
127
+ Developed by [CodeMeister](http://github.com/CodeMeister) at [Katana Code Ltd](http://katanacode.com)
128
+
129
+ ## About Katana Code
130
+
131
+ Katana Code are [iPhone app and Ruby on Rails Developers in Edinburgh, Scotland](http://katanacode.com/ "Katana Code").
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'CookieAlert'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
@@ -0,0 +1,12 @@
1
+ $(function(){
2
+
3
+ $("#cookie_alert.secondary-alert").on( 'mouseenter', function(e){
4
+ $("#cookie_alert_text").show();
5
+
6
+ });
7
+
8
+ $("#cookie_alert.secondary-alert").on( 'mouseleave', function(e){
9
+ $("#cookie_alert_text").hide();
10
+
11
+ });
12
+ });
@@ -0,0 +1,49 @@
1
+ #cookie_alert {
2
+ position: fixed;
3
+ bottom: 0;
4
+ left: 0;
5
+ color: navy;
6
+ background-color: #f4efb4;
7
+ border: 2px solid #444444;
8
+ }
9
+
10
+ #cookie_alert_message {
11
+ margin: 0;
12
+ padding: 5px;
13
+ }
14
+
15
+ #cookie_alert_title {
16
+ float: left;
17
+ width: 75px;
18
+ font-weight: bold;
19
+ font-size: 18px;
20
+ line-height: 18px;
21
+ vertical-align: top;
22
+ padding-bottom: 3px;
23
+ text-shadow: 1px 1px 0 white;
24
+
25
+
26
+ }
27
+
28
+ #cookie_alert_text {
29
+ margin-left: 80px;
30
+ line-height: 1.25em;
31
+ }
32
+
33
+ #cookie_alert a {
34
+ background-color: gold;
35
+ color: navy;
36
+ font-weight: normal;
37
+ text-decoration: none;
38
+ border: 1px solid navy;
39
+ padding: 0 1em;
40
+ margin: 0 5px;
41
+
42
+ }
43
+
44
+ #cookie_alert a:hover {
45
+ text-decoration: none;
46
+ background-color: navy;
47
+ color: gold;
48
+ border: 1px solid black;
49
+ }
@@ -0,0 +1,4 @@
1
+ module CookieAlert
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,42 @@
1
+ require_dependency "cookie_alert/application_controller"
2
+
3
+ module CookieAlert
4
+ class CookiesController < ApplicationController
5
+
6
+ # Implement cookie acceptance when a visitor click the 'accept' button
7
+ def cookie_accepted
8
+
9
+ # Get the visitor's current page URL or, if nil?, default to the application root
10
+ visitor_current_url = cookies.signed[CookieAlert.config.cookie_name.to_sym].split(CookieAlert.config.cookie_value_text_separator)[1] || main_app.root_path
11
+
12
+ # Set the Cookie value to 'accepted'
13
+ if CookieAlert.config.cookie_type == 'permanent'
14
+
15
+ # Set a permanent cookie
16
+ cookies.permanent.signed[CookieAlert.config.cookie_name.to_sym] = 'accepted'
17
+
18
+ elsif CookieAlert.config.cookie_type == 'fixed_duration'
19
+
20
+ # Set a fixed duration cookie
21
+ cookies.permanent.signed[CookieAlert.config.cookie_name.to_sym] = { value: 'accepted', expires: CookieAlert.config.num_days_until_cookie_expires.days.from_now }
22
+
23
+ else
24
+
25
+ # Set a session cookie
26
+ cookies.signed[CookieAlert.config.cookie_name.to_sym] = 'accepted'
27
+
28
+ end
29
+
30
+ # If the request is HTML then redirect the visitor back to their original page
31
+ # If the request is javascript then render the javascript partial
32
+ respond_to do |format|
33
+
34
+ format.html { redirect_to(visitor_current_url) }
35
+ format.js { render template: "cookie_alert/cookies/cookie_accepted" }
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,4 @@
1
+ module CookieAlert
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module CookieAlert
2
+ module CookieAlertHelper
3
+ end
4
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ <div id='cookie_alert'>
2
+ <div id='cookie_alert_message'>
3
+ <div id='cookie_alert_title'>
4
+ Cookies:
5
+ </div>
6
+ <div id='cookie_alert_text'>
7
+ We use cookies to help personalise and improve your web experience.
8
+ By using our website you consent to our use of cookies, some of which may have already been set on your device.
9
+ View our Cookie Policy to learn more or <%= link_to "Hide This Banner", cookie_alert_path, remote: true %>
10
+ </div>
11
+ </div>
12
+ </div>
13
+
@@ -0,0 +1,14 @@
1
+ <div id='cookie_alert'class='secondary-alert'>
2
+ <div id='cookie_alert_message'>
3
+ <div id='cookie_alert_title'>
4
+ Cookies:
5
+ </div>
6
+ <div id='cookie_alert_text' style="display: none;">
7
+ We use cookies to give you the best possible experience on our website.
8
+ By using our website you consent to our use of cookies, some of which may have already been set on your device.
9
+ View our Cookie Policy to learn more or <%= link_to "Hide This Banner", cookie_alert_path, remote: true %>
10
+ </div>
11
+ </div>
12
+ </div>
13
+
14
+
@@ -0,0 +1 @@
1
+ $('#cookie_alert').remove();
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>CookieAlert</title>
5
+ <%= stylesheet_link_tag "cookie-alert/application", :media => "all" %>
6
+ <%= javascript_include_tag "cookie-alert/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ CookieAlert::Engine.routes.draw do
2
+
3
+ root to: "cookies#cookie_accepted"
4
+
5
+ get "/", to: "cookies#cookie_accepted" , as: :cookie_accepted
6
+
7
+ end
@@ -0,0 +1,5 @@
1
+ module CookieAlert
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace CookieAlert
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module CookieAlert
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,182 @@
1
+ require "cookie_alert/engine"
2
+
3
+ module CookieAlert
4
+
5
+ # Creates or updates the configuration settings for CookieAlert
6
+ # @param &block [Initialiser Confirguration Block] block containing configuration settings for the module's Configuration object
7
+ def self.configure(&block)
8
+ yield @config ||= CookieAlert::Configuration.new
9
+
10
+ # Validate the configuration
11
+ config.cookie_type = 'session' unless ['session','fixed_duration','permanent'].include? config.cookie_type
12
+
13
+ config.user_must_accept_cookie_use = true unless [true,false].include? config.user_must_accept_cookie_use
14
+ config.use_secondary_alert = true unless [true,false].include? config.use_secondary_alert
15
+
16
+ config.max_alert_display_count = 5 unless config.max_alert_display_count.present? and config.max_alert_display_count > 2
17
+ config.num_days_until_cookie_expires = 60 unless config.num_days_until_cookie_expires.present? and config.num_days_until_cookie_expires > 1
18
+
19
+ config.cookie_name = config.cookie_name || '_we_use_cookies'
20
+ config.cookie_value_text_separator = config.cookie_value_text_separator || "~~"
21
+ config.primary_alert_template = config.primary_alert_template || 'cookie_alert/cookies/primary_alert'
22
+ config.secondary_alert_template = config.secondary_alert_template || 'cookie_alert/cookies/secondary_alert'
23
+ config.js_acceptance_template = config.js_acceptance_template || 'cookie_alert/cookies/cookie_accepted'
24
+ end
25
+
26
+ # Returns the configuration settings for CookieAlert
27
+ def self.config
28
+ @config
29
+ end
30
+
31
+ # Configuration Class
32
+ class Configuration
33
+ include ActiveSupport::Configurable
34
+
35
+ config_accessor :cookie_name
36
+ config_accessor :cookie_type
37
+ config_accessor :num_days_until_cookie_expires
38
+ config_accessor :user_must_accept_cookie_use
39
+ config_accessor :use_secondary_alert
40
+ config_accessor :max_alert_display_count
41
+ config_accessor :cookie_value_text_separator
42
+ config_accessor :primary_alert_template
43
+ config_accessor :secondary_alert_template
44
+ config_accessor :js_acceptance_template
45
+ end
46
+
47
+ # Sets the default configuration values
48
+ # Is over-ridden by a config/initializer/cookie_alert.rb file
49
+ configure do |config|
50
+ config.cookie_name = '_we_use_cookies'
51
+ config.cookie_type = 'session'
52
+ config.user_must_accept_cookie_use = true
53
+ config.use_secondary_alert = true
54
+ config.max_alert_display_count = 5
55
+ config.num_days_until_cookie_expires = 60
56
+ config.cookie_value_text_separator = "~~"
57
+ config.primary_alert_template = 'cookie_alert/cookies/primary_alert'
58
+ config.secondary_alert_template = 'cookie_alert/cookies/secondary_alert'
59
+ config.js_acceptance_template = 'cookie_alert/cookies/cookie_accepted'
60
+ end
61
+
62
+
63
+ # Primary helper method that decides which, if any, of the Alert templates should be rendered
64
+ def display_cookie_alert
65
+ # If the visitor has not seen the warning before
66
+ # set a cookie recording the first view
67
+ unless cookies.signed[CookieAlert.config.cookie_name.to_sym]
68
+
69
+ cookie_alert_set_display_count_cookie 1
70
+ cookie_alert_render_primary_alert
71
+
72
+ else
73
+
74
+ # If the warning has previously been accepted because the visitor has either clicked on the 'accept' link
75
+ # or it has been displayed the required number of times
76
+ if cookies.signed[CookieAlert.config.cookie_name.to_sym] == 'accepted'
77
+
78
+ # Don't display the notice
79
+ cookie_alert_render_nothing
80
+
81
+ else
82
+
83
+ # Retrieve the number of times the Alert has been displayed from the Cookie
84
+ num_views = cookie_alert_get_view_count
85
+
86
+ # MUST the Visitor accept the Cookie by clicking the link?
87
+ unless CookieAlert.config.user_must_accept_cookie_use
88
+
89
+ # is this past the max number of Warnings to display?
90
+ if num_views == CookieAlert.config.max_alert_display_count
91
+
92
+ # The visitor has accepted through usage, so set the Cookie to 'accepted'
93
+ cookie_alert_set_accepted_cookie
94
+
95
+ # Don't display the notive
96
+ cookie_alert_render_nothing
97
+
98
+ else
99
+
100
+ # Increment the view count & display the warning
101
+ cookie_alert_set_display_count_cookie num_views + 1
102
+ cookie_alert_render_primary_alert
103
+
104
+ end
105
+
106
+ else
107
+
108
+ # The user MUST accept the cookie use and hasn't done so yet
109
+ # Do we display the Full Alert of the Reminder?
110
+ if CookieAlert.config.use_secondary_alert == true and num_views >= CookieAlert.config.max_alert_display_count
111
+
112
+ # Display the reminder
113
+ cookie_alert_render_secondary_alert
114
+
115
+ else
116
+
117
+ # Display the full alert
118
+ cookie_alert_set_display_count_cookie num_views + 1
119
+ cookie_alert_render_primary_alert
120
+
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+
127
+
128
+ private
129
+
130
+
131
+ # Set the data value of the cookie to include the number of views and the current URL
132
+ # @param num_views [integer] the number of time the visitor has viewed an Alert
133
+ def cookie_alert_set_display_count_cookie num_views
134
+ cookie_alert_set_cookie num_views.to_s << CookieAlert.config.cookie_value_text_separator << request.fullpath
135
+ end
136
+
137
+ # Sets the value of the cookie to "accepted"
138
+ def cookie_alert_set_accepted_cookie
139
+ cookie_alert_set_cookie "accepted"
140
+ end
141
+
142
+ # Creates the Cookie, setting the expiry time and the data value
143
+ # @param cookie_value [string] data content of the Cookie
144
+ def cookie_alert_set_cookie cookie_value=''
145
+ if CookieAlert.config.cookie_type == 'permanent'
146
+ # Set a permanent cookie
147
+ cookies.permanent.signed[CookieAlert.config.cookie_name.to_sym] = cookie_value
148
+ elsif CookieAlert.config.cookie_type == 'fixed_duration'
149
+ # Set a fixed duration cookie
150
+ cookies.signed[CookieAlert.config.cookie_name.to_sym] = { value: cookie_value, expires: CookieAlert.config.num_days_until_cookie_expires.days.from_now }
151
+ else
152
+ # Set a session cookie
153
+ cookies.signed[CookieAlert.config.cookie_name.to_sym] = cookie_value
154
+ end
155
+ end
156
+
157
+ # Renders the primary Alert template
158
+ def cookie_alert_render_primary_alert
159
+ render partial: CookieAlert.config.primary_alert_template
160
+ end
161
+
162
+ # Renders the secondary Alert remplate
163
+ def cookie_alert_render_secondary_alert
164
+ render partial: CookieAlert.config.secondary_alert_template
165
+ end
166
+
167
+ # Renders a blank template for those times when an Alert should not be displayed
168
+ def cookie_alert_render_nothing
169
+ render partial: "cookie_alert/cookies/no_response"
170
+ end
171
+
172
+ # Gets the number of views from the Cookie data
173
+ def cookie_alert_get_view_count
174
+ cookies.signed[CookieAlert.config.cookie_name.to_sym].split(CookieAlert.config.cookie_value_text_separator)[0].to_i
175
+ end
176
+
177
+ # Gets the visitor's current page URL from the Cookie data
178
+ def cookie_alert_get_current_url
179
+ cookies.signed[CookieAlert.config.cookie_name.to_sym].split(CookieAlert.config.cookie_value_text_separator)[1]
180
+ end
181
+
182
+ end
@@ -0,0 +1,42 @@
1
+ module CookieAlert
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
6
+
7
+ desc "DESCRIPTION:\nCreates a configuration file, view templates, JavaScript and CSS files to your application.\n\n"
8
+
9
+ def create_install_files
10
+ say "\n\n ==========================================="
11
+ say " Starting CookieAlert installation"
12
+ say " ==========================================="
13
+
14
+ say "\n Installing configuration file:"
15
+ copy_file "cookie_alert.rb", "config/initializers/cookie_alert.rb"
16
+
17
+ say "\n Installing Primary Alert View:"
18
+ copy_file "_primary_alert.html.erb", "app/views/cookie_alert/cookies/_primary_alert.html.erb"
19
+
20
+ say "\n Installing Secondary Alert View:"
21
+ copy_file "_secondary_alert.html.erb", "app/views/cookie_alert/cookies/_secondary_alert.html.erb"
22
+
23
+ say "\n Installing JavaScript Response View:"
24
+ copy_file "cookie_accepted.js.erb", "app/views/cookie_alert/cookies/cookie_accepted.js.erb"
25
+
26
+
27
+ say "\n Installing StyleSheet:"
28
+ copy_file "cookie_alert.css", "app/assets/stylesheets/cookie_alert.css"
29
+
30
+ say "\n Installing JavaScript:"
31
+ copy_file "cookie_alert.js", "app/assets/javascripts/cookie_alert.js"
32
+
33
+ say "\n\n NOTE:=> run 'rails g cookie_alert:uninstall' to remove installed files"
34
+
35
+ say "\n ==========================================="
36
+ say " CookieAlert installation Completed"
37
+ say " ===========================================\n\n"
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,13 @@
1
+ <div id='cookie_alert'>
2
+ <div id='cookie_alert_message'>
3
+ <div id='cookie_alert_title'>
4
+ Cookies:
5
+ </div>
6
+ <div id='cookie_alert_text'>
7
+ We use cookies to help personalise and improve your web experience.
8
+ By using our website you consent to our use of cookies, some of which may have already been set on your device.
9
+ View our Cookie Policy to learn more or <%= link_to "Hide This Banner", cookie_alert_path, remote: true %>
10
+ </div>
11
+ </div>
12
+ </div>
13
+
@@ -0,0 +1,12 @@
1
+ <div id='cookie_alert'class='secondary-alert'>
2
+ <div id='cookie_alert_message'>
3
+ <div id='cookie_alert_title'>
4
+ Cookies:
5
+ </div>
6
+ <div id='cookie_alert_text' style="display: none;">
7
+ We use cookies to give you the best possible experience on our website.
8
+ By using our website you consent to our use of cookies, some of which may have already been set on your device.
9
+ View our Cookie Policy to learn more or <%= link_to "hide this banner", cookie_alert_path, remote: true %>
10
+ </div>
11
+ </div>
12
+ </div>
@@ -0,0 +1 @@
1
+ $('#cookie_alert').remove();
@@ -0,0 +1,49 @@
1
+ #cookie_alert {
2
+ position: fixed;
3
+ bottom: 0;
4
+ left: 0;
5
+ color: navy;
6
+ background-color: #f4efb4;
7
+ border: 2px solid #444444;
8
+ }
9
+
10
+ #cookie_alert_message {
11
+ margin: 0;
12
+ padding: 5px;
13
+ }
14
+
15
+ #cookie_alert_title {
16
+ float: left;
17
+ width: 75px;
18
+ font-weight: bold;
19
+ font-size: 18px;
20
+ line-height: 18px;
21
+ vertical-align: top;
22
+ padding-bottom: 3px;
23
+ text-shadow: 1px 1px 0 white;
24
+
25
+
26
+ }
27
+
28
+ #cookie_alert_text {
29
+ margin-left: 80px;
30
+ line-height: 1.25em;
31
+ }
32
+
33
+ #cookie_alert a {
34
+ background-color: gold;
35
+ color: navy;
36
+ font-weight: normal;
37
+ text-decoration: none;
38
+ border: 1px solid navy;
39
+ padding: 0 1em;
40
+ margin: 0 5px;
41
+
42
+ }
43
+
44
+ #cookie_alert a:hover {
45
+ text-decoration: none;
46
+ background-color: navy;
47
+ color: gold;
48
+ border: 1px solid black;
49
+ }
@@ -0,0 +1,12 @@
1
+ $(function(){
2
+
3
+ $("#cookie_alert.secondary-alert").on( 'mouseenter', function(e){
4
+ $("#cookie_alert_text").show();
5
+
6
+ });
7
+
8
+ $("#cookie_alert.secondary-alert").on( 'mouseleave', function(e){
9
+ $("#cookie_alert_text").hide();
10
+
11
+ });
12
+ });
@@ -0,0 +1,155 @@
1
+ CookieAlert.configure do |config|
2
+
3
+ # COOKIE NAME:
4
+ #
5
+ # INFO: The name of the cookie to be saved on the Visitor's browser
6
+ #
7
+ # TYPE : String
8
+ #
9
+ # VALUES : At least four sequential characters with no spaces. Stick to Alphanumeric, '-' and '_'
10
+ #
11
+ # DEFAULT: '_we_use_cookies'
12
+ #
13
+ config.cookie_name = '_we_use_cookies'
14
+
15
+
16
+ # COOKIE TYPE:
17
+ #
18
+ # INfO: This is the type of cookie that should be placed on the Visitor's browser type of
19
+ # being automatically removed.
20
+ #
21
+ # TYPE : String
22
+ #
23
+ # VALUES : 'session' -> The cookie will only last as long as the Visitor's browsing session
24
+ # 'fixed_duration' -> The cookie will live for a fixed number of days or until the Visitor manually deletes it
25
+ # 'permanent' -> The cookie will live indefinately until the Visitor manually deletes it
26
+ #
27
+ # DEFAULT: 'session'
28
+ #
29
+ config.cookie_type = 'session'
30
+
31
+
32
+ # NUM DAYS UNTIL COOKIE EXPIRES:
33
+ #
34
+ # INfO: This is the number of days the cookie should remain valid on the Visito's browser
35
+ #
36
+ # TYPE : Integer
37
+ #
38
+ # VALUES : Any integer value greater than 1
39
+ #
40
+ # DEFAULT: 60
41
+ #
42
+ # REQUIRES: config.cookie_type = 'fixed_duration'
43
+ #
44
+ config.num_days_until_cookie_expires = 60
45
+
46
+
47
+ # USER MUST ACCEPT COOKIE USE:
48
+ #
49
+ # INfO: This determines whether the Visitor MUST click a link accepting the warning
50
+ # OR whether the warning message will automatically dissapear after a set number of displays.
51
+ #
52
+ #
53
+ # TYPE : Boolean
54
+ #
55
+ # VALUES : TRUE -> if the Visitor MUSt accept the warning
56
+ # FALSE -> if the Warning should be removed after being displayed a specific number of times
57
+ #
58
+ # DEFAULT: TRUE
59
+ #
60
+ # WARNING: If set to TRUE you MUST include a link for the Visitor to click, accepting the Warning.
61
+ # Link path = cookie_alert_acceptance_path
62
+ #
63
+ config.user_must_accept_cookie_use = true
64
+
65
+
66
+ # USE SECONDARY ALERT:
67
+ #
68
+ # INfO: If you have selected that the Visitor MUST accept cookies, you then have the option to
69
+ # display a secondary alert after viewing the primary alert for a specific number of times
70
+ #
71
+ # TYPE : Boolean
72
+ #
73
+ # VALUES : TRUE -> The secondary Alert template will be rendered after a specific number of primary Alert displays
74
+ # FALSE -> The primary Alert template will always be rendered
75
+ #
76
+ # DEFAULT: TRUE
77
+ #
78
+ # NOTE: max_alert_display_count determines how many time the primary Alert should be displayed before rendering the reminder template
79
+ #
80
+ # REQUIRES: user_must_accept_cookie_use = TRUE
81
+ # max_alert_display_count > 1
82
+ #
83
+ config.use_secondary_alert = true
84
+
85
+
86
+ # MAX ALERT DISPLAY COUNT:
87
+ #
88
+ # INfO: This is the number of times the primary Alert should be displayed before
89
+ # either switching to the secondary alert or hiding any alert.
90
+ #
91
+ # TYPE : Integer
92
+ #
93
+ # VALUES : Any integer value greater than 2 to allow for an initial redirect_to
94
+ #
95
+ # DEFAULT: 5
96
+ #
97
+ # WARNING: A 'redirect_to' from a controller will result in the view count incrementing twice in succession
98
+ #
99
+ config.max_alert_display_count = 5
100
+
101
+
102
+ # COOKIE VALUE TEXT SEPARATOR:
103
+ #
104
+ # INfO: This is the character sequence used to separate multiple values stored in the cookie
105
+ # This only need changed if you use the default value and part of your routing table.
106
+ #
107
+ # TYPE : String
108
+ #
109
+ # VALUES : At least two sequential Alphanumeric charaters
110
+ #
111
+ # DEFAULT: '~~'
112
+ #
113
+ config.cookie_value_text_separator = "~~"
114
+
115
+
116
+ # PRIMARY ALERT TEMPLATE:
117
+ #
118
+ # INfO: The name of the the view to be rendered for the Primary Alert
119
+ #
120
+ # TYPE : String
121
+ #
122
+ # VALUES : Name of the View Template
123
+ #
124
+ # DEFAULT: 'cookie_alert/cookies/primary_alert'
125
+ #
126
+ config.primary_alert_template = 'cookie_alert/cookies/primary_alert'
127
+
128
+
129
+ # SECONDARY ALERT TEMPLATE:
130
+ #
131
+ # INfO: The name of the the view to be rendered for the Secondary Alert
132
+ #
133
+ # TYPE : String
134
+ #
135
+ # VALUES : Name of the View Template
136
+ #
137
+ # DEFAULT: 'cookie_alert/cookies/secondary_alert'
138
+ #
139
+ config.secondary_alert_template = 'cookie_alert/cookies/secondary_alert'
140
+
141
+
142
+ # COOKIE JavaScript ACCEPTANCE RESPONSE:
143
+ #
144
+ # INfO: The name of the the view to be rendered for a Javascript Response
145
+ # to the cookie being accepted
146
+ #
147
+ # TYPE : String
148
+ #
149
+ # VALUES : Name of the JavaScript View Template
150
+ #
151
+ # DEFAULT: 'cookie_alert/cookies/cookie_accepted'
152
+ #
153
+ config.js_acceptance_template = 'cookie_alert/cookies/cookie_accepted'
154
+
155
+ end
@@ -0,0 +1,40 @@
1
+ module CookieAlert
2
+ module Generators
3
+ class UninstallGenerator < Rails::Generators::Base
4
+
5
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
6
+
7
+ desc "DESCRIPTION:\nRemoves any previously installed files.\n\n"
8
+
9
+ def remove_install_files
10
+ say "\n\n ==========================================="
11
+ say " Uninstalling CookieAlert"
12
+ say " ==========================================="
13
+
14
+ say "\n Removing configuration file:"
15
+ remove_file "config/initializers/cookie_alert.rb"
16
+
17
+ say "\n Removing Primary Alert View:"
18
+ remove_file "app/views/cookie_alert/cookies/_primary_alert.html.erb"
19
+
20
+ say "\n Removing Secondary Alert View:"
21
+ remove_file "app/views/cookie_alert/cookies/_secondary_alert.html.erb"
22
+
23
+ say "\n Removing JavaScript Response View:"
24
+ remove_file "app/views/cookie_alert/cookies/cookie_accepted.js.erb"
25
+
26
+
27
+ say "\n Removing StyleSheet:"
28
+ remove_file "app/assets/stylesheets/cookie_alert.css"
29
+
30
+ say "\n Removing JavaScript:"
31
+ remove_file "app/assets/javascripts/cookie_alert.js"
32
+
33
+ say "\n ==========================================="
34
+ say " Uninstall Complete"
35
+ say " ===========================================\n\n"
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :cookie_alert do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cookie_alert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - CodeMeister
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jquery-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: github-markdown
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Display a visual warning on your site to let visitors know that you use
98
+ Cookes. Primarily intended for use with the UK Cookie Law
99
+ email:
100
+ - bob@katanacode.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - app/assets/javascripts/cookie_alert.js
106
+ - app/assets/stylesheets/cookie_alert.css
107
+ - app/controllers/cookie_alert/application_controller.rb
108
+ - app/controllers/cookie_alert/cookies_controller.rb
109
+ - app/helpers/cookie_alert/application_helper.rb
110
+ - app/helpers/cookie_alert/cookie_alert_helper.rb
111
+ - app/views/cookie_alert/cookies/_no_response.html
112
+ - app/views/cookie_alert/cookies/_primary_alert.html.erb
113
+ - app/views/cookie_alert/cookies/_secondary_alert.html.erb
114
+ - app/views/cookie_alert/cookies/cookie_accepted.js.erb
115
+ - app/views/layouts/cookie_alert/application.html.erb
116
+ - config/routes.rb
117
+ - lib/cookie_alert/engine.rb
118
+ - lib/cookie_alert/version.rb
119
+ - lib/cookie_alert.rb
120
+ - lib/generators/cookie_alert/install_generator.rb
121
+ - lib/generators/cookie_alert/templates/_primary_alert.html.erb
122
+ - lib/generators/cookie_alert/templates/_secondary_alert.html.erb
123
+ - lib/generators/cookie_alert/templates/cookie_accepted.js.erb
124
+ - lib/generators/cookie_alert/templates/cookie_alert.css
125
+ - lib/generators/cookie_alert/templates/cookie_alert.js
126
+ - lib/generators/cookie_alert/templates/cookie_alert.rb
127
+ - lib/generators/cookie_alert/uninstall_generator.rb
128
+ - lib/tasks/cookie_alert_tasks.rake
129
+ - MIT-LICENSE
130
+ - Rakefile
131
+ - README.md
132
+ homepage: https://github.com/KatanaCode/cookie_alert
133
+ licenses: []
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.0.3
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Notify visitors that your site uses Cookies. For Rails 3.1 +
155
+ test_files: []
156
+ has_rdoc: