forked from jm/rails-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
authlogic.rb
143 lines (117 loc) · 4.29 KB
/
authlogic.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Authlogic template.
log 'template', 'Applying authlogic template'
begin
raise ScriptError, "This application is already using authlogic." if File.exists?('spec/spec_helpers/authentication_spec_helper.rb')
rescue ScriptError => e
puts e.message
Kernel::exit(1)
end
unless self.respond_to?(:model)
@stand_alone = true
load_template('http://github.com/hectoregm/groundwork/raw/master/methods.rb')
end
# Add gem dependencies
gem 'haml' if templating_engine == "haml"
gem 'rdiscount'
gem 'justinfrench-formtastic', :lib => 'formtastic', :source => 'http://gems.github.com'
gem 'authlogic', :version => "= 2.0.11"
# Install gems
rake 'gems:install', :sudo => true
# Haml setup
run("haml --rails .") if templating_engine == "haml"
# Initializer for action_mailer configuration
initializer "action_mailer.rb", get_source("config/initializers/action_mailer.rb")
# Set I18n load path
environment(%q|config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]|)
# Rspec helper for authlogic
spec 'spec_helpers/authentication_spec_helper.rb'
generate :session, "user_session"
# Create routes
log 'route', 'config/routes.rb'
file('config/routes.rb', get_source('config/routes.rb'), false)
# Get migration
log 'migrate', 'db/migrate/create_users.rb'
file('db/migrate/20090316040456_create_users.rb',
get_source('db/migrate/20090316040456_create_users.rb'), false)
# Get models
model "user.rb"
model "user_mailer.rb"
model "user_observer.rb"
# Add observer
environment('config.active_record.observers = :user_observer')
# Get controllers
controller "application_controller.rb"
controller "sessions_controller.rb"
controller "users_controller.rb"
controller "password_resets_controller.rb"
controller 'home_controller.rb'
# Get views
view "users", "new.html.#{templating_engine}"
view "users", "edit.html.#{templating_engine}"
view 'users', "_semantic_form.html.#{templating_engine}"
view "users", "show.html.#{templating_engine}"
view "sessions", "new.html.#{templating_engine}"
view "user_mailer", "activation.text.html.#{templating_engine}"
view "user_mailer", "reset_password_instructions.text.html.#{templating_engine}"
view "user_mailer", "signup_notification.text.html.#{templating_engine}"
view "password_resets", "new.html.#{templating_engine}"
view "password_resets", "edit.html.#{templating_engine}"
view 'home', "index.html.#{templating_engine}"
view 'home', "index.es.html.#{templating_engine}"
#Get helpers
helper 'layout_helper.rb'
helper "#{templating_engine}_helper.rb"
# Modify layouts
layout "application.html.#{templating_engine}"
layout "single_column.html.#{templating_engine}"
# Get stylesheets
if templating_engine == "haml"
sass 'base.sass'
sass 'behaviors.sass'
sass 'colors.sass'
sass 'style.sass'
else
stylesheet 'base.css'
stylesheet 'style.css'
end
if requested? :bdd
if templating_engine == "haml"
haml_setup = <<-EOF.gsub(/^( ){4}/, '')
config.prepend_before(:all, :type => :helper) do
helper.extend Haml
helper.extend Haml::Helpers
helper.send :init_haml_helpers
end
end
EOF
gsub_file('spec/spec_helper.rb', /end\n$/, haml_setup)
end
# Get authentication related cucumber features
cp_r "features/registration", "features"
cp_r "features/authentication", "features"
cp_r "features/password_reset", "features"
# Get rspec tests
spec 'models/user_spec.rb'
spec 'models/user_mailer_spec.rb'
spec 'controllers/users_controller_spec.rb'
spec 'controllers/sessions_controller_spec.rb'
spec 'controllers/password_resets_controller_spec.rb'
spec 'helpers/layout_helper_spec.rb'
spec "helpers/#{templating_engine}_helper_spec.rb"
end
# Get i18n files
cp_r 'config/locales', 'config'
# Replace APP with the app name.
gsub_file("app/views/layouts/single_column.html.#{templating_engine}", /APP/, app_name)
gsub_file("app/views/layouts/application.html.#{templating_engine}", /APP/, app_name)
gsub_file('app/models/user_mailer.rb', /APP/, app_name)
gsub_file('config/locales/views/user_mailer/en.yml', /APP/, app_name)
gsub_file('config/locales/views/user_mailer/en.yml', /APP/, app_name)
gsub_file('config/locales/views/user_mailer/es.yml', /APP/, app_name)
if @stand_alone
rm 'public/index.html'
rake 'db:migrate'
rake 'db:test:load'
end
# Authlogic template.
log 'template', 'Successfully applied authlogic template'