bear 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ create_file 'app/views/admin/dashboard/index.html.haml' do
2
+ <<-FILE
3
+ %h1 #{app_name.humanize} Admin
4
+ FILE
5
+ end
6
+
7
+ create_file 'app/views/layouts/admin.html.haml' do
8
+ <<-FILE
9
+ !!! 5
10
+ %html
11
+ %head
12
+ %meta{ "http-equiv" => "Content-Type", :content => "text/html; charset=utf-8" }
13
+ %meta{ "http-equiv" => "X-UA-Compatible", :content => "IE=edge,chrome=1" }
14
+ %title
15
+ #{app_name.humanize}
16
+ = yield(:title)
17
+ %meta{ :name => "viewport", :content => "width=device-width; initial-scale=1.0" }
18
+ = csrf_meta_tag
19
+ = include_stylesheets(:admin, :media => "all")
20
+ = yield(:head)
21
+ %body
22
+ - unless flash_messages.blank?
23
+ #flash_messages= raw(flash_messages)
24
+
25
+ = yield
26
+ = include_javascripts(:common)
27
+ FILE
28
+ end
@@ -0,0 +1,115 @@
1
+ generate(:controller, "admin/users index new create edit update destroy")
2
+
3
+ inject_into_file 'config/routes.rb', :after => "devise_for :users\n" do
4
+ <<-'FILE'
5
+ namespace "admin" do
6
+ resources :users
7
+ end
8
+ FILE
9
+ end
10
+
11
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def index\n" do
12
+ <<-'FILE'
13
+ @users = User.paginate :page => params[:page], :per_page => 50
14
+ FILE
15
+ end
16
+
17
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def new\n" do
18
+ <<-'FILE'
19
+ @user = User.new
20
+ FILE
21
+ end
22
+
23
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def create\n" do
24
+ <<-'FILE'
25
+ @user = User.new
26
+ @user.attributes = params[:user]
27
+ if @user.save
28
+ flash[:notice] = "User created!"
29
+ redirect_to(admin_users_path)
30
+ else
31
+ render(:action => "new")
32
+ end
33
+ FILE
34
+ end
35
+
36
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def update\n" do
37
+ <<-'FILE'
38
+ params[:user].delete(:password) if params[:user][:password].blank?
39
+ params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
40
+ if @user.update_attributes(params[:user])
41
+ flash[:notice] = "Successfully updated #{@user.name}."
42
+ redirect_to(admin_users_url)
43
+ else
44
+ render(:action => "edit")
45
+ end
46
+ FILE
47
+ end
48
+
49
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def destroy\n" do
50
+ <<-'FILE'
51
+ @user.destroy
52
+ flash[:notice] = "User deleted."
53
+ redirect_to(admin_users_path)
54
+ FILE
55
+ end
56
+
57
+ gsub_file 'app/controllers/admin/users_controller.rb', /ApplicationController/, 'Admin::BaseController'
58
+
59
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "class Admin::UsersController < Admin::BaseController\n" do
60
+ <<-'FILE'
61
+ before_filter :find_user, :only => [ :edit, :update, :destroy ]
62
+
63
+ def find_user
64
+ @user = User.find(params[:id])
65
+ end
66
+
67
+ FILE
68
+ end
69
+
70
+ create_file 'app/views/admin/users/_form.html.haml' do
71
+ <<-'FILE'
72
+ = semantic_form_for([ :admin, @user ]) do |f|
73
+ = f.semnatic_errors
74
+ = f.inputs(:name, :email, :password, :password_confirmation)
75
+ = f.buttons
76
+ FILE
77
+ end
78
+
79
+ create_file 'app/views/admin/users/edit.html.haml' do
80
+ <<-'FILE'
81
+ = render(:partial => "form")
82
+ FILE
83
+ end
84
+
85
+ create_file 'app/views/admin/users/new.html.haml' do
86
+ <<-'FILE'
87
+ = render(:partial => "form")
88
+ FILE
89
+ end
90
+
91
+ create_file 'app/views/admin/users/index.html.haml' do
92
+ <<-FILE
93
+ - if !@users.blank?
94
+ %table
95
+ %thead
96
+ %tr
97
+ %th Name
98
+ %th Email
99
+ %th
100
+ %tbody
101
+ - @users.each do |user|
102
+ %tr
103
+ %td= link_to(user.name, edit_admin_user_path(user), :class => "edit_link")
104
+ %td= user.email
105
+ %td
106
+ - if user.id != current_user.id
107
+ = link_to("Delete", admin_user_path(user), :confirm => 'Are you sure?', :method => :delete, :class => "delete_link")
108
+ - else
109
+ That's you!
110
+ = will_paginate(@users)
111
+ - else
112
+ %p No users
113
+ FILE
114
+ end
115
+
@@ -0,0 +1,30 @@
1
+ run "rm spec/controllers/admin/users_controller_spec.rb"
2
+
3
+ create_file "spec/controllers/admin/users_controller_spec.rb" do
4
+ <<-"FILE"
5
+ require "spec_helper"
6
+ include Devise::TestHelpers
7
+
8
+ describe Admin::UsersController do
9
+ let(:admin) { Fabricate(:admin) }
10
+
11
+ before do
12
+ sign_in(admin)
13
+ end
14
+
15
+ describe "GET 'index'" do
16
+ it "should be successful" do
17
+ get "index"
18
+ response.should be_success
19
+ end
20
+ end
21
+
22
+ describe "GET 'new'" do
23
+ it "should be successful" do
24
+ get "new"
25
+ response.should be_success
26
+ end
27
+ end
28
+ end
29
+ FILE
30
+ end
@@ -0,0 +1,65 @@
1
+ run "mkdir app/views/shared"
2
+
3
+ run "rm app/helpers/application_helper.rb"
4
+ create_file "app/helpers/application_helper.rb" do
5
+ <<-"FILE"
6
+ module ApplicationHelper
7
+ def flash_messages
8
+ %w(notice warning error).collect { |message|
9
+ unless flash[message.to_sym].blank?
10
+ content_tag(:p, flash[message.to_sym], :class => "message" + message)
11
+ end
12
+ }.join
13
+ end
14
+ end
15
+ FILE
16
+ end
17
+
18
+ run "rm app/views/layouts/application.html.erb"
19
+ create_file "app/views/layouts/application.html.haml" do
20
+ <<-FILE
21
+ !!! 5
22
+
23
+ %html
24
+ %head
25
+ %meta{ "http-equiv" => "Content-Type", :content => "text/html; charset=utf-8" }
26
+ %meta{ "http-equiv" => "X-UA-Compatible", :content => "IE=edge,chrome=1" }
27
+ %title
28
+ #{app_name.humanize}
29
+ = yield(:title)
30
+ %meta{ :name => "description", :content => "" }
31
+ %meta{ :name => "author", :content => "" }
32
+ %meta{ :name => "viewport", :content => "width=device-width; initial-scale=1.0" }
33
+ = csrf_meta_tag
34
+ = include_stylesheets(:main, :media => "all")
35
+ = yield(:head)
36
+
37
+ %body
38
+ #header
39
+ .container_12
40
+ .grid_12
41
+ %h1= link_to("#{app_name.humanize}", root_path)
42
+ %ul
43
+ %li= link_to("Home", root_path)
44
+ .clear
45
+
46
+ - unless flash_messages.blank?
47
+ .container_12
48
+ .grid_12
49
+ #flash_messages= raw(flash_messages)
50
+ .clear
51
+
52
+ #content
53
+ .container_2
54
+ = yield
55
+ .clear
56
+
57
+ .container_12
58
+ .grid_12
59
+ #footer
60
+ .clear
61
+
62
+ = include_javascripts(:common)
63
+ = coffee_script_bundle
64
+ FILE
65
+ end
@@ -0,0 +1,100 @@
1
+ require "net/http"
2
+ require "net/https"
3
+ require "uri"
4
+ require "rbconfig"
5
+
6
+ say "Building Application with Bear..."
7
+
8
+ def get_remote_https_file(source, destination)
9
+ uri = URI.parse(source)
10
+ http = Net::HTTP.new(uri.host, uri.port)
11
+ http.use_ssl = true
12
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
13
+ request = Net::HTTP::Get.new(uri.request_uri)
14
+ response = http.request(request)
15
+ path = File.join(destination_root, destination)
16
+ File.open(path, "w") { |file| file.write(response.body) }
17
+ end
18
+
19
+ append_file ".gitignore" do
20
+ ".DS_Store"
21
+ ".bundle"
22
+ "capybara-*.html"
23
+ "config/database.yml"
24
+ "log/*.log"
25
+ "public/stylesheets/compiled/"
26
+ "public/system/**/**/**/*"
27
+ "public/uploads"
28
+ "tmp/**/*"
29
+ end
30
+
31
+ git :init
32
+
33
+ # Apply Gemfile
34
+ apply File.expand_path("../gemfile.rb", __FILE__)
35
+
36
+ # Apply Jammit
37
+ apply File.expand_path("../jammit.rb", __FILE__)
38
+
39
+ # Apply HAML generator
40
+ apply File.expand_path("../haml_generator.rb", __FILE__)
41
+
42
+ # Apply rails clean up
43
+ apply File.expand_path("../rails_clean.rb", __FILE__)
44
+
45
+ # Apply js
46
+ apply File.expand_path("../js.rb", __FILE__)
47
+
48
+ # Apply HTML5 Layout
49
+ apply File.expand_path("../application_layout.rb", __FILE__)
50
+
51
+ # Apply SASS
52
+ apply File.expand_path("../sass.rb", __FILE__)
53
+
54
+ # Apply Test Suite
55
+ apply File.expand_path("../test_suite.rb", __FILE__)
56
+
57
+ # Apply Devise?
58
+ apply File.expand_path("../devise.rb", __FILE__) if ENV["BEAR_AUTH"]
59
+
60
+ # Apply admin
61
+ apply File.expand_path("../admin.rb", __FILE__) if ENV["BEAR_ADMIN"]
62
+
63
+ # Apply db create and migrations
64
+ apply File.expand_path("../db.rb", __FILE__)
65
+
66
+ # Apply db seeds
67
+ apply File.expand_path("../db_seed.rb", __FILE__)
68
+
69
+ # Make a home controller
70
+ apply File.expand_path("../home_controller.rb", __FILE__)
71
+
72
+ # Make initializers
73
+ apply File.expand_path("../initializers.rb", __FILE__)
74
+
75
+ # Clean up generated routes
76
+ apply File.expand_path("../clean_routes.rb", __FILE__)
77
+
78
+ # Remove RSpec stuff we are not gonna use right away
79
+ apply File.expand_path("../rspec_clean.rb", __FILE__)
80
+
81
+ login_msg = (ENV["BEAR_ADMIN"]) ? "Login to admin with email #{ENV["BEAR_USER_EMAIL"]} and password #{ENV["BEAR_USER_PASSWORD"]}" : ""
82
+
83
+ say <<-D
84
+
85
+
86
+
87
+
88
+ ########################################################################
89
+
90
+ Bear says RAWR!!!
91
+
92
+ Next run...
93
+ rake spec
94
+ rake cucumber
95
+ rails s
96
+
97
+ #{login_msg}
98
+
99
+ ########################################################################
100
+ D
@@ -0,0 +1,8 @@
1
+ gsub_file("config/routes.rb", /get \"home\/index\"/, '')
2
+ gsub_file("config/routes.rb", /get \"users\/index\"/, '')
3
+ gsub_file("config/routes.rb", /get \"users\/new\"/, '')
4
+ gsub_file("config/routes.rb", /get \"users\/create\"/, '')
5
+ gsub_file("config/routes.rb", /get \"users\/edit\"/, '')
6
+ gsub_file("config/routes.rb", /get \"users\/update\"/, '')
7
+ gsub_file("config/routes.rb", /get \"users\/destroy\"/, '')
8
+ gsub_file("config/routes.rb", /get \"dashboard\/index\"/, '')
@@ -0,0 +1,2 @@
1
+ run "rake db:migrate"
2
+ run "rake db:test:prepare"
@@ -0,0 +1 @@
1
+ run 'rake db:seed'
@@ -0,0 +1,112 @@
1
+ say "Building authentication"
2
+ gsub_file 'config/application.rb', /:password/, ':password, :password_confirmation'
3
+
4
+ run 'rails generate devise:install'
5
+ run 'rails generate devise:views'
6
+
7
+ gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '### ActionMailer Config'
8
+
9
+ gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do
10
+ <<-RUBY
11
+ config.action_mailer.default_url_options = { :host => '0.0.0.0:3000' }
12
+ # A dummy setup for development - no deliveries, but logged
13
+ config.action_mailer.delivery_method = :smtp
14
+ config.action_mailer.perform_deliveries = false
15
+ config.action_mailer.raise_delivery_errors = true
16
+ config.action_mailer.default :charset => "utf-8"
17
+ RUBY
18
+ end
19
+
20
+ inject_into_file 'config/environments/test.rb', :after => "config.action_controller.allow_forgery_protection = false\n" do
21
+ <<-RUBY
22
+ config.action_mailer.default_url_options = { :host => '0.0.0.0:3000' }
23
+ RUBY
24
+ end
25
+
26
+ gsub_file 'config/environments/production.rb', /config.i18n.fallbacks = true/ do
27
+ <<-RUBY
28
+ config.i18n.fallbacks = true
29
+ config.action_mailer.default_url_options = { :host => 'yourhost.com' }
30
+ ### ActionMailer Config
31
+ # Setup for production - deliveries, no errors raised
32
+ config.action_mailer.delivery_method = :smtp
33
+ config.action_mailer.perform_deliveries = true
34
+ config.action_mailer.raise_delivery_errors = false
35
+ config.action_mailer.default :charset => "utf-8"
36
+ RUBY
37
+ end
38
+
39
+ run 'rails generate devise User'
40
+ run 'rm app/models/user.rb'
41
+
42
+ create_file 'app/models/user.rb' do
43
+ <<-RUBY
44
+ class User < ActiveRecord::Base
45
+ devise :database_authenticatable, :token_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
46
+
47
+ validates_presence_of :name
48
+ validates_uniqueness_of :name, :email, :case_sensitive => false, :scope => :deleted_at
49
+
50
+ default_scope :conditions => { :deleted_at => nil }
51
+
52
+ attr_accessible :name, :email, :password, :password_confirmation, :remember_me
53
+
54
+ def destroy
55
+ self.update_attribute(:deleted_at, Time.now.utc)
56
+ end
57
+
58
+ def self.find_with_destroyed(*args)
59
+ self.with_exclusive_scope { find(*args) }
60
+ end
61
+
62
+ def self.find_only_destroyed
63
+ self.with_exclusive_scope(:find => { :conditions => "deleted_at IS NOT NULL" }) do
64
+ all
65
+ end
66
+ end
67
+ end
68
+ RUBY
69
+ end
70
+
71
+ generate(:migration, "AddNameToUsers name:string")
72
+ generate(:migration, "AddDeletedAtToUsers deleted_at:datetime")
73
+
74
+ inject_into_file 'app/views/layouts/application.html.haml', :after => "%li= link_to(\"Home\", root_path)" do
75
+ <<-'FILE'
76
+ - if user_signed_in?
77
+ %li
78
+ = link_to('Logout', destroy_user_session_path)
79
+ - else
80
+ %li
81
+ = link_to('Login', new_user_session_path)
82
+ %li
83
+ User:
84
+ - if current_user
85
+ = current_user.name
86
+ - else
87
+ (not logged in)
88
+ FILE
89
+ end
90
+
91
+ devise_migration = Dir['db/migrate/*_devise_create_users.rb'].first
92
+
93
+ gsub_file devise_migration, /# t.confirmable/, 't.confirmable'
94
+ gsub_file devise_migration, /# t.token_authenticatable/, 't.token_authenticatable'
95
+ gsub_file devise_migration, /# add_index :users, :confirmation_token, :unique => true/, 'add_index :users, :confirmation_token, :unique => true'
96
+
97
+ append_file 'db/seeds.rb' do
98
+ <<-FILE
99
+
100
+ # Setup initial user so we can get in
101
+ user = User.create!(
102
+ :name => '#{ENV['BEAR_USER_NAME']}',
103
+ :email => '#{ENV['BEAR_USER_EMAIL']}',
104
+ :password => '#{ENV['BEAR_USER_PASSWORD']}',
105
+ :password_confirmation => '#{ENV['BEAR_USER_PASSWORD']}')
106
+ user.confirmed_at = user.confirmation_sent_at
107
+ user.save!
108
+ FILE
109
+ end
110
+
111
+ # make cukes and websteps for devise
112
+ apply File.expand_path("../devise/cucumber.rb", __FILE__)