rjax 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +49 -30
- data/lib/rjax/resolver.rb +2 -1
- data/lib/rjax/version.rb +1 -1
- data/spec/dummy/application.rb +10 -2
- data/spec/dummy/articles/_popular.erb +1 -0
- data/spec/rjax/rjax_spec.rb +7 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e33c4aeca28f67ea7b66ce8983a1fb38b31e5c50
|
4
|
+
data.tar.gz: dca13bfccced618784302aba09a4a66cebf88d24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 339cde6898cca5b9441175062f38c68698fc6d31b959774e858efb86950eb05ce0f48048e7b188e24b0dd3e1b1820401c6746cd213d534d49ce69d8ac495560d
|
7
|
+
data.tar.gz: fff2c86b83649ddc85f5f4f233b60d19150e5800cdf6785375854e7e0773fb3d3976ce9e0fd335314ab715a17fd74673754c7409e6eec94322a22d88ff176c43
|
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Solve template dispatch on ajax request
|
4
4
|
|
5
|
-
{<img src="https://
|
5
|
+
{<img src="https://codeclimate.com/github/jalkoby/rjax.png" />}[https://codeclimate.com/github/jalkoby/rjax]
|
6
6
|
{<img src="https://travis-ci.org/jalkoby/rjax.png?branch=master" alt="Build Status" />}[https://travis-ci.org/jalkoby/rjax]
|
7
7
|
{<img src="https://badge.fury.io/rb/rjax.png" alt="Gem Version" />}[http://badge.fury.io/rb/rjax]
|
8
8
|
|
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
== Usage
|
24
24
|
|
25
|
-
Rjax will be useful if you have a lot
|
25
|
+
Rjax will be useful if you have a lot actions which serve http and ajax requests. It might looks like:
|
26
26
|
|
27
27
|
def index
|
28
28
|
@users = User.all
|
@@ -31,34 +31,53 @@ Rjax will be useful if you have a lot action which serve http and ajax request.
|
|
31
31
|
render :index_ajax if request.xhr?
|
32
32
|
end
|
33
33
|
|
34
|
-
Rjax
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
34
|
+
Rjax adds `rjax` methods in rails controllers.
|
35
|
+
|
36
|
+
class UsersController < ApplicationController
|
37
|
+
def index
|
38
|
+
@users = User.all
|
39
|
+
rjax
|
40
|
+
end
|
41
|
+
# calling rjax method without arguments will render template;
|
42
|
+
# the name of template will contain action_name and wrapper;
|
43
|
+
# in this case expected `index_rjax` template;
|
44
|
+
|
45
|
+
def index
|
46
|
+
@users = User.all
|
47
|
+
rjax @users
|
48
|
+
end
|
49
|
+
# calling rjax method is similar to view helper render %collection%;
|
50
|
+
# the only different is also looks for partial with wrapped name;
|
51
|
+
# in this case it will look for partial `_user_rjax` or `_user` and pass variable `user`;
|
52
|
+
|
53
|
+
def index
|
54
|
+
@users = User.all
|
55
|
+
rjax :users => @users, :other => :variable
|
56
|
+
end
|
57
|
+
# calling rjax method with Hash will render partial with locals specified in hash;
|
58
|
+
# the name of partial might be specified in :partial key;
|
59
|
+
# if :partial key is missed expected that view folder contains partial with plural form of controller with or without wrapper;
|
60
|
+
# in this case it will be `_users_rjax` or `_users` partial
|
61
|
+
|
62
|
+
def show
|
63
|
+
@user = User.find(params[:id])
|
64
|
+
rjax @user
|
65
|
+
end
|
66
|
+
# in other cases rjax will render partial and pass this variable into partial;
|
67
|
+
# the name of partial will be singular form of controller with or without wrapper;
|
68
|
+
# in this case it will be `_user_rjax` or `_user` partial
|
69
|
+
|
70
|
+
# it also support respond_with
|
71
|
+
def index
|
72
|
+
respond_with do |format|
|
73
|
+
format.html { rjax }
|
74
|
+
format.json { rjax }
|
75
|
+
format.xml { rjax }
|
76
|
+
end
|
77
|
+
end
|
57
78
|
end
|
58
|
-
# render _user_rjax or _user partial with `user` variable
|
59
79
|
|
60
|
-
|
61
|
-
feel free to configure wrapper:
|
80
|
+
If you don't like rjax default wrapper you can configure it:
|
62
81
|
|
63
82
|
# config/initializers/rjax.rb
|
64
83
|
Rjax.config do |config|
|
@@ -66,9 +85,9 @@ feel free to configure wrapper:
|
|
66
85
|
config.prefix = "prefix"
|
67
86
|
end
|
68
87
|
|
69
|
-
prefix_%
|
88
|
+
prefix_%template%_suffix
|
70
89
|
|
71
|
-
_prefix_%
|
90
|
+
_prefix_%partial%_suffix
|
72
91
|
|
73
92
|
== Contributing
|
74
93
|
|
data/lib/rjax/resolver.rb
CHANGED
@@ -18,7 +18,8 @@ class Rjax::Resolver < Struct.new(:options, :controller)
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def general_partial
|
21
|
-
|
21
|
+
partial = options.has_key?(:partial) ? options.delete(:partial) : partial_name(:multi)
|
22
|
+
{ :partial => partial, :locals => options, :layout => false }
|
22
23
|
end
|
23
24
|
|
24
25
|
def collection_partial
|
data/lib/rjax/version.rb
CHANGED
data/spec/dummy/application.rb
CHANGED
@@ -20,7 +20,7 @@ class Dummy < Rails::Application
|
|
20
20
|
get :search, :popular, :on => :collection
|
21
21
|
end
|
22
22
|
resources :articles, :only => [:index, :show] do
|
23
|
-
get :search, :on => :collection
|
23
|
+
get :search, :popular, :on => :collection
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -49,6 +49,8 @@ class UsersController < BaseController
|
|
49
49
|
end
|
50
50
|
|
51
51
|
class ArticlesController < BaseController
|
52
|
+
respond_to :html
|
53
|
+
|
52
54
|
def index
|
53
55
|
rjax %w(Monday Tuesday Sunday)
|
54
56
|
end
|
@@ -57,7 +59,13 @@ class ArticlesController < BaseController
|
|
57
59
|
rjax :articles => %w(Monday Sunday)
|
58
60
|
end
|
59
61
|
|
62
|
+
def popular
|
63
|
+
rjax :articles => %w(Friday Saturday), :partial => 'popular'
|
64
|
+
end
|
65
|
+
|
60
66
|
def show
|
61
|
-
|
67
|
+
respond_with do |format|
|
68
|
+
format.html { rjax "Monday" }
|
69
|
+
end
|
62
70
|
end
|
63
71
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= articles.join(', ') %>
|
data/spec/rjax/rjax_spec.rb
CHANGED
@@ -40,6 +40,12 @@ describe Rjax, :type => :request do
|
|
40
40
|
body.should == "Monday, Sunday"
|
41
41
|
end
|
42
42
|
|
43
|
+
it 'use custom partial' do
|
44
|
+
ajax '/articles/popular'
|
45
|
+
|
46
|
+
body.should == "Friday, Saturday"
|
47
|
+
end
|
48
|
+
|
43
49
|
it 'collection instance partial' do
|
44
50
|
ajax '/articles/1'
|
45
51
|
|
@@ -56,6 +62,6 @@ describe Rjax, :type => :request do
|
|
56
62
|
end
|
57
63
|
|
58
64
|
def ajax(path)
|
59
|
-
get path, {}, { "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest", 'HTTP_ACCEPT' => '*/*' }
|
65
|
+
get path, { :format => :html }, { "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest", 'HTTP_ACCEPT' => '*/*' }
|
60
66
|
end
|
61
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rjax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Pchelincev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- spec/dummy/application.rb
|
106
106
|
- spec/dummy/articles/_article.erb
|
107
107
|
- spec/dummy/articles/_articles.erb
|
108
|
+
- spec/dummy/articles/_popular.erb
|
108
109
|
- spec/dummy/layouts/rjax.erb
|
109
110
|
- spec/dummy/users/_user_rjax.erb
|
110
111
|
- spec/dummy/users/_users_rjax.erb
|
@@ -140,6 +141,7 @@ test_files:
|
|
140
141
|
- spec/dummy/application.rb
|
141
142
|
- spec/dummy/articles/_article.erb
|
142
143
|
- spec/dummy/articles/_articles.erb
|
144
|
+
- spec/dummy/articles/_popular.erb
|
143
145
|
- spec/dummy/layouts/rjax.erb
|
144
146
|
- spec/dummy/users/_user_rjax.erb
|
145
147
|
- spec/dummy/users/_users_rjax.erb
|