cancan-rest-links 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -2,15 +2,14 @@
2
2
 
3
3
  REST link helpers for the [CanCan](http://github.com/ryanb/cancan) permission system.
4
4
 
5
- ## Update:Nov 26, 2010
5
+ ## Rails 3 install
6
6
 
7
- From changelog:
7
+ in Gemfile insert:
8
+ <pre>
9
+ gem 'cancan-rest-links'
10
+ </pre>
8
11
 
9
- * Removed dependency to Cream for labels
10
- * Created class methods on CanCan::Links::Rest for handling labels, including translations
11
- * Created a Generator to create a locale file for labels
12
- * Created a spec to test the generator
13
- * Created specs to test the REST link generation with and without label translations
12
+ Then run <code>$ bundle install</code> from the terminal.
14
13
 
15
14
  ## Rails 3 usage
16
15
 
@@ -18,10 +17,81 @@ See the demo app at [CanCan permits demo app](https://github.com/kristianmandrup
18
17
 
19
18
  Configure your Rails 3 app for use with CanCan and some Authentication solution like Authlogic or Devise.
20
19
 
20
+ This locale file should be placed in config/locales in your Rails 3 app. The generator will create the above locale file as _cream.en.yml_
21
+
21
22
  ## Use with CanCan permits
22
23
 
23
24
  [CanCan permits](https://github.com/kristianmandrup/cancan-permits) is a gem that lets you use Permits with CanCan to configure permissions.
24
25
 
26
+ ## REST links
27
+
28
+ These REST link helpers always check the _current_user_ to see if the user has the required permission access for the required action on the given model. If not, the link is not rendered.
29
+
30
+ The following is a list of the REST links available and the required CanCan permission level for the model instance(s) that is linked to.
31
+ Note that the CanCan _:manage_ level implies full permission and _:write_ full mutation access.
32
+
33
+ * Index :read
34
+ * Show :read
35
+ * Create :create
36
+ * Edit :edit
37
+ * Delete :destroy
38
+
39
+ Typically the REST links are used within views, partials and view helpers. Example
40
+
41
+ <pre>
42
+ <%= index_link(Post, 'To the posts') %>
43
+ <%= create_link(Post, 'Create a new post') %>
44
+ </pre>
45
+
46
+ For the create and index REST actions, you can pass either an instance or a class of a model object. The other REST options only work with model instances.
47
+
48
+ ### index_link
49
+
50
+ <pre>index_link(Post)
51
+ index_link(Post, 'To the posts')
52
+ index_link(@post)
53
+ index_link(@post, 'All the posts')
54
+ </pre>
55
+
56
+ ### create_link
57
+
58
+ <pre>create_link(Post)
59
+ create_link(Post, 'Create the post')
60
+ create_link(@post)
61
+ create_link(@post, 'Create the post')</pre>
62
+
63
+ ### edit_link
64
+
65
+ <pre>edit_link(@post)
66
+ edit_link(@post, 'Edit the post')</pre>
67
+
68
+ ### delete_link
69
+
70
+ <pre>delete_link(@post)
71
+ delete_link(@post, 'Delete the post')</pre>
72
+
73
+ ### show_link
74
+
75
+ <pre>show_link(@post)
76
+ show_link(@post, 'Show the post')</pre>
77
+
78
+ ## Locale file
79
+
80
+ A locale file with the following structure can be created to define define labels for the various REST actions.
81
+
82
+ <pre>
83
+ en:
84
+ cream:
85
+ confirm: 'Are you sure?'
86
+ actions:
87
+ rest:
88
+ index: "Index"
89
+ new: "New"
90
+ edit: "Edit"
91
+ delete: "Delete"
92
+ show: "Show"
93
+ </pre>
94
+
25
95
  ## Note on Patches/Pull Requests
26
96
 
27
97
  * Fork the project.
data/Rakefile CHANGED
@@ -9,12 +9,12 @@ begin
9
9
  gem.authors = ["Kristian Mandrup"]
10
10
  gem.add_development_dependency "rspec", ">= 2.0.0"
11
11
  gem.add_development_dependency "rspec-action_view", ">= 0.3.4"
12
+ gem.add_development_dependency 'generator-spec', ">= 0.7.0"
12
13
 
13
14
  gem.add_dependency 'cancan', "~> 1.4.0"
14
15
  gem.add_dependency 'require_all', "~> 1.2.0"
15
16
  gem.add_dependency 'sugar-high', "~> 0.3.0"
16
- gem.add_dependency 'r3_plugin_toolbox', ">= 0.4.0"
17
- gem.add_dependency 'generator-spec', ">= 0.7.0"
17
+ gem.add_dependency 'r3_plugin_toolbox', ">= 0.4.0"
18
18
  end
19
19
  Jeweler::GemcutterTasks.new
20
20
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -1,61 +1,59 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cancan-rest-links}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2010-11-26}
12
+ s.date = %q{2010-12-23}
13
13
  s.description = %q{Guard your links with permissions}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.markdown"
17
+ "README.markdown"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- ".rspec",
23
- "Changelog.txt",
24
- "Gemfile",
25
- "Ideas and Planning.txt",
26
- "LICENSE",
27
- "README.markdown",
28
- "Rakefile",
29
- "VERSION",
30
- "cancan-rest-links.gemspec",
31
- "lib/cancan-rest-links.rb",
32
- "lib/cancan-rest-links/labels.rb",
33
- "lib/cancan-rest-links/namespaces.rb",
34
- "lib/cancan-rest-links/rails/configure.rb",
35
- "lib/cancan-rest-links/rest_links.rb",
36
- "lib/generators/cancan/restlinks/restlinks_generator.rb",
37
- "lib/generators/cancan/restlinks/templates/en.yml",
38
- "log/development.log",
39
- "sandbox/link_with_cream_spec.rb",
40
- "spec/cancan-rest-links/generators/restlinks_generator.rb",
41
- "spec/cancan-rest-links/rails/configure_spec.rb",
42
- "spec/cancan-rest-links/rest_links_default_spec.rb",
43
- "spec/cancan-rest-links/rest_links_translate_spec.rb",
44
- "spec/cancan-rest-links/translate_spec.rb",
45
- "spec/spec_helper.rb"
21
+ ".rspec",
22
+ "Changelog.txt",
23
+ "Gemfile",
24
+ "Ideas and Planning.txt",
25
+ "LICENSE",
26
+ "README.markdown",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "cancan-rest-links.gemspec",
30
+ "lib/cancan-rest-links.rb",
31
+ "lib/cancan-rest-links/labels.rb",
32
+ "lib/cancan-rest-links/namespaces.rb",
33
+ "lib/cancan-rest-links/rails/configure.rb",
34
+ "lib/cancan-rest-links/rest_links.rb",
35
+ "lib/generators/cancan/restlinks/restlinks_generator.rb",
36
+ "lib/generators/cancan/restlinks/templates/restlinks.en.yml",
37
+ "log/development.log",
38
+ "sandbox/link_with_cream_spec.rb",
39
+ "spec/cancan-rest-links/generators/restlinks_generator.rb",
40
+ "spec/cancan-rest-links/rails/configure_spec.rb",
41
+ "spec/cancan-rest-links/rest_links_default_spec.rb",
42
+ "spec/cancan-rest-links/rest_links_translate_spec.rb",
43
+ "spec/cancan-rest-links/translate_spec.rb",
44
+ "spec/spec_helper.rb"
46
45
  ]
