lib/generators/janus/resource_generator.rb in janus-0.7.0 vs lib/generators/janus/resource_generator.rb in janus-0.8.0
- old
+ new
@@ -15,20 +15,21 @@
attributes += %w{remember_token:string:uniq remember_created_at:datetime} if strategies.include?('remember')
attributes += %w{confirmation_token:string:uniq confirmation_sent_at:datetime confirmed_at:datetime} if strategies.include?('confirmation')
attributes += %w{reset_password_token:string:uniq reset_password_sent_at:datetime} if strategies.include?('password')
attributes += %w{session_token:string:uniq} if strategies.include?('remote')
attributes += %w{sign_in_count:integer last_sign_in_at:datetime last_sign_in_ip:string current_sign_in_at:datetime current_sign_in_ip:string} if strategies.include?('track')
+ attributes += %w{authentication_token:string:uniq authentication_token_created_at:datetime} if strategies.include?('token')
generate('model', attributes.join(' '))
modules = [
- " include Janus::Models::Base",
" include Janus::Models::DatabaseAuthenticatable",
]
modules << " include Janus::Models::Rememberable" if strategies.include?('remember')
modules << " include Janus::Models::Confirmable" if strategies.include?('confirmation')
modules << " include Janus::Models::Trackable" if strategies.include?('track')
modules << " include Janus::Models::RemoteAuthenticatable" if strategies.include?('remote')
+ modules << " include Janus::Models::TokenAuthenticatable" if strategies.include?('token')
inject_into_class "app/models/#{singular_name}.rb", class_name, modules.join("\n") + "\n"
end
def create_controllers_and_views
if strategies.include?('session')
@@ -46,9 +47,24 @@
end
if strategies.include?('password')
template 'passwords_controller.erb', "app/controllers/#{plural_name}/passwords_controller.rb"
template 'passwords/new.html.erb', "app/views/#{plural_name}/passwords/new.html.erb"
template 'passwords/edit.html.erb', "app/views/#{plural_name}/passwords/edit.html.erb"
+ end
+ end
+
+ def create_mailer
+ return unless strategies.include?('registration') or strategies.include?('confirmation') or strategies.include?('password')
+ template 'mailer.rb', "app/mailers/#{singular_name}_mailer.rb"
+
+ if strategies.include?('confirmation')
+ template 'mailer/confirmation_instructions.html.erb', "app/views/#{singular_name}_mailer/confirmation_instructions.html.erb"
+ template 'mailer/confirmation_instructions.text.erb', "app/views/#{singular_name}_mailer/confirmation_instructions.text.erb"
+ end
+
+ if strategies.include?('password')
+ template 'mailer/reset_password_instructions.html.erb', "app/views/#{singular_name}_mailer/reset_password_instructions.html.erb"
+ template 'mailer/reset_password_instructions.text.erb', "app/views/#{singular_name}_mailer/reset_password_instructions.text.erb"
end
end
def add_janus_route
route "janus :#{plural_name}, " + controllers.map { |ctrl| ":#{ctrl} => true" }.join(', ')