splendeo-generators 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +119 -0
- data/LICENSE +20 -0
- data/README.rdoc +98 -0
- data/Rakefile +12 -0
- data/lib/nifty_generators.rb +3 -0
- data/rails_generators/splendeo_authentication/USAGE +50 -0
- data/rails_generators/splendeo_authentication/lib/insert_commands.rb +74 -0
- data/rails_generators/splendeo_authentication/splendeo_authentication_generator.rb +128 -0
- data/rails_generators/splendeo_authentication/templates/authentication.rb +61 -0
- data/rails_generators/splendeo_authentication/templates/authlogic_session.rb +2 -0
- data/rails_generators/splendeo_authentication/templates/fixtures.yml +24 -0
- data/rails_generators/splendeo_authentication/templates/migration.rb +20 -0
- data/rails_generators/splendeo_authentication/templates/sessions_controller.rb +45 -0
- data/rails_generators/splendeo_authentication/templates/sessions_helper.rb +2 -0
- data/rails_generators/splendeo_authentication/templates/tests/rspec/sessions_controller.rb +39 -0
- data/rails_generators/splendeo_authentication/templates/tests/rspec/user.rb +83 -0
- data/rails_generators/splendeo_authentication/templates/tests/rspec/users_controller.rb +26 -0
- data/rails_generators/splendeo_authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
- data/rails_generators/splendeo_authentication/templates/tests/shoulda/user.rb +85 -0
- data/rails_generators/splendeo_authentication/templates/tests/shoulda/users_controller.rb +27 -0
- data/rails_generators/splendeo_authentication/templates/tests/testunit/sessions_controller.rb +36 -0
- data/rails_generators/splendeo_authentication/templates/tests/testunit/user.rb +88 -0
- data/rails_generators/splendeo_authentication/templates/tests/testunit/users_controller.rb +23 -0
- data/rails_generators/splendeo_authentication/templates/user.rb +42 -0
- data/rails_generators/splendeo_authentication/templates/users_controller.rb +18 -0
- data/rails_generators/splendeo_authentication/templates/users_helper.rb +2 -0
- data/rails_generators/splendeo_authentication/templates/views/erb/login.html.erb +30 -0
- data/rails_generators/splendeo_authentication/templates/views/erb/signup.html.erb +24 -0
- data/rails_generators/splendeo_authentication/templates/views/haml/login.html.haml +30 -0
- data/rails_generators/splendeo_authentication/templates/views/haml/signup.html.haml +24 -0
- data/rails_generators/splendeo_config/USAGE +23 -0
- data/rails_generators/splendeo_config/splendeo_config_generator.rb +32 -0
- data/rails_generators/splendeo_config/templates/config.yml +8 -0
- data/rails_generators/splendeo_config/templates/load_config.rb +2 -0
- data/rails_generators/splendeo_layout/USAGE +25 -0
- data/rails_generators/splendeo_layout/splendeo_layout_generator.rb +76 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/ie.sass +103 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/buttons/icons/cross.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/buttons/icons/key.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/buttons/icons/tick.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/buttons/readme.txt +32 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/buttons/screen.sass +104 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/fancy-type/readme.txt +14 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/fancy-type/screen.sass +34 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/doc.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/email.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/external.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/feed.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/im.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/pdf.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/visited.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/xls.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/readme.txt +18 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/screen.sass +50 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/rtl/readme.txt +10 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/rtl/screen.sass +272 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/print.sass +75 -0
- data/rails_generators/splendeo_layout/templates/blueprint-sass/screen.sass +1062 -0
- data/rails_generators/splendeo_layout/templates/blueprint/ie.css +35 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/buttons/icons/cross.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/buttons/icons/key.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/buttons/icons/tick.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/buttons/readme.txt +32 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/buttons/screen.css +97 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/fancy-type/readme.txt +14 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/fancy-type/screen.css +71 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/doc.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/email.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/external.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/feed.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/im.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/pdf.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/visited.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/xls.png +0 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/readme.txt +18 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/screen.css +40 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/rtl/readme.txt +10 -0
- data/rails_generators/splendeo_layout/templates/blueprint/plugins/rtl/screen.css +110 -0
- data/rails_generators/splendeo_layout/templates/blueprint/print.css +29 -0
- data/rails_generators/splendeo_layout/templates/blueprint/screen.css +258 -0
- data/rails_generators/splendeo_layout/templates/haml/init.rb +16 -0
- data/rails_generators/splendeo_layout/templates/helper.rb +22 -0
- data/rails_generators/splendeo_layout/templates/layout.html.erb +34 -0
- data/rails_generators/splendeo_layout/templates/layout.html.haml +31 -0
- data/rails_generators/splendeo_layout/templates/stylesheet.css +77 -0
- data/rails_generators/splendeo_layout/templates/stylesheet.sass +63 -0
- data/rails_generators/splendeo_scaffold/USAGE +51 -0
- data/rails_generators/splendeo_scaffold/splendeo_scaffold_generator.rb +232 -0
- data/rails_generators/splendeo_scaffold/templates/actions/create.rb +9 -0
- data/rails_generators/splendeo_scaffold/templates/actions/destroy.rb +6 -0
- data/rails_generators/splendeo_scaffold/templates/actions/edit.rb +3 -0
- data/rails_generators/splendeo_scaffold/templates/actions/index.rb +3 -0
- data/rails_generators/splendeo_scaffold/templates/actions/new.rb +3 -0
- data/rails_generators/splendeo_scaffold/templates/actions/show.rb +3 -0
- data/rails_generators/splendeo_scaffold/templates/actions/update.rb +9 -0
- data/rails_generators/splendeo_scaffold/templates/controller.rb +3 -0
- data/rails_generators/splendeo_scaffold/templates/fixtures.yml +9 -0
- data/rails_generators/splendeo_scaffold/templates/helper.rb +2 -0
- data/rails_generators/splendeo_scaffold/templates/migration.rb +16 -0
- data/rails_generators/splendeo_scaffold/templates/model.rb +3 -0
- data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/create.rb +11 -0
- data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
- data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/index.rb +4 -0
- data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/rails_generators/splendeo_scaffold/templates/tests/rspec/controller.rb +8 -0
- data/rails_generators/splendeo_scaffold/templates/tests/rspec/model.rb +7 -0
- data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
- data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
- data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
- data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
- data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
- data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
- data/rails_generators/splendeo_scaffold/templates/tests/shoulda/controller.rb +5 -0
- data/rails_generators/splendeo_scaffold/templates/tests/shoulda/model.rb +7 -0
- data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/rails_generators/splendeo_scaffold/templates/tests/testunit/controller.rb +5 -0
- data/rails_generators/splendeo_scaffold/templates/tests/testunit/model.rb +7 -0
- data/rails_generators/splendeo_scaffold/templates/views/erb/_form.html.erb +10 -0
- data/rails_generators/splendeo_scaffold/templates/views/erb/edit.html.erb +14 -0
- data/rails_generators/splendeo_scaffold/templates/views/erb/index.html.erb +29 -0
- data/rails_generators/splendeo_scaffold/templates/views/erb/new.html.erb +7 -0
- data/rails_generators/splendeo_scaffold/templates/views/erb/show.html.erb +20 -0
- data/rails_generators/splendeo_scaffold/templates/views/haml/_form.html.haml +10 -0
- data/rails_generators/splendeo_scaffold/templates/views/haml/edit.html.haml +14 -0
- data/rails_generators/splendeo_scaffold/templates/views/haml/index.html.haml +25 -0
- data/rails_generators/splendeo_scaffold/templates/views/haml/new.html.haml +7 -0
- data/rails_generators/splendeo_scaffold/templates/views/haml/show.html.haml +20 -0
- data/test/test_helper.rb +119 -0
- data/test/test_splendeo_authentication_generator.rb +274 -0
- data/test/test_splendeo_config_generator.rb +37 -0
- data/test/test_splendeo_layout_generator.rb +42 -0
- data/test/test_splendeo_scaffold_generator.rb +534 -0
- metadata +212 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
0.3.2 (February 16th, 2010)
|
2
|
+
|
3
|
+
* Including all files in gem, was missing files in rails_generator directory
|
4
|
+
|
5
|
+
|
6
|
+
0.3.1 (February 16th, 2010)
|
7
|
+
|
8
|
+
* improving documentation
|
9
|
+
|
10
|
+
* fixing name of generated session model for authlogic in nifty_authorization
|
11
|
+
|
12
|
+
* use "username" instead of "login" for authlogic haml form template in nifty_authorization
|
13
|
+
|
14
|
+
|
15
|
+
0.3.0 (August 15th, 2009)
|
16
|
+
|
17
|
+
* adding attr_accessible to models in nifty_scaffold
|
18
|
+
|
19
|
+
* adding authlogic support with --authlogic option in nifty_authentication
|
20
|
+
|
21
|
+
* pluralize second argument for controller in nifty_authentication
|
22
|
+
|
23
|
+
* don't convert javascript/stylesheet arguments to strings in nifty_layout
|
24
|
+
|
25
|
+
* store request location and redirect to it when logging in under nifty_authentication
|
26
|
+
|
27
|
+
|
28
|
+
0.2.4 (May 5th, 2009)
|
29
|
+
|
30
|
+
* using root_url when no index action in nifty_scaffold
|
31
|
+
|
32
|
+
* making password editable in user model in nifty_authentication
|
33
|
+
|
34
|
+
* adding filter_parameter_logging :password in nifty_authentication
|
35
|
+
|
36
|
+
|
37
|
+
0.2.3 (February 20th, 2009)
|
38
|
+
|
39
|
+
* fixing nifty_authentication to work with Rails 2.3 application_controller.rb
|
40
|
+
|
41
|
+
* fixing password field in HAML signup page in nifty_authentication
|
42
|
+
|
43
|
+
|
44
|
+
0.2.2 (November 11th, 2008)
|
45
|
+
|
46
|
+
* fixing sessions_path reference in nifty_authentication
|
47
|
+
|
48
|
+
* adding more validations to user model in nifty_authentication
|
49
|
+
|
50
|
+
* cleaning up nifty_layout stylesheet
|
51
|
+
|
52
|
+
|
53
|
+
0.2.1 (November 10th, 2008)
|
54
|
+
|
55
|
+
* adding missing nifty_authentication files
|
56
|
+
|
57
|
+
|
58
|
+
0.2.0 (November 4th, 2008)
|
59
|
+
|
60
|
+
* adding nifty_authentication
|
61
|
+
|
62
|
+
|
63
|
+
0.1.8 (October 3rd, 2008)
|
64
|
+
|
65
|
+
* compatibility with RubyGems 1.3
|
66
|
+
|
67
|
+
* using f.error_messages instead of error_messages_for (thanks Zach Langley)
|
68
|
+
|
69
|
+
|
70
|
+
0.1.7 (August 15th, 2008)
|
71
|
+
|
72
|
+
* fixing shoulda tests
|
73
|
+
|
74
|
+
|
75
|
+
0.1.6 (August 7th, 2008)
|
76
|
+
|
77
|
+
* adding option to specify Shoulda as testing framework in nifty_scaffold generator
|
78
|
+
|
79
|
+
* adding options to manually specify rspec or testunit framework in nifty_scaffold generator
|
80
|
+
|
81
|
+
|
82
|
+
0.1.5 (August 7th, 2008)
|
83
|
+
|
84
|
+
* adding option to nifty layout to generate HAML views and SASS stylesheets
|
85
|
+
|
86
|
+
* adding option to nifty scaffold to generate HAML views
|
87
|
+
|
88
|
+
|
89
|
+
0.1.4 (July 21st, 2008)
|
90
|
+
|
91
|
+
* using same logic as model spec in model test for scaffold
|
92
|
+
|
93
|
+
* simplifying model spec generated by scaffold
|
94
|
+
|
95
|
+
* adding error_messages_for to form partial
|
96
|
+
|
97
|
+
|
98
|
+
0.1.3 (June 20th, 2008)
|
99
|
+
|
100
|
+
* using _url in controllers instead of _path
|
101
|
+
|
102
|
+
* improving the nifty_config default example YAML file
|
103
|
+
|
104
|
+
|
105
|
+
0.1.2 (May 16th, 2008)
|
106
|
+
|
107
|
+
* mentioning nifty_layout in nifty_scaffold generator
|
108
|
+
|
109
|
+
* adding nifty_config generator
|
110
|
+
|
111
|
+
|
112
|
+
0.1.1 (May 9th, 2008)
|
113
|
+
|
114
|
+
* adding tests and specs to scaffold generator
|
115
|
+
|
116
|
+
|
117
|
+
0.1.0 (May 8th, 2008)
|
118
|
+
|
119
|
+
* initial release
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 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,98 @@
|
|
1
|
+
= Splendeo Generators
|
2
|
+
|
3
|
+
A collection of useful Rails generator scripts for scaffolding, layout files, authentication, and more.
|
4
|
+
|
5
|
+
|
6
|
+
== Install
|
7
|
+
|
8
|
+
gem install splendeo-generators
|
9
|
+
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
Once you install the gem, the generators will be available to all Rails applications on your system. If you run script/generate without any additional arguments you should see the available generators listed.
|
14
|
+
|
15
|
+
To run the generator, go to your rails project directory and call it using the script/generate or script/destroy command.
|
16
|
+
|
17
|
+
script/generate splendeo_scaffold Recipe name:string index new
|
18
|
+
|
19
|
+
|
20
|
+
== Included Generators
|
21
|
+
|
22
|
+
* splendeo_layout: generates generic layout, stylesheet, and helper files.
|
23
|
+
* splendeo_scaffold: generates a controller and optional model/migration.
|
24
|
+
* splendeo_config: generates a config YAML file and loader.
|
25
|
+
* splendeo_authentication: generates user model with sign up and log in.
|
26
|
+
|
27
|
+
To view the README for each generator, run it with the +--help+ option.
|
28
|
+
|
29
|
+
script/generate splendeo_layout --help
|
30
|
+
|
31
|
+
|
32
|
+
== Troubleshooting and FAQs
|
33
|
+
|
34
|
+
<b>What is the difference between splendeo_scaffold and built-in scaffold?</b>
|
35
|
+
|
36
|
+
One of the primary differences is that splendeo_scaffold allows you to choose which controller actions to generate.
|
37
|
+
|
38
|
+
script/generate splendeo_scaffold post name:string index new edit
|
39
|
+
|
40
|
+
There are a few changes to the generated code as well, such as no XML format by default.
|
41
|
+
|
42
|
+
It also offers support for HAML, Shoulda, and RSpec.
|
43
|
+
|
44
|
+
|
45
|
+
<b>I get "undefined method 'title'" error.</b>
|
46
|
+
|
47
|
+
Try running splendeo_layout, that will generate this helper method. Or you can just change the templates to whatever approach you prefer for setting the title.
|
48
|
+
|
49
|
+
|
50
|
+
<b>I can't set new attributes in my model.</b>
|
51
|
+
|
52
|
+
Add the attribute to the attr_accessible line in the model.
|
53
|
+
|
54
|
+
|
55
|
+
<b>I get "undefined method 'root_url'" error.</b>
|
56
|
+
|
57
|
+
Some generators default redirecting to the root_url. Set this in your routes.rb file like this (substituting your controller name).
|
58
|
+
|
59
|
+
map.root :controller => 'foo'
|
60
|
+
|
61
|
+
|
62
|
+
<b>I get a missing database error.</b>
|
63
|
+
|
64
|
+
Run <tt>rake db:migrate</tt>.
|
65
|
+
|
66
|
+
|
67
|
+
<b>I get a routing error when I try to submit a form.</b>
|
68
|
+
|
69
|
+
Try restarting your development server. Sometimes it doesn't detect the change in the routing.
|
70
|
+
|
71
|
+
|
72
|
+
<b>The tests/specs don't work.</b>
|
73
|
+
|
74
|
+
Make sure you have mocha installed and require it in your spec/test helper.
|
75
|
+
|
76
|
+
gem install mocha
|
77
|
+
|
78
|
+
# in spec_helper.rb
|
79
|
+
config.mock_with :mocha
|
80
|
+
|
81
|
+
# in test_helper.rb
|
82
|
+
require 'mocha'
|
83
|
+
|
84
|
+
Also, make sure you're using Rails 2.1 or greater.
|
85
|
+
|
86
|
+
|
87
|
+
== Found a bug?
|
88
|
+
|
89
|
+
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
|
+
|
91
|
+
http://github.com/ryanb/splendeo-generators/issues
|
92
|
+
|
93
|
+
|
94
|
+
== Rails 3
|
95
|
+
|
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
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
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 splendeo_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 "session". 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
|
+
Make sure to setup the authlogic gem if you are using that option.
|
17
|
+
|
18
|
+
config.gem "authlogic"
|
19
|
+
|
20
|
+
Examples:
|
21
|
+
script/generate splendeo_authentication
|
22
|
+
|
23
|
+
Creates user model, users_controller, and sessions_controller.
|
24
|
+
|
25
|
+
script/generate splendeo_authentication account
|
26
|
+
|
27
|
+
Creates account model, accounts_controller, and sessions_controller.
|
28
|
+
|
29
|
+
script/generate splendeo_authentication Account UserSession
|
30
|
+
|
31
|
+
Creates account model, accounts_controller, and user_sessions_controller.
|
32
|
+
|
33
|
+
Methods:
|
34
|
+
There are several methods generated which you can use in your application.
|
35
|
+
Here's a common example of what you might add to your layout.
|
36
|
+
|
37
|
+
<% if logged_in? %>
|
38
|
+
Welcome <%= current_user.username %>! Not you?
|
39
|
+
<%= link_to "Log out", logout_path %>
|
40
|
+
<% else %>
|
41
|
+
<%= link_to "Sign up", signup_path %> or
|
42
|
+
<%= link_to "log in", login_path %>.
|
43
|
+
<% end %>
|
44
|
+
|
45
|
+
You can also restrict unregistered users from accessing a controller using
|
46
|
+
a before filter. For example.
|
47
|
+
|
48
|
+
before_filter :login_required, :except => [:index, :show]
|
49
|
+
|
50
|
+
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,128 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
|
2
|
+
class SplendeoAuthenticationGenerator < Rails::Generator::Base
|
3
|
+
attr_accessor :user_name, :session_name
|
4
|
+
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
6
|
+
super
|
7
|
+
|
8
|
+
@user_name = @args[0] || 'user'
|
9
|
+
@session_name = @args[1] || (options[:authlogic] ? @user_name + '_session' : '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 "authlogic_session.rb", "app/models/#{session_singular_name}.rb" if options[:authlogic]
|
23
|
+
m.template "users_controller.rb", "app/controllers/#{user_plural_name}_controller.rb"
|
24
|
+
m.template "users_helper.rb", "app/helpers/#{user_plural_name}_helper.rb"
|
25
|
+
m.template "views/#{view_language}/signup.html.#{view_language}", "app/views/#{user_plural_name}/new.html.#{view_language}"
|
26
|
+
|
27
|
+
m.directory "app/views/#{session_plural_name}"
|
28
|
+
m.template "sessions_controller.rb", "app/controllers/#{session_plural_name}_controller.rb"
|
29
|
+
m.template "sessions_helper.rb", "app/helpers/#{session_plural_name}_helper.rb"
|
30
|
+
m.template "views/#{view_language}/login.html.#{view_language}", "app/views/#{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 session_plural_name
|
37
|
+
m.route_name :login, 'login', :controller => session_plural_name, :action => 'new'
|
38
|
+
m.route_name :logout, 'logout', :controller => 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_controller_name}.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/#{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/#{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 session_singular_name
|
82
|
+
session_name.underscore
|
83
|
+
end
|
84
|
+
|
85
|
+
def session_plural_name
|
86
|
+
session_singular_name.pluralize
|
87
|
+
end
|
88
|
+
|
89
|
+
def session_class_name
|
90
|
+
session_name.camelize
|
91
|
+
end
|
92
|
+
|
93
|
+
def session_plural_class_name
|
94
|
+
session_plural_name.camelize
|
95
|
+
end
|
96
|
+
|
97
|
+
def application_controller_name
|
98
|
+
Rails.version >= '2.3.0' ? 'application_controller' : 'application'
|
99
|
+
end
|
100
|
+
|
101
|
+
protected
|
102
|
+
|
103
|
+
def view_language
|
104
|
+
options[:haml] ? 'haml' : 'erb'
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_framework
|
108
|
+
options[:test_framework] ||= File.exist?(destination_path("spec")) ? :rspec : :testunit
|
109
|
+
end
|
110
|
+
|
111
|
+
def add_options!(opt)
|
112
|
+
opt.separator ''
|
113
|
+
opt.separator 'Options:'
|
114
|
+
opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
|
115
|
+
opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
|
116
|
+
opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
|
117
|
+
opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = true }
|
118
|
+
opt.on("--authlogic", "Use Authlogic for authentication.") { |v| options[:authlogic] = true }
|
119
|
+
end
|
120
|
+
|
121
|
+
def banner
|
122
|
+
<<-EOS
|
123
|
+
Creates user model and controllers to handle registration and authentication.
|
124
|
+
|
125
|
+
USAGE: #{$0} #{spec.name} [user_name] [sessions_controller_name]
|
126
|
+
EOS
|
127
|
+
end
|
128
|
+
end
|