ninsho 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -123,9 +123,11 @@ en:
123
123
 
124
124
  ### Changelog
125
125
 
126
- * Current gem version 0.0.2
126
+ * Current gem version 0.0.3
127
127
  * Add more documentation on code
128
128
  * Add aouth token for Facebook friends
129
+ * Add handy helpers
130
+ * Released gem version 0.0.2
129
131
  * Released gem version 0.0.1
130
132
 
131
133
  ### Devs
@@ -137,7 +139,6 @@ en:
137
139
  * Add more flexibility to handle authentications and save multiple to fields
138
140
  * Add tests
139
141
  * Support for Mongoid
140
- * Add handy helpers
141
142
 
142
143
 
143
144
  ## Credits
@@ -1,9 +1,13 @@
1
1
  class NinshoController < Ninsho.parent_controller.constantize
2
2
 
3
- helpers = %w(resource resource_name resource_class resource_params)
4
- hide_action *helpers
5
- helper_method *helpers
6
-
3
+ # Sets the flash message with :key, using I18n.
4
+ # Example (i18n locale file):
5
+ #
6
+ # en:
7
+ # ninsho:
8
+ # :sessions
9
+ # signed_in: "Signed in successfully"
10
+ #
7
11
  def flash_message(key, action)
8
12
  message = I18n.t("ninsho.sessions.#{action}")
9
13
  flash[key] = message if message.present?
@@ -44,4 +48,5 @@ class NinshoController < Ninsho.parent_controller.constantize
44
48
  def build_resource_from_omniauth
45
49
  self.resource = resource_class.from_omniauth(resource_params)
46
50
  end
51
+
47
52
  end
@@ -57,11 +57,10 @@ module Ninsho
57
57
  def authenticate_#{PARENT_RESOURCE_NAME}!
58
58
  deny_access unless #{PARENT_RESOURCE_NAME}_signed_in?
59
59
  end
60
-
61
60
  METHODS
62
61
 
63
- define_method "link_#{RESOURCE_NAME}_with" do |provider|
64
- link_to "Connect with #{provider.to_s.capitalize}", "auth/#{provider.to_s}"
62
+ ActiveSupport.on_load(:action_controller) do
63
+ helper_method "current_#{PARENT_RESOURCE_NAME}", "#{PARENT_RESOURCE_NAME}_signed_in?"
65
64
  end
66
65
 
67
66
 
@@ -1,3 +1,3 @@
1
1
  module Ninsho
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ninsho
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-15 00:00:00.000000000 Z
12
+ date: 2013-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: orm_adapter
@@ -73,7 +73,6 @@ files:
73
73
  - Rakefile
74
74
  - app/controllers/ninsho/sessions_controller.rb
75
75
  - app/controllers/ninsho_controller.rb
76
- - app/helpers/ninsho_helper.rb
77
76
  - app/views/ninsho/sessions/new.html.erb
78
77
  - config/locales/en.yml
79
78
  - lib/generators/active_record/ninsho_generator.rb
@@ -1,74 +0,0 @@
1
- module NinshoHelper
2
-
3
- RESOURCE_NAME = Ninsho.resource_name.singularize
4
- PARENT_RESOURCE_NAME = Ninsho.parent_resource_name.to_s.downcase
5
-
6
- def store_location
7
- session[:return_to] = request.fullpath
8
- end
9
-
10
- def clear_return_to
11
- session[:return_to] = nil
12
- end
13
-
14
- def redirect_back_or(default)
15
- redirect_to(session[:return_to] || default )
16
- clear_return_to
17
- end
18
-
19
- def after_sign_in_path_for
20
- redirect_back_or redirect_to_root
21
- end
22
-
23
- def sign_out
24
- session["#{PARENT_RESOURCE_NAME}_id".to_sym] = nil
25
- end
26
-
27
- def sign_in_and_redirect(parent_id, path=nil)
28
- session["#{PARENT_RESOURCE_NAME}_id".to_sym] = parent_id
29
- redirect_to path
30
- end
31
-
32
- def sign_in(parent_id)
33
- session["#{PARENT_RESOURCE_NAME}_id".to_sym] = parent_id
34
- end
35
-
36
- class_eval <<-METHODS, __FILE__, __LINE__ + 1
37
- def current_#{PARENT_RESOURCE_NAME}
38
- @current_#{PARENT_RESOURCE_NAME} ||= #{Ninsho.parent_resource_name}.find(session[:#{PARENT_RESOURCE_NAME}_id]) if session[:#{PARENT_RESOURCE_NAME}_id]
39
- end
40
-
41
- def #{PARENT_RESOURCE_NAME}_signed_in?
42
- current_#{PARENT_RESOURCE_NAME}.present?
43
- end
44
-
45
- def authenticate_#{PARENT_RESOURCE_NAME}!
46
- deny_access unless #{PARENT_RESOURCE_NAME}_signed_in?
47
- end
48
-
49
- METHODS
50
-
51
- define_method "link_#{RESOURCE_NAME}_with" do |provider|
52
- link_to "Connect with #{provider.to_s.capitalize}", "auth/#{provider.to_s}"
53
- end
54
-
55
-
56
- # Method used by sessions controller to sign out a user.
57
- # You can overwrite it in your ApplicationController
58
- #
59
- # By default it is the root_path.
60
- def redirect_on_sign_out_path
61
- redirect_to_root
62
- end
63
-
64
- def redirect_on_sign_in_path
65
- redirect_to_root
66
- end
67
- def redirect_to_root
68
- redirect_to respond_to?(:root_path) ? root_path : "/"
69
- end
70
-
71
- def deny_access
72
- redirect_to_root
73
- end
74
- end