jquery-historyjs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ tmp
3
+ spec/support/*/Gemfile.lock
4
+ spec/support/*/public/javascripts
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in jquery-rails.gemspec
4
+ gemspec
5
+ # Rails is already being pulled in through gemspec
6
+ # gem "rails", :git => "git://github.com/rails/rails.git"
7
+ gem "rack", :git => "git://github.com/rack/rack.git"
8
+ gem "sprockets", :git => "git://github.com/sstephenson/sprockets.git"
9
+ gem "i18n", "0.6.0beta1"
@@ -0,0 +1,120 @@
1
+ GIT
2
+ remote: git://github.com/rack/rack.git
3
+ revision: a9beb476b27914794743d0677b327d5bafb5e8a3
4
+ specs:
5
+ rack (1.2.1)
6
+
7
+ GIT
8
+ remote: git://github.com/rails/rails.git
9
+ revision: 2fbbd08616c25dc2931eca914349dd2161766f69
10
+ specs:
11
+ actionmailer (3.1.0.beta)
12
+ actionpack (= 3.1.0.beta)
13
+ mail (~> 2.3.0)
14
+ actionpack (3.1.0.beta)
15
+ activemodel (= 3.1.0.beta)
16
+ activesupport (= 3.1.0.beta)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ i18n (~> 0.6.0beta1)
20
+ rack (~> 1.2.1)
21
+ rack-cache (~> 1.0.0)
22
+ rack-mount (~> 0.7.2)
23
+ rack-test (~> 0.5.7)
24
+ sprockets (~> 2.0.0.beta.2)
25
+ tzinfo (~> 0.3.23)
26
+ activemodel (3.1.0.beta)
27
+ activesupport (= 3.1.0.beta)
28
+ bcrypt-ruby (~> 2.1.4)
29
+ builder (~> 3.0.0)
30
+ i18n (~> 0.6.0beta1)
31
+ activerecord (3.1.0.beta)
32
+ activemodel (= 3.1.0.beta)
33
+ activesupport (= 3.1.0.beta)
34
+ arel (~> 2.1.0)
35
+ tzinfo (~> 0.3.23)
36
+ activeresource (3.1.0.beta)
37
+ activemodel (= 3.1.0.beta)
38
+ activesupport (= 3.1.0.beta)
39
+ activesupport (3.1.0.beta)
40
+ multi_json (~> 1.0.0)
41
+ rails (3.1.0.beta)
42
+ actionmailer (= 3.1.0.beta)
43
+ actionpack (= 3.1.0.beta)
44
+ activerecord (= 3.1.0.beta)
45
+ activeresource (= 3.1.0.beta)
46
+ activesupport (= 3.1.0.beta)
47
+ bundler (~> 1.0)
48
+ railties (= 3.1.0.beta)
49
+ railties (3.1.0.beta)
50
+ actionpack (= 3.1.0.beta)
51
+ activesupport (= 3.1.0.beta)
52
+ rack-ssl (~> 1.3.2)
53
+ rake (>= 0.8.7)
54
+ thor (~> 0.14.4)
55
+
56
+ GIT
57
+ remote: git://github.com/sstephenson/sprockets.git
58
+ revision: c4800417792744c11eb1fb888bbe9a3a82859952
59
+ specs:
60
+ sprockets (2.0.0.beta.2)
61
+ hike (~> 1.0)
62
+ rack (~> 1.0)
63
+ tilt (~> 1.0)
64
+
65
+ PATH
66
+ remote: .
67
+ specs:
68
+ jquery-rails (0.3)
69
+ rails (~> 3.1)
70
+ thor (~> 0.14.4)
71
+
72
+ GEM
73
+ remote: http://rubygems.org/
74
+ specs:
75
+ addressable (2.2.4)
76
+ arel (2.1.0)
77
+ bcrypt-ruby (2.1.4)
78
+ builder (3.0.0)
79
+ crack (0.1.8)
80
+ erubis (2.7.0)
81
+ hike (1.0.0)
82
+ i18n (0.6.0beta1)
83
+ mail (2.3.0)
84
+ i18n (>= 0.4.0)
85
+ mime-types (~> 1.16)
86
+ treetop (~> 1.4.8)
87
+ mime-types (1.16)
88
+ multi_json (1.0.0)
89
+ polyglot (0.3.1)
90
+ rack-cache (1.0.1)
91
+ rack (>= 0.4)
92
+ rack-mount (0.7.2)
93
+ rack (>= 1.0.0)
94
+ rack-ssl (1.3.2)
95
+ rack
96
+ rack-test (0.5.7)
97
+ rack (>= 1.0)
98
+ rake (0.8.7)
99
+ rspec (1.3.1)
100
+ thor (0.14.6)
101
+ tilt (1.3)
102
+ treetop (1.4.9)
103
+ polyglot (>= 0.3.1)
104
+ tzinfo (0.3.27)
105
+ webmock (1.6.2)
106
+ addressable (>= 2.2.2)
107
+ crack (>= 0.1.7)
108
+
109
+ PLATFORMS
110
+ ruby
111
+
112
+ DEPENDENCIES
113
+ bundler (~> 1.0.0)
114
+ i18n (= 0.6.0beta1)
115
+ jquery-rails!
116
+ rack!
117
+ rails!
118
+ rspec (~> 1.3)
119
+ sprockets!
120
+ webmock (~> 1.6.2)
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Andre Arko
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.
@@ -0,0 +1,39 @@
1
+ # jquery-historyjs
2
+
3
+ History.js for jQuery and Rails
4
+
5
+ ## Rails 3.1
6
+
7
+ This gem vendors History.js version 1.7 and the required dependencies for jQuery bindings for Rails 3.1 and greater. The files will be added to the asset pipeline and available for you to use.
8
+
9
+ //= require history
10
+
11
+ ### Installation
12
+
13
+ In your Gemfile, add this line:
14
+
15
+ gem "jquery-historyjs"
16
+
17
+ Then, run `bundle install` and add the aforementioned require line to your application.js.
18
+
19
+ You're done!
20
+
21
+ ## Rails 3.0
22
+
23
+ This gem adds a single generator to Rails 3, historyjs:install. Running the generator will fetch the history.js library and all of it's dependencies.
24
+
25
+ ### Installation
26
+
27
+ In your Gemfile, add this line:
28
+
29
+ gem "jquery-historyjs"
30
+
31
+ Then, run `bundle install`. To invoke the generator, run:
32
+
33
+ rails generate historyjs:install
34
+
35
+ You're done!
36
+
37
+ ## Credits
38
+
39
+ Thanks are due to the Rails Core Team without whom this gem wouldn't even be possible, and to André Arko for authoring the jquery-rails gem, upon which this gem is largely structured.
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ # require "spec/rake/spectask"
5
+ # desc "Run all examples"
6
+ # Spec::Rake::SpecTask.new(:spec) do |t|
7
+ # t.ruby_opts = ['-r test/unit']
8
+ # t.spec_opts = %w[--color]
9
+ # end
10
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/historyjs/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "jquery-historyjs"
6
+ s.version = Historyjs::Rails::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["William Weidendorf"]
9
+ s.email = ["wweidendorf@gmail.com"]
10
+ s.homepage = "http://github.com/wweidendorf/jquery-historyjs"
11
+ s.summary = "Use History.js with Rails 3 and jQuery"
12
+ s.description = "This gem provides History.js and the related HTML4 dependencies for using History.js with jQuery in your Rails 3+ application."
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "jquery-historyjs"
16
+
17
+ s.add_dependency "railties", "~> 3.0"
18
+ s.add_dependency "thor", "~> 0.14"
19
+ s.add_development_dependency "bundler", "~> 1.0.0"
20
+ s.add_development_dependency "rails", "~> 3.0"
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
24
+ s.require_path = 'lib'
25
+ end
@@ -0,0 +1,29 @@
1
+ require 'rails'
2
+
3
+ module Historyjs
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ desc "This generator installs HistoryJS #{Historyjs::Rails::HISTORYJS_VERSION}, JSON2, and Amplify Store #{Historyjs::Rails::AMPLIFY_STORE_VERSION}"
7
+ source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
8
+
9
+ def copy_historyjs
10
+ say_status("copying", "History.js (#{Historyjs::Rails::HISTORYJS_VERSION})", :green)
11
+
12
+ copy_file "history_core.js", "public/javascripts/history.js"
13
+ copy_file "history.html4.js", "public/javascripts/history.html4.js"
14
+ copy_file "history.adapter.jquery.js", "public/javascripts/history.adapter.jquery.js"
15
+ end
16
+
17
+ def copy_json2
18
+ say_status("copying", "JSON2 (#{Historyjs::Rails::JSON2_VERSION})", :green)
19
+ copy_file "json2.js", "public/javascripts/json2.js"
20
+ end
21
+
22
+ def copy_amplify_store
23
+ say_status("copying", "Amplify Store (#{Historyjs::Rails::AMPLIFY_STORE_VERSION[0..5]})", :green)
24
+ copy_file "amplify_store.js", "public/javascripts/amplify.store.js"
25
+ end
26
+
27
+ end
28
+ end
29
+ end if ::Rails.version < "3.1"
@@ -0,0 +1,10 @@
1
+ module Historyjs
2
+ module Rails
3
+ if ::Rails.version < "3.1"
4
+ require 'historyjs/rails/railtie'
5
+ else
6
+ require 'historyjs/rails/engine'
7
+ end
8
+ require 'historyjs/rails/version'
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # Configure Rails 3.1 to have assert_select_jquery() in tests
2
+ module Historyjs
3
+ module Rails
4
+
5
+ class Engine < ::Rails::Engine
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # Configure Rails 3.0 to use public/javascripts/jquery et al
2
+ module Historyjs
3
+ module Rails
4
+
5
+ class Railtie < ::Rails::Railtie
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Historyjs
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ HISTORYJS_VERSION = "1.7.0"
5
+ JSON2_VERSION = "8e0b15cb492f63067a88"
6
+ AMPLIFY_STORE_VERSION = "1.0beta"
7
+ end
8
+ end
@@ -0,0 +1 @@
1
+ require 'historyjs/rails'
@@ -0,0 +1,3 @@
1
+ require 'spec_helper'
2
+
3
+ it "should probably test something, but I'm damned if I know what"
@@ -0,0 +1,29 @@
1
+ # Set up RSpec
2
+ require 'webmock/rspec'
3
+
4
+ Spec::Runner.configure do |config|
5
+ config.include WebMock::API
6
+ end
7
+
8
+ # Set up generator tests
9
+ require 'rails/all'
10
+ require 'rails/generators'
11
+ require 'rails/generators/test_case'
12
+
13
+ class TestApp < Rails::Application
14
+ config.root = File.dirname(__FILE__)
15
+ end
16
+ Rails.application = TestApp
17
+
18
+ module Rails
19
+ def self.root
20
+ @root ||= File.expand_path("../../tmp/rails", __FILE__)
21
+ end
22
+ end
23
+ Rails.application.config.root = Rails.root
24
+
25
+ # Call configure to load the settings from
26
+ # Rails.application.config.generators to Rails::Generators
27
+ Rails::Generators.configure!
28
+
29
+
@@ -0,0 +1,251 @@
1
+ /*!
2
+ * Amplify Store - Persistent Client-Side Storage 1.0beta
3
+ *
4
+ * Copyright 2011 appendTo LLC. (http://appendto.com/team)
5
+ * Dual licensed under the MIT or GPL licenses.
6
+ * http://appendto.com/open-source-licenses
7
+ *
8
+ * http://amplifyjs.com
9
+ */
10
+ (function( amplify, undefined ) {
11
+
12
+ var store = amplify.store = function( key, value, options, type ) {
13
+ var type = store.type;
14
+ if ( options && options.type && options.type in store.types ) {
15
+ type = options.type;
16
+ }
17
+ return store.types[ type ]( key, value, options || {} );
18
+ };
19
+
20
+ store.types = {};
21
+ store.type = null;
22
+ store.addType = function( type, storage ) {
23
+ if ( !store.type ) {
24
+ store.type = type;
25
+ }
26
+
27
+ store.types[ type ] = storage;
28
+ store[ type ] = function( key, value, options ) {
29
+ options = options || {};
30
+ options.type = type;
31
+ return store( key, value, options );
32
+ };
33
+ }
34
+ store.error = function() {
35
+ return "amplify.store quota exceeded";
36
+ };
37
+
38
+ function createSimpleStorage( storageType, storage ) {
39
+ var values = storage.__amplify__ ? JSON.parse( storage.__amplify__ ) : {};
40
+ function remove( key ) {
41
+ if ( storage.removeItem ) {
42
+ storage.removeItem( key );
43
+ } else {
44
+ delete storage[ key ];
45
+ }
46
+ delete values[ key ];
47
+ }
48
+ store.addType( storageType, function( key, value, options ) {
49
+ var ret = value,
50
+ now = (new Date()).getTime(),
51
+ storedValue,
52
+ parsed;
53
+
54
+ if ( !key ) {
55
+ ret = {};
56
+ for ( key in values ) {
57
+ storedValue = storage[ key ];
58
+ parsed = storedValue ? JSON.parse( storedValue ) : { expires: -1 };
59
+ if ( parsed.expires && parsed.expires <= now ) {
60
+ remove( key );
61
+ } else {
62
+ ret[ key.replace( /^__amplify__/, "" ) ] = parsed.data;
63
+ }
64
+ }
65
+ storage.__amplify__ = JSON.stringify( values );
66
+ return ret;
67
+ }
68
+
69
+ // protect against overwriting built-in properties
70
+ key = "__amplify__" + key;
71
+
72
+ if ( value === undefined ) {
73
+ if ( values[ key ] ) {
74
+ storedValue = storage[ key ];
75
+ parsed = storedValue ? JSON.parse( storedValue ) : { expires: -1 };
76
+ if ( parsed.expires && parsed.expires <= now ) {
77
+ remove( key );
78
+ } else {
79
+ return parsed.data;
80
+ }
81
+ }
82
+ } else {
83
+ if ( value === null ) {
84
+ remove( key );
85
+ } else {
86
+ parsed = JSON.stringify({
87
+ data: value,
88
+ expires: options.expires ? now + options.expires : null
89
+ });
90
+ try {
91
+ storage[ key ] = parsed;
92
+ values[ key ] = true;
93
+ // quota exceeded
94
+ } catch( error ) {
95
+ // expire old data and try again
96
+ store[ storageType ]();
97
+ try {
98
+ storage[ key ] = parsed;
99
+ values[ key ] = true;
100
+ } catch( error ) {
101
+ throw store.error();
102
+ }
103
+ }
104
+ }
105
+ }
106
+
107
+ storage.__amplify__ = JSON.stringify( values );
108
+ return ret;
109
+ });
110
+ }
111
+
112
+ // localStorage + sessionStorage
113
+ // IE 8+, Firefox 3.5+, Safari 4+, Chrome 4+, Opera 10.5+, iPhone 2+, Android 2+
114
+ for ( var webStorageType in { localStorage: 1, sessionStorage: 1 } ) {
115
+ // try/catch for file protocol in Firefox
116
+ try {
117
+ if ( window[ webStorageType ].getItem ) {
118
+ createSimpleStorage( webStorageType, window[ webStorageType ] );
119
+ }
120
+ } catch( e ) {}
121
+ }
122
+
123
+ // globalStorage
124
+ // non-standard: Firefox 2+
125
+ // https://developer.mozilla.org/en/dom/storage#globalStorage
126
+ if ( window.globalStorage ) {
127
+ // try/catch for file protocol in Firefox
128
+ try {
129
+ createSimpleStorage( "globalStorage",
130
+ window.globalStorage[ window.location.hostname ] );
131
+ // Firefox 2.0 and 3.0 have sessionStorage and globalStorage
132
+ // make sure we defualt to globalStorage
133
+ // but don't default to globalStorage in 3.5+ which also has localStorage
134
+ if ( store.type === "sessionStorage" ) {
135
+ store.type = "globalStorage";
136
+ }
137
+ } catch( e ) {}
138
+ }
139
+
140
+ // userData
141
+ // non-standard: IE 5+
142
+ // http://msdn.microsoft.com/en-us/library/ms531424(v=vs.85).aspx
143
+ (function() {
144
+ // append to html instead of body so we can do this from the head
145
+ var div = document.createElement( "div" ),
146
+ attrKey = "amplify",
147
+ attrs;
148
+ div.style.display = "none";
149
+ document.getElementsByTagName( "head" )[ 0 ].appendChild( div );
150
+ if ( div.addBehavior ) {
151
+ div.addBehavior( "#default#userdata" );
152
+ div.load( attrKey );
153
+ attrs = div.getAttribute( attrKey ) ? JSON.parse( div.getAttribute( attrKey ) ) : {};
154
+
155
+ store.addType( "userData", function( key, value, options ) {
156
+ var ret = value,
157
+ now = (new Date()).getTime(),
158
+ attr,
159
+ parsed,
160
+ prevValue;
161
+
162
+ if ( !key ) {
163
+ ret = {};
164
+ for ( key in attrs ) {
165
+ attr = div.getAttribute( key );
166
+ parsed = attr ? JSON.parse( attr ) : { expires: -1 };
167
+ if ( parsed.expires && parsed.expires <= now ) {
168
+ div.removeAttribute( key );
169
+ delete attrs[ key ];
170
+ } else {
171
+ ret[ key ] = parsed.data;
172
+ }
173
+ }
174
+ div.setAttribute( attrKey, JSON.stringify( attrs ) );
175
+ div.save( attrKey );
176
+ return ret;
177
+ }
178
+
179
+ // convert invalid characters to dashes
180
+ // http://www.w3.org/TR/REC-xml/#NT-Name
181
+ // simplified to assume the starting character is valid
182
+ // also removed colon as it is invalid in HTML attribute names
183
+ key = key.replace( /[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g, "-" );
184
+
185
+ if ( value === undefined ) {
186
+ if ( key in attrs ) {
187
+ attr = div.getAttribute( key );
188
+ parsed = attr ? JSON.parse( attr ) : { expires: -1 };
189
+ if ( parsed.expires && parsed.expires <= now ) {
190
+ div.removeAttribute( key );
191
+ delete attrs[ key ];
192
+ } else {
193
+ return parsed.data;
194
+ }
195
+ }
196
+ } else {
197
+ if ( value === null ) {
198
+ div.removeAttribute( key );
199
+ delete attrs[ key ];
200
+ } else {
201
+ // we need to get the previous value in case we need to rollback
202
+ prevValue = div.getAttribute( key );
203
+ parsed = JSON.stringify({
204
+ data: value,
205
+ expires: (options.expires ? (now + options.expires) : null)
206
+ });
207
+ div.setAttribute( key, parsed );
208
+ attrs[ key ] = true;
209
+ }
210
+ }
211
+
212
+ div.setAttribute( attrKey, JSON.stringify( attrs ) );
213
+ try {
214
+ div.save( attrKey );
215
+ // quota exceeded
216
+ } catch ( error ) {
217
+ // roll the value back to the previous value
218
+ if ( prevValue === null ) {
219
+ div.removeAttribute( key );
220
+ delete attrs[ key ];
221
+ } else {
222
+ div.setAttribute( key, prevValue );
223
+ }
224
+
225
+ // expire old data and try again
226
+ store.userData();
227
+ try {
228
+ div.setAttribute( key, parsed );
229
+ attrs[ key ] = true;
230
+ div.save( attrKey );
231
+ } catch ( error ) {
232
+ // roll the value back to the previous value
233
+ if ( prevValue === null ) {
234
+ div.removeAttribute( key );
235
+ delete attrs[ key ];
236
+ } else {
237
+ div.setAttribute( key, prevValue );
238
+ }
239
+ throw store.error();
240
+ }
241
+ }
242
+ return ret;
243
+ });
244
+ }
245
+ }() );
246
+
247
+ // in-memory storage
248
+ // fallback for all browsers to enable the API even if we can't persist data
249
+ createSimpleStorage( "memory", {} );
250
+
251
+ }( this.amplify = this.amplify || {} ) );