rails-async 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +31 -7
- data/ROADMAP.md +0 -0
- data/Rakefile +17 -33
- data/app/controllers/async_controller.rb +1 -2
- data/app/helpers/async_helper.rb +8 -16
- data/app/models/async_cache.rb +37 -11
- data/init.rb +1 -0
- data/lib/async/engine.rb +0 -1
- data/lib/async/version.rb +3 -0
- data/rails-async.gemspec +90 -49
- data/test/helper.rb +11 -8
- data/test/rails_root/Gemfile +8 -0
- data/test/rails_root/README +256 -0
- data/test/rails_root/Rakefile +7 -0
- data/test/rails_root/app/controllers/application_controller.rb +8 -0
- data/test/rails_root/app/controllers/start_controller.rb +19 -0
- data/test/rails_root/app/helpers/application_helper.rb +2 -0
- data/test/rails_root/app/helpers/start_helper.rb +2 -0
- data/test/rails_root/app/views/layouts/application.html.erb +14 -0
- data/test/rails_root/app/views/start/_account.html.erb +1 -0
- data/test/rails_root/app/views/start/fast.html.erb +10 -0
- data/test/rails_root/app/views/start/fast_multi.html.erb +27 -0
- data/test/rails_root/app/views/start/index.html.erb +4 -0
- data/test/rails_root/app/views/start/slow.html.erb +8 -0
- data/test/rails_root/config.ru +4 -0
- data/test/rails_root/config/application.rb +42 -0
- data/test/rails_root/config/boot.rb +20 -0
- data/test/rails_root/config/database.yml +22 -0
- data/test/rails_root/config/environment.rb +5 -0
- data/test/rails_root/config/environments/development.rb +26 -0
- data/test/rails_root/config/environments/production.rb +49 -0
- data/test/rails_root/config/environments/test.rb +35 -0
- data/test/rails_root/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_root/config/initializers/inflections.rb +10 -0
- data/test/rails_root/config/initializers/mime_types.rb +5 -0
- data/test/rails_root/config/initializers/secret_token.rb +7 -0
- data/test/rails_root/config/initializers/session_store.rb +8 -0
- data/test/rails_root/config/locales/en.yml +5 -0
- data/test/rails_root/config/routes.rb +63 -0
- data/test/rails_root/db/schema.rb +15 -0
- data/test/rails_root/doc/README_FOR_APP +2 -0
- data/test/rails_root/public/404.html +26 -0
- data/test/rails_root/public/422.html +26 -0
- data/test/rails_root/public/500.html +26 -0
- data/test/rails_root/public/favicon.ico +0 -0
- data/test/rails_root/public/images/rails.png +0 -0
- data/test/rails_root/public/images/spinner.gif +0 -0
- data/test/rails_root/public/javascripts/jquery.js +6883 -0
- data/test/rails_root/public/javascripts/rails.js +132 -0
- data/test/rails_root/public/robots.txt +5 -0
- data/test/rails_root/script/rails +6 -0
- data/test/rails_root/test/functional/start_controller_test.rb +19 -0
- data/test/rails_root/test/performance/browsing_test.rb +9 -0
- data/test/rails_root/test/test_helper.rb +15 -0
- data/test/rails_root/test/unit/helpers/start_helper_test.rb +4 -0
- data/test/test_async_cache.rb +16 -0
- metadata +110 -33
- data/.document +0 -5
- data/.gitignore +0 -21
- data/README.rdoc +0 -17
- data/VERSION +0 -1
- data/test/test_async-rails.rb +0 -7
@@ -0,0 +1,132 @@
|
|
1
|
+
jQuery(function ($) {
|
2
|
+
var csrf_token = $('meta[name=csrf-token]').attr('content'),
|
3
|
+
csrf_param = $('meta[name=csrf-param]').attr('content');
|
4
|
+
|
5
|
+
$.fn.extend({
|
6
|
+
/**
|
7
|
+
* Triggers a custom event on an element and returns the event result
|
8
|
+
* this is used to get around not being able to ensure callbacks are placed
|
9
|
+
* at the end of the chain.
|
10
|
+
*
|
11
|
+
* TODO: deprecate with jQuery 1.4.2 release, in favor of subscribing to our
|
12
|
+
* own events and placing ourselves at the end of the chain.
|
13
|
+
*/
|
14
|
+
triggerAndReturn: function (name, data) {
|
15
|
+
var event = new $.Event(name);
|
16
|
+
this.trigger(event, data);
|
17
|
+
|
18
|
+
return event.result !== false;
|
19
|
+
},
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Handles execution of remote calls firing overridable events along the way
|
23
|
+
*/
|
24
|
+
callRemote: function () {
|
25
|
+
var el = this,
|
26
|
+
method = el.attr('method') || el.attr('data-method') || 'GET',
|
27
|
+
url = el.attr('action') || el.attr('href'),
|
28
|
+
dataType = el.attr('data-type') || 'script';
|
29
|
+
|
30
|
+
if (url === undefined) {
|
31
|
+
throw "No URL specified for remote call (action or href must be present).";
|
32
|
+
} else {
|
33
|
+
if (el.triggerAndReturn('ajax:before')) {
|
34
|
+
var data = el.is('form') ? el.serializeArray() : [];
|
35
|
+
$.ajax({
|
36
|
+
url: url,
|
37
|
+
data: data,
|
38
|
+
dataType: dataType,
|
39
|
+
type: method.toUpperCase(),
|
40
|
+
beforeSend: function (xhr) {
|
41
|
+
el.trigger('ajax:loading', xhr);
|
42
|
+
},
|
43
|
+
success: function (data, status, xhr) {
|
44
|
+
el.trigger('ajax:success', [data, status, xhr]);
|
45
|
+
},
|
46
|
+
complete: function (xhr) {
|
47
|
+
el.trigger('ajax:complete', xhr);
|
48
|
+
},
|
49
|
+
error: function (xhr, status, error) {
|
50
|
+
el.trigger('ajax:failure', [xhr, status, error]);
|
51
|
+
}
|
52
|
+
});
|
53
|
+
}
|
54
|
+
|
55
|
+
el.trigger('ajax:after');
|
56
|
+
}
|
57
|
+
}
|
58
|
+
});
|
59
|
+
|
60
|
+
/**
|
61
|
+
* confirmation handler
|
62
|
+
*/
|
63
|
+
$('a[data-confirm],input[data-confirm]').live('click', function () {
|
64
|
+
var el = $(this);
|
65
|
+
if (el.triggerAndReturn('confirm')) {
|
66
|
+
if (!confirm(el.attr('data-confirm'))) {
|
67
|
+
return false;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
});
|
71
|
+
|
72
|
+
|
73
|
+
/**
|
74
|
+
* remote handlers
|
75
|
+
*/
|
76
|
+
$('form[data-remote]').live('submit', function (e) {
|
77
|
+
$(this).callRemote();
|
78
|
+
e.preventDefault();
|
79
|
+
});
|
80
|
+
|
81
|
+
$('a[data-remote],input[data-remote]').live('click', function (e) {
|
82
|
+
$(this).callRemote();
|
83
|
+
e.preventDefault();
|
84
|
+
});
|
85
|
+
|
86
|
+
$('a[data-method]:not([data-remote])').live('click', function (e){
|
87
|
+
var link = $(this),
|
88
|
+
href = link.attr('href'),
|
89
|
+
method = link.attr('data-method'),
|
90
|
+
form = $('<form method="post" action="'+href+'"></form>'),
|
91
|
+
metadata_input = '<input name="_method" value="'+method+'" type="hidden" />';
|
92
|
+
|
93
|
+
if (csrf_param != null && csrf_token != null) {
|
94
|
+
metadata_input += '<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />';
|
95
|
+
}
|
96
|
+
|
97
|
+
form.hide()
|
98
|
+
.append(metadata_input)
|
99
|
+
.appendTo('body');
|
100
|
+
|
101
|
+
e.preventDefault();
|
102
|
+
form.submit();
|
103
|
+
});
|
104
|
+
|
105
|
+
/**
|
106
|
+
* disable-with handlers
|
107
|
+
*/
|
108
|
+
var disable_with_input_selector = 'input[data-disable-with]';
|
109
|
+
var disable_with_form_remote_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')';
|
110
|
+
var disable_with_form_not_remote_selector = 'form:not([data-remote]):has(' + disable_with_input_selector + ')';
|
111
|
+
|
112
|
+
var disable_with_input_function = function () {
|
113
|
+
$(this).find(disable_with_input_selector).each(function () {
|
114
|
+
var input = $(this);
|
115
|
+
input.data('enable-with', input.val())
|
116
|
+
.attr('value', input.attr('data-disable-with'))
|
117
|
+
.attr('disabled', 'disabled');
|
118
|
+
});
|
119
|
+
};
|
120
|
+
|
121
|
+
$(disable_with_form_remote_selector).live('ajax:before', disable_with_input_function);
|
122
|
+
$(disable_with_form_not_remote_selector).live('submit', disable_with_input_function);
|
123
|
+
|
124
|
+
$(disable_with_form_remote_selector).live('ajax:complete', function () {
|
125
|
+
$(this).find(disable_with_input_selector).each(function () {
|
126
|
+
var input = $(this);
|
127
|
+
input.removeAttr('disabled')
|
128
|
+
.val(input.data('enable-with'));
|
129
|
+
});
|
130
|
+
});
|
131
|
+
|
132
|
+
});
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class StartControllerTest < ActionController::TestCase
|
4
|
+
test "should get slow" do
|
5
|
+
get :slow
|
6
|
+
assert_response :success
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should get fast" do
|
10
|
+
get :fast
|
11
|
+
assert_response :success
|
12
|
+
end
|
13
|
+
|
14
|
+
test "should get index" do
|
15
|
+
get :index
|
16
|
+
assert_response :success
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
require 'minitest/unit'
|
6
|
+
|
7
|
+
class ActiveSupport::TestCase
|
8
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
9
|
+
#
|
10
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
11
|
+
# -- they do not yet inherit this setting
|
12
|
+
fixtures :all
|
13
|
+
|
14
|
+
# Add more helper methods to be used by all tests here...
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'helper'
|
2
|
+
MiniTest::Unit.autorun
|
3
|
+
|
4
|
+
describe AsyncCache do
|
5
|
+
before do
|
6
|
+
@async_cache = AsyncCache.instance
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when blocks are added" do
|
10
|
+
it "should increment counter" do
|
11
|
+
@async_cache.counter.must_equal 0
|
12
|
+
@async_cache.schedule { puts "hello world" }
|
13
|
+
@async_cache.counter.must_equal 1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-async
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Adam Bachman
|
@@ -14,56 +15,86 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-11-04 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
21
|
-
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
|
-
requirements:
|
26
|
-
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
31
|
-
type: :development
|
32
|
-
version_requirements: *id001
|
33
|
-
description: Don't wait for your pages to render.
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: The Rails Async engine lets your controllers respond instantly.
|
34
23
|
email: adam.bachman@gmail.com
|
35
24
|
executables: []
|
36
25
|
|
37
26
|
extensions: []
|
38
27
|
|
39
|
-
extra_rdoc_files:
|
40
|
-
|
41
|
-
- README.md
|
42
|
-
- README.rdoc
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
43
30
|
files:
|
44
|
-
- .
|
45
|
-
- .
|
31
|
+
- CHANGELOG.md
|
32
|
+
- init.rb
|
46
33
|
- LICENSE
|
47
|
-
- README.
|
34
|
+
- README.md
|
35
|
+
- ROADMAP.md
|
48
36
|
- Rakefile
|
49
|
-
- VERSION
|
50
37
|
- app/controllers/async_controller.rb
|
51
38
|
- app/helpers/async_helper.rb
|
52
39
|
- app/models/async_cache.rb
|
53
40
|
- config/routes.rb
|
54
|
-
- lib/async.rb
|
55
41
|
- lib/async/engine.rb
|
42
|
+
- lib/async/version.rb
|
43
|
+
- lib/async.rb
|
56
44
|
- rails-async.gemspec
|
57
45
|
- test/helper.rb
|
58
|
-
- test/
|
59
|
-
-
|
46
|
+
- test/test_async_cache.rb
|
47
|
+
- test/rails_root/Gemfile
|
48
|
+
- test/rails_root/README
|
49
|
+
- test/rails_root/Rakefile
|
50
|
+
- test/rails_root/app/controllers/application_controller.rb
|
51
|
+
- test/rails_root/app/controllers/start_controller.rb
|
52
|
+
- test/rails_root/app/helpers/application_helper.rb
|
53
|
+
- test/rails_root/app/helpers/start_helper.rb
|
54
|
+
- test/rails_root/app/views/layouts/application.html.erb
|
55
|
+
- test/rails_root/app/views/start/_account.html.erb
|
56
|
+
- test/rails_root/app/views/start/fast.html.erb
|
57
|
+
- test/rails_root/app/views/start/fast_multi.html.erb
|
58
|
+
- test/rails_root/app/views/start/index.html.erb
|
59
|
+
- test/rails_root/app/views/start/slow.html.erb
|
60
|
+
- test/rails_root/config.ru
|
61
|
+
- test/rails_root/config/application.rb
|
62
|
+
- test/rails_root/config/boot.rb
|
63
|
+
- test/rails_root/config/database.yml
|
64
|
+
- test/rails_root/config/environment.rb
|
65
|
+
- test/rails_root/config/environments/development.rb
|
66
|
+
- test/rails_root/config/environments/production.rb
|
67
|
+
- test/rails_root/config/environments/test.rb
|
68
|
+
- test/rails_root/config/initializers/backtrace_silencers.rb
|
69
|
+
- test/rails_root/config/initializers/inflections.rb
|
70
|
+
- test/rails_root/config/initializers/mime_types.rb
|
71
|
+
- test/rails_root/config/initializers/secret_token.rb
|
72
|
+
- test/rails_root/config/initializers/session_store.rb
|
73
|
+
- test/rails_root/config/locales/en.yml
|
74
|
+
- test/rails_root/config/routes.rb
|
75
|
+
- test/rails_root/db/schema.rb
|
76
|
+
- test/rails_root/doc/README_FOR_APP
|
77
|
+
- test/rails_root/public/404.html
|
78
|
+
- test/rails_root/public/422.html
|
79
|
+
- test/rails_root/public/500.html
|
80
|
+
- test/rails_root/public/favicon.ico
|
81
|
+
- test/rails_root/public/images/rails.png
|
82
|
+
- test/rails_root/public/images/spinner.gif
|
83
|
+
- test/rails_root/public/javascripts/jquery.js
|
84
|
+
- test/rails_root/public/javascripts/rails.js
|
85
|
+
- test/rails_root/public/robots.txt
|
86
|
+
- test/rails_root/script/rails
|
87
|
+
- test/rails_root/test/functional/start_controller_test.rb
|
88
|
+
- test/rails_root/test/performance/browsing_test.rb
|
89
|
+
- test/rails_root/test/test_helper.rb
|
90
|
+
- test/rails_root/test/unit/helpers/start_helper_test.rb
|
60
91
|
has_rdoc: true
|
61
92
|
homepage: http://github.com/abachman/rails-async
|
62
93
|
licenses: []
|
63
94
|
|
64
95
|
post_install_message:
|
65
|
-
rdoc_options:
|
66
|
-
|
96
|
+
rdoc_options: []
|
97
|
+
|
67
98
|
require_paths:
|
68
99
|
- lib
|
69
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -71,6 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
102
|
requirements:
|
72
103
|
- - ">="
|
73
104
|
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
74
106
|
segments:
|
75
107
|
- 0
|
76
108
|
version: "0"
|
@@ -79,6 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
111
|
requirements:
|
80
112
|
- - ">="
|
81
113
|
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
82
115
|
segments:
|
83
116
|
- 0
|
84
117
|
version: "0"
|
@@ -88,7 +121,51 @@ rubyforge_project:
|
|
88
121
|
rubygems_version: 1.3.7
|
89
122
|
signing_key:
|
90
123
|
specification_version: 3
|
91
|
-
summary: Simple
|
124
|
+
summary: Simple asynchronously loaded blocks in your Rails 3 views.
|
92
125
|
test_files:
|
93
126
|
- test/helper.rb
|
94
|
-
- test/
|
127
|
+
- test/test_async_cache.rb
|
128
|
+
- test/rails_root/Gemfile
|
129
|
+
- test/rails_root/README
|
130
|
+
- test/rails_root/Rakefile
|
131
|
+
- test/rails_root/app/controllers/application_controller.rb
|
132
|
+
- test/rails_root/app/controllers/start_controller.rb
|
133
|
+
- test/rails_root/app/helpers/application_helper.rb
|
134
|
+
- test/rails_root/app/helpers/start_helper.rb
|
135
|
+
- test/rails_root/app/views/layouts/application.html.erb
|
136
|
+
- test/rails_root/app/views/start/_account.html.erb
|
137
|
+
- test/rails_root/app/views/start/fast.html.erb
|
138
|
+
- test/rails_root/app/views/start/fast_multi.html.erb
|
139
|
+
- test/rails_root/app/views/start/index.html.erb
|
140
|
+
- test/rails_root/app/views/start/slow.html.erb
|
141
|
+
- test/rails_root/config.ru
|
142
|
+
- test/rails_root/config/application.rb
|
143
|
+
- test/rails_root/config/boot.rb
|
144
|
+
- test/rails_root/config/database.yml
|
145
|
+
- test/rails_root/config/environment.rb
|
146
|
+
- test/rails_root/config/environments/development.rb
|
147
|
+
- test/rails_root/config/environments/production.rb
|
148
|
+
- test/rails_root/config/environments/test.rb
|
149
|
+
- test/rails_root/config/initializers/backtrace_silencers.rb
|
150
|
+
- test/rails_root/config/initializers/inflections.rb
|
151
|
+
- test/rails_root/config/initializers/mime_types.rb
|
152
|
+
- test/rails_root/config/initializers/secret_token.rb
|
153
|
+
- test/rails_root/config/initializers/session_store.rb
|
154
|
+
- test/rails_root/config/locales/en.yml
|
155
|
+
- test/rails_root/config/routes.rb
|
156
|
+
- test/rails_root/db/schema.rb
|
157
|
+
- test/rails_root/doc/README_FOR_APP
|
158
|
+
- test/rails_root/public/404.html
|
159
|
+
- test/rails_root/public/422.html
|
160
|
+
- test/rails_root/public/500.html
|
161
|
+
- test/rails_root/public/favicon.ico
|
162
|
+
- test/rails_root/public/images/rails.png
|
163
|
+
- test/rails_root/public/images/spinner.gif
|
164
|
+
- test/rails_root/public/javascripts/jquery.js
|
165
|
+
- test/rails_root/public/javascripts/rails.js
|
166
|
+
- test/rails_root/public/robots.txt
|
167
|
+
- test/rails_root/script/rails
|
168
|
+
- test/rails_root/test/functional/start_controller_test.rb
|
169
|
+
- test/rails_root/test/performance/browsing_test.rb
|
170
|
+
- test/rails_root/test/test_helper.rb
|
171
|
+
- test/rails_root/test/unit/helpers/start_helper_test.rb
|
data/.document
DELETED
data/.gitignore
DELETED
data/README.rdoc
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
= async-rails
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Note on Patches/Pull Requests
|
6
|
-
|
7
|
-
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
-
* Send me a pull request. Bonus points for topic branches.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2010 Adam Bachman. See LICENSE for details.
|