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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05b33d7cc946a1aaa2f9a5277644700d402ceade
4
- data.tar.gz: ed4585c29a78e0aadff71aa550de05eee220e1dd
3
+ metadata.gz: e33c4aeca28f67ea7b66ce8983a1fb38b31e5c50
4
+ data.tar.gz: dca13bfccced618784302aba09a4a66cebf88d24
5
5
  SHA512:
6
- metadata.gz: adc9d0fcaa58363020f6c320c2f2b96ca3ea7116558057373495c10365000d41152e95955b7a605ae6c27d658c4f93b986cae33f5418b5ca00a399bcbd4996a1
7
- data.tar.gz: d2ba335efade55bf37327857c55d3b194353adc1d350789de294cd732e65cf0d11c5503e33aa5cf25ec7fc4fe3b65c82ce78ed250ec6547649d2ac9f748d15a4
6
+ metadata.gz: 339cde6898cca5b9441175062f38c68698fc6d31b959774e858efb86950eb05ce0f48048e7b188e24b0dd3e1b1820401c6746cd213d534d49ce69d8ac495560d
7
+ data.tar.gz: fff2c86b83649ddc85f5f4f233b60d19150e5800cdf6785375854e7e0773fb3d3976ce9e0fd335314ab715a17fd74673754c7409e6eec94322a22d88ff176c43
@@ -2,7 +2,7 @@
2
2
 
3
3
  Solve template dispatch on ajax request
4
4
 
5
- {<img src="https://travis-ci.org/jalkoby/rjax.png?branch=master" alt="Build Status" />}[https://travis-ci.org/jalkoby/rjax]
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 action which serve http and ajax request. It might looks like:
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 replace it with single method call
35
-
36
- def index
37
- @users = User.all
38
- rjax
39
- end
40
- # render index_rjax template
41
-
42
- def index
43
- @users = User.all
44
- rjax @users
45
- end
46
- # render _user_rjax or _user partial with variable `user`
47
-
48
- def index
49
- @users = User.all
50
- rjax :users => @users, :other => :variable
51
- end
52
- # render _users_rjax or _users partial with variables users & other
53
-
54
- def show
55
- @user = User.find(params[:id])
56
- rjax @user
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
- The name of partial is based on controller name. If you don't like rjax suffix or it's out your team's convention
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_%action_name%_suffix
88
+ prefix_%template%_suffix
70
89
 
71
- _prefix_%partial_name%_suffix
90
+ _prefix_%partial%_suffix
72
91
 
73
92
  == Contributing
74
93
 
@@ -18,7 +18,8 @@ class Rjax::Resolver < Struct.new(:options, :controller)
18
18
  private
19
19
 
20
20
  def general_partial
21
- { :partial => partial_name(:multi), :locals => options, :layout => false }
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
@@ -1,3 +1,3 @@
1
1
  module Rjax
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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
- rjax "Monday"
67
+ respond_with do |format|
68
+ format.html { rjax "Monday" }
69
+ end
62
70
  end
63
71
  end
@@ -0,0 +1 @@
1
+ <%= articles.join(', ') %>
@@ -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.0
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-02 00:00:00.000000000 Z
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