cream 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.document +5 -0
  2. data/.gitignore +39 -0
  3. data/.rspec +1 -0
  4. data/Changelog.txt +8 -0
  5. data/Gemfile +27 -0
  6. data/LICENSE +20 -0
  7. data/README.markdown +196 -0
  8. data/Rakefile +40 -0
  9. data/VERSION +1 -0
  10. data/app/views/auth_assist/menu/_admin_login_items.html.erb +11 -0
  11. data/app/views/auth_assist/menu/_login_items.html.erb +11 -0
  12. data/app/views/auth_assist/menu/_registration_items.html.erb +10 -0
  13. data/config/locales/en.yml +14 -0
  14. data/cream.gemspec +169 -0
  15. data/features/FEATURE_NOTES.txt +6 -0
  16. data/features/permission/adds_permission.feature +0 -0
  17. data/features/role_strategy/adds_role_strategy.feature +0 -0
  18. data/features/role_strategy/clears_role_strategy.feature +0 -0
  19. data/init.rb +1 -0
  20. data/lib/cream.rb +21 -0
  21. data/lib/cream/configure.rb +3 -0
  22. data/lib/cream/configure/after_init/role_config.rb +29 -0
  23. data/lib/cream/configure/rails.rb +23 -0
  24. data/lib/cream/controller/ability.rb +7 -0
  25. data/lib/cream/helper/authlabels.rb +21 -0
  26. data/lib/cream/helper/host.rb +11 -0
  27. data/lib/cream/helper/role.rb +48 -0
  28. data/lib/cream/namespaces.rb +5 -0
  29. data/lib/cream/role.rb +7 -0
  30. data/lib/cream/view/host_area.rb +12 -0
  31. data/lib/cream/view/role_area.rb +38 -0
  32. data/lib/cream/view/user_action_menu.rb +21 -0
  33. data/lib/generators/cream/config/DESIGN NOTES.markdown +61 -0
  34. data/lib/generators/cream/config/config_generator.rb +72 -0
  35. data/lib/generators/cream/config/modules/cancan_config.rb +22 -0
  36. data/lib/generators/cream/config/modules/cream_config.rb +23 -0
  37. data/lib/generators/cream/config/modules/devise_config.rb +108 -0
  38. data/lib/generators/cream/config/modules/helper.rb +57 -0
  39. data/lib/generators/cream/config/modules/permits_config.rb +15 -0
  40. data/lib/generators/cream/config/modules/roles_config.rb +15 -0
  41. data/lib/generators/cream/views/haml_util.rb +44 -0
  42. data/lib/generators/cream/views/views_generator.rb +34 -0
  43. data/lib/generators/cream_refactor.rb +82 -0
  44. data/log/development.log +0 -0
  45. data/sandbox/test.rb +40 -0
  46. data/spec/cream/configure/rails_spec.rb +51 -0
  47. data/spec/cream/helper/host_spec.rb +68 -0
  48. data/spec/cream/helper/role_spec.rb +187 -0
  49. data/spec/cream/view/host_area_spec.rb +61 -0
  50. data/spec/cream/view/role_area_spec.rb +124 -0
  51. data/spec/cream/view/role_ext_spec.rb +36 -0
  52. data/spec/generator_spec_helper.rb +26 -0
  53. data/spec/generators/cream/config/devise/existing_devise_users.rb +61 -0
  54. data/spec/generators/cream/config/empty_app/default_args_spec.rb +51 -0
  55. data/spec/generators/cream/config/permits/existing_permits_spec.rb +0 -0
  56. data/spec/generators/cream/config/permits/no_permits_spec.rb +0 -0
  57. data/spec/generators/cream/config/roles/default_roles.rb +51 -0
  58. data/spec/generators/cream/config/roles/roles_spec.rb +60 -0
  59. data/spec/generators/cream/shared_examples.rb +18 -0
  60. data/spec/generators/cream/views_generator_spec.rb +30 -0
  61. data/spec/spec_helper.rb +18 -0
  62. data/wiki/CONFIG_GENERATOR.txt +21 -0
  63. data/wiki/DESIGN.txt +21 -0
  64. data/wiki/INSTALLATION.txt +6 -0
  65. data/wiki/PERMITS.txt +32 -0
  66. data/wiki/ROLE_STRATEGIES.txt +40 -0
  67. data/wiki/SPEC_NOTES.txt +6 -0
  68. data/wiki/VIEWS_GENERATOR.txt +35 -0
  69. data/wiki/VIEW_HELPERS.txt +162 -0
  70. metadata +374 -0
