splendeo-generators 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/README.rdoc +13 -4
  2. data/rails_generators/splendeo_authentication/templates/sessions_controller.rb +4 -4
  3. data/rails_generators/splendeo_authentication/templates/users_controller.rb +1 -1
  4. data/rails_generators/splendeo_authentication/templates/views/erb/login.html.erb +1 -1
  5. data/rails_generators/splendeo_authentication/templates/views/erb/signup.html.erb +1 -1
  6. data/rails_generators/splendeo_authentication/templates/views/haml/login.html.haml +1 -1
  7. data/rails_generators/splendeo_authentication/templates/views/haml/signup.html.haml +1 -1
  8. data/rails_generators/splendeo_layout/USAGE +50 -8
  9. data/rails_generators/splendeo_layout/splendeo_layout_generator.rb +6 -10
  10. data/rails_generators/splendeo_layout/templates/config/locales/en.yml +4 -2
  11. data/rails_generators/splendeo_layout/templates/helper.rb +3 -3
  12. data/rails_generators/splendeo_scaffold/USAGE +27 -2
  13. data/rails_generators/splendeo_scaffold/splendeo_scaffold_generator.rb +70 -1
  14. data/rails_generators/splendeo_scaffold/templates/actions/create.rb +0 -1
  15. data/rails_generators/splendeo_scaffold/templates/actions/new.rb +0 -1
  16. data/rails_generators/splendeo_scaffold/templates/controller.rb +25 -6
  17. data/rails_generators/splendeo_scaffold/templates/model.rb +3 -0
  18. data/rails_generators/splendeo_scaffold/templates/views/erb/_link.html.erb +7 -0
  19. data/rails_generators/splendeo_scaffold/templates/views/erb/_link_destroy.html.erb +1 -0
  20. data/rails_generators/splendeo_scaffold/templates/views/erb/_link_edit.html.erb +1 -0
  21. data/rails_generators/splendeo_scaffold/templates/views/erb/_link_index.html.erb +1 -0
  22. data/rails_generators/splendeo_scaffold/templates/views/erb/_link_new.html.erb +1 -0
  23. data/rails_generators/splendeo_scaffold/templates/views/erb/_link_show.html.erb +1 -0
  24. data/rails_generators/splendeo_scaffold/templates/views/erb/_tagged_link.html.erb +12 -0
  25. data/rails_generators/splendeo_scaffold/templates/views/erb/edit.html.erb +2 -6
  26. data/rails_generators/splendeo_scaffold/templates/views/erb/index.html.erb +4 -12
  27. data/rails_generators/splendeo_scaffold/templates/views/erb/new.html.erb +1 -3
  28. data/rails_generators/splendeo_scaffold/templates/views/erb/show.html.erb +3 -9
  29. data/rails_generators/splendeo_scaffold/templates/views/haml/_link.html.haml +6 -0
  30. data/rails_generators/splendeo_scaffold/templates/views/haml/_link_destroy.html.haml +1 -0
  31. data/rails_generators/splendeo_scaffold/templates/views/haml/_link_edit.html.haml +1 -0
  32. data/rails_generators/splendeo_scaffold/templates/views/haml/_link_index.html.haml +1 -0
  33. data/rails_generators/splendeo_scaffold/templates/views/haml/_link_new.html.haml +1 -0
  34. data/rails_generators/splendeo_scaffold/templates/views/haml/_link_show.html.haml +1 -0
  35. data/rails_generators/splendeo_scaffold/templates/views/haml/_tagged_link.html.haml +9 -0
  36. data/rails_generators/splendeo_scaffold/templates/views/haml/edit.html.haml +2 -7
  37. data/rails_generators/splendeo_scaffold/templates/views/haml/index.html.haml +4 -10
  38. data/rails_generators/splendeo_scaffold/templates/views/haml/new.html.haml +1 -3
  39. data/rails_generators/splendeo_scaffold/templates/views/haml/show.html.haml +3 -11
  40. metadata +19 -5
data/README.rdoc CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  A collection of useful Rails generator scripts for scaffolding, layout files, authentication, and more.
4
4
 
5
+ This is a fork from Ryanb's nifty_generators (http://github.com/ryanb/nifty-generators). It extends it with
6
+ the following features:
7
+
8
+ * Everything is translatable in a i18n-compliant way
9
+ * formtastic is used for forms
10
+ * blueprintcss is included by default
11
+ * The scaffold generator supports declarative_authorization and cancan
5
12
 
6
13
  == Install
7
14
 
@@ -41,6 +48,10 @@ There are a few changes to the generated code as well, such as no XML format by
41
48
 
42
49
  It also offers support for HAML, Shoulda, and RSpec.
43
50
 
51
+ i18n + formtastic support make translations much easier.
52
+
53
+ Finally, blueprintcss is installed by default.
54
+
44
55
 
