rubycs-nifty-generators-compass 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/CHANGELOG +79 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +5 -0
  4. data/Rakefile +15 -0
  5. data/TODO +7 -0
  6. data/lib/nifty_generators.rb +3 -0
  7. data/nifty-generators-compass.gemspec +32 -0
  8. data/rails_generators/nifty_authentication/USAGE +46 -0
  9. data/rails_generators/nifty_authentication/lib/insert_commands.rb +74 -0
  10. data/rails_generators/nifty_authentication/nifty_authentication_generator.rb +118 -0
  11. data/rails_generators/nifty_authentication/templates/authentication.rb +49 -0
  12. data/rails_generators/nifty_authentication/templates/fixtures.yml +12 -0
  13. data/rails_generators/nifty_authentication/templates/migration.rb +15 -0
  14. data/rails_generators/nifty_authentication/templates/sessions_controller.rb +22 -0
  15. data/rails_generators/nifty_authentication/templates/sessions_helper.rb +2 -0
  16. data/rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb +25 -0
  17. data/rails_generators/nifty_authentication/templates/tests/rspec/user.rb +81 -0
  18. data/rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb +24 -0
  19. data/rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb +26 -0
  20. data/rails_generators/nifty_authentication/templates/tests/shoulda/user.rb +83 -0
  21. data/rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb +25 -0
  22. data/rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb +22 -0
  23. data/rails_generators/nifty_authentication/templates/tests/testunit/user.rb +86 -0
  24. data/rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb +21 -0
  25. data/rails_generators/nifty_authentication/templates/user.rb +38 -0
  26. data/rails_generators/nifty_authentication/templates/users_controller.rb +16 -0
  27. data/rails_generators/nifty_authentication/templates/users_helper.rb +2 -0
  28. data/rails_generators/nifty_authentication/templates/views/erb/login.html.erb +15 -0
  29. data/rails_generators/nifty_authentication/templates/views/erb/signup.html.erb +24 -0
  30. data/rails_generators/nifty_authentication/templates/views/haml/login.html.haml +15 -0
  31. data/rails_generators/nifty_authentication/templates/views/haml/signup.html.haml +24 -0
  32. data/rails_generators/nifty_config/USAGE +23 -0
  33. data/rails_generators/nifty_config/nifty_config_generator.rb +32 -0
  34. data/rails_generators/nifty_config/templates/config.yml +8 -0
  35. data/rails_generators/nifty_config/templates/load_config.rb +2 -0
  36. data/rails_generators/nifty_layout/USAGE +25 -0
  37. data/rails_generators/nifty_layout/nifty_layout_generator.rb +44 -0
  38. data/rails_generators/nifty_layout/templates/helper.rb +23 -0
  39. data/rails_generators/nifty_layout/templates/layout.html.erb +22 -0
  40. data/rails_generators/nifty_layout/templates/layout.html.haml +19 -0
  41. data/rails_generators/nifty_layout/templates/stylesheet.css +81 -0
  42. data/rails_generators/nifty_layout/templates/stylesheet.sass +67 -0
  43. data/rails_generators/nifty_scaffold/USAGE +51 -0
  44. data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +232 -0
  45. data/rails_generators/nifty_scaffold/templates/actions/create.rb +9 -0
  46. data/rails_generators/nifty_scaffold/templates/actions/destroy.rb +6 -0
  47. data/rails_generators/nifty_scaffold/templates/actions/edit.rb +3 -0
  48. data/rails_generators/nifty_scaffold/templates/actions/index.rb +3 -0
  49. data/rails_generators/nifty_scaffold/templates/actions/new.rb +3 -0
  50. data/rails_generators/nifty_scaffold/templates/actions/show.rb +3 -0
  51. data/rails_generators/nifty_scaffold/templates/actions/update.rb +9 -0
  52. data/rails_generators/nifty_scaffold/templates/controller.rb +3 -0
  53. data/rails_generators/nifty_scaffold/templates/fixtures.yml +9 -0
  54. data/rails_generators/nifty_scaffold/templates/helper.rb +2 -0
  55. data/rails_generators/nifty_scaffold/templates/migration.rb +16 -0
  56. data/rails_generators/nifty_scaffold/templates/model.rb +2 -0
  57. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  58. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  59. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  60. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  61. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  62. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  63. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  64. data/rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb +8 -0
  65. data/rails_generators/nifty_scaffold/templates/tests/rspec/model.rb +7 -0
  66. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  67. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  68. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  69. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  70. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  71. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  72. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  73. data/rails_generators/nifty_scaffold/templates/tests/shoulda/controller.rb +5 -0
  74. data/rails_generators/nifty_scaffold/templates/tests/shoulda/model.rb +7 -0
  75. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  76. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  77. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  78. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  79. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  80. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  81. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  82. data/rails_generators/nifty_scaffold/templates/tests/testunit/controller.rb +5 -0
  83. data/rails_generators/nifty_scaffold/templates/tests/testunit/model.rb +7 -0
  84. data/rails_generators/nifty_scaffold/templates/views/erb/_form.html.erb +10 -0
  85. data/rails_generators/nifty_scaffold/templates/views/erb/edit.html.erb +14 -0
  86. data/rails_generators/nifty_scaffold/templates/views/erb/index.html.erb +29 -0
  87. data/rails_generators/nifty_scaffold/templates/views/erb/new.html.erb +7 -0
  88. data/rails_generators/nifty_scaffold/templates/views/erb/show.html.erb +20 -0
  89. data/rails_generators/nifty_scaffold/templates/views/haml/_form.html.haml +10 -0
  90. data/rails_generators/nifty_scaffold/templates/views/haml/edit.html.haml +14 -0
  91. data/rails_generators/nifty_scaffold/templates/views/haml/index.html.haml +25 -0
  92. data/rails_generators/nifty_scaffold/templates/views/haml/new.html.haml +7 -0
  93. data/rails_generators/nifty_scaffold/templates/views/haml/show.html.haml +20 -0
  94. data/tasks/deployment.rake +2 -0
  95. data/test/test_helper.rb +117 -0
  96. data/test/test_nifty_authentication_generator.rb +160 -0
  97. data/test/test_nifty_config_generator.rb +37 -0
  98. data/test/test_nifty_layout_generator.rb +42 -0
  99. data/test/test_nifty_scaffold_generator.rb +533 -0
  100. metadata +165 -0
