rotten-generators 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. data/.document +5 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +10 -0
  5. data/Rakefile +56 -0
  6. data/VERSION +1 -0
  7. data/cucumber.yml +1 -0
  8. data/features/rotten.feature +9 -0
  9. data/features/step_definitions/rotten_steps.rb +0 -0
  10. data/features/support/env.rb +4 -0
  11. data/generators.gemspec +126 -0
  12. data/lib/rotten_generators.rb +3 -0
  13. data/rails_generators/rotten_authentication/lib/insert_commands.rb +74 -0
  14. data/rails_generators/rotten_authentication/rotten_authentication_generator.rb +102 -0
  15. data/rails_generators/rotten_authentication/templates/authentication.rb +37 -0
  16. data/rails_generators/rotten_authentication/templates/fixtures.yml +12 -0
  17. data/rails_generators/rotten_authentication/templates/migration.rb +15 -0
  18. data/rails_generators/rotten_authentication/templates/sessions_controller.rb +22 -0
  19. data/rails_generators/rotten_authentication/templates/sessions_helper.rb +2 -0
  20. data/rails_generators/rotten_authentication/templates/tests/rspec/sessions_controller.rb +25 -0
  21. data/rails_generators/rotten_authentication/templates/tests/rspec/user.rb +81 -0
  22. data/rails_generators/rotten_authentication/templates/tests/rspec/users_controller.rb +24 -0
  23. data/rails_generators/rotten_authentication/templates/user.rb +38 -0
  24. data/rails_generators/rotten_authentication/templates/users_controller.rb +16 -0
  25. data/rails_generators/rotten_authentication/templates/users_helper.rb +2 -0
  26. data/rails_generators/rotten_authentication/templates/views/haml/login.html.haml +15 -0
  27. data/rails_generators/rotten_authentication/templates/views/haml/signup.html.haml +24 -0
  28. data/rails_generators/rotten_controller/rotten_controller_generator.rb +52 -0
  29. data/rails_generators/rotten_controller/templates/controller.rb +38 -0
  30. data/rails_generators/rotten_controller/templates/controller_spec.rb +25 -0
  31. data/rails_generators/rotten_controller/templates/helper.rb +2 -0
  32. data/rails_generators/rotten_controller/templates/helper_spec.rb +11 -0
  33. data/rails_generators/rotten_controller/templates/view.html.haml +2 -0
  34. data/rails_generators/rotten_controller/templates/view_spec.rb +12 -0
  35. data/rails_generators/rotten_layout/USAGE +1 -0
  36. data/rails_generators/rotten_layout/rotten_layout_generator.rb +63 -0
  37. data/rails_generators/rotten_layout/templates/helper.rb +30 -0
  38. data/rails_generators/rotten_layout/templates/js/jquery-1.3.2.min.js +19 -0
  39. data/rails_generators/rotten_layout/templates/js/jquery-ui-1.7.2.min.js +298 -0
  40. data/rails_generators/rotten_layout/templates/layout.html.haml +45 -0
  41. data/rails_generators/rotten_layout/templates/one_column.html.haml +11 -0
  42. data/rails_generators/rotten_layout/templates/sass/colour.sass +1 -0
  43. data/rails_generators/rotten_layout/templates/sass/form.sass +1 -0
  44. data/rails_generators/rotten_layout/templates/sass/handheld.sass +1 -0
  45. data/rails_generators/rotten_layout/templates/sass/ie.sass +1 -0
  46. data/rails_generators/rotten_layout/templates/sass/layout.sass +1 -0
  47. data/rails_generators/rotten_layout/templates/sass/print.sass +1 -0
  48. data/rails_generators/rotten_layout/templates/sass/reset.sass +137 -0
  49. data/rails_generators/rotten_layout/templates/sass/screen.sass +5 -0
  50. data/rails_generators/rotten_layout/templates/sass/type.sass +1 -0
  51. data/rails_generators/rotten_layout/templates/shared_analytics.html.haml +10 -0
  52. data/rails_generators/rotten_layout/templates/shared_flash_messages.html.haml +12 -0
  53. data/rails_generators/rotten_layout/templates/shared_footer.html.haml +15 -0
  54. data/rails_generators/rotten_layout/templates/shared_header.html.haml +5 -0
  55. data/rails_generators/rotten_layout/templates/shared_navigation.html.haml +3 -0
  56. data/rails_generators/rotten_layout/templates/shared_sidebar.html.haml +13 -0
  57. data/rails_generators/rotten_layout/templates/two_column_left.html.haml +15 -0
  58. data/rails_generators/rotten_layout/templates/two_column_right.html.haml +14 -0
  59. data/rails_generators/rotten_scaffold/USAGE +48 -0
  60. data/rails_generators/rotten_scaffold/rotten_scaffold_generator.rb +204 -0
  61. data/rails_generators/rotten_scaffold/templates/actions/create.rb +9 -0
  62. data/rails_generators/rotten_scaffold/templates/actions/destroy.rb +6 -0
  63. data/rails_generators/rotten_scaffold/templates/actions/edit.rb +3 -0
  64. data/rails_generators/rotten_scaffold/templates/actions/index.rb +3 -0
  65. data/rails_generators/rotten_scaffold/templates/actions/new.rb +3 -0
  66. data/rails_generators/rotten_scaffold/templates/actions/show.rb +3 -0
  67. data/rails_generators/rotten_scaffold/templates/actions/update.rb +9 -0
  68. data/rails_generators/rotten_scaffold/templates/controller.rb +3 -0
  69. data/rails_generators/rotten_scaffold/templates/fixtures.yml +9 -0
  70. data/rails_generators/rotten_scaffold/templates/helper.rb +2 -0
  71. data/rails_generators/rotten_scaffold/templates/migration.rb +16 -0
  72. data/rails_generators/rotten_scaffold/templates/model.rb +2 -0
  73. data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  74. data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  75. data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  76. data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  77. data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  78. data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  79. data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  80. data/rails_generators/rotten_scaffold/templates/tests/rspec/controller.rb +8 -0
  81. data/rails_generators/rotten_scaffold/templates/tests/rspec/model.rb +7 -0
  82. data/rails_generators/rotten_scaffold/templates/views/haml/_form.html.haml +14 -0
  83. data/rails_generators/rotten_scaffold/templates/views/haml/edit.html.haml +14 -0
  84. data/rails_generators/rotten_scaffold/templates/views/haml/index.html.haml +25 -0
  85. data/rails_generators/rotten_scaffold/templates/views/haml/new.html.haml +7 -0
  86. data/rails_generators/rotten_scaffold/templates/views/haml/show.html.haml +20 -0
  87. data/spec/rotten_spec.rb +7 -0
  88. data/spec/spec.opts +3 -0
  89. data/spec/spec_helper.rb +9 -0
  90. metadata +143 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Peter Coulton
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,10 @@
1
+ = Rotten Generators
2
+
3
+ Rotten Scaffold is
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Peter Coulton. See LICENSE for details.
8
+
9
+ rotten_scaffold is copied from nifty_scaffold http://github.com/ryanb/nifty-generators/tree/master
10
+
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "generators"
8
+ gem.summary = "Collection of rails generators"
9
+ gem.email = "peter@petercoulton.com"
10
+ gem.homepage = "http://github.com/rotten/generators"
11
+ gem.authors = ["Peter Coulton"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ end
24
+
25
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+ begin
32
+ require 'cucumber/rake/task'
33
+ Cucumber::Rake::Task.new(:features)
34
+ rescue LoadError
35
+ task :features do
36
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
37
+ end
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "rotten-generators #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.9.0
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ autotest: --format pretty features
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
File without changes
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'rotten_generators'
3
+
4
+ require 'spec/expectations'
@@ -0,0 +1,126 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{generators}
5
+ s.version = "0.9.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Peter Coulton"]
9
+ s.date = %q{2009-06-26}
10
+ s.email = %q{peter@petercoulton.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "cucumber.yml",
23
+ "features/rotten.feature",
24
+ "features/step_definitions/rotten_steps.rb",
25
+ "features/support/env.rb",
26
+ "generators.gemspec",
27
+ "lib/rotten_generators.rb",
28
+ "rails_generators/rotten_authentication/lib/insert_commands.rb",
29
+ "rails_generators/rotten_authentication/rotten_authentication_generator.rb",
30
+ "rails_generators/rotten_authentication/templates/authentication.rb",
31
+ "rails_generators/rotten_authentication/templates/fixtures.yml",
32
+ "rails_generators/rotten_authentication/templates/migration.rb",
33
+ "rails_generators/rotten_authentication/templates/sessions_controller.rb",
34
+ "rails_generators/rotten_authentication/templates/sessions_helper.rb",
35
+ "rails_generators/rotten_authentication/templates/tests/rspec/sessions_controller.rb",
36
+ "rails_generators/rotten_authentication/templates/tests/rspec/user.rb",
37
+ "rails_generators/rotten_authentication/templates/tests/rspec/users_controller.rb",
38
+ "rails_generators/rotten_authentication/templates/user.rb",
39
+ "rails_generators/rotten_authentication/templates/users_controller.rb",
40
+ "rails_generators/rotten_authentication/templates/users_helper.rb",
41
+ "rails_generators/rotten_authentication/templates/views/haml/login.html.haml",
42
+ "rails_generators/rotten_authentication/templates/views/haml/signup.html.haml",
43
+ "rails_generators/rotten_controller/rotten_controller_generator.rb",
44
+ "rails_generators/rotten_controller/templates/controller.rb",
45
+ "rails_generators/rotten_controller/templates/controller_spec.rb",
46
+ "rails_generators/rotten_controller/templates/helper.rb",
47
+ "rails_generators/rotten_controller/templates/helper_spec.rb",
48
+ "rails_generators/rotten_controller/templates/view.html.haml",
49
+ "rails_generators/rotten_controller/templates/view_spec.rb",
50
+ "rails_generators/rotten_layout/USAGE",
51
+ "rails_generators/rotten_layout/rotten_layout_generator.rb",
52
+ "rails_generators/rotten_layout/templates/helper.rb",
53
+ "rails_generators/rotten_layout/templates/js/jquery-1.3.2.min.js",
54
+ "rails_generators/rotten_layout/templates/js/jquery-ui-1.7.2.min.js",
55
+ "rails_generators/rotten_layout/templates/layout.html.haml",
56
+ "rails_generators/rotten_layout/templates/one_column.html.haml",
57
+ "rails_generators/rotten_layout/templates/sass/colour.sass",
58
+ "rails_generators/rotten_layout/templates/sass/form.sass",
59
+ "rails_generators/rotten_layout/templates/sass/handheld.sass",
60
+ "rails_generators/rotten_layout/templates/sass/ie.sass",
61
+ "rails_generators/rotten_layout/templates/sass/layout.sass",
62
+ "rails_generators/rotten_layout/templates/sass/print.sass",
63
+ "rails_generators/rotten_layout/templates/sass/reset.sass",
64
+ "rails_generators/rotten_layout/templates/sass/screen.sass",
65
+ "rails_generators/rotten_layout/templates/sass/type.sass",
66
+ "rails_generators/rotten_layout/templates/shared_analytics.html.haml",
67
+ "rails_generators/rotten_layout/templates/shared_flash_messages.html.haml",
68
+ "rails_generators/rotten_layout/templates/shared_footer.html.haml",
69
+ "rails_generators/rotten_layout/templates/shared_header.html.haml",
70
+ "rails_generators/rotten_layout/templates/shared_navigation.html.haml",
71
+ "rails_generators/rotten_layout/templates/shared_sidebar.html.haml",
72
+ "rails_generators/rotten_layout/templates/two_column_left.html.haml",
73
+ "rails_generators/rotten_layout/templates/two_column_right.html.haml",
74
+ "rails_generators/rotten_scaffold/USAGE",
75
+ "rails_generators/rotten_scaffold/rotten_scaffold_generator.rb",
76
+ "rails_generators/rotten_scaffold/templates/actions/create.rb",
77
+ "rails_generators/rotten_scaffold/templates/actions/destroy.rb",
78
+ "rails_generators/rotten_scaffold/templates/actions/edit.rb",
79
+ "rails_generators/rotten_scaffold/templates/actions/index.rb",
80
+ "rails_generators/rotten_scaffold/templates/actions/new.rb",
81
+ "rails_generators/rotten_scaffold/templates/actions/show.rb",
82
+ "rails_generators/rotten_scaffold/templates/actions/update.rb",
83
+ "rails_generators/rotten_scaffold/templates/controller.rb",
84
+ "rails_generators/rotten_scaffold/templates/fixtures.yml",
85
+ "rails_generators/rotten_scaffold/templates/helper.rb",
86
+ "rails_generators/rotten_scaffold/templates/migration.rb",
87
+ "rails_generators/rotten_scaffold/templates/model.rb",
88
+ "rails_generators/rotten_scaffold/templates/tests/rspec/actions/create.rb",
89
+ "rails_generators/rotten_scaffold/templates/tests/rspec/actions/destroy.rb",
90
+ "rails_generators/rotten_scaffold/templates/tests/rspec/actions/edit.rb",
91
+ "rails_generators/rotten_scaffold/templates/tests/rspec/actions/index.rb",
92
+ "rails_generators/rotten_scaffold/templates/tests/rspec/actions/new.rb",
93
+ "rails_generators/rotten_scaffold/templates/tests/rspec/actions/show.rb",
94
+ "rails_generators/rotten_scaffold/templates/tests/rspec/actions/update.rb",
95
+ "rails_generators/rotten_scaffold/templates/tests/rspec/controller.rb",
96
+ "rails_generators/rotten_scaffold/templates/tests/rspec/model.rb",
97
+ "rails_generators/rotten_scaffold/templates/views/haml/_form.html.haml",
98
+ "rails_generators/rotten_scaffold/templates/views/haml/edit.html.haml",
99
+ "rails_generators/rotten_scaffold/templates/views/haml/index.html.haml",
100
+ "rails_generators/rotten_scaffold/templates/views/haml/new.html.haml",
101
+ "rails_generators/rotten_scaffold/templates/views/haml/show.html.haml",
102
+ "spec/rotten_spec.rb",
103
+ "spec/spec.opts",
104
+ "spec/spec_helper.rb"
105
+ ]
106
+ s.has_rdoc = true
107
+ s.homepage = %q{http://github.com/rotten/generators}
108
+ s.rdoc_options = ["--charset=UTF-8"]
109
+ s.require_paths = ["lib"]
110
+ s.rubygems_version = %q{1.3.1}
111
+ s.summary = %q{Collection of rails generators}
112
+ s.test_files = [
113
+ "spec/rotten_spec.rb",
114
+ "spec/spec_helper.rb"
115
+ ]
116
+
117
+ if s.respond_to? :specification_version then
118
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
119
+ s.specification_version = 2
120
+
121
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
122
+ else
123
+ end
124
+ else
125
+ end
126
+ end
@@ -0,0 +1,3 @@
1
+ module RottenGenerators
2
+ # nothing to see here, the real action is under rails_generators
3
+ end
@@ -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,102 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
+
3
+ class RottenAuthenticationGenerator < Rails::Generator::Base
4
+ attr_accessor :user_name, :sessions_name
5
+
6
+ def initialize(runtime_args, runtime_options = {})
7
+ super
8
+
9
+ @user_name = @args[0] || 'user'
10
+ @sessions_name = @args[1] || 'sessions'
11
+ end
12
+
13
+ def manifest
14
+ record do |m|
15
+ m.directory "app/models"
16
+ m.directory "app/controllers"
17
+ m.directory "app/helpers"
18
+ m.directory "app/views"
19
+ m.directory "lib"
20
+
21
+ m.directory "app/views/#{user_plural_name}"
22
+ m.template "user.rb", "app/models/#{user_singular_name}.rb"
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/#{sessions_underscore_name}"
28
+ m.template "sessions_controller.rb", "app/controllers/#{sessions_underscore_name}_controller.rb"
29
+ m.template "sessions_helper.rb", "app/helpers/#{sessions_underscore_name}_helper.rb"
30
+ m.template "views/#{view_language}/login.html.#{view_language}", "app/views/#{sessions_underscore_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 sessions_underscore_name
37
+ m.route_name :login, 'login', :controller => sessions_underscore_name, :action => 'new'
38
+ m.route_name :logout, 'logout', :controller => sessions_underscore_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
+ 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
+ end
52
+ end
53
+
54
+ def user_singular_name
55
+ user_name.underscore
56
+ end
57
+
58
+ def user_plural_name
59
+ user_singular_name.pluralize
60
+ end
61
+
62
+ def user_class_name
63
+ user_name.camelize
64
+ end
65
+
66
+ def user_plural_class_name
67
+ user_plural_name.camelize
68
+ end
69
+
70
+ def sessions_underscore_name
71
+ sessions_name.underscore
72
+ end
73
+
74
+ def sessions_class_name
75
+ sessions_name.camelize
76
+ end
77
+
78
+ def application_controller_name
79
+ Rails.version >= '2.3.0' ? 'application_controller' : 'application'
80
+ end
81
+
82
+ protected
83
+
84
+ def view_language
85
+ 'haml'
86
+ end
87
+
88
+ def test_framework
89
+ :rspec
90
+ end
91
+
92
+ def add_options!(opt)
93
+ end
94
+
95
+ def banner
96
+ <<-EOS
97
+ Creates user model and controllers to handle registration and authentication.
98
+
99
+ USAGE: #{$0} #{spec.name} [user_name] [sessions_controller_name]
100
+ EOS
101
+ end
102
+ end
@@ -0,0 +1,37 @@
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?
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
+ redirect_to login_url
35
+ end
36
+ end
37
+ end