iain-pizza-generators 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/CHANGELOG +67 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +238 -0
  4. data/Rakefile +16 -0
  5. data/TODO +7 -0
  6. data/lib/pizza_generators.rb +3 -0
  7. data/pizza-generators.gemspec +53 -0
  8. data/rails_generators/pizza_authentication/USAGE +46 -0
  9. data/rails_generators/pizza_authentication/lib/insert_commands.rb +74 -0
  10. data/rails_generators/pizza_authentication/pizza_authentication_generator.rb +123 -0
  11. data/rails_generators/pizza_authentication/templates/authentication.rb +43 -0
  12. data/rails_generators/pizza_authentication/templates/fixtures.yml +26 -0
  13. data/rails_generators/pizza_authentication/templates/migration.rb +33 -0
  14. data/rails_generators/pizza_authentication/templates/session.rb +3 -0
  15. data/rails_generators/pizza_authentication/templates/sessions_controller.rb +24 -0
  16. data/rails_generators/pizza_authentication/templates/sessions_helper.rb +2 -0
  17. data/rails_generators/pizza_authentication/templates/tests/rspec/sessions_controller.rb +45 -0
  18. data/rails_generators/pizza_authentication/templates/tests/rspec/user.rb +45 -0
  19. data/rails_generators/pizza_authentication/templates/tests/rspec/users_controller.rb +33 -0
  20. data/rails_generators/pizza_authentication/templates/tests/shoulda/sessions_controller.rb +44 -0
  21. data/rails_generators/pizza_authentication/templates/tests/shoulda/user.rb +83 -0
  22. data/rails_generators/pizza_authentication/templates/tests/shoulda/users_controller.rb +25 -0
  23. data/rails_generators/pizza_authentication/templates/tests/testunit/sessions_controller.rb +32 -0
  24. data/rails_generators/pizza_authentication/templates/tests/testunit/user.rb +86 -0
  25. data/rails_generators/pizza_authentication/templates/tests/testunit/users_controller.rb +21 -0
  26. data/rails_generators/pizza_authentication/templates/user.rb +3 -0
  27. data/rails_generators/pizza_authentication/templates/users_controller.rb +13 -0
  28. data/rails_generators/pizza_authentication/templates/users_helper.rb +2 -0
  29. data/rails_generators/pizza_authentication/templates/views/erb/login.html.erb +15 -0
  30. data/rails_generators/pizza_authentication/templates/views/erb/signup.html.erb +24 -0
  31. data/rails_generators/pizza_authentication/templates/views/haml/login.html.haml +15 -0
  32. data/rails_generators/pizza_authentication/templates/views/haml/signup.html.haml +19 -0
  33. data/rails_generators/pizza_config/USAGE +23 -0
  34. data/rails_generators/pizza_config/pizza_config_generator.rb +32 -0
  35. data/rails_generators/pizza_config/templates/config.yml +8 -0
  36. data/rails_generators/pizza_config/templates/load_config.rb +2 -0
  37. data/rails_generators/pizza_layout/USAGE +25 -0
  38. data/rails_generators/pizza_layout/pizza_layout_generator.rb +55 -0
  39. data/rails_generators/pizza_layout/templates/_menu.html.haml +4 -0
  40. data/rails_generators/pizza_layout/templates/application.sass +5 -0
  41. data/rails_generators/pizza_layout/templates/definition_lists.sass +8 -0
  42. data/rails_generators/pizza_layout/templates/forms.sass +79 -0
  43. data/rails_generators/pizza_layout/templates/helper.rb +41 -0
  44. data/rails_generators/pizza_layout/templates/layout.html.erb +22 -0
  45. data/rails_generators/pizza_layout/templates/layout.html.haml +25 -0
  46. data/rails_generators/pizza_layout/templates/layout.sass +121 -0
  47. data/rails_generators/pizza_layout/templates/required.png +0 -0
  48. data/rails_generators/pizza_layout/templates/reset.sass +39 -0
  49. data/rails_generators/pizza_layout/templates/stylesheet.css +81 -0
  50. data/rails_generators/pizza_layout/templates/tables.sass +23 -0
  51. data/rails_generators/pizza_layout/templates/will_paginate.rb +9 -0
  52. data/rails_generators/pizza_scaffold/USAGE +51 -0
  53. data/rails_generators/pizza_scaffold/pizza_scaffold_generator.rb +233 -0
  54. data/rails_generators/pizza_scaffold/templates/actions/create.rb +4 -0
  55. data/rails_generators/pizza_scaffold/templates/actions/destroy.rb +4 -0
  56. data/rails_generators/pizza_scaffold/templates/actions/edit.rb +0 -0
  57. data/rails_generators/pizza_scaffold/templates/actions/index.rb +3 -0
  58. data/rails_generators/pizza_scaffold/templates/actions/new.rb +0 -0
  59. data/rails_generators/pizza_scaffold/templates/actions/show.rb +0 -0
  60. data/rails_generators/pizza_scaffold/templates/actions/update.rb +4 -0
  61. data/rails_generators/pizza_scaffold/templates/controller.rb +11 -0
  62. data/rails_generators/pizza_scaffold/templates/fixtures.yml +9 -0
  63. data/rails_generators/pizza_scaffold/templates/helper.rb +2 -0
  64. data/rails_generators/pizza_scaffold/templates/migration.rb +16 -0
  65. data/rails_generators/pizza_scaffold/templates/model.rb +21 -0
  66. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/create.rb +15 -0
  67. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/destroy.rb +10 -0
  68. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/edit.rb +8 -0
  69. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/index.rb +8 -0
  70. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/new.rb +8 -0
  71. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/show.rb +8 -0
  72. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/update.rb +15 -0
  73. data/rails_generators/pizza_scaffold/templates/tests/rspec/controller.rb +8 -0
  74. data/rails_generators/pizza_scaffold/templates/tests/rspec/model.rb +7 -0
  75. data/rails_generators/pizza_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  76. data/rails_generators/pizza_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  77. data/rails_generators/pizza_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  78. data/rails_generators/pizza_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  79. data/rails_generators/pizza_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  80. data/rails_generators/pizza_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  81. data/rails_generators/pizza_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  82. data/rails_generators/pizza_scaffold/templates/tests/shoulda/controller.rb +5 -0
  83. data/rails_generators/pizza_scaffold/templates/tests/shoulda/model.rb +7 -0
  84. data/rails_generators/pizza_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  85. data/rails_generators/pizza_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  86. data/rails_generators/pizza_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  87. data/rails_generators/pizza_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  88. data/rails_generators/pizza_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  89. data/rails_generators/pizza_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  90. data/rails_generators/pizza_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  91. data/rails_generators/pizza_scaffold/templates/tests/testunit/controller.rb +5 -0
  92. data/rails_generators/pizza_scaffold/templates/tests/testunit/model.rb +7 -0
  93. data/rails_generators/pizza_scaffold/templates/views/erb/_form.html.erb +10 -0
  94. data/rails_generators/pizza_scaffold/templates/views/erb/edit.html.erb +14 -0
  95. data/rails_generators/pizza_scaffold/templates/views/erb/index.html.erb +29 -0
  96. data/rails_generators/pizza_scaffold/templates/views/erb/new.html.erb +7 -0
  97. data/rails_generators/pizza_scaffold/templates/views/erb/show.html.erb +20 -0
  98. data/rails_generators/pizza_scaffold/templates/views/haml/_form.html.haml +10 -0
  99. data/rails_generators/pizza_scaffold/templates/views/haml/edit.html.haml +13 -0
  100. data/rails_generators/pizza_scaffold/templates/views/haml/index.html.haml +31 -0
  101. data/rails_generators/pizza_scaffold/templates/views/haml/new.html.haml +8 -0
  102. data/rails_generators/pizza_scaffold/templates/views/haml/show.html.haml +17 -0
  103. data/tasks/deployment.rake +5 -0
  104. data/test/test_helper.rb +117 -0
  105. data/test/test_pizza_authentication_generator.rb +158 -0
  106. data/test/test_pizza_config_generator.rb +37 -0
  107. data/test/test_pizza_layout_generator.rb +42 -0
  108. data/test/test_pizza_scaffold_generator.rb +532 -0
  109. metadata +237 -0
