Skip to content

Commit

Permalink
devise installs cleanly -- don't know if it owrk, bit it installs
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip (flip) Kromer committed Jan 3, 2012
1 parent 1aa177f commit d24867a
Show file tree
Hide file tree
Showing 23 changed files with 176 additions and 77 deletions.
9 changes: 5 additions & 4 deletions _application.rb
Expand Up @@ -35,18 +35,19 @@
RUBY
end

gsub_file('config/environments/development.rb',
/^\s*# config.cache_store = :mem_cache_store.*/,
inject_into_file 'config/environments/development.rb',
:after => "config.action_controller.perform_caching = false.*\n" do
<<-RUBY
# # mimic production caching if env var is set
# if ENV['MIMIC_PRODUCTION_CACHING']
# config.action_controller.perform_caching = true
# config.cache_store = :dalli_store
# end
RUBY
)
end

inject_into_file 'config/environments/development.rb', :before => " # Print deprecation notices" do
inject_into_file 'config/environments/development.rb',
:before => " # Print deprecation notices" do
<<-RUBY
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
Expand Down
31 changes: 11 additions & 20 deletions _boilerplate.rb
Expand Up @@ -2,15 +2,10 @@

puts "Setting up HTML5 Boilerplate with HAML, SASS, and Compass ...".magenta

remove_file 'app/assets/stylesheets/application.css'
copy_static_file 'app/assets/stylesheets/application.sass'
copy_static_file 'app/assets/stylesheets/bootstrap.sass'

copy_static_file 'config/compass.rb'
copy_static_file 'app/assets/stylesheets/bootstrap.sass'
copy_static_file 'app/views/misc/bootstrap_demo.html.erb'

gsub_file( 'app/assets/javascripts/application.js', /.*require jquery\s+\n?/, '')

inject_into_file 'config/application.rb', :after => "config.assets.enabled = true\n" do
<<-RUBY
Expand All @@ -20,7 +15,6 @@
RUBY
end


%w[
bootstrap/bootstrap-dropdown.js
bootstrap/bootstrap-scrollspy.js
Expand All @@ -35,6 +29,16 @@
git :add => '.'
git :commit => "-am 'Twitter Bootstrap Helpers.'"

%w[
jasmine/jasmine.js
jasmine/jasmine-fixture.js
jasmine/jasmine-html.js
jasmine/jasmine-jquery.js
jasmine/jasmine-stealth.js
].each{|asset| copy_static_file("public/assets/#{asset}")}
git :add => '.'
git :commit => "-am 'Jasmine - javascript test framework.'"

%w[
hashgrid.js
].each{|asset| copy_static_file("public/assets/#{asset}")}
Expand All @@ -55,16 +59,3 @@
].each{|asset| copy_static_file("public/assets/#{asset}")}
git :add => '.'
git :commit => "-am 'javascript utils.'"

%w[
app/views/layouts/application.html.haml
app/views/layouts/_flashes.html.haml
app/views/layouts/_footer.html.haml
app/views/layouts/_htmlhead.html.haml
app/views/layouts/_javascripts.html.haml
app/views/layouts/_sidebar.html.haml
app/views/layouts/_topbar.html.haml
app/assets/stylesheets/page.sass
].each{|asset| copy_static_file(asset)}
git :add => '.'
git :commit => "-am 'javascript utils.'"
46 changes: 39 additions & 7 deletions _devise.rb
Expand Up @@ -2,20 +2,24 @@

puts "Setting up devise ... ".magenta

skip_migration = false

generate 'devise:install'

#
# clear out old migrations
#
Dir['db/migrate/*create_users.rb'].each{|old_migration| puts old_migration ; remove_file(old_migration) }
Dir['db/migrate/*create_users.rb'].each{|old_migration| puts old_migration ; remove_file(old_migration) } unless skip_migration

#
# Generate User model
#
generate "nifty:scaffold User name:string is_local:boolean index --rspec --haml --skip-migration"
generate "nifty:scaffold User name:string username:string index --rspec --haml #{skip_migration ? '--skip-migration' : '' }"
remove_file 'spec/fixtures/users.yml'
remove_file 'spec/models/user_spec.rb'

