From cd904ad347cea6cedf52496aecc988cd4f6522c6 Mon Sep 17 00:00:00 2001 From: Stjepan Hadjic Date: Wed, 19 Jun 2013 12:51:53 +0200 Subject: [PATCH] inital commit --- .gitignore | 30 +++---- Gemfile | 4 + LICENSE.txt | 22 ++++++ README.md | 31 +++++++- Rakefile | 1 + app/assets/javascripts/cookies_eu.js | 8 ++ app/views/cookies_eu/_cookies_eu.html.erb | 7 ++ cookies_eu.gemspec | 24 ++++++ lib/cookies_eu.rb | 7 ++ lib/cookies_eu/engine.rb | 4 + lib/cookies_eu/version.rb | 3 + vendor/javacripts/jquery.cookie.js | 95 +++++++++++++++++++++++ 12 files changed, 218 insertions(+), 18 deletions(-) create mode 100644 Gemfile create mode 100644 LICENSE.txt create mode 100644 Rakefile create mode 100644 app/assets/javascripts/cookies_eu.js create mode 100644 app/views/cookies_eu/_cookies_eu.html.erb create mode 100644 cookies_eu.gemspec create mode 100644 lib/cookies_eu.rb create mode 100644 lib/cookies_eu/engine.rb create mode 100644 lib/cookies_eu/version.rb create mode 100644 vendor/javacripts/jquery.cookie.js diff --git a/.gitignore b/.gitignore index 54cb8bb..205057d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,16 @@ *.rbc -*.sassc -.sass-cache -capybara-*.html -.rspec -/.bundle -/vendor/bundle -/log/* -/tmp/* -/db/*.sqlite3 -/public/system/* -/coverage/ -/spec/tmp/* -**.orig -rerun.txt -pickle-email-*.html \ No newline at end of file +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..c671025 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in cookies_eu.gemspec +gemspec diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..624b297 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,22 @@ +Copyright (c) 2013 Stjepan Hadjic + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 9199b45..5db484c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,29 @@ -cookies_eu -========== +# CookiesEu -Rails gem for eu cookies law +TODO: Write a gem description + +## Installation + +Add this line to your application's Gemfile: + + gem 'cookies_eu' + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install cookies_eu + +## Usage + +TODO: Write usage instructions here + +## Contributing + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..2995527 --- /dev/null +++ b/Rakefile @@ -0,0 +1 @@ +require "bundler/gem_tasks" diff --git a/app/assets/javascripts/cookies_eu.js b/app/assets/javascripts/cookies_eu.js new file mode 100644 index 0000000..b0f9dae --- /dev/null +++ b/app/assets/javascripts/cookies_eu.js @@ -0,0 +1,8 @@ +//= require jquery +//= require jquery.cookie + +$('.cookies_eu_ok').click(function(e){ + e.preventDefault(); + $.cookie('consented', 'true'); + $(this).parent().remove(); +} \ No newline at end of file diff --git a/app/views/cookies_eu/_cookies_eu.html.erb b/app/views/cookies_eu/_cookies_eu.html.erb new file mode 100644 index 0000000..5624850 --- /dev/null +++ b/app/views/cookies_eu/_cookies_eu.html.erb @@ -0,0 +1,7 @@ +<% if cookie['consented'] != 'true' %> +
+ <%= t('cookies_eu.span_text') %> + + <%= t('cookies_eu.learn_more') %> +
+<% end %> \ No newline at end of file diff --git a/cookies_eu.gemspec b/cookies_eu.gemspec new file mode 100644 index 0000000..6a0a8f5 --- /dev/null +++ b/cookies_eu.gemspec @@ -0,0 +1,24 @@ +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'cookies_eu/version' + +Gem::Specification.new do |spec| + spec.name = "cookies_eu" + spec.version = CookiesEu::VERSION + spec.authors = ["Stjepan Hadjic"] + spec.email = ["stjepan.hadjic@infinum.hr"] + spec.description = %q{Displays a cookie consent} + spec.summary = %q{Displays a cookie consent. If you dont disable cokkies in settings, we assume you are ok with us using cookies} + spec.homepage = "" + spec.license = "MIT" + + spec.files = `git ls-files`.split($/) + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } + spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.require_paths = ["lib"] + + spec.add_development_dependency "jquery-rails" + spec.add_development_dependency "bundler", "~> 1.3" + spec.add_development_dependency "rake" +end diff --git a/lib/cookies_eu.rb b/lib/cookies_eu.rb new file mode 100644 index 0000000..44e7369 --- /dev/null +++ b/lib/cookies_eu.rb @@ -0,0 +1,7 @@ +require "cookies_eu/version" +require "cookies_eu/engine" + +module CookiesEu + BACKGROUND = '#f2f2f2' + LINK = 'www.google.ie' +end diff --git a/lib/cookies_eu/engine.rb b/lib/cookies_eu/engine.rb new file mode 100644 index 0000000..c98f918 --- /dev/null +++ b/lib/cookies_eu/engine.rb @@ -0,0 +1,4 @@ +module CookiesEu + class Engine < ::Rails::Engine + end +end \ No newline at end of file diff --git a/lib/cookies_eu/version.rb b/lib/cookies_eu/version.rb new file mode 100644 index 0000000..22e3d21 --- /dev/null +++ b/lib/cookies_eu/version.rb @@ -0,0 +1,3 @@ +module CookiesEu + VERSION = "0.0.3" +end diff --git a/vendor/javacripts/jquery.cookie.js b/vendor/javacripts/jquery.cookie.js new file mode 100644 index 0000000..c4f99af --- /dev/null +++ b/vendor/javacripts/jquery.cookie.js @@ -0,0 +1,95 @@ +/*! + * jQuery Cookie Plugin v1.3.1 + * https://github.com/carhartl/jquery-cookie + * + * Copyright 2013 Klaus Hartl + * Released under the MIT license + */ +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else { + // Browser globals. + factory(jQuery); + } +}(function ($) { + + var pluses = /\+/g; + + function raw(s) { + return s; + } + + function decoded(s) { + return decodeURIComponent(s.replace(pluses, ' ')); + } + + function converted(s) { + if (s.indexOf('"') === 0) { + // This is a quoted cookie as according to RFC2068, unescape + s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); + } + try { + return config.json ? JSON.parse(s) : s; + } catch(er) {} + } + + var config = $.cookie = function (key, value, options) { + + // write + if (value !== undefined) { + options = $.extend({}, config.defaults, options); + + if (typeof options.expires === 'number') { + var days = options.expires, t = options.expires = new Date(); + t.setDate(t.getDate() + days); + } + + value = config.json ? JSON.stringify(value) : String(value); + + return (document.cookie = [ + config.raw ? key : encodeURIComponent(key), + '=', + config.raw ? value : encodeURIComponent(value), + options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE + options.path ? '; path=' + options.path : '', + options.domain ? '; domain=' + options.domain : '', + options.secure ? '; secure' : '' + ].join('')); + } + + // read + var decode = config.raw ? raw : decoded; + var cookies = document.cookie.split('; '); + var result = key ? undefined : {}; + for (var i = 0, l = cookies.length; i < l; i++) { + var parts = cookies[i].split('='); + var name = decode(parts.shift()); + var cookie = decode(parts.join('=')); + + if (key && key === name) { + result = converted(cookie); + break; + } + + if (!key) { + result[name] = converted(cookie); + } + } + + return result; + }; + + config.defaults = {}; + + $.removeCookie = function (key, options) { + if ($.cookie(key) !== undefined) { + // Must not alter options, thus extending a fresh object... + $.cookie(key, '', $.extend({}, options, { expires: -1 })); + return true; + } + return false; + }; + +}));