handy-generators 0.0.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 (40) hide show
  1. data/.document +5 -0
  2. data/.gitignore +23 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +53 -0
  6. data/VERSION +1 -0
  7. data/handy-generators.gemspec +86 -0
  8. data/lib/handy-generators.rb +0 -0
  9. data/rails_generators/handy_setup/handy_setup_generator.rb +93 -0
  10. data/rails_generators/handy_setup/lib/insert_commands.rb +106 -0
  11. data/rails_generators/handy_setup/templates/admin_controller.rb +3 -0
  12. data/rails_generators/handy_setup/templates/admin_home_controller.rb +6 -0
  13. data/rails_generators/handy_setup/templates/admin_sessions_controller.rb +26 -0
  14. data/rails_generators/handy_setup/templates/admin_users_controller.rb +44 -0
  15. data/rails_generators/handy_setup/templates/application_controller.rb +56 -0
  16. data/rails_generators/handy_setup/templates/authlogic_session.rb +3 -0
  17. data/rails_generators/handy_setup/templates/layout.html.erb +16 -0
  18. data/rails_generators/handy_setup/templates/migration.rb +28 -0
  19. data/rails_generators/handy_setup/templates/routes.rb +24 -0
  20. data/rails_generators/handy_setup/templates/seed.rb +4 -0
  21. data/rails_generators/handy_setup/templates/sessions_controller.rb +25 -0
  22. data/rails_generators/handy_setup/templates/style.css +54 -0
  23. data/rails_generators/handy_setup/templates/subdomain_fu.rb +3 -0
  24. data/rails_generators/handy_setup/templates/user.rb +3 -0
  25. data/rails_generators/handy_setup/templates/users_controller.rb +42 -0
  26. data/rails_generators/handy_setup/templates/views/_form_user.html.erb +11 -0
  27. data/rails_generators/handy_setup/templates/views/admin_edit_user.html.erb +9 -0
  28. data/rails_generators/handy_setup/templates/views/admin_form_user.html.erb +14 -0
  29. data/rails_generators/handy_setup/templates/views/admin_home_index.html.erb +2 -0
  30. data/rails_generators/handy_setup/templates/views/admin_index_users.html.erb +23 -0
  31. data/rails_generators/handy_setup/templates/views/admin_new_user.html.erb +7 -0
  32. data/rails_generators/handy_setup/templates/views/admin_show_user.html.erb +41 -0
  33. data/rails_generators/handy_setup/templates/views/edit_user.html.erb +9 -0
  34. data/rails_generators/handy_setup/templates/views/login.html.erb +14 -0
  35. data/rails_generators/handy_setup/templates/views/new_user.html.erb +7 -0
  36. data/rails_generators/handy_setup/templates/views/show_user.html.erb +37 -0
  37. data/rails_generators/handy_setup/templates/views/signup.html.erb +24 -0
  38. data/test/helper.rb +10 -0
  39. data/test/test_handy-generators.rb +7 -0
  40. metadata +134 -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,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ .project
