localstorageshim-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in localstorageshim-rails.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Nathan Broadbent
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # localstorageshim-rails
2
+
3
+ Rails wrapper for https://github.com/mattpowell/localstorageshim
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'localstorageshim-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install localstorageshim-rails
18
+
19
+ ## Usage
20
+
21
+ `localstorage.js` will be automatically added to `config.assets.precompile`, so it will be compiled when you run `rake assets:precompile`.
22
+
23
+ In your application layout, add the following line (for ERb):
24
+
25
+ <%= localstorage_shim %>
26
+
27
+ This will add a conditional comment to load the localstorage shim for IE 6 & 7.
28
+
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ module Localstorageshim
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ initializer "ransack_ui.view_helpers" do
5
+ ActionView::Base.send :include, ViewHelpers
6
+ end
7
+
8
+ initializer :assets do
9
+ # Precompile asset since it's a conditional include
10
+ ::Rails.application.config.assets.precompile += %w(localstorageshim.js)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Localstorageshim
2
+ module Rails
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Localstorageshim
2
+ module ViewHelpers
3
+ def localstorage_shim
4
+ <<-HTML.strip.html_safe
5
+ <!--[if lte IE 7]>
6
+ <script src="#{asset_path 'localstorageshim'}" type="text/javascript" id="ie-localstorage-shim"></script>
7
+ <![endif]-->
8
+ HTML
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require "localstorageshim-rails/version"
2
+ require "localstorageshim-rails/view_helpers"
3
+ require "localstorageshim-rails/engine"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'localstorageshim-rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "localstorageshim-rails"
8
+ gem.version = Localstorageshim::Rails::VERSION
9
+ gem.authors = ["Nathan Broadbent"]
10
+ gem.email = ["nathan.f77@gmail.com"]
11
+ gem.description = %q{Add localstorageshim.js to your Rails application}
12
+ gem.summary = %q{Rails wrapper for localstorageshim.js}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,117 @@
1
+ /*
2
+ Content-Type: multipart/related; boundary="_IE_LOCALSTORAGE_SHIM"
3
+
4
+ --_IE_LOCALSTORAGE_SHIM
5
+ Content-Location:storeone
6
+ Content-Transfer-Encoding:base64
7
+
8
+ R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
9
+
10
+ --_IE_LOCALSTORAGE_SHIM
11
+ Content-Location:storetwo
12
+ Content-Transfer-Encoding:base64
13
+
14
+ PGh0bWw+PGhlYWQ+PHRpdGxlPjwvdGl0bGU+PC9oZWFkPjxib2R5PjxiIGlkPSJsb2NhbHN0b3JhZ2UtaWVzaGltLWluamVjdCIgY2xhc3M9InVzZXJEYXRhIiBzdHlsZT0iYmVoYXZpb3I6dXJsKCcjZGVmYXVsdCN1c2VyRGF0YScpIj48L2I+PHNjcmlwdD4oZnVuY3Rpb24gZ2V0VXNlckRhdGEoKXt2YXIgaWQ9ImxvY2Fsc3RvcmFnZS1pZXNoaW0taW5qZWN0IixiPWRvY3VtZW50LmdldEVsZW1lbnRCeUlkKGlkKTt0cnl7Yi5sb2FkKGlkKX1jYXRjaChlKXtzZXRUaW1lb3V0KGdldFVzZXJEYXRhLDApfX0oKSk8L3NjcmlwdD48L2JvZHk+PC9odG1sPg==
15
+
16
+ --_IE_LOCALSTORAGE_SHIM--
17
+ */
18
+ (function() {
19
+ var DEBUG = false,
20
+ DONT_ENUMERATE = ['getItem', 'setItem', 'removeItem', 'key', 'clear', 'length'],
21
+ iframe = document.createElement('iframe'),
22
+ src = document.getElementById('ie-localstorage-shim'),
23
+ localStorageShim = {},
24
+ CustomError;
25
+
26
+ /**
27
+ * Custom error used to rethrow as a QUOTA_EXCEEDED_ERR error.
28
+ * @constructor
29
+ */
30
+ CustomError = function(name, msg) { this.name = name; this.message = msg;};
31
+ CustomError.prototype = new Error;
32
+
33
+ //reference the tiniest gif ever via mhtml (http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever)
34
+ iframe.src = src ? 'mhtml:' + src.getAttribute('src', -1) + '!storetwo' : '/favicon.ico';
35
+ iframe.style.display = 'none';
36
+
37
+ iframe.attachEvent('onload', createLocalStorageObject);
38
+ src.parentNode.insertBefore(iframe,src);
39
+
40
+ function cleanStorageKey(key) {
41
+ return key ? 'ie' + key.replace(/[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g, '-' ) : key ;
42
+ }
43
+ function uncleanStorageKey(key) {
44
+ //for the moment we can only get rid of the 'ie' prefix
45
+ return key ? key.replace(/^ie/,'') : key;
46
+ }
47
+ function createLocalStorageObject() {
48
+ var doc = iframe.contentWindow.document,
49
+ id = 'localstorage-ieshim-inject',
50
+ storageElement = doc.getElementById(id),
51
+ _storedKeys = [];
52
+
53
+ function syncStoredKeys() {
54
+ var storageAttr;
55
+ _storedKeys = [];
56
+ try{
57
+ storageAttr = storageElement.XMLDocument.documentElement.attributes;
58
+ for (var x = 0, l = storageAttr.length; x<l; x++) {
59
+ _storedKeys.push(storageAttr[x].nodeName);
60
+ }
61
+ }catch(e) {
62
+ //unable to pre-populate _storedKeys. This may be the first time userData is used or it may not be ready yet.
63
+ if (DEBUG) throw e;
64
+ }
65
+ localStorageShim.length = _storedKeys.length;
66
+ }
67
+ localStorageShim = {
68
+ 'getItem': function(key) {
69
+ var val = null;
70
+ key = cleanStorageKey(key);
71
+ try{
72
+ storageElement.load(id);
73
+ val = storageElement.getAttribute(key);
74
+ }catch(e) {
75
+ if (DEBUG) throw e;
76
+ }
77
+
78
+ return val;
79
+ },
80
+ 'setItem': function(key, value) {
81
+ key = cleanStorageKey(key);
82
+ try{
83
+ storageElement.setAttribute(key, value.toString());//.toString() per https://developer.mozilla.org/en/DOM/Storage
84
+ syncStoredKeys();
85
+ storageElement.save(id);
86
+ }catch(e) {
87
+ throw new CustomError('QUOTA_EXCEEDED_ERR', 'userData quota exceeded.');//-2147217407
88
+ }
89
+ syncStoredKeys();//adds to internal cache and updates length
90
+ },
91
+ 'removeItem': function(key) {
92
+ key = cleanStorageKey(key);
93
+ try {
94
+ storageElement.removeAttribute(key);
95
+ syncStoredKeys();//updates internal store and localStorage.length
96
+ storageElement.save(id);
97
+ }catch(e) {
98
+ if (DEBUG) throw e;
99
+ }
100
+ },
101
+ 'key': function(index) {
102
+ syncStoredKeys();
103
+ return uncleanStorageKey(_storedKeys[index]);
104
+ },
105
+ 'clear': function() {
106
+ syncStoredKeys();//updates internal store and localStorage.length
107
+ for (var x = _storedKeys.length-1, key; x >= 0; x--) {
108
+ key = localStorageShim.key(x);
109
+ key && localStorageShim.removeItem(key);
110
+ }
111
+ },
112
+ 'length': _storedKeys.length
113
+ };
114
+ window['localStorage'] = window['localStorage'] || localStorageShim;
115
+ syncStoredKeys();
116
+ }
117
+ }());
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: localstorageshim-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nathan Broadbent
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-22 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Add localstorageshim.js to your Rails application
15
+ email:
16
+ - nathan.f77@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/localstorageshim-rails.rb
27
+ - lib/localstorageshim-rails/engine.rb
28
+ - lib/localstorageshim-rails/version.rb
29
+ - lib/localstorageshim-rails/view_helpers.rb
30
+ - localstorageshim-rails.gemspec
31
+ - vendor/assets/javascripts/localstorageshim.js
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ segments:
45
+ - 0
46
+ hash: 1307240248453593848
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ segments:
54
+ - 0
55
+ hash: 1307240248453593848
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.24
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Rails wrapper for localstorageshim.js
62
+ test_files: []