diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..59f6023 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +testrun.txt \ No newline at end of file diff --git a/bootstrap.rb b/bootstrap.rb new file mode 100644 index 0000000..6062c1a --- /dev/null +++ b/bootstrap.rb @@ -0,0 +1,11 @@ +require 'rails/generators/named_base' + +module Bootstrap + module Generators + class Base < Rails::Generators::NamedBase #:nodoc: + def self.source_root + @_bootstrap_girl_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'bootstrap', generator_name, 'templates')) + end + end + end +end \ No newline at end of file diff --git a/bootstrap/setup/setup_generator.rb b/bootstrap/setup/setup_generator.rb new file mode 100644 index 0000000..46f91e2 --- /dev/null +++ b/bootstrap/setup/setup_generator.rb @@ -0,0 +1,56 @@ +require 'generators/bootstrap' + +module Bootstrap + module Generators + class SetupGenerator < Base + desc "Description:\n Sets up the initial application with devise as the underlying authentication system." + class_option :email, :type => :string, :default => "admin@site.com", :desc => "The initial admin account email" + class_option :password, :type => :string, :default => "password", :desc => "The initial admin account password" + + def setup_devise + # install other packages we need + generate "devise:install", "installing devise" + generate "devise #{name}" + generate "formtastic:install" + + resource = name.tableize + + # TODO: need to add a root path, for admin it should go to dashboard??? + route = <<-ROUTE + devise_for :#{resource}, :path_names => { :sign_in => 'signin', :sign_out => 'signout' } + as :#{resource.singularize} do + get "/signin" => "devise/sessions#new" + get "/signout" => "devise/sessions#destroy" + end + ROUTE + + gsub_file "config/routes.rb", "devise_for :#{resource}", route + + # devise forms with formtastic support. + run "cp -r #{self.class.source_root}/devise #{Rails.root}/app/views/" + + rake "db:migrate" + + # create initial admin account + # TODO: need to add super_user/admin role, after we add CanCan + email = options[:email] + password = options[:password] + admin = "Account.create!(:email => '#{email}', :password => '#{password}', :password_confirmation => '#{password}')" + run "rails runner \"#{admin}\"" + + + # TODO: update other devise templates to use Formtastic + # TODO: setup i18n file for Formtastic + + + + #rake "test" + end + + def self.banner + "rails generate bootstrap:#{generator_name} [options]" + end + + end + end +end \ No newline at end of file diff --git a/bootstrap/setup/templates/devise/confirmations/new.html.haml b/bootstrap/setup/templates/devise/confirmations/new.html.haml new file mode 100644 index 0000000..810b8ca --- /dev/null +++ b/bootstrap/setup/templates/devise/confirmations/new.html.haml @@ -0,0 +1,9 @@ +%h2 Resend confirmation instructions += form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| + = devise_error_messages! + %p + = f.label :email + %br/ + = f.text_field :email + %p= f.submit "Resend confirmation instructions" += render :partial => "devise/shared/links" diff --git a/bootstrap/setup/templates/devise/mailer/confirmation_instructions.html.haml b/bootstrap/setup/templates/devise/mailer/confirmation_instructions.html.haml new file mode 100644 index 0000000..7840b9c --- /dev/null +++ b/bootstrap/setup/templates/devise/mailer/confirmation_instructions.html.haml @@ -0,0 +1,4 @@ +%p + Welcome #{@resource.email}! +%p You can confirm your account through the link below: +%p= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) diff --git a/bootstrap/setup/templates/devise/mailer/reset_password_instructions.html.haml b/bootstrap/setup/templates/devise/mailer/reset_password_instructions.html.haml new file mode 100644 index 0000000..4fc4743 --- /dev/null +++ b/bootstrap/setup/templates/devise/mailer/reset_password_instructions.html.haml @@ -0,0 +1,6 @@ +%p + Hello #{@resource.email}! +%p Someone has requested a link to change your password, and you can do this through the link below. +%p= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) +%p If you didn't request this, please ignore this email. +%p Your password won't change until you access the link above and create a new one. diff --git a/bootstrap/setup/templates/devise/mailer/unlock_instructions.html.haml b/bootstrap/setup/templates/devise/mailer/unlock_instructions.html.haml new file mode 100644 index 0000000..34b0e9e --- /dev/null +++ b/bootstrap/setup/templates/devise/mailer/unlock_instructions.html.haml @@ -0,0 +1,5 @@ +%p + Hello #{@resource.email}! +%p Your account has been locked due to an excessive amount of unsuccessful sign in attempts. +%p Click the link below to unlock your account: +%p= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) diff --git a/bootstrap/setup/templates/devise/passwords/edit.html.haml b/bootstrap/setup/templates/devise/passwords/edit.html.haml new file mode 100644 index 0000000..543d47e --- /dev/null +++ b/bootstrap/setup/templates/devise/passwords/edit.html.haml @@ -0,0 +1,14 @@ +%h2 Change your password += form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| + = devise_error_messages! + = f.hidden_field :reset_password_token + %p + = f.label :password + %br/ + = f.password_field :password + %p + = f.label :password_confirmation + %br/ + = f.password_field :password_confirmation + %p= f.submit "Change my password" += render :partial => "devise/shared/links" diff --git a/bootstrap/setup/templates/devise/passwords/new.html.haml b/bootstrap/setup/templates/devise/passwords/new.html.haml new file mode 100644 index 0000000..de2274f --- /dev/null +++ b/bootstrap/setup/templates/devise/passwords/new.html.haml @@ -0,0 +1,9 @@ +%h2 Forgot your password? += form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| + = devise_error_messages! + %p + = f.label :email + %br/ + = f.text_field :email + %p= f.submit "Send me reset password instructions" += render :partial => "devise/shared/links" diff --git a/bootstrap/setup/templates/devise/registrations/edit.html.haml b/bootstrap/setup/templates/devise/registrations/edit.html.haml new file mode 100644 index 0000000..d252d9a --- /dev/null +++ b/bootstrap/setup/templates/devise/registrations/edit.html.haml @@ -0,0 +1,27 @@ +%h2 + Edit #{resource_name.to_s.humanize} += form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| + = devise_error_messages! + %p + = f.label :email + %br/ + = f.text_field :email + %p + = f.label :password + %i (leave blank if you don't want to change it) + %br/ + = f.password_field :password + %p + = f.label :password_confirmation + %br/ + = f.password_field :password_confirmation + %p + = f.label :current_password + %i (we need your current password to confirm your changes) + %br/ + = f.password_field :current_password + %p= f.submit "Update" +%h3 Cancel my account +%p + Unhappy? #{link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete}. += link_to "Back", :back diff --git a/bootstrap/setup/templates/devise/registrations/new.html.haml b/bootstrap/setup/templates/devise/registrations/new.html.haml new file mode 100644 index 0000000..b03da35 --- /dev/null +++ b/bootstrap/setup/templates/devise/registrations/new.html.haml @@ -0,0 +1,17 @@ +%h2 Sign up += form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| + = devise_error_messages! + %p + = f.label :email + %br/ + = f.text_field :email + %p + = f.label :password + %br/ + = f.password_field :password + %p + = f.label :password_confirmation + %br/ + = f.password_field :password_confirmation + %p= f.submit "Sign up" += render :partial => "devise/shared/links" diff --git a/bootstrap/setup/templates/devise/sessions/new.html.haml b/bootstrap/setup/templates/devise/sessions/new.html.haml new file mode 100644 index 0000000..335e40e --- /dev/null +++ b/bootstrap/setup/templates/devise/sessions/new.html.haml @@ -0,0 +1,11 @@ +%h2 Sign in += semantic_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |form| + -form.inputs do + =form.input :email + =form.input :password + - if devise_mapping.rememberable? + =form.input :remember_me + -form.buttons do + =form.commit_button + += render :partial => "devise/shared/links" diff --git a/bootstrap/setup/templates/devise/shared/_links.haml b/bootstrap/setup/templates/devise/shared/_links.haml new file mode 100644 index 0000000..a754735 --- /dev/null +++ b/bootstrap/setup/templates/devise/shared/_links.haml @@ -0,0 +1,15 @@ +- if controller_name != 'sessions' + = link_to "Sign in", new_session_path(resource_name) + %br/ +- if devise_mapping.registerable? && controller_name != 'registrations' + = link_to "Sign up", new_registration_path(resource_name) + %br/ +- if devise_mapping.recoverable? && controller_name != 'passwords' + = link_to "Forgot your password?", new_password_path(resource_name) + %br/ +- if devise_mapping.confirmable? && controller_name != 'confirmations' + = link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) + %br/ +- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' + = link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) + %br/ diff --git a/bootstrap/setup/templates/devise/unlocks/new.html.haml b/bootstrap/setup/templates/devise/unlocks/new.html.haml new file mode 100644 index 0000000..afb0daa --- /dev/null +++ b/bootstrap/setup/templates/devise/unlocks/new.html.haml @@ -0,0 +1,9 @@ +%h2 Resend unlock instructions += form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| + = devise_error_messages! + %p + = f.label :email + %br/ + = f.text_field :email + %p= f.submit "Resend unlock instructions" += render :partial => "devise/shared/links" diff --git a/template.rb b/template.rb index caeef45..b863023 100644 --- a/template.rb +++ b/template.rb @@ -18,6 +18,8 @@ # # * Google Fonts??? # +# * Look at including http://github.com/himmel/html5-boilerplate +# # Graeme Nelson, 2010 # If we are running rvm, lets create a new gemset based on @@ -48,7 +50,13 @@ # Let's setup the gems we only need for testing gem "shoulda", ">= 2.11.2", :group => :test gem "factory_girl_rails", ">= 1.0.0", :group => :test -gem "mocha", ">= 0.9.8", :group => :test +gem "mocha", ">= 0.9.8", :group => :test +gem 'cover_me', '>= 1.0.0.pre1', :require => false, :group => :test + +# add cover_me to the test/test_helper.rb, if we add more things to the test_helper.rb +# we might want to consider overwriting the file since there isn't much in the default +# version. +gsub_file("test/test_helper.rb", "require 'rails/test_help'", "require 'rails/test_help'\nrequire 'cover_me'") # Let's get the generators we want from rails generator, factory_girl, shoulda git :clone => "--depth 0 http://github.com/indirect/rails3-generators.git" @@ -145,7 +153,7 @@ module ActionView::Helpers::AssetTagHelper % cd #{app_name} % gem install bundler --version '>= 1.0.0.rc.1' % bundle install -% rails g app:setup +% rails g bootstrap:setup DOCS