45
56
  <b>I get "undefined method 'title'" error.</b>
46
57
 
@@ -88,11 +99,9 @@ Also, make sure you're using Rails 2.1 or greater.
88
99
 
89
100
  If you are having a problem with Splendeo Generators, first look at the FAQs above. If you still cannot resolve it, please submit an issue here.
90
101
 
91
- http://github.com/ryanb/splendeo-generators/issues
102
+ http://github.com/splendeo/splendeo-generators/issues
92
103
 
93
104
 
94
105
  == Rails 3
95
106
 
96
- Splendeo Generators does not yet officially work with Rails 3, but a fork is available here.
97
-
98
- http://github.com/dvyjones/splendeo-generators
107
+ Splendeo Generators does not work with Rails 3.
@@ -8,7 +8,7 @@ class <%= session_plural_class_name %>Controller < ApplicationController
8
8
  @<%= session_singular_name %> = <%= session_class_name %>.new(params[:<%= session_singular_name %>])
9
9
  if @<%= session_singular_name %>.save
10
10
  flash[:notice] = t('flash_notice_logged_in')
11
- redirect_to_target_or_default(root_url)
11
+ redirect_to_target_or_default(root_path)
12
12
  else
13
13
  flash.now[:error] = t('flash_error_invalid_login')
14
14
  render :action => 'new'
@@ -19,7 +19,7 @@ class <%= session_plural_class_name %>Controller < ApplicationController
19
19
  @<%= session_singular_name %> = <%= session_class_name %>.find
20
20
  @<%= session_singular_name %>.destroy
21
21
  flash[:notice] = t('flash_notice_logged_out')
22
- redirect_to root_url
22
+ redirect_to root_path
23
23
  end
24
24
  <%- else -%>
25
25
  def new
@@ -30,7 +30,7 @@ class <%= session_plural_class_name %>Controller < ApplicationController
30
30
  if <%= user_singular_name %>
31
31
  session[:<%= user_singular_name %>_id] = <%= user_singular_name %>.id
32
32
  flash[:notice] = t('flash_notice_logged_in')
33
- redirect_to_target_or_default(root_url)
33
+ redirect_to_target_or_default(root_path)
34
34
  else
35
35
  flash.now[:error] = t('flash_error_invalid_login')
36
36
  render :action => 'new'
@@ -40,7 +40,7 @@ class <%= session_plural_class_name %>Controller < ApplicationController
40
40
  def destroy
41
41
  session[:<%= user_singular_name %>_id] = nil
42
42
  flash[:notice] = t('flash_notice_logged_out')
43
- redirect_to root_url
43
+ redirect_to root_path
44
44
  end
45
45
  <%- end -%>
46
46
  end
@@ -10,7 +10,7 @@ class <%= user_plural_class_name %>Controller < ApplicationController
10
10
  session[:<%= user_singular_name %>_id] = @<%= user_singular_name %>.id
11
11
  <%- end -%>
12
12
  flash[:notice] = t('flash_notice_signed_up')
13
- redirect_to root_url
13
+ redirect_to root_path
14
14
  else
15
15
  render :action => 'new'
16
16
  end
@@ -1,6 +1,6 @@
1
1
  <%% title t('log_in_title') %>
2
2
 
3
- <p><%%= t('sign_up_message', :url => signup_path) %></p>
3
+ <p><%%= t('sign_up_message', :link => link_to(t("sign_up_link"), signup_path)) %></p>
4
4
 
5
5
  <%- if options[:authlogic] -%>
6
6
  <%% semantic_form_for @<%= session_singular_name %> do |f| %>
@@ -1,6 +1,6 @@
1
1
  <%% title t('sign_up_title') %>
2
2
 
3
- <p><%%= t('log_in_message', :url => login_path) %></p>
3
+ <p><%%= t('log_in_message', :link => link_to(t("log_in_link"), login_path)) %></p>
4
4
 
5
5
  <%% semantic_form_for @<%= user_singular_name %> do |f| %>
6
6
  <%%= f.error_message_on :base %>
@@ -1,6 +1,6 @@
1
1
  - title t('log_in_title')
2
2
 
3
- %p== t('sign_up_message', :url => signup_path)
3
+ %p= t('sign_up_message', :link => link_to(t("sign_up_link"), signup_path))
4
4
 
5
5
  <%- if options[:authlogic] -%>
6
6
  - semantic_form_for @<%= session_singular_name %> do |f|
@@ -1,6 +1,6 @@
1
1
  - title t('sign_up_title')
2
2
 
3
- %p=t('log_in_message', :url => login_path)
3
+ %p= t('log_in_message', :link => link_to(t("log_in_link"), login_path))
4
4
 
5
5
  - semantic_form_for @<%= user_singular_name %> do |f|
6
6
  = f.error_message_on :base
@@ -3,23 +3,65 @@ Description:
3
3
  helper which will give some structure to a starting Rails app.
