storejs-rails 1.3.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e90ab21426ffaa9bdd48a6aaa0fd354f8d01f3df
4
+ data.tar.gz: 9be20559a1d2bc0afe49b60a0a1cbd66deeff5bb
5
+ SHA512:
6
+ metadata.gz: 60ac471a0d948945274885e074304ffde669eabd7c5354961a6b39e70f82107422ec754f4436a57844b8038dc3dfcd7ccaeb70729f6f0ef7dfff66328248f09c
7
+ data.tar.gz: 2580bca3a473d5e6ad952a9473b7949c5e2c4d7c02be1775ff7c210f34956d146f6c6b69f4e2ef9a78972a8031d3c0e4705a7c2b7b305f2161b6143161974224
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,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tomek Wałkuski
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
+ # storejs-rails
2
+
3
+ marcuswestin's store.js exposes a simple API for cross browser local storage.
4
+ storejs-rails packages it to use with Rails asset pipeline.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem "storejs-rails"
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install storejs-rails
19
+
20
+ ## Usage
21
+
22
+ Add this line to `app/assets/javascripts/application.js`:
23
+
24
+ //= require store
25
+
26
+ ## Documentation
27
+
28
+ [marcuswestin/store.js](https://github.com/marcuswestin/store.js)
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,6 @@
1
+ module Storejs
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Storejs
2
+ module Rails
3
+ VERSION = "1.3.14"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "storejs/rails/version"
2
+ require "storejs/rails/engine"
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require "storejs/rails/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "storejs-rails"
10
+ spec.version = Storejs::Rails::VERSION
11
+ spec.authors = ["Tomek Wałkuski"]
12
+ spec.email = ["ja@jestem.tw"]
13
+ spec.description = "Package https://github.com/marcuswestin/store.js to use with Rails asset pipeline"
14
+ spec.summary = spec.description
15
+ spec.homepage = "https://github.com/tomekw/storejs-rails"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,165 @@
1
+ ;(function(win){
2
+ var store = {},
3
+ doc = win.document,
4
+ localStorageName = 'localStorage',
5
+ scriptTag = 'script',
6
+ storage
7
+
8
+ store.disabled = false
9
+ store.set = function(key, value) {}
10
+ store.get = function(key) {}
11
+ store.remove = function(key) {}
12
+ store.clear = function() {}
13
+ store.transact = function(key, defaultVal, transactionFn) {
14
+ var val = store.get(key)
15
+ if (transactionFn == null) {
16
+ transactionFn = defaultVal
17
+ defaultVal = null
18
+ }
19
+ if (typeof val == 'undefined') { val = defaultVal || {} }
20
+ transactionFn(val)
21
+ store.set(key, val)
22
+ }
23
+ store.getAll = function() {}
24
+ store.forEach = function() {}
25
+
26
+ store.serialize = function(value) {
27
+ return JSON.stringify(value)
28
+ }
29
+ store.deserialize = function(value) {
30
+ if (typeof value != 'string') { return undefined }
31
+ try { return JSON.parse(value) }
32
+ catch(e) { return value || undefined }
33
+ }
34
+
35
+ // Functions to encapsulate questionable FireFox 3.6.13 behavior
36
+ // when about.config::dom.storage.enabled === false
37
+ // See https://github.com/marcuswestin/store.js/issues#issue/13
38
+ function isLocalStorageNameSupported() {
39
+ try { return (localStorageName in win && win[localStorageName]) }
40
+ catch(err) { return false }
41
+ }
42
+
43
+ if (isLocalStorageNameSupported()) {
44
+ storage = win[localStorageName]
45
+ store.set = function(key, val) {
46
+ if (val === undefined) { return store.remove(key) }
47
+ storage.setItem(key, store.serialize(val))
48
+ return val
49
+ }
50
+ store.get = function(key) { return store.deserialize(storage.getItem(key)) }
51
+ store.remove = function(key) { storage.removeItem(key) }
52
+ store.clear = function() { storage.clear() }
53
+ store.getAll = function() {
54
+ var ret = {}
55
+ store.forEach(function(key, val) {
56
+ ret[key] = val
57
+ })
58
+ return ret
59
+ }
60
+ store.forEach = function(callback) {
61
+ for (var i=0; i<storage.length; i++) {
62
+ var key = storage.key(i)
63
+ callback(key, store.get(key))
64
+ }
65
+ }
66
+ } else if (doc.documentElement.addBehavior) {
67
+ var storageOwner,
68
+ storageContainer
69
+ // Since #userData storage applies only to specific paths, we need to
70
+ // somehow link our data to a specific path. We choose /favicon.ico
71
+ // as a pretty safe option, since all browsers already make a request to
72
+ // this URL anyway and being a 404 will not hurt us here. We wrap an
73
+ // iframe pointing to the favicon in an ActiveXObject(htmlfile) object
74
+ // (see: http://msdn.microsoft.com/en-us/library/aa752574(v=VS.85).aspx)
75
+ // since the iframe access rules appear to allow direct access and
76
+ // manipulation of the document element, even for a 404 page. This
77
+ // document can be used instead of the current document (which would
78
+ // have been limited to the current path) to perform #userData storage.
79
+ try {
80
+ storageContainer = new ActiveXObject('htmlfile')
81
+ storageContainer.open()
82
+ storageContainer.write('<'+scriptTag+'>document.w=window</'+scriptTag+'><iframe src="/favicon.ico"></iframe>')
83
+ storageContainer.close()
84
+ storageOwner = storageContainer.w.frames[0].document
85
+ storage = storageOwner.createElement('div')
86
+ } catch(e) {
87
+ // somehow ActiveXObject instantiation failed (perhaps some special
88
+ // security settings or otherwse), fall back to per-path storage
89
+ storage = doc.createElement('div')
90
+ storageOwner = doc.body
91
+ }
92
+ function withIEStorage(storeFunction) {
93
+ return function() {
94
+ var args = Array.prototype.slice.call(arguments, 0)
95
+ args.unshift(storage)
96
+ // See http://msdn.microsoft.com/en-us/library/ms531081(v=VS.85).aspx
97
+ // and http://msdn.microsoft.com/en-us/library/ms531424(v=VS.85).aspx
98
+ storageOwner.appendChild(storage)
99
+ storage.addBehavior('#default#userData')
100
+ storage.load(localStorageName)
101
+ var result = storeFunction.apply(store, args)
102
+ storageOwner.removeChild(storage)
103
+ return result
104
+ }
105
+ }
106
+
107
+ // In IE7, keys may not contain special chars. See all of https://github.com/marcuswestin/store.js/issues/40
108
+ var forbiddenCharsRegex = new RegExp("[!\"#$%&'()*+,/\\\\:;<=>?@[\\]^`{|}~]", "g")
109
+ function ieKeyFix(key) {
110
+ return key.replace(forbiddenCharsRegex, '___')
111
+ }
112
+ store.set = withIEStorage(function(storage, key, val) {
113
+ key = ieKeyFix(key)
114
+ if (val === undefined) { return store.remove(key) }
115
+ storage.setAttribute(key, store.serialize(val))
116
+ storage.save(localStorageName)
117
+ return val
118
+ })
119
+ store.get = withIEStorage(function(storage, key) {
120
+ key = ieKeyFix(key)
121
+ return store.deserialize(storage.getAttribute(key))
122
+ })
123
+ store.remove = withIEStorage(function(storage, key) {
124
+ key = ieKeyFix(key)
125
+ storage.removeAttribute(key)
126
+ storage.save(localStorageName)
127
+ })
128
+ store.clear = withIEStorage(function(storage) {
129
+ var attributes = storage.XMLDocument.documentElement.attributes
130
+ storage.load(localStorageName)
131
+ for (var i=0, attr; attr=attributes[i]; i++) {
132
+ storage.removeAttribute(attr.name)
133
+ }
134
+ storage.save(localStorageName)
135
+ })
136
+ store.getAll = function(storage) {
137
+ var ret = {}
138
+ store.forEach(function(key, val) {
139
+ ret[key] = val
140
+ })
141
+ return ret
142
+ }
143
+ store.forEach = withIEStorage(function(storage, callback) {
144
+ var attributes = storage.XMLDocument.documentElement.attributes
145
+ for (var i=0, attr; attr=attributes[i]; ++i) {
146
+ callback(attr.name, store.deserialize(storage.getAttribute(attr.name)))
147
+ }
148
+ })
149
+ }
150
+
151
+ try {
152
+ var testKey = '__storejs__'
153
+ store.set(testKey, testKey)
154
+ if (store.get(testKey) != testKey) { store.disabled = true }
155
+ store.remove(testKey)
156
+ } catch(e) {
157
+ store.disabled = true
158
+ }
159
+ store.enabled = !store.disabled
160
+
161
+ if (typeof module != 'undefined' && module.exports) { module.exports = store }
162
+ else if (typeof define === 'function' && define.amd) { define(store) }
163
+ else { win.store = store }
164
+
165
+ })(this.window || global);
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: storejs-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.14
5
+ platform: ruby
6
+ authors:
7
+ - Tomek Wałkuski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '1.3'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :development
41
+ description: Package https://github.com/marcuswestin/store.js to use with Rails asset pipeline
42
+ email:
43
+ - ja@jestem.tw
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/storejs/rails.rb
54
+ - lib/storejs/rails/engine.rb
55
+ - lib/storejs/rails/version.rb
56
+ - storejs-rails.gemspec
57
+ - vendor/assets/javascripts/store.js
58
+ homepage: https://github.com/tomekw/storejs-rails
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.1.9
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Package https://github.com/marcuswestin/store.js to use with Rails asset pipeline
82
+ test_files: []