Class: Nifty::Generators::AuthenticationGenerator

Inherits:
Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/nifty/authentication/authentication_generator.rb

Instance Method Summary collapse

Methods inherited from Base

banner, source_root

Instance Method Details

#create_controller_filesObject



24
25
26
27
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 24

def create_controller_files
  template 'users_controller.rb', "app/controllers/#{user_plural_name}_controller.rb"
  template 'sessions_controller.rb', "app/controllers/#{session_plural_name}_controller.rb"
end

#create_include_lineObject



55
56
57
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 55

def create_include_line
  inject_into_class "app/controllers/application_controller.rb", "ApplicationController", "  include Authentication\n"
end

#create_lib_filesObject



39
40
41
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 39

def create_lib_files
  template 'authentication.rb', 'lib/authentication.rb'
end

#create_migrationObject



51
52
53
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 51

def create_migration
  migration_template 'migration.rb', "db/migrate/create_#{user_plural_name}.rb"
end

#create_model_filesObject



19
20
21
22
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 19

def create_model_files
  template 'user.rb', "app/models/#{user_singular_name}.rb"
  template 'authlogic_session.rb', "app/models/#{user_singular_name}_session.rb" if options.authlogic?
end

#create_routesObject



43
44
45
46
47
48
49
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 43

def create_routes
  route "resources #{user_plural_name.to_sym.inspect}"
  route "resources #{session_plural_name.to_sym.inspect}"
  route "match 'login' => '#{session_plural_name}#new', :as => :login"
  route "match 'logout' => '#{session_plural_name}#destroy', :as => :logout"
  route "match 'signup' => '#{user_plural_name}#new', :as => :signup"
end

#create_test_filesObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 59

def create_test_files
  if test_framework == :rspec
    template 'fixtures.yml', "spec/fixtures/#{user_plural_name}.yml"
    template 'tests/rspec/user.rb', "spec/models/#{user_singular_name}_spec.rb"
    template 'tests/rspec/users_controller.rb', "spec/controllers/#{user_plural_name}_controller_spec.rb"
    template 'tests/rspec/sessions_controller.rb', "spec/controllers/#{session_plural_name}_controller_spec.rb"
  else
    template 'fixtures.yml', "test/fixtures/#{user_plural_name}.yml"
    template "tests/#{test_framework}/user.rb", "test/unit/#{user_singular_name}_test.rb"
    template "tests/#{test_framework}/users_controller.rb", "test/functional/#{user_plural_name}_controller_test.rb"
    template "tests/#{test_framework}/sessions_controller.rb", "test/functional/#{session_plural_name}_controller_test.rb"
  end
end

#create_view_filesObject



34
35
36
37
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 34

def create_view_files
  template "views/#{view_language}/signup.html.#{view_language}", "app/views/#{user_plural_name}/new.html.#{view_language}"
  template "views/#{view_language}/login.html.#{view_language}", "app/views/#{session_plural_name}/new.html.#{view_language}"
end

#crete_helper_filesObject



29
30
31
32
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 29

def crete_helper_files
  template 'users_helper.rb', "app/helpers/#{user_plural_name}_helper.rb"
  template 'sessions_helper.rb', "app/helpers/#{session_plural_name}_helper.rb"
end