somatics3-generators 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/Rakefile +9 -1
  2. data/VERSION +1 -1
  3. data/bin/somatics +0 -0
  4. data/bin/somatify +0 -0
  5. data/lib/generators/somatics/associated/associated_generator.rb +184 -0
  6. data/lib/generators/somatics/associated/templates/migration.rb +11 -0
  7. data/lib/generators/somatics/attributes/attributes_generator.rb +8 -5
  8. data/lib/generators/somatics/authenticated/authenticated_generator.rb +27 -195
  9. data/lib/generators/somatics/authenticated/templates/partial_form.html.erb +23 -0
  10. data/lib/generators/somatics/authenticated_controller/authenticated_controller_generator.rb +14 -299
  11. data/lib/generators/somatics/authenticated_controller/templates/locales_en.yml +6 -0
  12. data/lib/generators/somatics/authenticated_controller/templates/locales_zh-TW.yml +6 -0
  13. data/lib/generators/somatics/authenticated_controller/templates/login.html.erb +10 -8
  14. data/lib/generators/somatics/authenticated_controller/templates/sessions_controller.rb +11 -43
  15. data/lib/generators/somatics/install/install_generator.rb +26 -3
  16. data/lib/generators/somatics/install/templates/config/locales/devise_zh-TW.yml +39 -0
  17. data/lib/generators/somatics/install/templates/controller_admin.rb +8 -4
  18. data/lib/generators/somatics/install/templates/helper_admin.rb +39 -3
  19. data/lib/generators/somatics/install/templates/initializer_paper_trail.rb +2 -0
  20. data/lib/generators/somatics/install/templates/layout_admin.html.erb +4 -4
  21. data/lib/generators/somatics/install/templates/lib/active_record/diff.rb +61 -0
  22. data/lib/generators/somatics/install/templates/lib/tasks/heroku.rake +30 -0
  23. data/lib/generators/somatics/install/templates/lib/tasks/svn.rake +47 -0
  24. data/lib/generators/somatics/install/templates/partial_versions.html.erb +56 -0
  25. data/lib/generators/somatics/install/templates/public/stylesheets/application.css +863 -0
  26. data/lib/generators/somatics/install/templates/public/stylesheets/somatics/base.css +3 -0
  27. data/lib/generators/somatics/install/templates/public/themes/default/stylesheets/application.css +951 -0
  28. data/lib/generators/somatics/install/templates/view_index.html.erb +46 -1
  29. data/lib/generators/somatics/scaffold/scaffold_generator.rb +0 -1
  30. data/lib/generators/somatics/scaffold_controller/scaffold_controller_generator.rb +31 -60
  31. data/lib/generators/somatics/scaffold_controller/templates/controller.rb +4 -21
  32. data/lib/generators/somatics/scaffold_controller/templates/view_index.html.erb +3 -4
  33. data/lib/generators/somatics/scaffold_controller/templates/view_show.html.erb +2 -0
  34. data/lib/generators/somatics/settings/settings_generator.rb +7 -3
  35. data/lib/generators/somatics/settings_controller/templates/controller.rb +4 -20
  36. data/lib/generators/somatics/settings_controller/templates/partial_form.html.erb +1 -1
  37. data/lib/generators/somatics/settings_controller/templates/view_index.html.erb +2 -2
  38. data/somatics3-generators.gemspec +28 -37
  39. data/templates/somatics.rb +76 -121
  40. metadata +70 -64
  41. data/lib/generators/somatics/authenticated/templates/mailer.rb +0 -25
  42. data/lib/generators/somatics/authenticated/templates/migration.rb +0 -26
  43. data/lib/generators/somatics/authenticated/templates/model.rb +0 -83
  44. data/lib/generators/somatics/authenticated/templates/observer.rb +0 -11
  45. data/lib/generators/somatics/authenticated/templates/test/mailer_test.rb +0 -31
  46. data/lib/generators/somatics/authenticated/templates/test/model_functional_test.rb +0 -93
  47. data/lib/generators/somatics/authenticated/templates/test/sessions_functional_test.rb +0 -82
  48. data/lib/generators/somatics/authenticated/templates/test/unit_test.rb +0 -164
  49. data/lib/generators/somatics/authenticated/templates/test/users.yml +0 -60
  50. data/lib/generators/somatics/authenticated_controller/templates/_model_partial.html.erb +0 -8
  51. data/lib/generators/somatics/authenticated_controller/templates/activation.erb +0 -3
  52. data/lib/generators/somatics/authenticated_controller/templates/authenticated_system.rb +0 -189
  53. data/lib/generators/somatics/authenticated_controller/templates/authenticated_test_helper.rb +0 -10
  54. data/lib/generators/somatics/authenticated_controller/templates/config/initializers/site_keys.rb +0 -38
  55. data/lib/generators/somatics/authenticated_controller/templates/controller.rb +0 -55
  56. data/lib/generators/somatics/authenticated_controller/templates/helper.rb +0 -91
  57. data/lib/generators/somatics/authenticated_controller/templates/mailer.rb +0 -25
  58. data/lib/generators/somatics/authenticated_controller/templates/migration.rb +0 -26
  59. data/lib/generators/somatics/authenticated_controller/templates/model.rb +0 -83
  60. data/lib/generators/somatics/authenticated_controller/templates/observer.rb +0 -11
  61. data/lib/generators/somatics/authenticated_controller/templates/session_helper.rb +0 -2
  62. data/lib/generators/somatics/authenticated_controller/templates/signup.html.erb +0 -19
  63. data/lib/generators/somatics/authenticated_controller/templates/signup_notification.erb +0 -8
  64. data/lib/generators/somatics/authenticated_controller/templates/test/mailer_test.rb +0 -31
  65. data/lib/generators/somatics/authenticated_controller/templates/test/model_functional_test.rb +0 -93
  66. data/lib/generators/somatics/authenticated_controller/templates/test/sessions_functional_test.rb +0 -82
  67. data/lib/generators/somatics/authenticated_controller/templates/test/unit_test.rb +0 -164
  68. data/lib/generators/somatics/authenticated_controller/templates/test/users.yml +0 -60
  69. data/lib/generators/somatics/scaffold_controller/templates/builder_index.pdf.prawn +0 -25
  70. data/lib/generators/somatics/settings_controller/templates/builder_index.pdf.prawn +0 -25
  71. data/lib/generators/somatics/settings_controller/templates/model.rb +0 -54