data/CHANGELOG ADDED
@@ -0,0 +1,67 @@
1
+ * fixing password field in HAML signup page in nifty_authentication
2
+
3
+ 0.2.2 (November 11th, 2008)
4
+
5
+ * fixing sessions_path reference in nifty_authentication
6
+
7
+ * adding more validations to user model in nifty_authentication
8
+
9
+ * cleaning up nifty_layout stylesheet
10
+
11
+ 0.2.1 (November 10th, 2008)
12
+
13
+ * adding missing nifty_authentication files
14
+
15
+ 0.2.0 (November 4th, 2008)
16
+
17
+ * adding nifty_authentication
18
+
19
+ 0.1.8 (October 3rd, 2008)
20
+
21
+ * compatibility with RubyGems 1.3
22
+
23
+ * using f.error_messages instead of error_messages_for (thanks Zach Langley)
24
+
25
+ 0.1.7 (August 15th, 2008)
26
+
27
+ * fixing shoulda tests
28
+
29
+ 0.1.6 (August 7th, 2008)
30
+
31
+ * adding option to specify Shoulda as testing framework in nifty_scaffold generator
32
+
33
+ * adding options to manually specify rspec or testunit framework in nifty_scaffold generator
34
+
35
+ 0.1.5 (August 7th, 2008)
36
+
37
+ * adding option to nifty layout to generate HAML views and SASS stylesheets
38
+
39
+ * adding option to nifty scaffold to generate HAML views
40
+
41
+ 0.1.4 (July 21st, 2008)
42
+
43
+ * using same logic as model spec in model test for scaffold
44
+
45
+ * simplifying model spec generated by scaffold
46
+
47
+ * adding error_messages_for to form partial
48
+
49
+ 0.1.3 (June 20th, 2008)
50
+
51
+ * using _url in controllers instead of _path
52
+
53
+ * improving the nifty_config default example YAML file
54
+
55
+ 0.1.2 (May 16th, 2008)
56
+
57
+ * mentioning nifty_layout in nifty_scaffold generator
58
+
59
+ * adding nifty_config generator
60
+
61
+ 0.1.1 (May 9th, 2008)
62
+
63
+ * adding tests and specs to scaffold generator
64
+
65
+ 0.1.0 (May 8th, 2008)
66
+
67
+ * initial release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Ryan Bates
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,238 @@
1
+ = Pizza Generators
2
+
3
+ A collection of useful Rails generator scripts.
4
+
5
+ *NOTE* This is a fork of Ryan Bates' Nifty Generators. It has been altered so it fits the plugins I use. Use at your own risk!
6
+
7
+
8
+ == Install
9
+
10
+ gem install iain-pizza-generators
11
+
12
+ == Why Pizza?
13
+
14
+ Here is what is Pizza compared to Nifty:
15
+
16
+ ==== Done
17
+
18
+ * Haml is default for pizza_scaffold, use <tt>--erb</tt> to switch back to erb
19
+ * definition_list_for (from http://github.com/iain/model_based_html)
20
+ * table_for (from http://github.com/iain/model_based_html)
21
+ * form_for (from http://github.com/iain/fieldset_helper)
22
+ * ResourceController (from http://github.com/giraffesoft/resource_controller)
23
+ * Rails i18n and supposes Mr. T (from http://github.com/iain/mr.-t)
24
+ * WillPaginate (from http://github.com/mislav/will_paginate)
25
+ * Some validations for models automaticly entered and some belongs_to stuff too
26
+ * reset.sass for layout will keep your view tidy
27
+ * A main menu was added in app/views/shared/_menu.html.haml
28
+ * Provides a cancel_link helper
29
+ * Added WillPaginate.translate! to support i18n (see below)
30
+ * A cancel link for every form
31
+ * AuthLogic usage with pizza_authentication (from http://github.com/binarylogic/authlogic)
32
+ * Added gem dependencies to pizza-generators (my first try, so hopefully that works)
33
+
34
+ ==== Todo
35
+
36
+ * Add an internet only stylesheet and iepngfix.htc to pizza_layout
37
+ * Add message_block gem (from http://github.com/railsgarden/message_block)
38
+ * Use a FactoryGirl instead of fixtures
39
+ * Cucumber stories for RESTful controller in scaffold
40
+ * Update ERB, Test::Unit and Shoulda all over the place
41
+ * Do something with Rails shiny new feature: Templates
42
+ * Make the required plugins gems so they can be a gem dependency (not sure though)
43
+
44
+ == Setting up
45
+
46
+ Before doing anything, add these lines to <tt>config/environment.rb</tt>
47
+
48
+ config.gem "haml"
49
+ config.gem "authlogic"
50
+ config.gem "giraffesoft-resource_controller", :lib => "resource_controller", :source => "http://gems.github.com"
51
+ config.gem "mislav-will_paginate", :lib => "will_paginate", :source => "http://gems.github.com"
52
+ config.gem "rspec"
53
+ config.gem "rspec-rails"
54
+ config.gem "mocha"
55
+
56
+ Then run these commands:
57
+
58
+ sudo rake gems:install # this should have already been done via the gem dependencies
59
+ rake gems:unpack
60
+ haml --rails .
61
+ ./script/generate rspec
62
+
63
+ Install plugins:
64
+
65
+ ./script/plugin install git://github.com/iain/fieldset_helper.git
66
+ ./script/plugin install git://github.com/iain/mr.-t.git
67
+ ./script/plugin install git://github.com/iain/model_based_html.git
68
+ ./script/plugin install git://github.com/iain/i18n_label.git
69
+
70
+ Configure rspec to use mocha, in <tt>spec/spec_helper.rb</tt>
71
+
72
+ config.mock_with :mocha
73
+
74
+ Generate layout (required for all other generators):
75
+
76
+ ./script/generate pizza_layout
77
+
78
+ Add the layout helper to be included every where, in <tt>app/controllers/application.rb</tt>
79
+
80
+ helper :layout
81
+
82
+ Enable the cancel_link helper by adding code described below.
83
+
84
+ Generate authentication (optional):
85
+
86
+ ./script/generate pizza_authentication
87
+
88
+ Edit <tt>config/routes.rb</tt> to singularize the user_session resource:
89
+
90
+ map.resource :user_session
91
+
92
+ And add a root route:
93
+
94
+ map.root :login # for example
95
+
96
+ Edit <tt>spec/spec_helper.rb</tt> for authentication testing:
97
+
98
+ require 'authlogic/testing/test_unit_helpers'
99
+
100
+ Inspect the generated migration for creating the users table, to enable or disable any attributes that you do or don't want.
101
+
102
+ Run <tt>rake db:migrate</tt>
103
+
104
+ And see if the specs run: <tt>rake spec</tt>
105
+
106
+ == Usage
107
+
108
+ Once you install the gem, the generators will be available to all Rails
109
+ applications on your system. If you run script/generate without any
110
+ additional arguments you should see the available generators listed.
111
+
112
+ To run the generator, go to your rails project directory and call it
113
+ using the script/generate or script/destroy command.
114
+
115
+ script/generate pizza_scaffold Recipe name:string index new
116
+
117
+
118
+ == Included Generators
119
+
120
+ * pizza_layout: generates generic layout, stylesheet, and helper files.
121
+ * pizza_scaffold: generates a controller and optional model/migration.
122
+ * pizza_config: generates a config YAML file and loader.
123
+ * pizza_authentication: generates user model with sign up and log in.
124
+
125
+ Run the command with the <tt>--help</tt> option to learn more.
126
+
127
+ script/generate pizza_layout --help
128
+
129
+
130
+ == Troubleshooting
131
+
132
+ <b>Namespaced controllers howto</b>
133
+
134
+ Just scaffold a RescourceController. Move the controller and views to it's desired subfolders and add the namespace to the name of the class, e.g. Admin::PostsController. Configure your routes and you're done!
135
+
136
+ <b>I get "undefined method 'title'" error.</b>
137
+
138
+ Try running pizza_layout, that will generate this helper method. Or
139
+ you can just change the templates to whatever approach you prefer for
140
+ setting the title.
141
+
142
+
143
+ <b>I get "undefined method 'root_url'" error.</b>
144
+
145
+ Some generators default redirecting to the root_url. Set this in your
146
+ routes.rb file like this (substituting your controller name).
147
+
148
+ map.root :controller => 'foo'
149
+
150
+
151
+ <b>I get a missing database error.</b>
152
+
153
+ Run <tt>rake db:migrate</tt>.
154
+
155
+
156
+ <b>Forms don't work.</b>
157
+
158
+ Try restarting your development server. Sometimes it doesn't detect the
159
+ change in the routing.
160
+
161
+
162
+ <b>I can't set new attributes in my User model.</b>
163
+
164
+ Add the attribute to the attr_accessible line in the model.
165
+
166
+
167
+ <b>The tests/specs don't work.</b>
168
+
169
+ Make sure you have mocha installed and require it in your spec/test helper.
170
+
171
+ gem install mocha
172
+
173
+ # in spec_helper.rb
174
+ config.mock_with :mocha
175
+
176
+ # in test_helper.rb
177
+ require 'mocha'
178
+
179
+ Also, make sure you're using Rails 2.2.2 or greater.
180
+
181
+ <b>How to use the cancel_link?</b>
182
+
183
+ Add this code to your ApplicationController:
184
+
185
+ before_filter :remember_back
186
+ private
187
+ def remember_back
188
+ session[:back] = request.referrer if request.get?
189
+ end
190
+
191
+ <b>Translating will_paginate</b>
192
+
193
+ Pizza_layout adds an easy way to translate will_paginate. It will automatically be called when Rails loads.
194
+
195
+ Your translations should look something like this:
196
+
197
+ en:
198
+ pagination:
199
+ class: "pagination"
200
+ previous_label: "&laquo; Previous"
201
+ next_label: "Next &raquo;"
202
+ inner_window: 4 # links around the current_page
203
+ outer_window: 1 # links around beginning and end
204
+ separator: ' '
205
+ param_name: :page
206
+ params: ~
207
+ renderer: "WillPaginate::LinkRenderer"
208
+ page_links: true
209
+ container: true
210
+
211
+ The initializer will use the properties from the default_locale. Any other language just needs to define their own exceptions to this. So if :en is the default locale and you would switch to :nl, you'd only need to do:
212
+
213
+ nl:
214
+ pagination:
215
+ previous_label: "&laquo; Vorige"
216
+ next_label: "Volgende &raquo;"
217
+
218
+ When you support switching locales, you need to call WillPaginate.translate! everytime you switch locales. This can be done by adding to your ApplicationController:
219
+
220
+ before_filter :set_locale
221
+ private
222
+ def set_locale
223
+ I18n.locale = params[:locale]
224
+ WillPaginate.translate!
225
+ end
226
+
227
+ For more information, read mislav's code on github:
228
+ http://github.com/mislav/will_paginate/blob/master/lib/will_paginate/view_helpers.rb
229
+
230
+
231
+ == Development
232
+
233
+ This project can be found on github at the following URL.
234
+
235
+ http://github.com/iain/pizza-generators and http://github.com/ryanb/nifty-generators
236
+
237
+ If you wish the generators behaved differently, please consider
238
+ forking the project and modifying to your heart's content. (I did that! - Iain)
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('pizza-generators', '0.1.1') do |p|
6
+ p.project = "pizzagenerators"
7
+ p.description = "A collection of useful generator scripts for Rails."
8
+ p.url = "http://github.com/iain/pizza-generators"
9
+ p.author = 'Ryan Bates, Iain Hecker'
10
+ p.email = "iain@iain.nl"
11
+ p.ignore_pattern = ["script/*"]
12
+ p.development_dependencies = []
13
+ p.runtime_dependencies = ["authlogic", "giraffesoft-resource_controller", "mislave-will_paginate", "rspec", "rspec-rails", "mocha", "haml"]
14
+ end
15
+
16
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/TODO ADDED
@@ -0,0 +1,7 @@
1
+
2
+ Nifty Scaffold
3
+ - add some validation for attributes/action names
4
+ - refactor out long methods in scaffold generator
5
+
6
+ Nifty Config
7
+ - make it easier to specify non environment specific configs
@@ -0,0 +1,3 @@
1
+ module PizzaGenerators
2
+ # nothing to see here, the real action is under rails_generators
3
+ end
@@ -0,0 +1,53 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{pizza-generators}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ryan Bates, Iain Hecker"]
9
+ s.date = %q{2009-01-26}
10
+ s.description = %q{A collection of useful generator scripts for Rails.}
11
+ s.email = %q{iain@iain.nl}
12
+ s.extra_rdoc_files = ["lib/pizza_generators.rb", "README.rdoc", "LICENSE", "tasks/deployment.rake", "CHANGELOG", "TODO"]
13
+ s.files = ["pizza-generators.gemspec", "Rakefile", "lib/pizza_generators.rb", "rails_generators/pizza_authentication/USAGE", "rails_generators/pizza_authentication/templates/migration.rb", "rails_generators/pizza_authentication/templates/sessions_helper.rb", "rails_generators/pizza_authentication/templates/users_helper.rb", "rails_generators/pizza_authentication/templates/tests/shoulda/users_controller.rb", "rails_generators/pizza_authentication/templates/tests/shoulda/user.rb", "rails_generators/pizza_authentication/templates/tests/shoulda/sessions_controller.rb", "rails_generators/pizza_authentication/templates/tests/testunit/users_controller.rb", "rails_generators/pizza_authentication/templates/tests/testunit/user.rb", "rails_generators/pizza_authentication/templates/tests/testunit/sessions_controller.rb", "rails_generators/pizza_authentication/templates/tests/rspec/users_controller.rb", "rails_generators/pizza_authentication/templates/tests/rspec/user.rb", "rails_generators/pizza_authentication/templates/tests/rspec/sessions_controller.rb", "rails_generators/pizza_authentication/templates/users_controller.rb", "rails_generators/pizza_authentication/templates/fixtures.yml", "rails_generators/pizza_authentication/templates/user.rb", "rails_generators/pizza_authentication/templates/authentication.rb", "rails_generators/pizza_authentication/templates/session.rb", "rails_generators/pizza_authentication/templates/sessions_controller.rb", "rails_generators/pizza_authentication/templates/views/erb/signup.html.erb", "rails_generators/pizza_authentication/templates/views/erb/login.html.erb", "rails_generators/pizza_authentication/templates/views/haml/login.html.haml", "rails_generators/pizza_authentication/templates/views/haml/signup.html.haml", "rails_generators/pizza_authentication/lib/insert_commands.rb", "rails_generators/pizza_authentication/pizza_authentication_generator.rb", "rails_generators/pizza_scaffold/USAGE", "rails_generators/pizza_scaffold/templates/controller.rb", "rails_generators/pizza_scaffold/templates/migration.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/controller.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/index.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/show.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/new.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/create.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/edit.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/update.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/model.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/controller.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/index.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/show.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/new.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/create.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/edit.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/update.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/model.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/controller.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/index.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/show.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/new.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/create.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/edit.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/update.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/model.rb", "rails_generators/pizza_scaffold/templates/actions/index.rb", "rails_generators/pizza_scaffold/templates/actions/show.rb", "rails_generators/pizza_scaffold/templates/actions/new.rb", "rails_generators/pizza_scaffold/templates/actions/create.rb", "rails_generators/pizza_scaffold/templates/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/actions/edit.rb", "rails_generators/pizza_scaffold/templates/actions/update.rb", "rails_generators/pizza_scaffold/templates/model.rb", "rails_generators/pizza_scaffold/templates/helper.rb", "rails_generators/pizza_scaffold/templates/fixtures.yml", "rails_generators/pizza_scaffold/templates/views/erb/show.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/index.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/_form.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/edit.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/new.html.erb", "rails_generators/pizza_scaffold/templates/views/haml/edit.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/index.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/_form.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/show.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/new.html.haml", "rails_generators/pizza_scaffold/pizza_scaffold_generator.rb", "rails_generators/pizza_config/USAGE", "rails_generators/pizza_config/templates/config.yml", "rails_generators/pizza_config/templates/load_config.rb", "rails_generators/pizza_config/pizza_config_generator.rb", "rails_generators/pizza_layout/USAGE", "rails_generators/pizza_layout/templates/layout.html.haml", "rails_generators/pizza_layout/templates/stylesheet.css", "rails_generators/pizza_layout/templates/_menu.html.haml", "rails_generators/pizza_layout/templates/will_paginate.rb", "rails_generators/pizza_layout/templates/layout.html.erb", "rails_generators/pizza_layout/templates/definition_lists.sass", "rails_generators/pizza_layout/templates/required.png", "rails_generators/pizza_layout/templates/forms.sass", "rails_generators/pizza_layout/templates/layout.sass", "rails_generators/pizza_layout/templates/helper.rb", "rails_generators/pizza_layout/templates/reset.sass", "rails_generators/pizza_layout/templates/application.sass", "rails_generators/pizza_layout/templates/tables.sass", "rails_generators/pizza_layout/pizza_layout_generator.rb", "test/test_pizza_config_generator.rb", "test/test_pizza_authentication_generator.rb", "test/test_pizza_layout_generator.rb", "test/test_pizza_scaffold_generator.rb", "test/test_helper.rb", "README.rdoc", "LICENSE", "tasks/deployment.rake", "CHANGELOG", "TODO", "Manifest"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/iain/pizza-generators}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Pizza-generators", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{pizzagenerators}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{A collection of useful generator scripts for Rails.}
21
+ s.test_files = ["test/test_pizza_config_generator.rb", "test/test_pizza_authentication_generator.rb", "test/test_pizza_layout_generator.rb", "test/test_pizza_scaffold_generator.rb", "test/test_helper.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<authlogic>, [">= 0"])
29
+ s.add_runtime_dependency(%q<giraffesoft-resource_controller>, [">= 0"])
30
+ s.add_runtime_dependency(%q<mislave-will_paginate>, [">= 0"])
31
+ s.add_runtime_dependency(%q<rspec>, [">= 0"])
32
+ s.add_runtime_dependency(%q<rspec-rails>, [">= 0"])
33
+ s.add_runtime_dependency(%q<mocha>, [">= 0"])
34
+ s.add_runtime_dependency(%q<haml>, [">= 0"])
35
+ else
36
+ s.add_dependency(%q<authlogic>, [">= 0"])
37
+ s.add_dependency(%q<giraffesoft-resource_controller>, [">= 0"])
38
+ s.add_dependency(%q<mislave-will_paginate>, [">= 0"])
39
+ s.add_dependency(%q<rspec>, [">= 0"])
40
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
41
+ s.add_dependency(%q<mocha>, [">= 0"])
42
+ s.add_dependency(%q<haml>, [">= 0"])
43
+ end
44
+ else
45
+ s.add_dependency(%q<authlogic>, [">= 0"])
46
+ s.add_dependency(%q<giraffesoft-resource_controller>, [">= 0"])
47
+ s.add_dependency(%q<mislave-will_paginate>, [">= 0"])
48
+ s.add_dependency(%q<rspec>, [">= 0"])
49
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
50
+ s.add_dependency(%q<mocha>, [">= 0"])
51
+ s.add_dependency(%q<haml>, [">= 0"])
52
+ end
53
+ end
@@ -0,0 +1,46 @@
1
+ Description:
2
+ Generates a user model, users controller, and sessions controller. The
3
+ users controller handles the registration and the sessions controller
4
+ handles authentication. This is similar to restful_authentication, but
5
+ simpler.
6
+
7
+ IMPORTANT: This generator uses the "title" helper method which is generated
8
+ by the pizza_layout generator. You may want to run that generator first.
9
+
10
+ Usage:
11
+ If you do not pass any arguments, the model name will default to "user", and
12
+ the authentication controller will default to "sessions". You can override
13
+ each of these respectively by passing one or two arguments. Either name can
14
+ be CamelCased or under_scored.
15
+
16
+ Examples:
17
+ script/generate pizza_authentication
18
+
19
+ Creates user model, users_controller, and sessions_controller.
20
+
21
+ script/generate pizza_authentication account
22
+
23
+ Creates account model, accounts_controller, and sessions_controller.
24
+
25
+ script/generate pizza_authentication Account CurrentSession
26
+
27
+ Creates account model, accounts_controller, and current_sessions_controller.
28
+
29
+ Methods:
30
+ There are several methods generated which you can use in your application.
31
+ Here's a common example of what you might add to your layout.
32
+
33
+ <% if logged_in? %>
34
+ Welcome <%= current_user.username %>! Not you?
35
+ <%= link_to "Log out", logout_path %>
36
+ <% else %>
37
+ <%= link_to "Sign up", signup_path %> or
38
+ <%= link_to "log in", login_path %>.
39
+ <% end %>
40
+
41
+ You can also restrict unregistered users from accessing a controller using
42
+ a before filter. For example.
43
+
44
+ before_filter :login_required, :except => [:index, :show]
45
+
46
+ See the generated file lib/authentication.rb for details.
@@ -0,0 +1,74 @@
1
+ Rails::Generator::Commands::Create.class_eval do
2
+ def route_resource(*resources)
3
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
4
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
5
+
6
+ logger.route "map.resource #{resource_list}"
7
+ unless options[:pretend]
8
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
9
+ "#{match}\n map.resource #{resource_list}\n"
10
+ end
11
+ end
12
+ end
13
+
14
+ def route_name(name, path, route_options = {})
15
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
16
+
17
+ logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
18
+ unless options[:pretend]
19
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
20
+ "#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
21
+ end
22
+ end
23
+ end
24
+
25
+ def insert_into(file, line)
26
+ logger.insert "#{line} into #{file}"
27
+ unless options[:pretend]
28
+ gsub_file file, /^(class|module) .+$/ do |match|
29
+ "#{match}\n #{line}"
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ Rails::Generator::Commands::Destroy.class_eval do
36
+ def route_resource(*resources)
37
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
38
+ look_for = "\n map.resource #{resource_list}\n"
39
+ logger.route "map.resource #{resource_list}"
40
+ unless options[:pretend]
41
+ gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
42
+ end
43
+ end
44
+
45
+ def route_name(name, path, route_options = {})
46
+ look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
47
+ logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
48
+ unless options[:pretend]
49
+ gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
50
+ end
51
+ end
52
+
53
+ def insert_into(file, line)
54
+ logger.remove "#{line} from #{file}"
55
+ unless options[:pretend]
56
+ gsub_file file, "\n #{line}", ''
57
+ end
58
+ end
59
+ end
60
+
61
+ Rails::Generator::Commands::List.class_eval do
62
+ def route_resource(*resources)
63
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
64
+ logger.route "map.resource #{resource_list}"
65
+ end
66
+
67
+ def route_name(name, path, options = {})
68
+ logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
69
+ end
70
+
71
+ def insert_into(file, line)
72
+ logger.insert "#{line} into #{file}"
73
+ end
74
+ end
@@ -0,0 +1,123 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
+ class PizzaAuthenticationGenerator < Rails::Generator::Base
3
+ attr_accessor :user_name, :user_session_name
4
+
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+
8
+ @user_name = @args[0] || 'user'
9
+ @user_session_name = @user_name + '_session'
10
+ end
11
+
12
+ def manifest
13
+ record do |m|
14
+ m.directory "app/models"
15
+ m.directory "app/controllers"
16
+ m.directory "app/helpers"
17
+ m.directory "app/views"
18
+ m.directory "lib"
19
+
20
+ m.directory "app/views/#{user_plural_name}"
21
+ m.template "user.rb", "app/models/#{user_singular_name}.rb"
22
+ m.template "users_controller.rb", "app/controllers/#{user_plural_name}_controller.rb"
23
+ m.template "users_helper.rb", "app/helpers/#{user_plural_name}_helper.rb"
24
+ m.template "views/#{view_language}/signup.html.#{view_language}", "app/views/#{user_plural_name}/new.html.#{view_language}"
25
+
26
+ m.directory "app/views/#{user_session_plural_name}"
27
+ m.template "session.rb", "app/models/#{user_session_singular_name}.rb"
28
+ m.template "sessions_controller.rb", "app/controllers/#{user_session_plural_name}_controller.rb"
29
+ m.template "sessions_helper.rb", "app/helpers/#{user_session_plural_name}_helper.rb"
30
+ m.template "views/#{view_language}/login.html.#{view_language}", "app/views/#{user_session_plural_name}/new.html.#{view_language}"
31
+
32
+ m.template "authentication.rb", "lib/authentication.rb"
33
+ m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{user_plural_name}"
34
+
35
+ m.route_resources user_plural_name
36
+ m.route_resources user_session_plural_name
37
+ m.route_name :login, 'login', :controller => user_session_plural_name, :action => 'new'
38
+ m.route_name :logout, 'logout', :controller => user_session_plural_name, :action => 'destroy'
39
+ m.route_name :signup, 'signup', :controller => user_plural_name, :action => 'new'
40
+
41
+ m.insert_into 'app/controllers/application.rb', 'include Authentication'
42
+
43
+ if test_framework == :rspec
44
+ m.directory "spec"
45
+ m.directory "spec/fixtures"
46
+ m.directory "spec/controllers"
47
+ m.directory "spec/models"
48
+ m.template "fixtures.yml", "spec/fixtures/#{user_plural_name}.yml"
49
+ m.template "tests/rspec/user.rb", "spec/models/#{user_singular_name}_spec.rb"
50
+ m.template "tests/rspec/users_controller.rb", "spec/controllers/#{user_plural_name}_controller_spec.rb"
51
+ m.template "tests/rspec/sessions_controller.rb", "spec/controllers/#{user_session_plural_name}_controller_spec.rb"
52
+ else
53
+ m.directory "test"
54
+ m.directory "test/fixtures"
55
+ m.directory "test/functional"
56
+ m.directory "test/unit"
57
+ m.template "fixtures.yml", "test/fixtures/#{user_plural_name}.yml"
58
+ m.template "tests/#{test_framework}/user.rb", "test/unit/#{user_singular_name}_test.rb"
59
+ m.template "tests/#{test_framework}/users_controller.rb", "test/functional/#{user_plural_name}_controller_test.rb"
60
+ m.template "tests/#{test_framework}/sessions_controller.rb", "test/functional/#{user_session_plural_name}_controller_test.rb"
61
+ end
62
+ end
63
+ end
64
+
65
+ def user_singular_name
66
+ user_name.underscore
67
+ end
68
+
69
+ def user_plural_name
70
+ user_singular_name.pluralize
71
+ end
72
+
73
+ def user_class_name
74
+ user_name.camelize
75
+ end
76
+
77
+ def user_plural_class_name
78
+ user_plural_name.camelize
79
+ end
80
+
81
+ def user_session_class_name
82
+ user_session_name.camelize
83
+ end
84
+
85
+ def user_session_singular_name
86
+ user_session_name.underscore
87
+ end
88
+
89
+ def user_session_plural_name
90
+ user_session_singular_name.pluralize
91
+ end
92
+
93
+ def user_session_plural_class_name
94
+ user_session_plural_name.camelize
95
+ end
96
+
97
+ protected
98
+
99
+ def view_language
100
+ options[:erb] ? 'erb' : 'haml'
101
+ end
102
+
103
+ def test_framework
104
+ options[:test_framework] ||= File.exist?(destination_path("spec")) ? :rspec : :testunit
105
+ end
106
+
107
+ def add_options!(opt)
108
+ opt.separator ''
109
+ opt.separator 'Options:'
110
+ opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
111
+ opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
112
+ opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
113
+ opt.on("--erb", "Generate ERB views instead of HAML.") { |v| options[:erb] = true }
114
+ end
115
+
116
+ def banner
117
+ <<-EOS
118
+ Creates user model and controllers to handle registration and authentication.
119
+
120
+ USAGE: #{$0} #{spec.name} [user_name] [sessions_controller_name]
121
+ EOS
122
+ end
123
+ end