# Rails::Generators.invoke "migration", %w(add_fields_to_users name:string username:string is_local:boolean --orm=active_record)

#
# Generate Devise
#
Expand All @@ -33,6 +37,7 @@
inject_into_file 'config/environments/development.rb', :after => %Q{config.action_mailer.raise_delivery_errors = false\n} do
%Q{config.action_mailer.default_url_options = { :host => 'localhost:3000' }\n}
end

# override user login routes
gsub_file 'config/routes.rb', /devise_for :users$/, %q{devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :sign_up => 'signup' }}

Expand All @@ -44,14 +49,41 @@
end
}

copy_static_file "app/models/user.rb"
%w[
app/models/user.rb
app/views/users/show.html.haml
app/views/users/index.html.haml
].each do |file|
remove_file file
copy_static_file file
end

%w[ confirmations/new passwords/edit passwords/new registrations/edit registrations/new sessions/new unlocks/new ].each do |devise_view_file|
copy_static_file "app/views/devise/#{devise_view_file}.html.haml"
end

old_migration = Dir['db/migrate/*[0-9]_create_users.rb'].first and remove_file(old_migration)
Rails::Generators.invoke "migration", %w(add_fields_to_users name:string username:string is_local:boolean --orm=active_record)
# migration_template 'db/migrate/create_users.rb'

git :add => '.'
git :commit => "-am 'Generated user auth layer with devise.'"

#
# post-install
#

inject_into_file 'config/application.rb', :after => "config.assets.enabled = true\n" do
<<-RUBY
# don't hit the DB when compiling assets
config.assets.initialize_on_precompile = false
RUBY
end

git :add => '.'
git :commit => "-am 'devise post-install maintenance.'"

#
# run migration
#

rake 'db:migrate'
git :add => '.'
git :commit => "-am 'Ran devise migration.'"
7 changes: 5 additions & 2 deletions _friendly_id.rb
Expand Up @@ -3,6 +3,9 @@
puts "Setting up friendly_id ... ".magenta

generate 'friendly_id'
git :add => '.'
git :commit => "-am 'Generated friendly_id migration.'"

git :add => '.'
git :commit => "-am 'Generated friendly_id migration.'"
rake 'db:migrate'
git :add => '.'
git :commit => "-am 'Ran friendly_id migration.'"
1 change: 0 additions & 1 deletion _gemfile.rb
Expand Up @@ -60,7 +60,6 @@
gem 'awesome_print'
gem 'pry'
end
RUBY

git :commit => "-am 'Gemfile.'"
8 changes: 0 additions & 8 deletions _javascripts.rb

This file was deleted.

27 changes: 19 additions & 8 deletions _layouts.rb
Expand Up @@ -2,14 +2,25 @@

puts "Creating default layout ...".magenta

remove_file 'app/views/layouts/_footer.html.haml'
copy_static_file 'app/views/layouts/_footer.html.haml'
# we do the jquery including
gsub_file( 'app/assets/javascripts/application.js', /.*require jquery\s+\n?/, '')

remove_file 'app/views/layouts/_header.html.haml'
copy_static_file 'app/views/layouts/_header.html.haml'
remove_file 'app/assets/stylesheets/application.css'

copy_static_file 'app/views/layouts/_nav.html.haml'
%w[
app/views/layouts/application.html.haml
app/views/layouts/_flashes.html.haml
app/views/layouts/_footer.html.haml
app/views/layouts/_htmlhead.html.haml
app/views/layouts/_javascripts.html.haml
app/views/layouts/_sidebar.html.haml
app/views/layouts/_topbar.html.haml
app/assets/stylesheets/application.sass
app/assets/stylesheets/page.sass
].each do |asset|
remove_file asset
copy_static_file asset
end

# This needs to be kept up to date as the boilerplate and sporkd gem get updated
remove_file 'app/views/layouts/application.html.haml'
copy_static_file 'app/views/layouts/application.html.haml'
git :add => '.'
git :commit => "-am 'layout files.'"
1 change: 1 addition & 0 deletions _special_pages.rb
Expand Up @@ -8,6 +8,7 @@
match 'admin/demo' => 'misc#demo'
match 'admin/bootstrap_demo' => 'misc#bootstrap_demo'
RUBY
end