@@ -1,60 +0,0 @@
1
- <%
2
- ## this code must match that in templates/model.rb
3
- require 'digest/sha1'
4
- def make_fake_token
5
- @fake_token_counter ||= 0
6
- @fake_token_counter += 1
7
- Digest::SHA1.hexdigest(@fake_token_counter.to_s)
8
- end
9
- salts = (1..2).map{ make_fake_token }
10
- passwds = salts.map{ |salt| password_digest('monkey', salt) }
11
- -%>
12
-
13
- quentin:
14
- id: 1
15
- login: quentin
16
- email: quentin@example.com
17
- salt: <%= salts[0] %> # SHA1('0')
18
- crypted_password: <%= passwds[0] %> # 'monkey'
19
- created_at: <%%= 5.days.ago.to_s :db %>
20
- remember_token_expires_at: <%%= 1.days.from_now.to_s %>
21
- remember_token: <%= make_fake_token %>
22
- <% if options[:include_activation] -%>
23
- activation_code:
24
- activated_at: <%%= 5.days.ago.to_s :db %>
25
- <% end -%>
26
- <% if options[:stateful] -%>
27
- state: active
28
- <% end -%>
29
-
30
- aaron:
31
- id: 2
32
- login: aaron
33
- email: aaron@example.com
34
- salt: <%= salts[1] %> # SHA1('1')
35
- crypted_password: <%= passwds[1] %> # 'monkey'
36
- created_at: <%%= 1.days.ago.to_s :db %>
37
- remember_token_expires_at:
38
- remember_token:
39
- <% if options[:include_activation] -%>
40
- activation_code: <%= make_fake_token %>
41
- activated_at:
42
- <% end -%>
43
- <% if options[:stateful] %>
44
- state: pending
45
- <% end -%>
46
-
47
-
48
- old_password_holder:
49
- id: 3
50
- login: old_password_holder
51
- email: salty_dog@example.com
52
- salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
53
- crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
54
- created_at: <%%= 1.days.ago.to_s :db %>
55
- <% if options[:include_activation] %>
56
- activation_code:
57
- activated_at: <%%= 5.days.ago.to_s :db %>
58
- <% end %>
59
- <% if options[:stateful] %>
60
- state: active<% end %>
@@ -1,8 +0,0 @@
1
- <%% if logged_in? -%>
2
- <div id="<%= file_name %>-bar-greeting">Logged in as <%%= link_to_current_<%= file_name %> :content_method => :login %></div>
3
- <div id="<%= file_name %>-bar-action" >(<%%= link_to "Log out", logout_path, { :title => "Log out" } %>)</div>
4
- <%% else -%>
5
- <div id="<%= file_name %>-bar-greeting"><%%= link_to_login_with_IP 'Not logged in', :style => 'border: none;' %></div>
6
- <div id="<%= file_name %>-bar-action" ><%%= link_to "Log in", login_path, { :title => "Log in" } %> /
7
- <%%= link_to "Sign up", signup_path, { :title => "Create an account" } %></div>
8
- <%% end -%>
@@ -1,3 +0,0 @@
1
- <%%=h @<%= file_name %>.login %>, your account has been activated. Welcome aboard!
2
-
3
- <%%=h @url %>
@@ -1,189 +0,0 @@
1
- module <%= model_class_name %>AuthenticatedSystem
2
- protected
3
- # Returns true or false if the <%= file_name %> is logged in.
4
- # Preloads @current_<%= file_name %> with the <%= file_name %> model if they're logged in.
5
- def <%= file_name %>_logged_in?
6
- !!current_<%= file_name %>
7
- end
8
-
9
- # Accesses the current <%= file_name %> from the session.
10
- # Future calls avoid the database because nil is not equal to false.
11
- def current_<%= file_name %>
12
- @current_<%= file_name %> ||= (<%= file_name %>_login_from_session || <%= file_name %>_login_from_basic_auth || <%= file_name %>_login_from_cookie) unless @current_<%= file_name %> == false
13
- end
14
-
15
- # Store the given <%= file_name %> id in the session.
16
- def current_<%= file_name %>=(new_<%= file_name %>)
17
- session[:<%= file_name %>_id] = new_<%= file_name %> ? new_<%= file_name %>.id : nil
18
- @current_<%= file_name %> = new_<%= file_name %> || false
19
- end
20
-
21
- # Check if the <%= file_name %> is authorized
22
- #
23
- # Override this method in your controllers if you want to restrict access
24
- # to only a few actions or if you want to check if the <%= file_name %>
25
- # has the correct rights.
26
- #
27
- # Example:
28
- #
29
- # # only allow nonbobs
30
- # def authorized?
31
- # current_<%= file_name %>.login != "bob"
32
- # end
33
- #
34
- def <%= file_name %>_authorized?(action = action_name, resource = nil)
35
- <%= file_name %>_logged_in?
36
- end
37
-
38
- # Filter method to enforce a login requirement.
39
- #
40
- # To require logins for all actions, use this in your controllers:
41
- #
42
- # before_filter :login_required
43
- #
44
- # To require logins for specific actions, use this in your controllers:
45
- #
46
- # before_filter :login_required, :only => [ :edit, :update ]
47
- #
48
- # To skip this in a subclassed controller:
49
- #
50
- # skip_before_filter :login_required
51
- #
52
- def <%= file_name %>_login_required
53
- <%= file_name %>_authorized? || <%= file_name %>_access_denied
54
- end
55
-
56
- # Redirect as appropriate when an access request fails.
57
- #
58
- # The default action is to redirect to the login screen.
59
- #
60
- # Override this method in your controllers if you want to have special
61
- # behavior in case the <%= file_name %> is not authorized
62
- # to access the requested action. For example, a popup window might
63
- # simply close itself.
64
- def <%= file_name %>_access_denied
65
- respond_to do |format|
66
- format.html do
67
- store_location
68
- redirect_to <%= controller_routing_name %>_login_path
69
- end
70
- # format.any doesn't work in rails version < http://dev.rubyonrails.org/changeset/8987
71
- # Add any other API formats here. (Some browsers, notably IE6, send Accept: */* and trigger
72
- # the 'format.any' block incorrectly. See http://bit.ly/ie6_borken or http://bit.ly/ie6_borken2
73
- # for a workaround.)
74
- format.any(:json, :xml) do
75
- request_http_basic_authentication 'Web Password'
76
- end
77
- end
78
- end
79
-
80
- # Store the URI of the current request in the session.
81
- #
82
- # We can return to this location by calling #redirect_back_or_default.
83
- def store_location
84
- session[:return_to] = request.request_uri
85
- end
86
-
87
- # Redirect to the URI stored by the most recent store_location call or
88
- # to the passed default. Set an appropriately modified
89
- # after_filter :store_location, :only => [:index, :new, :show, :edit]
90
- # for any controller you want to be bounce-backable.
91
- def redirect_back_or_default(default)
92
- redirect_to(session[:return_to] || default)
93
- session[:return_to] = nil
94
- end
95
-
96
- # Inclusion hook to make #current_<%= file_name %> and #logged_in?
97
- # available as ActionView helper methods.
98
- def self.included(base)
99
- base.send :helper_method, :current_<%= file_name %>, :<%= file_name %>_logged_in?, :<%= file_name %>_authorized? if base.respond_to? :helper_method
100
- end
101
-
102
- #
103
- # Login
104
- #
105
-
106
- # Called from #current_<%= file_name %>. First attempt to login by the <%= file_name %> id stored in the session.
107
- def <%= file_name %>_login_from_session
108
- self.current_<%= file_name %> = <%= model_class_name %>.find_by_id(session[:<%= file_name %>_id]) if session[:<%= file_name %>_id]
109
- end
110
-
111
- # Called from #current_<%= file_name %>. Now, attempt to login by basic authentication information.
112
- def <%= file_name %>_login_from_basic_auth
113
- authenticate_with_http_basic do |login, password|
114
- self.current_<%= file_name %> = <%= model_class_name %>.authenticate(login, password)
115
- end
116
- end
117
-
118
- #
119
- # Logout
120
- #
121
-
122
- # Called from #current_<%= file_name %>. Finaly, attempt to login by an expiring token in the cookie.
123
- # for the paranoid: we _should_ be storing <%= file_name %>_token = hash(cookie_token, request IP)
124
- def <%= file_name %>_login_from_cookie
125
- <%= file_name %> = cookies[:auth_token] && <%= model_class_name %>.find_by_remember_token(cookies[:auth_token])
126
- if <%= file_name %> && <%= file_name %>.remember_token?
127
- self.current_<%= file_name %> = <%= file_name %>
128
- <%= file_name %>_handle_remember_cookie! false # freshen cookie token (keeping date)
129
- self.current_<%= file_name %>
130
- end
131
- end
132
-
133
- # This is ususally what you want; resetting the session willy-nilly wreaks
134
- # havoc with forgery protection, and is only strictly necessary on login.
135
- # However, **all session state variables should be unset here**.
136
- def <%= file_name %>_logout_keeping_session!
137
- # Kill server-side auth cookie
138
- @current_<%= file_name %>.forget_me if @current_<%= file_name %>.is_a? <%= model_class_name %>
139
- @current_<%= file_name %> = false # not logged in, and don't do it for me
140
- <%= file_name %>_kill_remember_cookie! # Kill client-side auth cookie
141
- session[:<%= file_name %>_id] = nil # keeps the session but kill our variable
142
- # explicitly kill any other session variables you set
143
- end
144
-
145
- # The session should only be reset at the tail end of a form POST --
146
- # otherwise the request forgery protection fails. It's only really necessary
147
- # when you cross quarantine (logged-out to logged-in).
148
- def <%= file_name %>_logout_killing_session!
149
- <%= file_name %>_logout_keeping_session!
150
- reset_session
151
- end
152
-
153
- #
154
- # Remember_me Tokens
155
- #
156
- # Cookies shouldn't be allowed to persist past their freshness date,
157
- # and they should be changed at each login
158
-
159
- # Cookies shouldn't be allowed to persist past their freshness date,
160
- # and they should be changed at each login
161
-
162
- def <%= file_name %>_valid_remember_cookie?
163
- return nil unless @current_<%= file_name %>
164
- (@current_<%= file_name %>.remember_token?) &&
165
- (cookies[:auth_token] == @current_<%= file_name %>.remember_token)
166
- end
167
-
168
- # Refresh the cookie auth token if it exists, create it otherwise
169
- def <%= file_name %>_handle_remember_cookie!(new_cookie_flag)
170
- return unless @current_<%= file_name %>
171
- case
172
- when <%= file_name %>_valid_remember_cookie? then @current_<%= file_name %>.refresh_token # keeping same expiry date
173
- when new_cookie_flag then @current_<%= file_name %>.remember_me
174
- else @current_<%= file_name %>.forget_me
175
- end
176
- <%= file_name %>_send_remember_cookie!
177
- end
178
-
179
- def <%= file_name %>_kill_remember_cookie!
180
- cookies.delete :auth_token
181
- end
182
-
183
- def <%= file_name %>_send_remember_cookie!
184
- cookies[:auth_token] = {
185
- :value => @current_<%= file_name %>.remember_token,
186
- :expires => @current_<%= file_name %>.remember_token_expires_at }
187
- end
188
-
189
- end
@@ -1,10 +0,0 @@
1
- module <%= model_class_name %>AuthenticatedTestHelper
2
- # Sets the current <%= file_name %> in the session from the <%= file_name %> fixtures.
3
- def login_as(<%= file_name %>)
4
- @request.session[:<%= file_name %>_id] = <%= file_name %> ? (<%= file_name %>.is_a?(<%= file_name.camelize %>) ? <%= file_name %>.id : <%= table_name %>(<%= file_name %>).id) : nil
5
- end
6
-
7
- def authorize_as(<%= file_name %>)
8
- @request.env["HTTP_AUTHORIZATION"] = <%= file_name %> ? ActionController::HttpAuthentication::Basic.encode_credentials(<%= table_name %>(<%= file_name %>).login, 'monkey') : nil
9
- end
10
- end
@@ -1,38 +0,0 @@
1
-
2
- # A Site key gives additional protection against a dictionary attack if your
3
- # DB is ever compromised. With no site key, we store
4
- # DB_password = hash(user_password, DB_user_salt)
5
- # If your database were to be compromised you'd be vulnerable to a dictionary
6
- # attack on all your stupid users' passwords. With a site key, we store
7
- # DB_password = hash(user_password, DB_user_salt, Code_site_key)
8
- # That means an attacker needs access to both your site's code *and* its
9
- # database to mount an "offline dictionary attack.":http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/web-authentication.html
10
- #
11
- # It's probably of minor importance, but recommended by best practices: 'defense
12
- # in depth'. Needless to say, if you upload this to github or the youtubes or
13
- # otherwise place it in public view you'll kinda defeat the point. Your users'
14
- # passwords are still secure, and the world won't end, but defense_in_depth -= 1.
15
- #
16
- # Please note: if you change this, all the passwords will be invalidated, so DO
17
- # keep it someplace secure. Use the random value given or type in the lyrics to
18
- # your favorite Jay-Z song or something; any moderately long, unpredictable text.
19
- REST_AUTH_SITE_KEY = '<%= $rest_auth_site_key_from_generator %>'
20
-
21
- # Repeated applications of the hash make brute force (even with a compromised
22
- # database and site key) harder, and scale with Moore's law.
23
- #
24
- # bq. "To squeeze the most security out of a limited-entropy password or
25
- # passphrase, we can use two techniques [salting and stretching]... that are
26
- # so simple and obvious that they should be used in every password system.
27
- # There is really no excuse not to use them." http://tinyurl.com/37lb73
28
- # Practical Security (Ferguson & Scheier) p350
29
- #
30
- # A modest 10 foldings (the default here) adds 3ms. This makes brute forcing 10
31
- # times harder, while reducing an app that otherwise serves 100 reqs/s to 78 signin
32
- # reqs/s, an app that does 10reqs/s to 9.7 reqs/s
33
- #
34
- # More:
35
- # * http://www.owasp.org/index.php/Hashing_Java
36
- # * "An Illustrated Guide to Cryptographic Hashes":http://www.unixwiz.net/techtips/iguide-crypto-hashes.html
37
-
38
- REST_AUTH_DIGEST_STRETCHES = <%= $rest_auth_digest_stretches_from_generator %>
@@ -1,55 +0,0 @@
1
- class <%= controller_class_name %>Controller < ApplicationController
2
- # Be sure to include AuthenticationSystem in Application Controller instead
3
- include <%= model_class_name %>AuthenticatedSystem
4
-
5
- skip_before_filter :<%= file_name %>_login_required
6
-
7
- def new
8
- @<%= file_name %> = <%= model_class_name %>.new
9
- end
10
-
11
- def create
12
- <%= file_name %>_logout_keeping_session!
13
- @<%= file_name %> = <%= model_class_name %>.new(params[:<%= file_name %>])
14
- <% if options[:stateful] -%>
15
- @<%= file_name %>.register! if @<%= file_name %> && @<%= file_name %>.valid?
16
- success = @<%= file_name %> && @<%= file_name %>.valid?
17
- <% else -%>
18
- success = @<%= file_name %> && @<%= file_name %>.save
19
- <% end -%>
20
- if success && @<%= file_name %>.errors.empty?
21
- <% if !options[:include_activation] -%>
22
- # Protects against session fixation attacks, causes request forgery
23
- # protection if visitor resubmits an earlier form using back
24
- # button. Uncomment if you understand the tradeoffs.
25
- # reset session
26
- self.current_<%= file_name %> = @<%= file_name %> # !! now logged in
27
- <% end -%>
28
- redirect_back_or_default('/')
29
- flash[:notice] = "Thanks for signing up! We're sending you an email with your activation code."
30
- else
31
- flash[:error] = "We couldn't set up that account, sorry. Please try again, or contact an admin (link is above)."
32
- render :action => 'new'
33
- end
34
- end
35
-
36
- <% if options[:include_activation] -%>
37
- def activate
38
- <%= file_name %>_logout_keeping_session!
39
- <%= file_name %> = <%= model_class_name %>.find_by_activation_code(params[:activation_code]) unless params[:activation_code].blank?
40
- case
41
- when (!params[:activation_code].blank?) && <%= file_name %> && !<%= file_name %>.active?
42
- <%= file_name %>.activate!
43
- flash[:notice] = "Signup complete! Please sign in to continue."
44
- redirect_to "/#{controller_plural_name}/login"
45
- when params[:activation_code].blank?
46
- flash[:error] = "The activation code was missing. Please follow the URL from your email."
47
- redirect_back_or_default('/')
48
- else
49
- flash[:error] = "We couldn't find a <%= file_name %> with that activation code -- check your email? Or maybe you've already activated -- try signing in."
50
- redirect_back_or_default('/')
51
- end
52
- end
53
- end
54
- <% end -%>
55
- end
@@ -1,91 +0,0 @@
1
- module <%= controller_class_name %>Helper
2
- #
3
- # Use this to wrap view elements that the user can't access.
4
- # !! Note: this is an *interface*, not *security* feature !!
5
- # You need to do all access control at the controller level.
6
- #
7
- # Example:
8
- # <%%= if_authorized?(:index, User) do link_to('List all users', users_path) end %> |
9
- # <%%= if_authorized?(:edit, @user) do link_to('Edit this user', edit_user_path) end %> |
10
- # <%%= if_authorized?(:destroy, @user) do link_to 'Destroy', @user, :confirm => 'Are you sure?', :method => :delete end %>
11
- #
12
- #
13
- def if_authorized?(action, resource, &block)
14
- if authorized?(action, resource)
15
- yield action, resource
16
- end
17
- end
18
-
19
- #
20
- # Link to user's page ('<%= table_name %>/1')
21
- #
22
- # By default, their login is used as link text and link title (tooltip)
23
- #
24
- # Takes options
25
- # * :content_text => 'Content text in place of <%= file_name %>.login', escaped with
26
- # the standard h() function.
27
- # * :content_method => :<%= file_name %>_instance_method_to_call_for_content_text
28
- # * :title_method => :<%= file_name %>_instance_method_to_call_for_title_attribute
29
- # * as well as link_to()'s standard options
30
- #
31
- # Examples:
32
- # link_to_<%= file_name %> @<%= file_name %>
33
- # # => <a href="/<%= table_name %>/3" title="barmy">barmy</a>
34
- #
35
- # # if you've added a .name attribute:
36
- # content_tag :span, :class => :vcard do
37
- # (link_to_<%= file_name %> <%= file_name %>, :class => 'fn n', :title_method => :login, :content_method => :name) +
38
- # ': ' + (content_tag :span, <%= file_name %>.email, :class => 'email')
39
- # end
40
- # # => <span class="vcard"><a href="/<%= table_name %>/3" title="barmy" class="fn n">Cyril Fotheringay-Phipps</a>: <span class="email">barmy@blandings.com</span></span>
41
- #
42
- # link_to_<%= file_name %> @<%= file_name %>, :content_text => 'Your user page'
43
- # # => <a href="/<%= table_name %>/3" title="barmy" class="nickname">Your user page</a>
44
- #
45
- def link_to_<%= file_name %>(<%= file_name %>, options={})
46
- raise "Invalid <%= file_name %>" unless <%= file_name %>
47
- options.reverse_merge! :content_method => :login, :title_method => :login, :class => :nickname
48
- content_text = options.delete(:content_text)
49
- content_text ||= <%= file_name %>.send(options.delete(:content_method))
50
- options[:title] ||= <%= file_name %>.send(options.delete(:title_method))
51
- link_to h(content_text), <%= controller_routing_name.singularize %>_path(<%= file_name %>), options
52
- end
53
-
54
- #
55
- # Link to login page using remote ip address as link content
56
- #
57
- # The :title (and thus, tooltip) is set to the IP address
58
- #
59
- # Examples:
60
- # link_to_login_with_IP
61
- # # => <a href="/login" title="169.69.69.69">169.69.69.69</a>
62
- #
63
- # link_to_login_with_IP :content_text => 'not signed in'
64
- # # => <a href="/login" title="169.69.69.69">not signed in</a>
65
- #
66
- def link_to_login_with_IP content_text=nil, options={}
67
- ip_addr = request.remote_ip
68
- content_text ||= ip_addr
69
- options.reverse_merge! :title => ip_addr
70
- if tag = options.delete(:tag)
71
- content_tag tag, h(content_text), options
72
- else
73
- link_to h(content_text), login_path, options
74
- end
75
- end
76
-
77
- #
78
- # Link to the current user's page (using link_to_<%= file_name %>) or to the login page
79
- # (using link_to_login_with_IP).
80
- #
81
- def link_to_current_<%= file_name %>(options={})
82
- if current_<%= file_name %>
83
- link_to_<%= file_name %> current_<%= file_name %>, options
84
- else
85
- content_text = options.delete(:content_text) || 'not signed in'
86
- # kill ignored options from link_to_<%= file_name %>
87
- [:content_method, :title_method].each{|opt| options.delete(opt)}
88
- link_to_login_with_IP content_text, options
89
- end
90
- end
91
- end