21
+
22
+ ## PROJECT::SPECIFIC
23
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 jordinl
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,17 @@
1
+ = handy-generators
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 jordinl. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "handy-generators"
8
+ gem.summary = %Q{Application and Scaffold generators}
9
+ gem.description = %Q{Application and Scaffold generators. With admin in a subdomain (using subdomain-fu), authentication (using authlogic) and users}
10
+ gem.email = "jordinoguera83@gmail.com"
11
+ gem.homepage = "http://github.com/jordinl/handy-generators"
12
+ gem.authors = ["jordinl"]
13
+ gem.add_dependency('authlogic')
14
+ gem.add_dependency('subdomain-fu')
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "handy-generators #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,86 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{handy-generators}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jordinl"]
12
+ s.date = %q{2010-08-14}
13
+ s.description = %q{Application and Scaffold generators. With admin in a subdomain (using subdomain-fu), authentication (using authlogic) and users}
14
+ s.email = %q{jordinoguera83@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "handy-generators.gemspec",
27
+ "lib/handy-generators.rb",
28
+ "rails_generators/handy_setup/handy_setup_generator.rb",
29
+ "rails_generators/handy_setup/lib/insert_commands.rb",
30
+ "rails_generators/handy_setup/templates/admin_controller.rb",
31
+ "rails_generators/handy_setup/templates/admin_home_controller.rb",
32
+ "rails_generators/handy_setup/templates/admin_sessions_controller.rb",
33
+ "rails_generators/handy_setup/templates/admin_users_controller.rb",
34
+ "rails_generators/handy_setup/templates/application_controller.rb",
35
+ "rails_generators/handy_setup/templates/authlogic_session.rb",
36
+ "rails_generators/handy_setup/templates/layout.html.erb",
37
+ "rails_generators/handy_setup/templates/migration.rb",
38
+ "rails_generators/handy_setup/templates/routes.rb",
39
+ "rails_generators/handy_setup/templates/seed.rb",
40
+ "rails_generators/handy_setup/templates/sessions_controller.rb",
41
+ "rails_generators/handy_setup/templates/style.css",
42
+ "rails_generators/handy_setup/templates/subdomain_fu.rb",
43
+ "rails_generators/handy_setup/templates/user.rb",
44
+ "rails_generators/handy_setup/templates/users_controller.rb",
45
+ "rails_generators/handy_setup/templates/views/_form_user.html.erb",
46
+ "rails_generators/handy_setup/templates/views/admin_edit_user.html.erb",
47
+ "rails_generators/handy_setup/templates/views/admin_form_user.html.erb",
48
+ "rails_generators/handy_setup/templates/views/admin_home_index.html.erb",
49
+ "rails_generators/handy_setup/templates/views/admin_index_users.html.erb",
50
+ "rails_generators/handy_setup/templates/views/admin_new_user.html.erb",
51
+ "rails_generators/handy_setup/templates/views/admin_show_user.html.erb",
52
+ "rails_generators/handy_setup/templates/views/edit_user.html.erb",
53
+ "rails_generators/handy_setup/templates/views/login.html.erb",
54
+ "rails_generators/handy_setup/templates/views/new_user.html.erb",
55
+ "rails_generators/handy_setup/templates/views/show_user.html.erb",
56
+ "rails_generators/handy_setup/templates/views/signup.html.erb",
57
+ "test/helper.rb",
58
+ "test/test_handy-generators.rb"
59
+ ]
60
+ s.homepage = %q{http://github.com/jordinl/handy-generators}
61
+ s.rdoc_options = ["--charset=UTF-8"]
62
+ s.require_paths = ["lib"]
63
+ s.rubygems_version = %q{1.3.7}
64
+ s.summary = %q{Application and Scaffold generators}
65
+ s.test_files = [
66
+ "test/test_handy-generators.rb",
67
+ "test/helper.rb"
68
+ ]
69
+
70
+ if s.respond_to? :specification_version then
71
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
72
+ s.specification_version = 3
73
+
74
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
75
+ s.add_runtime_dependency(%q<authlogic>, [">= 0"])
76
+ s.add_runtime_dependency(%q<subdomain-fu>, [">= 0"])
77
+ else
78
+ s.add_dependency(%q<authlogic>, [">= 0"])
79
+ s.add_dependency(%q<subdomain-fu>, [">= 0"])
80
+ end
81
+ else
82
+ s.add_dependency(%q<authlogic>, [">= 0"])
83
+ s.add_dependency(%q<subdomain-fu>, [">= 0"])
84
+ end
85
+ end
86
+
File without changes
@@ -0,0 +1,93 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
+ class HandySetupGenerator < Rails::Generator::Base
3
+
4
+ def initialize(runtime_args, runtime_options = {})
5
+ super
6
+ end
7
+
8
+ def manifest
9
+ record do |m|
10
+ m.directory "app/models"
11
+ m.directory "app/controllers"
12
+ m.directory "app/controllers/admin"
13
+ m.directory "app/helpers"
14
+ m.directory "app/views"
15
+
16
+ #`script/plugin install git://github.com/binarylogic/authlogic.git`
17
+ #`script/plugin install git://github.com/mbleigh/subdomain-fu.git`
18
+
19
+ m.gem_dependency "Authlogic", "config.gem 'authlogic'"
20
+ m.gem_dependency "Subdomain-fu", "config.gem 'subdomain-fu'"
21
+
22
+ `rm public/index.html`
23
+
24
+ `script/generate controller home index`
25
+ m.directory "app/views/users"
26
+ `rm app/controllers/application_controller.rb`
27
+ m.template "application_controller.rb", "app/controllers/application_controller.rb"
28
+ m.template "user.rb", "app/models/user.rb"
29
+ m.template "authlogic_session.rb", "app/models/user_session.rb"
30
+ m.template "users_controller.rb", "app/controllers/users_controller.rb"
31
+ m.template "views/new_user.html.erb", "app/views/users/new.html.erb"
32
+ m.template "views/edit_user.html.erb", "app/views/users/edit.html.erb"
33
+ m.template "views/_form_user.html.erb", "app/views/users/_form.html.erb"
34
+ m.template "views/show_user.html.erb", "app/views/users/show.html.erb"
35
+
36
+ m.directory "app/views/layouts"
37
+ m.template "layout.html.erb", "app/views/layouts/application.html.erb"
38
+ m.template "style.css", "public/stylesheets/application.css"
39
+
40
+ m.directory "app/views/user_sessions"
41
+ m.template "sessions_controller.rb", "app/controllers/user_sessions_controller.rb"
42
+ m.template "views/login.html.erb", "app/views/user_sessions/new.html.erb"
43
+
44
+ m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_users"
45
+
46
+ m.template "subdomain_fu.rb", "config/initializers/subdomain_fu.rb"
47
+ m.directory "app/controllers/admin"
48
+ m.template "admin_controller.rb", "app/controllers/admin_controller.rb"
49
+ m.template "admin_home_controller.rb", "app/controllers/admin/home_controller.rb"
50
+ m.directory "app/views/admin"
51
+ m.directory "app/views/admin/home"
52
+ m.template "views/admin_home_index.html.erb", "app/views/admin/home/index.html.erb"
53
+ m.template "admin_sessions_controller.rb", "app/controllers/admin/user_sessions_controller.rb"
54
+ m.directory "app/views/admin/user_sessions"
55
+ m.template "views/login.html.erb", "app/views/admin/user_sessions/new.html.erb"
56
+
57
+ m.template "admin_users_controller.rb", "app/controllers/admin/users_controller.rb"
58
+ m.directory "app/views/admin/users"
59
+ m.template "views/admin_edit_user.html.erb", "app/views/admin/users/edit.html.erb"
60
+ m.template "views/admin_new_user.html.erb", "app/views/admin/users/new.html.erb"
61
+ m.template "views/admin_show_user.html.erb", "app/views/admin/users/show.html.erb"
62
+ m.template "views/admin_form_user.html.erb", "app/views/admin/users/_form.html.erb"
63
+ m.template "views/admin_index_users.html.erb", "app/views/admin/users/index.html.erb"
64
+ `rm db/seeds.rb`
65
+ m.template "seed.rb", "db/seeds.rb"
66
+
67
+ `rm config/routes.rb`
68
+ m.template "routes.rb", "config/routes.rb"
69
+ #m.root_route :controller => :home
70
+ #m.route_resources :users
71
+ #m.route_resources :user_sessions
72
+ #m.named_resource :account, :controller => "users"
73
+ #m.route_name :login, 'login', :controller => :user_sessions, :action => 'new'
74
+ #m.route_name :logout, 'logout', :controller => :user_sessions, :action => 'destroy'
75
+ #m.route_name :signup, 'signup', :controller => :users, :action => 'new'
76
+
77
+ end
78
+ end
79
+
80
+ def application_controller_name
81
+ Rails.version >= '2.3.0' ? 'application_controller' : 'application'
82
+ end
83
+
84
+ protected
85
+
86
+ def banner
87
+ <<-EOS
88
+ Creates user model and controllers to handle registration and authentication.
89
+
90
+ USAGE: #{$0} #{spec.name} [user_name] [sessions_controller_name]
91
+ EOS
92
+ end
93
+ end
@@ -0,0 +1,106 @@
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 named_resource(*resources)
15
+ resource_list = resources.map { |r| r.inspect }.join(', ')
16
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
17
+
18
+ logger.route "map.resource #{resource_list}"
19
+ unless options[:pretend]
20
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
21
+ "#{match}\n map.resource #{resource_list}\n"
22
+ end
23
+ end
24
+ end
25
+
26
+ def root_route(controller)
27
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
28
+
29
+ logger.route "map.root :#{controller.keys[0]} => :#{controller.values[0]}"
30
+ unless options[:pretend]
31
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
32
+ "#{match}\n map.root :#{controller.keys[0]} => :#{controller.values[0]}\n"
33
+ end
34
+ end
35
+ end
36
+
37
+ def route_name(name, path, route_options = {})
38
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
39
+
40
+ logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
41
+ unless options[:pretend]
42
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
43
+ "#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
44
+ end
45
+ end
46
+ end
47
+
48
+ def gem_dependency(gem_name, command)
49
+ logger.insert "Gem dependency: #{gem_name}"
50
+ file = "config/environment.rb"
51
+
52
+ gsub_file file, "Rails::Initializer.run do |config|" do |match|
53
+ "#{match}\n #{command}"
54
+ end
55
+ end
56
+
57
+ def insert_into(file, line)
58
+ logger.insert "#{line} into #{file}"
59
+ unless options[:pretend]
60
+ gsub_file file, /^(class|module) .+$/ do |match|
61
+ "#{match}\n #{line}"
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ Rails::Generator::Commands::Destroy.class_eval do
68
+ def route_resource(*resources)
69
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
70
+ look_for = "\n map.resource #{resource_list}\n"
71
+ logger.route "map.resource #{resource_list}"
72
+ unless options[:pretend]
73
+ gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
74
+ end
75
+ end
76
+
77
+ def route_name(name, path, route_options = {})
78
+ look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
79
+ logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
80
+ unless options[:pretend]
81
+ gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
82
+ end
83
+ end
84
+
85
+ def insert_into(file, line)
86
+ logger.remove "#{line} from #{file}"
87
+ unless options[:pretend]
88
+ gsub_file file, "\n #{line}", ''
89
+ end
90
+ end
91
+ end
92
+
93
+ Rails::Generator::Commands::List.class_eval do
94
+ def route_resource(*resources)
95
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
96
+ logger.route "map.resource #{resource_list}"
97
+ end
98
+
99
+ def route_name(name, path, options = {})
100
+ logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
101
+ end
102
+
103
+ def insert_into(file, line)
104
+ logger.insert "#{line} into #{file}"
105
+ end
106
+ end
@@ -0,0 +1,3 @@
1
+ class AdminController < ApplicationController
2
+ before_filter :require_admin
3
+ end
@@ -0,0 +1,6 @@
1
+ class Admin::HomeController < AdminController
2
+
3
+ def index
4
+ end
5
+
6
+ end
@@ -0,0 +1,26 @@
1
+ class Admin::UserSessionsController < AdminController
2
+ skip_before_filter :require_user, :only => [:new, :create]
3
+ skip_before_filter :require_admin, :only => [:new, :create]
4
+ before_filter :require_no_user, :only => [:new, :create]
5
+ before_filter :require_admin, :only => :destroy
6
+
7
+ def new
8
+ @user_session = UserSession.new
9
+ end
10
+
11
+ def create
12
+ @user_session = UserSession.new(params[:user_session])
13
+ if @user_session.save
14
+ flash[:notice] = "Login successful!"
15
+ redirect_back_or_default root_url
16
+ else
17
+ render :action => :new
18
+ end
19
+ end
20
+
21
+ def destroy
22
+ current_user_session.destroy
23
+ flash[:notice] = "Logout successful!"
24
+ redirect_back_or_default login_url
25
+ end
26
+ end
@@ -0,0 +1,44 @@
1
+ class Admin::UsersController < AdminController
2
+
3
+ before_filter :get_user, :except => [:new, :create, :index]
4
+
5
+ def index
6
+ @users = User.all
7
+ end
8
+
9
+ def new
10
+ @user = User.new
11
+ end
12
+
13
+ def create
14
+ @user = User.new(params[:user])
15
+ if @user.save
16
+ flash[:notice] = "User was successfully created!"
17
+ redirect_back_or_default admin_users_url
18
+ else
19
+ render :action => :new
20
+ end
21
+ end
22
+
23
+ def show
24
+ end
25
+
26
+ def edit
27
+ end
28
+
29
+ def update
30
+ if @user.update_attributes(params[:user])
31
+ flash[:notice] = "Account updated!"
32
+ redirect_to admin_users_url
33
+ else
34
+ render :action => :edit
35
+ end
36
+ end
37
+
38
+ protected
39
+
40
+ def get_user
41
+ @user = User.find(params[:id])
42
+ end
43
+
44
+ end
@@ -0,0 +1,56 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all
6
+ helper_method :current_user_session, :current_user
7
+ filter_parameter_logging :password, :password_confirmation
8
+
9
+ before_filter :require_user
10
+
11
+ private
12
+ def current_user_session
13
+ return @current_user_session if defined?(@current_user_session)
14
+ @current_user_session = UserSession.find
15
+ end
16
+
17
+ def current_user
18
+ return @current_user if defined?(@current_user)
19
+ @current_user = current_user_session && current_user_session.record
20
+ end
21
+
22
+ def require_user
23
+ unless current_user
24
+ store_location
25
+ flash[:notice] = "You must be logged in to access this page"
26
+ redirect_to login_url
27
+ return false
28
+ end
29
+ end
30
+
31
+ def require_no_user
32
+ if current_user
33
+ store_location
34
+ flash[:notice] = "You must be logged out to access this page"
35
+ redirect_to root_url
36
+ return false
37
+ end
38
+ end
39
+
40
+ def require_admin
41
+ unless current_user.admin
42
+ current_user_session.destroy if current_user_session
43
+ flash[:notice] = "You don't have permission to access this page"
44
+ redirect_to admin_login_url
45
+ end
46
+ end
47
+
48
+ def store_location
49
+ session[:return_to] = request.request_uri
50
+ end
51
+
52
+ def redirect_back_or_default(default)
53
+ redirect_to(session[:return_to] || default)
54
+ session[:return_to] = nil
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ # app/models/user_session.rb
2
+ class UserSession < Authlogic::Session::Base
3
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7
+ <%%= stylesheet_link_tag 'application' %>
8
+ </head>
9
+ <body>
10
+
11
+ <p style="color: green"><%%= flash[:notice] %></p>
12
+
13
+ <%%= yield %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,28 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :login, :null => false # optional, you can use email instead, or both
5
+ t.string :email, :null => false # optional, you can use login instead, or both
6
+ t.string :crypted_password, :null => false # optional, see below
7
+ t.string :password_salt, :null => false # optional, but highly recommended
8
+ t.string :persistence_token, :null => false # required
9
+ t.string :single_access_token, :null => false # optional, see Authlogic::Session::Params
10
+ t.string :perishable_token, :null => false # optional, see Authlogic::Session::Perishability
11
+ t.boolean :admin, :default => false
12
+
13
+ # Magic columns, just like ActiveRecord's created_at and updated_at. These are automatically maintained by Authlogic if they are present.
14
+ t.integer :login_count, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
15
+ t.integer :failed_login_count, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
16
+ t.datetime :last_request_at # optional, see Authlogic::Session::MagicColumns
17
+ t.datetime :current_login_at # optional, see Authlogic::Session::MagicColumns
18
+ t.datetime :last_login_at # optional, see Authlogic::Session::MagicColumns
19
+ t.string :current_login_ip # optional, see Authlogic::Session::MagicColumns
20
+ t.string :last_login_ip # optional, see Authlogic::Session::MagicColumns
21
+ t.timestamps
22
+ end
23
+ end
24
+
25
+ def self.down
26
+ drop_table :users
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ map.namespace :admin, :path_prefix => '', :conditions => { :subdomain => 'admin' } do |admin|
4
+ admin.root :controller => 'home'
5
+ admin.logout 'logout', :controller => 'user_sessions', :action => :destroy
6
+ admin.login 'login', :controller => 'user_sessions', :action => :new
7
+ admin.resources 'users'
8
+ admin.resources 'user_sessions'
9
+ end
10
+
11
+ map.root :controller => 'home'
12
+
13
+ map.signup 'signup', :controller => 'users', :action => 'new'
14
+ map.logout 'logout', :controller => 'user_sessions', :action => 'destroy'
15
+ map.login 'login', :controller => 'user_sessions', :action => 'new'
16
+
17
+ map.resource :account, :controller => :users
18
+
19
+ map.resources :user_sessions
20
+
21
+ map.connect ':controller/:action/:id'
22
+ map.connect ':controller/:action/:id.:format'
23
+
24
+ end
@@ -0,0 +1,4 @@
1
+ @admin = User.create(:login => "admin", :email => "admin@test.com", :password => "pass", :password_confirmation => "pass")
2
+ @admin.update_attributes(:admin => true)
3
+
4
+ User.create(:login => "user", :email => "user@test.com", :password => "pass", :password_confirmation => "pass")
@@ -0,0 +1,25 @@
1
+ class UserSessionsController < ApplicationController
2
+ skip_before_filter :require_user, :only => [:new, :create]
3
+ before_filter :require_no_user, :only => [:new, :create]
4
+ before_filter :require_user, :only => :destroy
5
+
6
+ def new
7
+ @user_session = UserSession.new
8
+ end
9
+
10
+ def create
11
+ @user_session = UserSession.new(params[:user_session])
12
+ if @user_session.save
13
+ flash[:notice] = "Login successful!"
14
+ redirect_back_or_default root_url
15
+ else
16
+ render :action => :new
17
+ end
18
+ end
19
+
20
+ def destroy
21
+ current_user_session.destroy
22
+ flash[:notice] = "Logout successful!"
23
+ redirect_back_or_default login_url
24
+ end
25
+ end
@@ -0,0 +1,54 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ .fieldWithErrors {
20
+ padding: 2px;
21
+ background-color: red;
22
+ display: table;
23
+ }
24
+
25
+ #errorExplanation {
26
+ width: 400px;
27
+ border: 2px solid red;
28
+ padding: 7px;
29
+ padding-bottom: 12px;
30
+ margin-bottom: 20px;
31
+ background-color: #f0f0f0;
32
+ }
33
+
34
+ #errorExplanation h2 {
35
+ text-align: left;
36
+ font-weight: bold;
37
+ padding: 5px 5px 5px 15px;
38
+ font-size: 12px;
39
+ margin: -7px;
40
+ background-color: #c00;
41
+ color: #fff;
42
+ }
43
+
44
+ #errorExplanation p {
45
+ color: #333;
46
+ margin-bottom: 0;
47
+ padding: 5px;
48
+ }
49
+
50
+ #errorExplanation ul li {
51
+ font-size: 12px;
52
+ list-style: square;
53
+ }
54
+
@@ -0,0 +1,3 @@
1
+ SubdomainFu.tld_sizes = {:development => 0,
2
+ :test => 0,
3
+ :production => 1} # set all at once (also the defaults)
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ acts_as_authentic
3
+ end
@@ -0,0 +1,42 @@
1
+ class UsersController < ApplicationController
2
+ skip_before_filter :require_user, :only => [:new, :create]
3
+ before_filter :require_no_user, :only => [:new, :create]
4
+ before_filter :require_user, :only => [:show, :edit, :update]
5
+
6
+ before_filter :get_user, :except => [:new, :create]
7
+
8
+ def new
9
+ @user = User.new
10
+ end
11
+
12
+ def create
13
+ @user = User.new(params[:user])
14
+ if @user.save
15
+ flash[:notice] = "Account registered!"
16
+ redirect_back_or_default account_url
17
+ else
18
+ render :action => :new
19
+ end
20
+ end
21
+
22
+ def show
23
+ end
24
+
25
+ def edit
26
+ end
27
+
28
+ def update
29
+ if @user.update_attributes(params[:user])
30
+ flash[:notice] = "Account updated!"
31
+ redirect_to root_url
32
+ else
33
+ render :action => :edit
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ def get_user
40
+ @user = @current_user
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ <%%= form.label :login %><br />
2
+ <%%= form.text_field :login %><br />
3
+ <br />
4
+ <%%= form.label :email, "Email Address" %><br />
5
+ <%%= form.text_field :email %><br />
6
+ <br />
7
+ <%%= form.label :password, form.object.new_record? ? nil : "Change password" %><br />
8
+ <%%= form.password_field :password %><br />
9
+ <br />
10
+ <%%= form.label :password_confirmation %><br />
11
+ <%%= form.password_field :password_confirmation %><br />
@@ -0,0 +1,9 @@
1
+ <h1>Edit user</h1>
2
+
3
+ <%% form_for [:admin, @user] do |f| %>
4
+ <%%= f.error_messages %>
5
+ <%%= render :partial => "form", :object => f %>
6
+ <%%= f.submit "Update" %>
7
+ <%% end %>
8
+
9
+ <br /><%%= link_to "Show", [:admin, @user] %>
@@ -0,0 +1,14 @@
1
+ <%%= form.label :login %><br />
2
+ <%%= form.text_field :login %><br />
3
+ <br />
4
+ <%%= form.label :email, "Email Address" %><br />
5
+ <%%= form.text_field :email %><br />
6
+ <br />
7
+ <%%= form.label :password, form.object.new_record? ? nil : "Change password" %><br />
8
+ <%%= form.password_field :password %><br />
9
+ <br />
10
+ <%%= form.label :password_confirmation %><br />
11
+ <%%= form.password_field :password_confirmation %><br />
12
+ <br />
13
+ <%%= form.label :admin %><br />
14
+ <%%= form.check_box :admin %><br />
@@ -0,0 +1,2 @@
1
+ <h1>Admin::Home#Index</h1>
2
+ Find me in app/controllers/admin/home/index.html.erb
@@ -0,0 +1,23 @@
1
+ <h1>Listing users</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Login</th>
6
+ <th>Email</th>
7
+ <th>Actions</th>
8
+ </tr>
9
+
10
+ <%% @users.each do |user| %>
11
+
12
+ <tr>
13
+ <td><%%=h user.login %></td>
14
+ <td><%%=h user.email %></td>
15
+ <td><%%= link_to 'Show', admin_user_path(user) %></td>
16
+ <td><%%= link_to 'Edit', edit_admin_user_path(user) %></td>
17
+ <td><%%= link_to 'Destroy', [:admin, user], :confirm => 'Are you sure?', :method => :delete%></td>
18
+ </tr>
19
+
20
+ <%% end %>
21
+ </table>
22
+
23
+ <%%= link_to 'New user', new_admin_user_path %>
@@ -0,0 +1,7 @@
1
+ <h1>Create User</h1>
2
+
3
+ <%% form_for [:admin, @user] do |f| %>
4
+ <%%= f.error_messages %>
5
+ <%%= render :partial => "form", :object => f %>
6
+ <%%= f.submit "Create" %>
7
+ <%% end %>
@@ -0,0 +1,41 @@
1
+ <p>
2
+ <b>Login:</b>
3
+ <%%=h @user.login %>
4
+ </p>
5
+
6
+ <p>
7
+ <b>Login count:</b>
8
+ <%%=h @user.login_count %>
9
+ </p>
10
+
11
+ <p>
12
+ <b>Last request at:</b>
13
+ <%%=h @user.last_request_at %>
14
+ </p>
15
+
16
+ <p>
17
+ <b>Last login at:</b>
18
+ <%%=h @user.last_login_at %>
19
+ </p>
20
+
21
+ <p>
22
+ <b>Current login at:</b>
23
+ <%%=h @user.current_login_at %>
24
+ </p>
25
+
26
+ <p>
27
+ <b>Last login ip:</b>
28
+ <%%=h @user.last_login_ip %>
29
+ </p>
30
+
31
+ <p>
32
+ <b>Current login ip:</b>
33
+ <%%=h @user.current_login_ip %>
34
+ </p>
35
+
36
+ <p>
37
+ <b>Admin:</b>
38
+ <%%= @user.admin %>
39
+ </p>
40
+
41
+ <%%= link_to 'Edit', edit_account_path %>
@@ -0,0 +1,9 @@
1
+ <h1>Edit My Account</h1>
2
+
3
+ <%% form_for @user, :url => account_path do |f| %>
4
+ <%%= f.error_messages %>
5
+ <%%= render :partial => "form", :object => f %>
6
+ <%%= f.submit "Update" %>
7
+ <%% end %>
8
+
9
+ <br /><%%= link_to "My Profile", account_path %>
@@ -0,0 +1,14 @@
1
+ <h1>Login</h1>
2
+
3
+ <%% form_for @user_session do |f| %>
4
+ <%%= f.error_messages %>
5
+ <%%= f.label :login %><br />
6
+ <%%= f.text_field :login %><br />
7
+ <br />
8
+ <%%= f.label :password %><br />
9
+ <%%= f.password_field :password %><br />
10
+ <br />
11
+ <%%= f.check_box :remember_me %><%%= f.label :remember_me %><br />
12
+ <br />
13
+ <%%= f.submit "Login" %>
14
+ <%% end %>
@@ -0,0 +1,7 @@
1
+ <h1>Register</h1>
2
+
3
+ <%% form_for @user, :url => account_path do |f| %>
4
+ <%%= f.error_messages %>
5
+ <%%= render :partial => "form", :object => f %>
6
+ <%%= f.submit "Register" %>
7
+ <%% end %>
@@ -0,0 +1,37 @@
1
+ <p>
2
+ <b>Login:</b>
3
+ <%%=h @user.login %>
4
+ </p>
5
+
6
+ <p>
7
+ <b>Login count:</b>
8
+ <%%=h @user.login_count %>
9
+ </p>
10
+
11
+ <p>
12
+ <b>Last request at:</b>
13
+ <%%=h @user.last_request_at %>
14
+ </p>
15
+
16
+ <p>
17
+ <b>Last login at:</b>
18
+ <%%=h @user.last_login_at %>
19
+ </p>
20
+
21
+ <p>
22
+ <b>Current login at:</b>
23
+ <%%=h @user.current_login_at %>
24
+ </p>
25
+
26
+ <p>
27
+ <b>Last login ip:</b>
28
+ <%%=h @user.last_login_ip %>
29
+ </p>
30
+
31
+ <p>
32
+ <b>Current login ip:</b>
33
+ <%%=h @user.current_login_ip %>
34
+ </p>
35
+
36
+
37
+ <%%= link_to 'Edit', edit_account_path %>
@@ -0,0 +1,24 @@
1
+ <%% title "Sign up" %>
2
+
3
+ <p>Already have an account? <%%= link_to "Log in", login_path %>.</p>
4
+
5
+ <%% form_for @user do |f| %>
6
+ <%%= f.error_messages %>
7
+ <p>
8
+ <%%= f.label :username %><br />
9
+ <%%= f.text_field :username %>
10
+ </p>
11
+ <p>
12
+ <%%= f.label :email, "Email Address" %><br />
13
+ <%%= f.text_field :email %>
14
+ </p>
15
+ <p>
16
+ <%%= f.label :password %><br />
17
+ <%%= f.password_field :password %>
18
+ </p>
19
+ <p>
20
+ <%%= f.label :password_confirmation, "Confirm Password" %><br />
21
+ <%%= f.password_field :password_confirmation %>
22
+ </p>
23
+ <p><%%= f.submit "Sign up" %></p>
24
+ <%% end %>
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'handy-generators'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestHandyGenerators < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: handy-generators
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - jordinl
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-14 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: authlogic
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: subdomain-fu
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: Application and Scaffold generators. With admin in a subdomain (using subdomain-fu), authentication (using authlogic) and users
50
+ email: jordinoguera83@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - LICENSE
57
+ - README.rdoc
58
+ files:
59
+ - .document
60
+ - .gitignore
61
+ - LICENSE
62
+ - README.rdoc
63
+ - Rakefile
64
+ - VERSION
65
+ - handy-generators.gemspec
66
+ - lib/handy-generators.rb
67
+ - rails_generators/handy_setup/handy_setup_generator.rb
68
+ - rails_generators/handy_setup/lib/insert_commands.rb
69
+ - rails_generators/handy_setup/templates/admin_controller.rb
70
+ - rails_generators/handy_setup/templates/admin_home_controller.rb
71
+ - rails_generators/handy_setup/templates/admin_sessions_controller.rb
72
+ - rails_generators/handy_setup/templates/admin_users_controller.rb
73
+ - rails_generators/handy_setup/templates/application_controller.rb
74
+ - rails_generators/handy_setup/templates/authlogic_session.rb
75
+ - rails_generators/handy_setup/templates/layout.html.erb
76
+ - rails_generators/handy_setup/templates/migration.rb
77
+ - rails_generators/handy_setup/templates/routes.rb
78
+ - rails_generators/handy_setup/templates/seed.rb
79
+ - rails_generators/handy_setup/templates/sessions_controller.rb
80
+ - rails_generators/handy_setup/templates/style.css
81
+ - rails_generators/handy_setup/templates/subdomain_fu.rb
82
+ - rails_generators/handy_setup/templates/user.rb
83
+ - rails_generators/handy_setup/templates/users_controller.rb
84
+ - rails_generators/handy_setup/templates/views/_form_user.html.erb
85
+ - rails_generators/handy_setup/templates/views/admin_edit_user.html.erb
86
+ - rails_generators/handy_setup/templates/views/admin_form_user.html.erb
87
+ - rails_generators/handy_setup/templates/views/admin_home_index.html.erb
88
+ - rails_generators/handy_setup/templates/views/admin_index_users.html.erb
89
+ - rails_generators/handy_setup/templates/views/admin_new_user.html.erb
90
+ - rails_generators/handy_setup/templates/views/admin_show_user.html.erb
91
+ - rails_generators/handy_setup/templates/views/edit_user.html.erb
92
+ - rails_generators/handy_setup/templates/views/login.html.erb
93
+ - rails_generators/handy_setup/templates/views/new_user.html.erb
94
+ - rails_generators/handy_setup/templates/views/show_user.html.erb
95
+ - rails_generators/handy_setup/templates/views/signup.html.erb
96
+ - test/helper.rb
97
+ - test/test_handy-generators.rb
98
+ has_rdoc: true
99
+ homepage: http://github.com/jordinl/handy-generators
100
+ licenses: []
101
+
102
+ post_install_message:
103
+ rdoc_options:
104
+ - --charset=UTF-8
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ requirements: []
126
+
127
+ rubyforge_project:
128
+ rubygems_version: 1.3.7
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Application and Scaffold generators
132
+ test_files:
133
+ - test/test_handy-generators.rb
134
+ - test/helper.rb