47
46
  s.homepage = %q{http://github.com/kristianmandrup/cancan-rest-links}
48
- s.rdoc_options = ["--charset=UTF-8"]
49
47
  s.require_paths = ["lib"]
50
48
  s.rubygems_version = %q{1.3.7}
51
49
  s.summary = %q{Rest link helpers for CanCan}
52
50
  s.test_files = [
53
51
  "spec/cancan-rest-links/generators/restlinks_generator.rb",
54
- "spec/cancan-rest-links/rails/configure_spec.rb",
55
- "spec/cancan-rest-links/rest_links_default_spec.rb",
56
- "spec/cancan-rest-links/rest_links_translate_spec.rb",
57
- "spec/cancan-rest-links/translate_spec.rb",
58
- "spec/spec_helper.rb"
52
+ "spec/cancan-rest-links/rails/configure_spec.rb",
53
+ "spec/cancan-rest-links/rest_links_default_spec.rb",
54
+ "spec/cancan-rest-links/rest_links_translate_spec.rb",
55
+ "spec/cancan-rest-links/translate_spec.rb",
56
+ "spec/spec_helper.rb"
59
57
  ]
60
58
 
61
59
  if s.respond_to? :specification_version then
@@ -63,30 +61,42 @@ Gem::Specification.new do |s|
63
61
  s.specification_version = 3
64
62
 
65
63
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
64
+ s.add_runtime_dependency(%q<cancan>, ["~> 1.4.0"])
65
+ s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
66
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.0"])
67
+ s.add_runtime_dependency(%q<r3_plugin_toolbox>, ["~> 0.4.0"])
66
68
  s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
67
69
  s.add_development_dependency(%q<rspec-action_view>, [">= 0.3.4"])
70
+ s.add_development_dependency(%q<generator-spec>, [">= 0.7.0"])
68
71
  s.add_runtime_dependency(%q<cancan>, ["~> 1.4.0"])
69
72
  s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
70
73
  s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.0"])
71
74
  s.add_runtime_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
72
- s.add_runtime_dependency(%q<generator-spec>, [">= 0.7.0"])
73
75
  else
76
+ s.add_dependency(%q<cancan>, ["~> 1.4.0"])
77
+ s.add_dependency(%q<require_all>, ["~> 1.2.0"])
78
+ s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
79
+ s.add_dependency(%q<r3_plugin_toolbox>, ["~> 0.4.0"])
74
80
  s.add_dependency(%q<rspec>, [">= 2.0.0"])
75
81
  s.add_dependency(%q<rspec-action_view>, [">= 0.3.4"])
82
+ s.add_dependency(%q<generator-spec>, [">= 0.7.0"])
76
83
  s.add_dependency(%q<cancan>, ["~> 1.4.0"])
77
84
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
78
85
  s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
79
86
  s.add_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
80
- s.add_dependency(%q<generator-spec>, [">= 0.7.0"])
81
87
  end
82
88
  else
89
+ s.add_dependency(%q<cancan>, ["~> 1.4.0"])
90
+ s.add_dependency(%q<require_all>, ["~> 1.2.0"])
91
+ s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
92
+ s.add_dependency(%q<r3_plugin_toolbox>, ["~> 0.4.0"])
83
93
  s.add_dependency(%q<rspec>, [">= 2.0.0"])
84
94
  s.add_dependency(%q<rspec-action_view>, [">= 0.3.4"])
95
+ s.add_dependency(%q<generator-spec>, [">= 0.7.0"])
85
96
  s.add_dependency(%q<cancan>, ["~> 1.4.0"])
86
97
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
87
98
  s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
88
99
  s.add_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
89
- s.add_dependency(%q<generator-spec>, [">= 0.7.0"])
90
100
  end
91
101
  end
92
102
 
@@ -25,7 +25,7 @@ module CanCan::Links
25
25
  end
26
26
 
27
27
  def translate_labels
28
- ns_actions = 'cream.actions'
28
+ ns_actions = 'cream.actions.rest'
29
29
  tlabels =rest_labels.inject({}) {|result, action|
30
30
  result[action.to_sym] = t("#{ns_actions}.#{action}").humanize
31
31
  result
@@ -7,7 +7,7 @@ require 'logging_assist'
7
7
  module Cancan
8
8
  module Generators
9
9
  class RestlinksGenerator < Rails::Generators::Base
10
- desc "Configures Rails app for use with RestLinks"
10
+ desc "Configures Rails app for use with CanCan REST links"
11
11
 
12
12
  source_root File.dirname(__FILE__) + '/templates'
13
13
 
@@ -21,7 +21,7 @@ module Cancan
21
21
  # extend Rails3::Assist::UseMacro
22
22
 
23
23
  def copy_locale
24
- template "en.yml", "config/locales/cream.en.yml"
24
+ template "restlinks.en.yml", "config/locales/cream.en.yml"
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,10 @@
1
+ en:
2
+ cream:
3
+ confirm: 'Are you sure?'
4
+ actions:
5
+ rest:
6
+ index: "Index"
7
+ new: "New"
8
+ edit: "Edit"
9
+ delete: "Delete"
10
+ show: "Show"
@@ -13,9 +13,9 @@ end
13
13
 
14
14
 
15
15
  describe 'Restlinks generator' do
16
- use_helpers :controller, :special, :file
16
+ use_helpers :special, :file
17
17
 
18
- setup_generator :licenses do
18
+ setup_generator :cancan_rest_links do
19
19
  tests Cancan::Generators::RestlinksGenerator
20
20
  end
21
21
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,13 +14,72 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-26 00:00:00 +01:00
17
+ date: 2010-12-23 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rspec
22
- prerelease: false
21
+ name: cancan
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 4
30
+ - 0
31
+ version: 1.4.0
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: require_all
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 2
45
+ - 0
46
+ version: 1.2.0
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: sugar-high
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ - 3
60
+ - 0
61
+ version: 0.3.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: r3_plugin_toolbox
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ - 4
75
+ - 0
76
+ version: 0.4.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
82
+ requirement: &id005 !ruby/object:Gem::Requirement
24
83
  none: false
25
84
  requirements:
26
85
  - - ">="
@@ -31,11 +90,11 @@ dependencies:
31
90
  - 0
32
91
  version: 2.0.0
33
92
  type: :development
34
- version_requirements: *id001
93
+ prerelease: false
94
+ version_requirements: *id005
35
95
  - !ruby/object:Gem::Dependency
36
96
  name: rspec-action_view
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
97
+ requirement: &id006 !ruby/object:Gem::Requirement
39
98
  none: false
40
99
  requirements:
41
100
  - - ">="
@@ -46,11 +105,26 @@ dependencies:
46
105
  - 4
47
106
  version: 0.3.4
48
107
  type: :development
49
- version_requirements: *id002
108
+ prerelease: false
109
+ version_requirements: *id006
50
110
  - !ruby/object:Gem::Dependency
51
- name: cancan
111
+ name: generator-spec
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ segments:
118
+ - 0
119
+ - 7
120
+ - 0
121
+ version: 0.7.0
122
+ type: :development
52
123
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
124
+ version_requirements: *id007
125
+ - !ruby/object:Gem::Dependency
126
+ name: cancan
127
+ requirement: &id008 !ruby/object:Gem::Requirement
54
128
  none: false
55
129
  requirements:
56
130
  - - ~>
@@ -61,11 +135,11 @@ dependencies:
61
135
  - 0
62
136
  version: 1.4.0
63
137
  type: :runtime
64
- version_requirements: *id003
138
+ prerelease: false
139
+ version_requirements: *id008
65
140
  - !ruby/object:Gem::Dependency
66
141
  name: require_all
67
- prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
142
+ requirement: &id009 !ruby/object:Gem::Requirement
69
143
  none: false
70
144
  requirements:
71
145
  - - ~>
@@ -76,11 +150,11 @@ dependencies:
76
150
  - 0
77
151
  version: 1.2.0
78
152
  type: :runtime
79
- version_requirements: *id004
153
+ prerelease: false
154
+ version_requirements: *id009
80
155
  - !ruby/object:Gem::Dependency
81
156
  name: sugar-high
82
- prerelease: false
83
- requirement: &id005 !ruby/object:Gem::Requirement
157
+ requirement: &id010 !ruby/object:Gem::Requirement
84
158
  none: false
85
159
  requirements:
86
160
  - - ~>
@@ -91,11 +165,11 @@ dependencies:
91
165
  - 0
92
166
  version: 0.3.0
93
167
  type: :runtime
94
- version_requirements: *id005
168
+ prerelease: false
169
+ version_requirements: *id010
95
170
  - !ruby/object:Gem::Dependency
96
171
  name: r3_plugin_toolbox
97
- prerelease: false
98
- requirement: &id006 !ruby/object:Gem::Requirement
172
+ requirement: &id011 !ruby/object:Gem::Requirement
99
173
  none: false
100
174
  requirements:
101
175
  - - ">="
@@ -106,22 +180,8 @@ dependencies:
106
180
  - 0
107
181
  version: 0.4.0
108
182
  type: :runtime
109
- version_requirements: *id006
110
- - !ruby/object:Gem::Dependency
111
- name: generator-spec
112
183
  prerelease: false
113
- requirement: &id007 !ruby/object:Gem::Requirement
114
- none: false
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- segments:
119
- - 0
120
- - 7
121
- - 0
122
- version: 0.7.0
123
- type: :runtime
124
- version_requirements: *id007
184
+ version_requirements: *id011
125
185
  description: Guard your links with permissions
126
186
  email: kmandrup@gmail.com
127
187
  executables: []
@@ -133,7 +193,6 @@ extra_rdoc_files:
133
193
  - README.markdown
134
194
  files:
135
195
  - .document
136
- - .gitignore
137
196
  - .rspec
138
197
  - Changelog.txt
139
198
  - Gemfile
@@ -149,7 +208,7 @@ files:
149
208
  - lib/cancan-rest-links/rails/configure.rb
150
209
  - lib/cancan-rest-links/rest_links.rb
151
210
  - lib/generators/cancan/restlinks/restlinks_generator.rb
152
- - lib/generators/cancan/restlinks/templates/en.yml
211
+ - lib/generators/cancan/restlinks/templates/restlinks.en.yml
153
212
  - log/development.log
154
213
  - sandbox/link_with_cream_spec.rb
155
214
  - spec/cancan-rest-links/generators/restlinks_generator.rb
@@ -163,8 +222,8 @@ homepage: http://github.com/kristianmandrup/cancan-rest-links
163
222
  licenses: []
164
223
 
165
224
  post_install_message:
166
- rdoc_options:
167
- - --charset=UTF-8
225
+ rdoc_options: []
226
+
168
227
  require_paths:
169
228
  - lib
170
229
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
@@ -1,9 +0,0 @@
1
- en:
2
- cream:
3
- confirm: 'Are you sure?'
4
- actions:
5
- index: "Index"
6
- new: "New"
7
- edit: "Edit"
8
- delete: "Delete"
9
- show: "Show"