4
4
 
5
5
  The generator takes one argument which will be the name of the
6
- layout and stylesheet files. If no argument is passed then it defaults
7
- to "application".
6
+ layout and stylesheet files. If no argument is passed then it defaults
7
+ to "application".
8
8
 
9
9
  The helper module includes some methods which can be called in any
10
10
  template or partial to set variables to be used in the layout, such as
11
11
  page title and javascript/stylesheet includes.
12
+
13
+ Includes formtastic & blueprint stylesheets by default. Blueprint plugins
14
+ are available but commented out by default.
15
+
16
+ Includes a sample English locale for easy i18n. Note that if you are
17
+ translating to other languages, you may need to complete it with text for
18
+ translating rails' internal messages. Get the files you need from
19
+
20
+ http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale
21
+
22
+ and then add the parts contained on en.yml.
23
+
24
+ The helper includes a --skip-locale option that deactivates the generation
25
+ of the locale file.
26
+
27
+ The helper admits a --haml option that generates haml and sass files.
28
+ On this case it will also generate a haml plugin initialization file.
29
+
12
30
 
13
31
  Examples:
14
32
  script/generate splendeo_layout
15
33
 
16
- Layout: app/views/layouts/application.html.erb
17
- Stylesheet: public/stylesheets/application.css
18
- Helper: app/helpers/layout_helper.rb
34
+ Layout: app/views/layouts/application.html.erb
35
+ Stylesheets: public/stylesheets/application.css
36
+ public/stylesheets/blueprint/*
37
+ public/stylesheets/formtastic.css
38
+ public/stylesheets/formtastic_changes.css
39
+ Helper: app/helpers/layout_helper.rb
40
+ Initializers: config/initializers/formtastic.rb
41
+ Locale: config/locales/en.yml
19
42
 
20
43
 
21
44
  script/generate splendeo_layout admin
22
45
 
23
- Layout: app/views/layouts/admin.html.erb
24
- Stylesheet: public/stylesheets/admin.css
25
- Helper: app/helpers/layout_helper.rb
46
+ Layout: app/views/layouts/admin.html.erb
47
+ Stylesheets: public/stylesheets/admin.css
48
+ public/stylesheets/blueprint/*
49
+ public/stylesheets/formtastic.css
50
+ public/stylesheets/formtastic_changes.css
51
+ Helper: app/helpers/layout_helper.rb
52
+ Initializers: config/initializers/formtastic.rb
53
+ Locale: config/locales/en.yml
54
+
55
+
56
+ script/generate splendeo_layout --haml
57
+
58
+ Layout: app/views/layouts/application.html.haml
59
+ Stylesheets: public/stylesheets/sass/application.sass
60
+ public/stylesheets/sass/blueprint/*
61
+ public/stylesheets/sass/formtastic.sass
62
+ public/stylesheets/sass/formtastic_changes.sass
63
+ Helper: app/helpers/layout_helper.rb
64
+ Initializers: config/initializers/formtastic.rb
65
+ Locale: config/locales/en.yml
66
+ Plugin: vendor/plugins/haml/init.rb
67
+
@@ -38,11 +38,10 @@ class SplendeoLayoutGenerator < Rails::Generator::Base
38
38
 
39
39
  m.template "layout.html.haml", "app/views/layouts/#{file_name}.html.haml"
40
40
  m.file "sass/stylesheet.sass", "public/stylesheets/sass/#{file_name}.sass"
41
-
42
- unless options[:skip_formtastic]
43
- m.file 'sass/formtastic.sass', 'public/stylesheets/sass/formtastic.sass'
44
- m.file 'sass/formtastic_changes.sass', 'public/stylesheets/sass/formtastic_changes.sass'
45
- end
41
+
42
+ m.file 'sass/formtastic.sass', 'public/stylesheets/sass/formtastic.sass'
43
+ m.file 'sass/formtastic_changes.sass', 'public/stylesheets/sass/formtastic_changes.sass'
44
+
46
45
  else
47
46
 
48
47
  m.directory 'public/stylesheets/blueprint'
@@ -63,10 +62,8 @@ class SplendeoLayoutGenerator < Rails::Generator::Base
63
62
  m.template "layout.html.erb", "app/views/layouts/#{file_name}.html.erb"
64
63
  m.file "css/stylesheet.css", "public/stylesheets/#{file_name}.css"
65
64
 
66
- unless options[:skip_formtastic]
67
- m.file 'css/formtastic.css', 'public/stylesheets/formtastic.css'
68
- m.file 'css/formtastic_changes.css', 'public/stylesheets/formtastic_changes.css'
69
- end
65
+ m.file 'css/formtastic.css', 'public/stylesheets/formtastic.css'
66
+ m.file 'css/formtastic_changes.css', 'public/stylesheets/formtastic_changes.css'
70
67
  end
71
68
  m.file "helper.rb", "app/helpers/layout_helper.rb"
72
69
  end
@@ -83,7 +80,6 @@ class SplendeoLayoutGenerator < Rails::Generator::Base
83
80
  opt.separator 'Options:'
84
81
  opt.on("--haml", "Generate HAML for view, and SASS for stylesheet.") { |v| options[:haml] = v }
85
82
  opt.on("--skip-locale", "Skips the generation of a locale file") { |v| options[:skip_locale] = true }
86
- opt.on("--skip-formtastic", "Skips the generation formtastic-related files") { |v| options[:skip_formtastic] = true }
87
83
  end
88
84
 
89
85
  def banner
@@ -21,10 +21,12 @@ en:
21
21
 
22
22
  # Authentication
23
23
  log_in_button: "Log In"
24
- log_in_message: "Already have an account? <a href='{{url}}>Log in!</a>"
24
+ log_in_message: "Already have an account? {{link}}"
25
+ log_in_link: "Log in!"
25
26
  log_in_title: "Log In"
26
27
  sign_up_button: "Sign Up"
27
- sign_up_message: "Don't have an account? <a href='{{url}}'>Sign up!</a>"
28
+ sign_up_message: "Don't have an account? {{link}}"
29
+ sign_up_link: "Sign up!"
28
30
  sign_up_title: "Sign Up"
29
31
  login_label: "Login"
30
32
  password_label: "Password"
@@ -7,15 +7,15 @@ module LayoutHelper
7
7
  @content_for_title = page_title.to_s
8
8
  @show_title = show_title
9
9
  end
10
-
10
+
11
11
  def show_title?
12
12
  @show_title
13
13
  end
14
-
14
+
15
15
  def stylesheet(*args)
16
16
  content_for(:head) { stylesheet_link_tag(*args) }
17
17
  end
18
-
18
+
19
19
  def javascript(*args)
20
20
  content_for(:head) { javascript_include_tag(*args) }
21
21
  end
@@ -4,6 +4,8 @@ Description:
4
4
  resource-oriented application. Tests or specs are also generated depending
5
5
  on if you have a "spec" directory or not.
6
6
 
7
+ Haml, declarative_authorization and cancan are also supported on this generator.
8
+
7
9
  IMPORTANT: This generator uses the "title" helper method which is generated
8
10
  by the splendeo_layout generator. You may want to run that generator first.
9
11
 
@@ -30,6 +32,16 @@ Usage:
30
32
  Adding an "!" in the mix of arguments will invert the passed controller
31
33
  actions. This will include all 7 controller actitons except the ones
32
34
  mentioned. This option doesn't affect model attributes.
35
+
36
+ The --haml option generates haml views instead of erb.
37
+
38
+ The --declarative option will use declarative_authorization on the controller,
39
+ model & views. This option will be activated automatically if there's a file
40
+ named config/authorization_rules.
41
+ The --cancan option will do the same but using cancan. This option will be
42
+ activated automatically if declarative authorization isn't active and there's a
43
+ file named models/ability.rb
44
+ Use --skip-authorization if you want to generate without authorization.
33
45
 
34
46
  Examples:
35
47
  script/generate splendeo_scaffold post
@@ -37,15 +49,28 @@ Examples:
37
49
  Will create a controller called "posts" it will contain all seven
38
50
  CRUD actions along with the views. A model will NOT be created,
39
51
  instead it will look for an existing model and use those attributes.
40
-
52
+
41
53
  script/generate splendeo_scaffold post name:string content:text index new edit
42
54
 
43
55
  Will create a Post model and migration file with the name and content
44
56
  attributes. It will also create a controller with index, new, create,
45
57
  edit, and update actions. Notice the create and update actions are
46
58
  added automatically with new and edit.
47
-
59
+
48
60
  script/generate splendeo_scaffold post ! show new
49
61
 
50
62
  Creates a posts controller (no model) with index, edit, update, and
51
63
  destroy actions.
64
+
65
+ script/generate splendeo_scaffold post name:string content:text --declarative
66
+
67
+ Will create a model and migration file, and controller called "posts".
68
+ Declarative authorization will be used to authorize the model, controller and
69
+ view links.
70
+
71
+ script/generate splendeo_scaffold post --haml
72
+
73
+ Will create the controller with all 7 views. It will try to look for an existing
74
+ model. Views will be generated using haml instead of erb.
75
+
76
+
@@ -109,10 +109,14 @@ class SplendeoScaffoldGenerator < Rails::Generator::Base
109
109
  names.all? { |n| action? n.to_s }
110
110
  end
111
111
 
112
- def actions_with_find
112
+ def member_actions
113
113
  %w[ show edit update destroy ].select{|a| action?(a)}
114
114
  end
115
115
 
116
+ def new_actions
117
+ %w[ new create ].select{|a| action?(a)}
118
+ end
119
+
116
120
  def singular_name
117
121
  name.underscore
118
122
  end
@@ -135,6 +139,30 @@ class SplendeoScaffoldGenerator < Rails::Generator::Base
135
139
  end.join(" \n").strip
136
140
  end
137
141
 
142
+ def tabify(text, ident)
143
+ tab_string = ' ' * ident
144
+ return tab_string + text.rstrip.gsub("\n", "\n#{tab_string}") + "\n"
145
+ end
146
+
147
+ def link(action, options={})
148
+ if action? action
149
+ @action = action
150
+
151
+ instance_variable = options[:instance_variable].nil? ? true : options[:instance_variable]
152
+ @tag= options[:tag]
153
+ ident = options[:ident].nil? ? 0 : options[:ident]
154
+
155
+ if(@tag.present?)
156
+ text = read_template("views/#{view_language}/_tagged_link.html.#{view_language}")
157
+ else
158
+ text = read_template("views/#{view_language}/_link.html.#{view_language}")
159
+ end
160
+ text = text.gsub("@#{singular_name}", singular_name) if instance_variable == false
161
+
162
+ return tabify(text, ident)
163
+ end
164
+ end
165
+
138
166
  def render_form
139
167
  if form_partial?
140
168
  if options[:haml]
@@ -189,6 +217,29 @@ class SplendeoScaffoldGenerator < Rails::Generator::Base
189
217
  test_framework == :rspec
190
218
  end
191
219
 
220
+ def declarative?
221
+ authorization_framework == :declarative_authorization
222
+ end
223
+
224
+ def cancan?
225
+ authorization_framework == :cancan
226
+ end
227
+
228
+ def authorized?
229
+ af = authorization_framework
230
+ return (af==:cancan or af==:declarative_authorization)
231
+ end
232
+
233
+ def authorized_verb
234
+ return 'permitted_to?' if declarative?
235
+ return 'can?' if cancan?
236
+ end
237
+
238
+ def authorization_context
239
+ return ":#{plural_name}" if [:index,:new].include? @action
240
+ return "@#{singular_name}"
241
+ end
242
+
192
243
  protected
193
244
 
194
245
  def view_language
@@ -199,6 +250,19 @@ protected
199
250
  options[:test_framework] ||= default_test_framework
200
251
  end
201
252
 
253
+ def authorization_framework
254
+ return nil if options[:skip_authorization]
255
+ options[:authorization_framework] ||= default_authorization_framework
256
+ return options[:authorization_framework]
257
+ end
258
+
259
+ def default_authorization_framework
260
+ return nil if options[:skip_authorization]
261
+ return :declarative_authorization if(File.exist?(destination_path("config/authorization_rules.rb")))
262
+ return :cancan if(File.exist?(destination_path("models/ability.rb")))
263
+ return nil
264
+ end
265
+
202
266
  def default_test_framework
203
267
  File.exist?(destination_path("spec")) ? :rspec : :testunit
204
268
  end
@@ -210,6 +274,11 @@ protected
210
274
  opt.on("--skip-migration", "Don't generate migration file for model.") { |v| options[:skip_migration] = v }
211
275
  opt.on("--skip-timestamps", "Don't add timestamps to migration file.") { |v| options[:skip_timestamps] = v }
212
276
  opt.on("--skip-controller", "Don't generate controller, helper, or views.") { |v| options[:skip_controller] = v }
277
+
278
+ opt.on("--skip-authorization", "Don't generate authorization controls") { |v| options[:skip_authorization] = v }
279
+ opt.on("--declarative", "Include basic declarative authorization commands on models and controllers.") {|v| options[:authorization_framework] = :declarative_authorization}
280
+ opt.on("--cancan", "Include basic declarative authorization commands on models and controllers.") {|v| options[:authorization_framework] = :cancan}
281
+
213
282
  opt.on("--invert", "Generate all controller actions except these mentioned.") { |v| options[:invert] = v }
214
283
  opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = v }
215
284
  opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
@@ -1,5 +1,4 @@
1
1
  def create
2
- @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
3
2
  if @<%= singular_name %>.save
4
3
  flash[:notice] = t('flash_notice_successfully_created', :model => <%=class_name%>.human_name)
5
4
  redirect_to <%= item_path('url') %>
@@ -1,3 +1,2 @@
1
1
  def new
2
- @<%= singular_name %> = <%= class_name %>.new
3
2
  end
@@ -1,17 +1,34 @@
1
1
  class <%= plural_class_name %>Controller < ApplicationController
2
2
 
3
- <%- if actions_with_find.length > 0 -%>
4
- before_filter :find_<%= singular_name %>, :only => [ <%= actions_with_find.collect{|a| ":#{a}"}.join(', ') %> ]
3
+ <%- if declarative? -%>
4
+ filter_resource_access
5
+ <%- elsif cancan? -%>
6
+ load_and_authorize_resource
7
+ <%- else -%>
8
+ <%- if member_actions.length > 0 -%>
9
+ before_filter :load_<%= singular_name %>, :only => [ <%= member_actions.collect{|a| ":#{a}"}.join(', ') %> ]
10
+ <%- end -%>
11
+ <%- if new_actions.length > 0 -%>
12
+ before_filter :new_<%= singular_name %>_from_params, :only => [ <%= new_actions.collect{|a| ":#{a}"}.join(', ') %> ]
13
+ <%- end -%>
5
14
  <%- end -%>
6
15
 
7
16
  <%= controller_methods :actions %>
8
17
 
9
- <%- if actions_with_find.length > 0 -%>
10
- protected
18
+ protected
11
19
 
12
- def find_<%= singular_name %>
20
+ <%- unless authorized? -%>
21
+
22
+ <%- if new_actions.length > 0 -%>
23
+ def new_<%= singular_name %>_from_params
24
+ @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
25
+ end
26
+ <%- end -%>
27
+
28
+ <%- if member_actions.length > 0 -%>
29
+ def load_<%= singular_name %>
13
30
  @<%= singular_name %> = <%= class_name %>.find(params[:id])
14
- rescue ActiveRecord::RecordNotFound => msg
31
+ rescue ActiveRecord::RecordNotFound => msg
15
32
  flash[:error] = msg
16
33
  <%- if action?(:index) -%>
17
34
  redirect_to :action => :index
@@ -19,5 +36,7 @@ class <%= plural_class_name %>Controller < ApplicationController
19
36
  redirect_to root_path
20
37
  <%- end -%>
21
38
  end
39
+ <%- end -%>
40
+
22
41
  <%- end -%>
23
42
  end
@@ -1,3 +1,6 @@
1
1
  class <%= class_name %> < ActiveRecord::Base
2
2
  attr_accessible <%= attributes.map { |a| ":#{a.name}" }.join(", ") %>
3
+ <%- if declarative? -%>
4
+ using_access_control
5
+ <%- end -%>
3
6
  end
@@ -0,0 +1,7 @@
1
+ <%- if authorized? -%>
2
+ <%% if <%= authorized_verb %> :<%= @action %>, <%= authorization_context %> %>
3
+ <%= read_template "views/erb/_link_#{@action}.html.erb" -%>
4
+ <%% end %>
5
+ <%- else -%>
6
+ <%= read_template "views/erb/_link_#{@action}.html.erb" -%>
7
+ <%- end -%>
@@ -0,0 +1 @@
1
+ <%%= link_to t("destroy_link"), @<%= singular_name %>, :confirm => t('destroy_confirmation'), :method => :delete %>
@@ -0,0 +1 @@
1
+ <%%= link_to t("edit_link"), edit_<%= singular_name %>_path(@<%= singular_name %>) %>
@@ -0,0 +1 @@
1
+ <%%= link_to t("back_to_list_link"), <%= plural_name %>_path %>
@@ -0,0 +1 @@
1
+ <%%= link_to t("new_link", :model => <%= class_name %>.human_name), new_<%= singular_name %>_path %>
@@ -0,0 +1 @@
1
+ <%%= link_to t("show_link"), @<%= singular_name %> %>
@@ -0,0 +1,12 @@
1
+ <%- if authorized? -%>
2
+ <%% if <%= authorized_verb %> :<%= @action %>, <%= authorization_context %> %>
3
+ <<%= @tag %>>
4
+ <%= read_template "views/erb/_link_#{@action}.html.erb" -%>
5
+ </<%= @tag %>>
6
+ <%% end %>
7
+ <%- else -%>
8
+ <<%= @tag %>>
9
+ <%= read_template "views/erb/_link_#{@action}.html.erb" -%>
10
+ </<%= @tag %>>
11
+ <%- end -%>
12
+
@@ -4,11 +4,7 @@
4
4
 
5
5
  <%- if actions? :show, :index -%>
6
6
  <p>
7
- <%- if action? :show -%>
8
- <%%= link_to t("show_link"), @<%= singular_name %> %> |
9
- <%- end -%>
10
- <%- if action? :index -%>
11
- <%%= link_to t("view_all_link"), <%= plural_name %>_path %>
12
- <%- end -%>
7
+ <%= link :show, :ident => 1 -%>
8
+ <%= link :index, :ident => 1 -%>
13
9
  </p>
14
10
  <%- end -%>
@@ -11,19 +11,11 @@
11
11
  <%- for attribute in attributes -%>
12
12
  <td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
13
13
  <%- end -%>
14
- <%- if action? :show -%>
15
- <td><%%= link_to t("show_link"), <%= singular_name %> %></td>
16
- <%- end -%>
17
- <%- if action? :edit -%>
18
- <td><%%= link_to t("edit_link"), edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
19
- <%- end -%>
20
- <%- if action? :destroy -%>
21
- <td><%%= link_to t("destroy_link"), <%= singular_name %>, :confirm => t('destroy_confirmation'), :method => :delete %></td>
22
- <%- end -%>
14
+ <%= link :show, :ident => 3, :tag => :td, :instance_variable => false -%>
15
+ <%= link :edit, :ident => 3, :tag => :td, :instance_variable => false -%>
16
+ <%= link :destroy, :ident => 3, :tag => :td, :instance_variable => false -%>
23
17
  </tr>
24
18
  <%% end %>
25
19
  </table>
26
20
 
27
- <%- if action? :new -%>
28
- <p><%%= link_to t("new_link", :model => <%= class_name %>.human_name), new_<%= singular_name %>_path %></p>
29
- <%- end -%>
21
+ <%= link :new, :tag => :p -%>
@@ -2,6 +2,4 @@
2
2
 
3
3
  <%= render_form %>
4
4
 
5
- <%- if action? :index -%>
6
- <p><%%= link_to t("back_to_list_link"), <%= plural_name %>_path %></p>
7
- <%- end -%>
5
+ <%= link :index, :tag => :p -%>
@@ -8,13 +8,7 @@
8
8
  <%- end -%>
9
9
 
10
10
  <p>
11
- <%- if action? :edit -%>
12
- <%%= link_to t('edit_link'), edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
13
- <%- end -%>
14
- <%- if action? :destroy -%>
15
- <%%= link_to t('destroy_link'), @<%= singular_name %>, :confirm => t('destroy_confirmation'), :method => :delete %> |
16
- <%- end -%>
17
- <%- if action? :index -%>
18
- <%%= link_to t("view_all_link"), <%= plural_name %>_path %>
19
- <%- end -%>
11
+ <%= link :edit, :ident => 1 -%>
12
+ <%= link :destroy, :ident => 1 -%>
13
+ <%= link :index, :ident => 1 -%>
20
14
  </p>
@@ -0,0 +1,6 @@
1
+ <%- if authorized? -%>
2
+ - if <%= authorized_verb %> :<%= @action %>, <%= authorization_context %>
3
+ <%= read_template "views/haml/_link_#{@action}.html.haml" -%>
4
+ <%- else -%>
5
+ <%= read_template "views/haml/_link_#{@action}.html.haml" -%>
6
+ <%- end -%>
@@ -0,0 +1 @@
1
+ = link_to t("destroy_link"), @<%= singular_name %>, :confirm => t('destroy_confirmation'), :method => :delete
@@ -0,0 +1 @@
1
+ = link_to t("edit_link"), edit_<%= singular_name %>_path(@<%= singular_name %>)
@@ -0,0 +1 @@
1
+ = link_to t("back_to_list_link"), <%= plural_name %>_path
@@ -0,0 +1 @@
1
+ = link_to t("new_link", :model => <%= class_name %>.human_name), new_<%= singular_name %>_path
@@ -0,0 +1 @@
1
+ = link_to t("show_link"), @<%= singular_name %>
@@ -0,0 +1,9 @@
1
+ <%- if authorized? -%>
2
+ - if <%= authorized_verb %> :<%= @action %>, <%= authorization_context %>
3
+ %<%= @tag %>
4
+ <%= read_template "views/haml/_link_#{@action}.html.haml" -%>
5
+ <%- else -%>
6
+ %<%= @tag %>
7
+ <%= read_template "views/haml/_link_#{@action}.html.haml" -%>
8
+ <%- end -%>
9
+
@@ -4,11 +4,6 @@
4
4
 
5
5
  <%- if actions? :show, :index -%>
6
6
  %p
7
- <%- if action? :show -%>
8
- = link_to t("show_link"), <%= singular_name %>_path(@<%= singular_name %>)
9
- |
10
- <%- end -%>
11
- <%- if action? :index -%>
12
- = link_to t("view_all_link"), <%= plural_name %>_path
13
- <%- end -%>
7
+ <%= link :show , :ident => 1 -%>
8
+ <%= link :index, :ident => 1 -%>
14
9
  <%- end -%>
@@ -10,16 +10,10 @@
10
10
  <%- for attribute in attributes -%>
11
11
  %td= h <%= singular_name %>.<%= attribute.name %>
12
12
  <%- end -%>
13
- <%- if action? :show -%>
14
- %td= link_to t('show_link'), <%= singular_name %>
15
- <%- end -%>
16
- <%- if action? :edit -%>
17
- %td= link_to t('edit_link'), edit_<%= singular_name %>_path(<%= singular_name %>)
18
- <%- end -%>
19
- <%- if action? :destroy -%>
20
- %td= link_to t('destroy_link'), <%= singular_name %>, :confirm => t('destroy_confirmation'), :method => :delete
21
- <%- end -%>
13
+ <%= link :show, :ident => 3, :tag => :td, :instance_variable => false -%>
14
+ <%= link :edit, :ident => 3, :tag => :td, :instance_variable => false -%>
15
+ <%= link :destroy, :ident => 3, :tag => :td, :instance_variable => false -%>
22
16
 
23
17
  <%- if actions? :new -%>
24
- %p= link_to t("new_link", :model => <%= class_name %>.human_name), new_<%= singular_name %>_path
18
+ <%= link :new, :tag => :p -%>
25
19
  <%- end -%>
@@ -2,6 +2,4 @@
2
2
 
3
3
  <%= render_form %>
4
4
 
5
- <%- if action? :index -%>
6
- %p= link_to t("back_to_list_link"), <%= plural_name %>_path
7
- <%- end -%>
5
+ <%= link :index, :tag => :p -%>
@@ -8,14 +8,6 @@
8
8
  <%- end -%>
9
9
 
10
10
  %p
11
- <%- if action? :edit -%>
12
- = link_to t('edit_link'), edit_<%= singular_name %>_path(@<%= singular_name %>)
13
- |
14
- <%- end -%>
15
- <%- if action? :destroy -%>
16
- = link_to t('destroy_link'), @<%= singular_name %>, :confirm => t('destroy_confirmation'), :method => :delete
17
- |
18
- <%- end -%>
19
- <%- if action? :index -%>
20
- = link_to t('view_all_link'), <%= plural_name %>_path
21
- <%- end -%>
11
+ <%= link :edit, :ident => 1 %>
12
+ <%= link :destroy, :ident => 1 %>
13
+ <%= link :index, :ident => 1 %>
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Bates
@@ -16,11 +16,11 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-02-16 00:00:00 +01:00
19
+ date: 2010-04-07 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies: []
22
22
 
23
- description: A fork of ryanb's nifty-generators, with i18n and blueprint.
23
+ description: ryanb's nifty-generators + i18n, blueprint, formtastic, declarative_authorization and cancan.
24
24
  email: egarcia@splendeo.es
25
25
  executables: []
26
26
 
@@ -38,15 +38,29 @@ files:
38
38
  - test/test_splendeo_authentication_generator.rb
39
39
  - test/test_splendeo_layout_generator.rb
40
40
  - rails_generators/splendeo_scaffold/templates/model.rb
41
+ - rails_generators/splendeo_scaffold/templates/views/haml/_link_new.html.haml
42
+ - rails_generators/splendeo_scaffold/templates/views/haml/_link_destroy.html.haml
43
+ - rails_generators/splendeo_scaffold/templates/views/haml/_link_edit.html.haml
44
+ - rails_generators/splendeo_scaffold/templates/views/haml/_tagged_link.html.haml
45
+ - rails_generators/splendeo_scaffold/templates/views/haml/_link_index.html.haml
46
+ - rails_generators/splendeo_scaffold/templates/views/haml/_link_show.html.haml
41
47
  - rails_generators/splendeo_scaffold/templates/views/haml/show.html.haml
42
48
  - rails_generators/splendeo_scaffold/templates/views/haml/_form.html.haml
43
49
  - rails_generators/splendeo_scaffold/templates/views/haml/index.html.haml
50
+ - rails_generators/splendeo_scaffold/templates/views/haml/_link.html.haml
44
51
  - rails_generators/splendeo_scaffold/templates/views/haml/edit.html.haml
45
52
  - rails_generators/splendeo_scaffold/templates/views/haml/new.html.haml
46
53
  - rails_generators/splendeo_scaffold/templates/views/erb/_form.html.erb
54
+ - rails_generators/splendeo_scaffold/templates/views/erb/_tagged_link.html.erb
55
+ - rails_generators/splendeo_scaffold/templates/views/erb/_link_edit.html.erb
47
56
  - rails_generators/splendeo_scaffold/templates/views/erb/edit.html.erb
57
+ - rails_generators/splendeo_scaffold/templates/views/erb/_link_index.html.erb
58
+ - rails_generators/splendeo_scaffold/templates/views/erb/_link_destroy.html.erb
48
59
  - rails_generators/splendeo_scaffold/templates/views/erb/show.html.erb
60
+ - rails_generators/splendeo_scaffold/templates/views/erb/_link_new.html.erb
61
+ - rails_generators/splendeo_scaffold/templates/views/erb/_link.html.erb
49
62
  - rails_generators/splendeo_scaffold/templates/views/erb/index.html.erb
63
+ - rails_generators/splendeo_scaffold/templates/views/erb/_link_show.html.erb
50
64
  - rails_generators/splendeo_scaffold/templates/views/erb/new.html.erb
51
65
  - rails_generators/splendeo_scaffold/templates/helper.rb
52
66
  - rails_generators/splendeo_scaffold/templates/controller.rb