data/CHANGELOG ADDED
@@ -0,0 +1,79 @@
1
+ 0.2.4 (May 5th, 2009)
2
+
3
+ * using root_url when no index action in nifty_scaffold
4
+
5
+ * making password editable in user model in nifty_authentication
6
+
7
+ * adding filter_parameter_logging :password in nifty_authentication
8
+
9
+ 0.2.3 (February 20th, 2009)
10
+
11
+ * fixing nifty_authentication to work with Rails 2.3 application_controller.rb
12
+
13
+ * fixing password field in HAML signup page in nifty_authentication
14
+
15
+ 0.2.2 (November 11th, 2008)
16
+
17
+ * fixing sessions_path reference in nifty_authentication
18
+
19
+ * adding more validations to user model in nifty_authentication
20
+
21
+ * cleaning up nifty_layout stylesheet
22
+
23
+ 0.2.1 (November 10th, 2008)
24
+
25
+ * adding missing nifty_authentication files
26
+
27
+ 0.2.0 (November 4th, 2008)
28
+
29
+ * adding nifty_authentication
30
+
31
+ 0.1.8 (October 3rd, 2008)
32
+
33
+ * compatibility with RubyGems 1.3
34
+
35
+ * using f.error_messages instead of error_messages_for (thanks Zach Langley)
36
+
37
+ 0.1.7 (August 15th, 2008)
38
+
39
+ * fixing shoulda tests
40
+
41
+ 0.1.6 (August 7th, 2008)
42
+
43
+ * adding option to specify Shoulda as testing framework in nifty_scaffold generator
44
+
45
+ * adding options to manually specify rspec or testunit framework in nifty_scaffold generator
46
+
47
+ 0.1.5 (August 7th, 2008)
48
+
49
+ * adding option to nifty layout to generate HAML views and SASS stylesheets
50
+
51
+ * adding option to nifty scaffold to generate HAML views
52
+
53
+ 0.1.4 (July 21st, 2008)
54
+
55
+ * using same logic as model spec in model test for scaffold
56
+
57
+ * simplifying model spec generated by scaffold
58
+
59
+ * adding error_messages_for to form partial
60
+
61
+ 0.1.3 (June 20th, 2008)
62
+
63
+ * using _url in controllers instead of _path
64
+
65
+ * improving the nifty_config default example YAML file
66
+
67
+ 0.1.2 (May 16th, 2008)
68
+
69
+ * mentioning nifty_layout in nifty_scaffold generator
70
+
71
+ * adding nifty_config generator
72
+
73
+ 0.1.1 (May 9th, 2008)
74
+
75
+ * adding tests and specs to scaffold generator
76
+
77
+ 0.1.0 (May 8th, 2008)
78
+
79
+ * 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,5 @@
1
+ = Nifty Generators with Compass
2
+
3
+ A fork of Ryan Bates' classical nifty_generator[http://github.com/ryanb/nifty-generators/] created to use together with the Compass[http://wiki.github.com/chriseppstein/compass] web frontend framework
4
+
5
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('nifty-generators-compass', '0.0.1') do |p|
6
+ p.project = "niftygeneratorscompass"
7
+ p.description = "Nifty generators to use with Compass."
8
+ p.url = "http://github.com/rubycs/nifty-generators-compass"
9
+ p.author = 'rubycs'
10
+ p.email = "rubycs (at) clair (dot) ro"
11
+ p.ignore_pattern = ["script/*"]
12
+ p.development_dependencies = []
13
+ end
14
+
15
+ 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 NiftyGeneratorsCompass
2
+ # nothing to see here, the real action is under rails_generators
3
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{nifty-generators-compass}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["rubycs"]
9
+ s.date = %q{2009-06-07}
10
+ s.description = %q{Nifty generators to use with Compass.}
11
+ s.email = %q{rubycs (at) clair (dot) ro}
12
+ s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "TODO", "tasks/deployment.rake", "LICENSE", "lib/nifty_generators.rb"]
13
+ s.files = ["CHANGELOG", "README.rdoc", "Rakefile", "TODO", "test/test_nifty_layout_generator.rb", "test/test_nifty_scaffold_generator.rb", "test/test_helper.rb", "test/test_nifty_config_generator.rb", "test/test_nifty_authentication_generator.rb", "rails_generators/nifty_layout/templates/layout.html.erb", "rails_generators/nifty_layout/templates/stylesheet.sass", "rails_generators/nifty_layout/templates/stylesheet.css", "rails_generators/nifty_layout/templates/layout.html.haml", "rails_generators/nifty_layout/templates/helper.rb", "rails_generators/nifty_layout/USAGE", "rails_generators/nifty_layout/nifty_layout_generator.rb", "rails_generators/nifty_config/nifty_config_generator.rb", "rails_generators/nifty_config/templates/load_config.rb", "rails_generators/nifty_config/templates/config.yml", "rails_generators/nifty_config/USAGE", "rails_generators/nifty_scaffold/templates/migration.rb", "rails_generators/nifty_scaffold/templates/fixtures.yml", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/new.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/index.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/edit.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/show.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/destroy.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/controller.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/model.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/new.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/index.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/edit.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/show.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/destroy.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/model.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/new.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/index.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/edit.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/show.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/destroy.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/controller.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/model.rb", "rails_generators/nifty_scaffold/templates/actions/create.rb", "rails_generators/nifty_scaffold/templates/actions/new.rb", "rails_generators/nifty_scaffold/templates/actions/index.rb", "rails_generators/nifty_scaffold/templates/actions/edit.rb", "rails_generators/nifty_scaffold/templates/actions/show.rb", "rails_generators/nifty_scaffold/templates/actions/destroy.rb", "rails_generators/nifty_scaffold/templates/actions/update.rb", "rails_generators/nifty_scaffold/templates/views/haml/show.html.haml", "rails_generators/nifty_scaffold/templates/views/haml/edit.html.haml", "rails_generators/nifty_scaffold/templates/views/haml/index.html.haml", "rails_generators/nifty_scaffold/templates/views/haml/new.html.haml", "rails_generators/nifty_scaffold/templates/views/haml/_form.html.haml", "rails_generators/nifty_scaffold/templates/views/erb/_form.html.erb", "rails_generators/nifty_scaffold/templates/views/erb/show.html.erb", "rails_generators/nifty_scaffold/templates/views/erb/index.html.erb", "rails_generators/nifty_scaffold/templates/views/erb/edit.html.erb", "rails_generators/nifty_scaffold/templates/views/erb/new.html.erb", "rails_generators/nifty_scaffold/templates/controller.rb", "rails_generators/nifty_scaffold/templates/model.rb", "rails_generators/nifty_scaffold/templates/helper.rb", "rails_generators/nifty_scaffold/USAGE", "rails_generators/nifty_scaffold/nifty_scaffold_generator.rb", "rails_generators/nifty_authentication/templates/sessions_helper.rb", "rails_generators/nifty_authentication/templates/authentication.rb", "rails_generators/nifty_authentication/templates/users_helper.rb", "rails_generators/nifty_authentication/templates/migration.rb", "rails_generators/nifty_authentication/templates/fixtures.yml", "rails_generators/nifty_authentication/templates/tests/testunit/user.rb", "rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb", "rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb", "rails_generators/nifty_authentication/templates/tests/rspec/user.rb", "rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb", "rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb", "rails_generators/nifty_authentication/templates/tests/shoulda/user.rb", "rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb", "rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb", "rails_generators/nifty_authentication/templates/views/haml/login.html.haml", "rails_generators/nifty_authentication/templates/views/haml/signup.html.haml", "rails_generators/nifty_authentication/templates/views/erb/signup.html.erb", "rails_generators/nifty_authentication/templates/views/erb/login.html.erb", "rails_generators/nifty_authentication/templates/user.rb", "rails_generators/nifty_authentication/templates/sessions_controller.rb", "rails_generators/nifty_authentication/templates/users_controller.rb", "rails_generators/nifty_authentication/USAGE", "rails_generators/nifty_authentication/lib/insert_commands.rb", "rails_generators/nifty_authentication/nifty_authentication_generator.rb", "tasks/deployment.rake", "LICENSE", "lib/nifty_generators.rb", "nifty-generators-compass.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/rubycs/nifty-generators-compass}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Nifty-generators-compass", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{niftygeneratorscompass}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Nifty generators to use with Compass.}
21
+ s.test_files = ["test/test_nifty_layout_generator.rb", "test/test_nifty_scaffold_generator.rb", "test/test_helper.rb", "test/test_nifty_config_generator.rb", "test/test_nifty_authentication_generator.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
+ else
29
+ end
30
+ else
31
+ end
32
+ 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 nifty_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 nifty_authentication
18
+
19
+ Creates user model, users_controller, and sessions_controller.
20
+
21
+ script/generate nifty_authentication account
22
+
23
+ Creates account model, accounts_controller, and sessions_controller.
24
+
25
+ script/generate nifty_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,118 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
+ class NiftyAuthenticationGenerator < Rails::Generator::Base
3
+ attr_accessor :user_name, :sessions_name
4
+
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+
8
+ @user_name = @args[0] || 'user'
9
+ @sessions_name = @args[1] || 'sessions'
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/#{sessions_underscore_name}"
27
+ m.template "sessions_controller.rb", "app/controllers/#{sessions_underscore_name}_controller.rb"
28
+ m.template "sessions_helper.rb", "app/helpers/#{sessions_underscore_name}_helper.rb"
29
+ m.template "views/#{view_language}/login.html.#{view_language}", "app/views/#{sessions_underscore_name}/new.html.#{view_language}"
30
+
31
+ m.template "authentication.rb", "lib/authentication.rb"
32
+ m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{user_plural_name}"
33
+
34
+ m.route_resources user_plural_name
35
+ m.route_resources sessions_underscore_name
36
+ m.route_name :login, 'login', :controller => sessions_underscore_name, :action => 'new'
37
+ m.route_name :logout, 'logout', :controller => sessions_underscore_name, :action => 'destroy'
38
+ m.route_name :signup, 'signup', :controller => user_plural_name, :action => 'new'
39
+
40
+ m.insert_into "app/controllers/#{application_controller_name}.rb", 'include Authentication'
41
+
42
+ if test_framework == :rspec
43
+ m.directory "spec"
44
+ m.directory "spec/fixtures"
45
+ m.directory "spec/controllers"
46
+ m.directory "spec/models"
47
+ m.template "fixtures.yml", "spec/fixtures/#{user_plural_name}.yml"
48
+ m.template "tests/rspec/user.rb", "spec/models/#{user_singular_name}_spec.rb"
49
+ m.template "tests/rspec/users_controller.rb", "spec/controllers/#{user_plural_name}_controller_spec.rb"
50
+ m.template "tests/rspec/sessions_controller.rb", "spec/controllers/#{sessions_underscore_name}_controller_spec.rb"
51
+ else
52
+ m.directory "test"
53
+ m.directory "test/fixtures"
54
+ m.directory "test/functional"
55
+ m.directory "test/unit"
56
+ m.template "fixtures.yml", "test/fixtures/#{user_plural_name}.yml"
57
+ m.template "tests/#{test_framework}/user.rb", "test/unit/#{user_singular_name}_test.rb"
58
+ m.template "tests/#{test_framework}/users_controller.rb", "test/functional/#{user_plural_name}_controller_test.rb"
59
+ m.template "tests/#{test_framework}/sessions_controller.rb", "test/functional/#{sessions_underscore_name}_controller_test.rb"
60
+ end
61
+ end
62
+ end
63
+
64
+ def user_singular_name
65
+ user_name.underscore
66
+ end
67
+
68
+ def user_plural_name
69
+ user_singular_name.pluralize
70
+ end
71
+
72
+ def user_class_name
73
+ user_name.camelize
74
+ end
75
+
76
+ def user_plural_class_name
77
+ user_plural_name.camelize
78
+ end
79
+
80
+ def sessions_underscore_name
81
+ sessions_name.underscore
82
+ end
83
+
84
+ def sessions_class_name
85
+ sessions_name.camelize
86
+ end
87
+
88
+ def application_controller_name
89
+ Rails.version >= '2.3.0' ? 'application_controller' : 'application'
90
+ end
91
+
92
+ protected
93
+
94
+ def view_language
95
+ options[:haml] ? 'haml' : 'erb'
96
+ end
97
+
98
+ def test_framework
99
+ options[:test_framework] ||= File.exist?(destination_path("spec")) ? :rspec : :testunit
100
+ end
101
+
102
+ def add_options!(opt)
103
+ opt.separator ''
104
+ opt.separator 'Options:'
105
+ opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
106
+ opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
107
+ opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
108
+ opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = true }
109
+ end
110
+
111
+ def banner
112
+ <<-EOS
113
+ Creates user model and controllers to handle registration and authentication.
114
+
115
+ USAGE: #{$0} #{spec.name} [user_name] [sessions_controller_name]
116
+ EOS
117
+ end
118
+ end
@@ -0,0 +1,49 @@
1
+ # This module is included in your application controller which makes
2
+ # several methods available to all controllers and views. Here's a
3
+ # common example you might add to your application layout file.
4
+ #
5
+ # <%% if logged_in? %>
6
+ # Welcome <%%= current_user.username %>! Not you?
7
+ # <%%= link_to "Log out", logout_path %>
8
+ # <%% else %>
9
+ # <%%= link_to "Sign up", signup_path %> or
10
+ # <%%= link_to "log in", login_path %>.
11
+ # <%% end %>
12
+ #
13
+ # You can also restrict unregistered users from accessing a controller using
14
+ # a before filter. For example.
15
+ #
16
+ # before_filter :login_required, :except => [:index, :show]
17
+ module Authentication
18
+ def self.included(controller)
19
+ controller.send :helper_method, :current_<%= user_singular_name %>, :logged_in?, :redirect_to_target_or_default
20
+ controller.filter_parameter_logging :password
21
+ end
22
+
23
+ def current_<%= user_singular_name %>
24
+ @current_<%= user_singular_name %> ||= <%= user_class_name %>.find(session[:<%= user_singular_name %>_id]) if session[:<%= user_singular_name %>_id]
25
+ end
26
+
27
+ def logged_in?
28
+ current_<%= user_singular_name %>
29
+ end
30
+
31
+ def login_required
32
+ unless logged_in?
33
+ flash[:error] = "You must first log in or sign up before accessing this page."
34
+ store_target_location
35
+ redirect_to login_url
36
+ end
37
+ end
38
+
39
+ def redirect_to_target_or_default(default)
40
+ redirect_to(session[:return_to] || default)
41
+ session[:return_to] = nil
42
+ end
43
+
44
+ private
45
+
46
+ def store_target_location
47
+ session[:return_to] = request.request_uri
48
+ end
49
+ end