Expand Down
5 changes: 2 additions & 3 deletions files/app/helpers/application_helper.rb
Expand Up @@ -5,9 +5,8 @@ def title(text)
@title = text
end

def skip_sidebar
@show_sidebar = false
end
def skip_sidebar() @skip_sidebar = true ; end
def show_sidebar?() not @skip_sidebar ; end

def has_javascript(javascript)
content_for(:javascript){ javascript_include_tag(javascript) }
Expand Down
43 changes: 37 additions & 6 deletions files/app/models/user.rb
@@ -1,14 +1,45 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
#
# Attributes and scopes
#
attr_accessible :email, :password, :password_confirmation, :remember_me
attr_accessible :name, :username, :is_local
attr_accessible :name, :username, :shibboleth

# Include default devise modules. Others available are: :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

# scopes for arel
scope :alphabetically, order("users.name ASC")
scope :by_id, order("users.id ASC")

#
# Validations
#

validates :name, :presence => true, :length => {:minimum => 1, :maximum => 100}

# require users to know a magic watchword to register. Set this value in
# config/app_config.yaml or use an environment variable -- on heroku, run
# heroku config:add SIGNUP_SHIBBOLETH=your_shibboleth
validates_format_of :shibboleth, :with => /\A#{Settings.signup_shibboleth}\z/, :on => :create, :message => "is wrong - find They Who Hold the Secret and ask them. Also: No Homers"

#
# Plugins
#


#
# Methods
#


def titleize
name
end

def short_name
name.gsub(/^(\w+\W+\w).*/, '\1')
end

end
4 changes: 2 additions & 2 deletions files/app/views/layouts/application.html.haml
Expand Up @@ -6,8 +6,8 @@
= render :partial => 'layouts/topbar'
= render :partial => 'layouts/flashes'

.container-fluid{ :class => (@show_sidebar ? '' : 'no-sidebar') }
= render :partial => 'layouts/sidebar' if @show_sidebar
.container-fluid{ :class => (show_sidebar? ? '' : 'no-sidebar') }
= render :partial => 'layouts/sidebar' if show_sidebar?

.content#main{ :role => 'main' }
= yield
Expand Down
27 changes: 27 additions & 0 deletions files/app/views/users/index.html.haml
@@ -0,0 +1,27 @@
- title "Users"

.right
%p.clear
To set your user image, visit <a href="http://gravatar.com/">gravatar.com</a>

%hr/

%table.users.horizontal
%tr
%th &nbsp;
%th= link_to 'Name', users_path(:order => 'name')
%th Email
- for user in @users
%tr.hcard
%td.photo= image_tag avatar_url(user)
%td.fn.n= link_to_rsrc user
%td.email= user.email

.buttons
- if user_signed_in?
%p
To create a new user,
= link_to "sign out", destroy_user_session_path
and then go through the signup process
- else
= link_to "New user", new_user_registration_path, :class => :button
16 changes: 16 additions & 0 deletions files/app/views/users/show.html.haml
@@ -0,0 +1,16 @@
- title "Lunchlady user #{@user.titleize}"

%table.vertical.user
%tr
%th Name
%td.td_12= @user.name
%td.td_5.photo{:rowspan => 4 }
= image_tag avatar_url(@user, :s => 200)
%br/
%span.quiet
Set your image at <a href="http://gravatar.com/">gravatar.com</a>
%tr
%th Email
%td= @user.email
%tr
%td.empty &nbsp;
5 changes: 5 additions & 0 deletions old/_javascripts.rb
@@ -0,0 +1,5 @@
get "https://github.com/dotjay/hashgrid/raw/v5/hashgrid.js", "public/javascripts/hashgrid.js"

inject_into_file 'app/views/layouts/_javascripts.html.haml', :before => %Q{\n\s*= yield :javascripts} do
%Q{= javascript_include_tag('hashgrid') if Rails.env.development?}
end
File renamed without changes.

0 comments on commit d24867a

Please sign in to comment.