@@ -0,0 +1,6 @@
1
+ # Notes and Status
2
+
3
+ Currently these specs are a work in progress.
4
+ I am first building up a skeleton structure for the specs and then plan to gradually implement them as described in the DESIGN.txt document :)
5
+
6
+ You are most welcome to help in the effort!
@@ -0,0 +1,35 @@
1
+ The `views` generator generates views (partials) for use with menus.
2
+
3
+ It is sometimes the case that you want to have menu items in a main navigation menu that enable the user to log in/out, register a new user account or edit an existing user account. The menu items partials ensure that these menuitems are only shown as appropriate in relation to the current user login status, so that log out and edit account is only shown if the user is currently logged in and vice-versa.
4
+
5
+ <pre>$ rails g cream:views</pre>
6
+
7
+ Create HAML views
8
+
9
+ <pre>$ rails g cream:views --template_engine haml</pre>
10
+
11
+ Example usage:
12
+ <pre>ul.menu
13
+ render 'cream/login_items'
14
+ render 'cream/registration_items'
15
+
16
+ ul.admin_menu_
17
+ render 'cream/admin_login_items'</pre>
18
+
19
+
20
+ <pre>module RolePermit
21
+ class Moderator
22
+ def initialize(ability)
23
+ super
24
+ end
25
+
26
+
27
+ def permit?(user)
28
+ super
29
+ return if !user.role?(:moderator)
30
+ can :read, :all
31
+ user.owns(Comment)
32
+ user.owns(Book, :author)
33
+ end
34
+ end
35
+ end</pre>
@@ -0,0 +1,162 @@
1
+ ## View helpers ##
2
+
3
+ Currently the view helpers only target use with devise and cancan.
4
+ The default labels are always loaded from the `cream` locale file, which is generated by the `config` generator.
5
+
6
+ ### Rest link helpers ###
7
+
8
+ Display a link (anchor tag) for a given object only if the current user has permission to execute that action.
9
+
10
+ * show_link or read_link
11
+ * edit_link or update_link
12
+ * create_link or new_link
13
+ * destroy_link or delete_link
14
+
15
+ Each Rest helper method takes an object for which to create the link. Optionally provide a label as the second argument.
16
+
17
+ Example usage:
18
+
19
+ <%= create_link project %>
20
+ <%= create_link project, 'Create new project' %>
21
+
22
+ ### Session link helpers ###
23
+
24
+ Show links for performing user authentication and registration actions
25
+
26
+ * log_out_link or sign_out_link
27
+ * log_in_link or sign_in_link
28
+
29
+ Each of these methods take an optional options hash.
30
+ If no role option given, they default to create link for basic 'user' role.
31
+
32
+ Example usage:
33
+
34
+ <%= log_out_link %>
35
+ <%= log_out_link :label => 'Log me out' %>
36
+ <%= log_out_link :role => 'admin', :label => 'Log me out' %>
37
+
38
+
39
+ ### Registration link helpers ###
40
+
41
+ Show links for performing user authentication and registration actions
42
+
43
+ * register_link or sign_up_link
44
+ * edit_profile_link or edit_registration_link
45
+
46
+ Each of these methods take an optional options hash.
47
+ If no role option given, they default to create link for basic 'user' role.
48
+
49
+ Example usage:
50
+
51
+ <%= register_link %>
52
+ <%= register_link :label => 'Register me' %>
53
+ <%= register_link :role => 'admin', :label => 'Register me' %>
54
+
55
+ ### Registration Menu item helpers ###
56
+
57
+ Show menu links for registration conditionally
58
+
59
+ * edit_user_menu_item or edit_registration_menu_item
60
+ * register_menu_item or sign_up_menu_item
61
+
62
+ 1) only shown if user is currently logged in
63
+ 2) only shown if user is NOT currently logged in (and hence already registered)
64
+
65
+ Example usage:
66
+
67
+ ul.menu
68
+ <%= register_menu_item %>
69
+
70
+ ### Session Menu item helpers ###
71
+
72
+ Show menu links for session operations conditionally
73
+
74
+ * logout_menu_item or sign_out_menu_item
75
+ * login_menu_item or sign_in_menu_item
76
+
77
+ 1) only shown if user is currently logged in
78
+ 2) only shown if user is NOT currently logged in
79
+
80
+ ul.menu
81
+ <%= login_menu_item %>
82
+ <%= logout_menu_item %>
83
+
84
+
85
+ ## Block helpers ##
86
+
87
+ Execute block if user is logged in (or not logged in)
88
+ * user_block
89
+ * not_user_block
90
+
91
+ Execute block if user is logged and is admin (or not admin)
92
+ * admin_block
93
+ * not_admin_block
94
+
95
+ Execute block if ip is localhost (or not localhost)
96
+ * localhost_block
97
+ * not_localhost_block
98
+
99
+ Execute block if role is included in list of roles (or not)
100
+ * roles_block
101
+ * not_roles_block
102
+
103
+ ## Block area helpers ##
104
+
105
+ Create div.user 'area' and execute block if user is logged in as a user (or not)
106
+
107
+ * user_area
108
+ * not_user_area
109
+
110
+ Create div.admin 'area' and execute block if user is admin (or not admin)
111
+
112
+ * admin_area
113
+ * not_admin_area
114
+
115
+ Example:
116
+ <pre>
117
+ <% admin_area do %>
118
+ ul.admin_menu
119
+ ...
120
+
121
+ If logged in as admin, results in:
122
+
123
+ div.admin
124
+ ul.admin_menu
125
+ ...
126
+ </pre>
127
+
128
+ ## Roles block area helpers ##
129
+
130
+ Creates are if role is one included in list of roles (or not)
131
+
132
+ * roles_area
133
+ * not_roles_area
134
+
135
+ Example:
136
+ <pre>
137
+ <% roles_area 'admin, 'editor', :class => 'special' do %>
138
+ ul.admin_menu
139
+ ...
140
+
141
+ If logged in as either 'editor' or 'admin', results in:
142
+
143
+ div.special
144
+ ul.admin_menu
145
+ ...
146
+
147
+ </pre>
148
+
149
+ ## Misc helpers ##
150
+
151
+ * user? -
152
+ * admin?
153
+ * role?
154
+ * localhost?
155
+
156
+ Examples
157
+ <pre>
158
+ <%= current_user.username if user? %>
159
+ <%= "Admin: #{current_user.username}" if admin? %>
160
+ <%= "Special user!" if role?('admin', 'reviewer') %>
161
+ <%= "Running on localhost!" if localhost? %>
162
+ </pre>
metadata ADDED
@@ -0,0 +1,374 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cream
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 6
9
+ version: 0.5.6
10
+ platform: ruby
11
+ authors:
12
+ - Kristian Mandrup
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-26 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ - beta
33
+ - 22
34
+ version: 2.0.0.beta.22
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: generator-spec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 0
47
+ - 6
48
+ - 4
49
+ version: 0.6.4
50
+ type: :development
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec-action_view
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ - 3
63
+ - 1
64
+ version: 0.3.1
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rails-app-spec
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ - 2
78
+ - 13
79
+ version: 0.2.13
80
+ type: :development
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: require_all
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 1
92
+ - 1
93
+ - 0
94
+ version: 1.1.0
95
+ type: :runtime
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: devise-links
99
+ prerelease: false
100
+ requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ - 1
108
+ - 1
109
+ version: 0.1.1
110
+ type: :runtime
111
+ version_requirements: *id006
112
+ - !ruby/object:Gem::Dependency
113
+ name: cancan-rest-links
114
+ prerelease: false
115
+ requirement: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ~>
119
+ - !ruby/object:Gem::Version
120
+ segments:
121
+ - 0
122
+ - 1
123
+ - 1
124
+ version: 0.1.1
125
+ type: :runtime
126
+ version_requirements: *id007
127
+ - !ruby/object:Gem::Dependency
128
+ name: cancan-permits
129
+ prerelease: false
130
+ requirement: &id008 !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ~>
134
+ - !ruby/object:Gem::Version
135
+ segments:
136
+ - 0
137
+ - 1
138
+ - 1
139
+ version: 0.1.1
140
+ type: :runtime
141
+ version_requirements: *id008
142
+ - !ruby/object:Gem::Dependency
143
+ name: devise
144
+ prerelease: false
145
+ requirement: &id009 !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ segments:
151
+ - 1
152
+ - 1
153
+ - 2
154
+ version: 1.1.2
155
+ type: :runtime
156
+ version_requirements: *id009
157
+ - !ruby/object:Gem::Dependency
158
+ name: cancan
159
+ prerelease: false
160
+ requirement: &id010 !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ~>
164
+ - !ruby/object:Gem::Version
165
+ segments:
166
+ - 1
167
+ - 3
168
+ - 4
169
+ version: 1.3.4
170
+ type: :runtime
171
+ version_requirements: *id010
172
+ - !ruby/object:Gem::Dependency
173
+ name: rails
174
+ prerelease: false
175
+ requirement: &id011 !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ~>
179
+ - !ruby/object:Gem::Version
180
+ segments:
181
+ - 3
182
+ - 0
183
+ - 0
184
+ version: 3.0.0
185
+ type: :runtime
186
+ version_requirements: *id011
187
+ - !ruby/object:Gem::Dependency
188
+ name: rails3_artifactor
189
+ prerelease: false
190
+ requirement: &id012 !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ~>
194
+ - !ruby/object:Gem::Version
195
+ segments:
196
+ - 0
197
+ - 2
198
+ - 4
199
+ version: 0.2.4
200
+ type: :runtime
201
+ version_requirements: *id012
202
+ - !ruby/object:Gem::Dependency
203
+ name: logging_assist
204
+ prerelease: false
205
+ requirement: &id013 !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ~>
209
+ - !ruby/object:Gem::Version
210
+ segments:
211
+ - 0
212
+ - 1
213
+ - 3
214
+ version: 0.1.3
215
+ type: :runtime
216
+ version_requirements: *id013
217
+ - !ruby/object:Gem::Dependency
218
+ name: r3_plugin_toolbox
219
+ prerelease: false
220
+ requirement: &id014 !ruby/object:Gem::Requirement
221
+ none: false
222
+ requirements:
223
+ - - ~>
224
+ - !ruby/object:Gem::Version
225
+ segments:
226
+ - 0
227
+ - 3
228
+ - 6
229
+ version: 0.3.6
230
+ type: :runtime
231
+ version_requirements: *id014
232
+ - !ruby/object:Gem::Dependency
233
+ name: sugar-high
234
+ prerelease: false
235
+ requirement: &id015 !ruby/object:Gem::Requirement
236
+ none: false
237
+ requirements:
238
+ - - ~>
239
+ - !ruby/object:Gem::Version
240
+ segments:
241
+ - 0
242
+ - 2
243
+ - 10
244
+ version: 0.2.10
245
+ type: :runtime
246
+ version_requirements: *id015
247
+ description: Provides assistance for setting up Session, Role and Permission systems for a Rails 3 app. Support for multiple ORMs
248
+ email: kmandrup@gmail.com
249
+ executables: []
250
+
251
+ extensions: []
252
+
253
+ extra_rdoc_files:
254
+ - LICENSE
255
+ - README.markdown
256
+ files:
257
+ - .document
258
+ - .gitignore
259
+ - .rspec
260
+ - Changelog.txt
261
+ - Gemfile
262
+ - LICENSE
263
+ - README.markdown
264
+ - Rakefile
265
+ - VERSION
266
+ - app/views/auth_assist/menu/_admin_login_items.html.erb
267
+ - app/views/auth_assist/menu/_login_items.html.erb
268
+ - app/views/auth_assist/menu/_registration_items.html.erb
269
+ - config/locales/en.yml
270
+ - cream.gemspec
271
+ - features/FEATURE_NOTES.txt
272
+ - features/permission/adds_permission.feature
273
+ - features/role_strategy/adds_role_strategy.feature
274
+ - features/role_strategy/clears_role_strategy.feature
275
+ - init.rb
276
+ - lib/cream.rb
277
+ - lib/cream/configure.rb
278
+ - lib/cream/configure/after_init/role_config.rb
279
+ - lib/cream/configure/rails.rb
280
+ - lib/cream/controller/ability.rb
281
+ - lib/cream/helper/authlabels.rb
282
+ - lib/cream/helper/host.rb
283
+ - lib/cream/helper/role.rb
284
+ - lib/cream/namespaces.rb
285
+ - lib/cream/role.rb
286
+ - lib/cream/view/host_area.rb
287
+ - lib/cream/view/role_area.rb
288
+ - lib/cream/view/user_action_menu.rb
289
+ - lib/generators/cream/config/DESIGN NOTES.markdown
290
+ - lib/generators/cream/config/config_generator.rb
291
+ - lib/generators/cream/config/modules/cancan_config.rb
292
+ - lib/generators/cream/config/modules/cream_config.rb
293
+ - lib/generators/cream/config/modules/devise_config.rb
294
+ - lib/generators/cream/config/modules/helper.rb
295
+ - lib/generators/cream/config/modules/permits_config.rb
296
+ - lib/generators/cream/config/modules/roles_config.rb
297
+ - lib/generators/cream/views/haml_util.rb
298
+ - lib/generators/cream/views/views_generator.rb
299
+ - lib/generators/cream_refactor.rb
300
+ - log/development.log
301
+ - sandbox/test.rb
302
+ - spec/cream/configure/rails_spec.rb
303
+ - spec/cream/helper/host_spec.rb
304
+ - spec/cream/helper/role_spec.rb
305
+ - spec/cream/view/host_area_spec.rb
306
+ - spec/cream/view/role_area_spec.rb
307
+ - spec/cream/view/role_ext_spec.rb
308
+ - spec/generator_spec_helper.rb
309
+ - spec/generators/cream/config/devise/existing_devise_users.rb
310
+ - spec/generators/cream/config/empty_app/default_args_spec.rb
311
+ - spec/generators/cream/config/permits/existing_permits_spec.rb
312
+ - spec/generators/cream/config/permits/no_permits_spec.rb
313
+ - spec/generators/cream/config/roles/default_roles.rb
314
+ - spec/generators/cream/config/roles/roles_spec.rb
315
+ - spec/generators/cream/shared_examples.rb
316
+ - spec/generators/cream/views_generator_spec.rb
317
+ - spec/spec_helper.rb
318
+ - wiki/CONFIG_GENERATOR.txt
319
+ - wiki/DESIGN.txt
320
+ - wiki/INSTALLATION.txt
321
+ - wiki/PERMITS.txt
322
+ - wiki/ROLE_STRATEGIES.txt
323
+ - wiki/SPEC_NOTES.txt
324
+ - wiki/VIEWS_GENERATOR.txt
325
+ - wiki/VIEW_HELPERS.txt
326
+ has_rdoc: true
327
+ homepage: http://github.com/kristianmandrup/devise-assistant
328
+ licenses: []
329
+
330
+ post_install_message:
331
+ rdoc_options:
332
+ - --charset=UTF-8
333
+ require_paths:
334
+ - lib
335
+ required_ruby_version: !ruby/object:Gem::Requirement
336
+ none: false
337
+ requirements:
338
+ - - ">="
339
+ - !ruby/object:Gem::Version
340
+ segments:
341
+ - 0
342
+ version: "0"
343
+ required_rubygems_version: !ruby/object:Gem::Requirement
344
+ none: false
345
+ requirements:
346
+ - - ">="
347
+ - !ruby/object:Gem::Version
348
+ segments:
349
+ - 0
350
+ version: "0"
351
+ requirements: []
352
+
353
+ rubyforge_project:
354
+ rubygems_version: 1.3.7
355
+ signing_key:
356
+ specification_version: 3
357
+ summary: Integrates Devise, Roles and CanCan with Permits for a Rails 3 app
358
+ test_files:
359
+ - spec/cream/configure/rails_spec.rb
360
+ - spec/cream/helper/host_spec.rb
361
+ - spec/cream/helper/role_spec.rb
362
+ - spec/cream/view/host_area_spec.rb
363
+ - spec/cream/view/role_area_spec.rb
364
+ - spec/cream/view/role_ext_spec.rb
365
+ - spec/generator_spec_helper.rb
366
+ - spec/generators/cream/config/devise/existing_devise_users.rb
367
+ - spec/generators/cream/config/empty_app/default_args_spec.rb
368
+ - spec/generators/cream/config/permits/existing_permits_spec.rb
369
+ - spec/generators/cream/config/permits/no_permits_spec.rb
370
+ - spec/generators/cream/config/roles/default_roles.rb
371
+ - spec/generators/cream/config/roles/roles_spec.rb
372
+ - spec/generators/cream/shared_examples.rb
373
+ - spec/generators/cream/views_generator_spec.rb
374
+ - spec/spec_helper.rb