public
Description: my random ruby scripts
Homepage:
Clone URL: git://github.com/kastner/ruby-junk.git
Click here to lend your support to: ruby-junk and make a donation at www.pledgie.com !
ruby-junk / template.rb
100644 145 lines (120 sloc) 4.081 kb
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
144
145
PROJECT = root.split("/")[-1]
 
gem 'mislav-will_paginate', :lib => 'will_paginate', :source => 'http://gems.github.com'
gem 'ambethia-smtp-tls', :lib => 'smtp-tls', :source => "http://gems.github.com"
gem 'sqlite3-ruby', :lib => 'sqlite3'
 
rake "gems:install", :sudo => true
 
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
run "rm -f public/javascripts/*"
 
file 'README.md', <<README
#{PROJECT.humanize}
#{"-" * PROJECT.size}
 
README
 
file '.gitignore', <<IGNORE
.DS_Store
log/*.log
tmp/**/*
config/database.yml
config/initializers/action_mailer_configs.rb
db/*.sqlite3
IGNORE
 
capify!
 
file 'config/deploy.rb' do
  host = ask "\nServer to deploy to?"
  <<-END
default_run_options[:pty] = true
set :use_sudo, false
set :ssh_options, { :forward_agent => true }
set :domain, "#{host}"
set :application, "#{PROJECT}"
set :repository, "git@github.com:#{`whoami`.chomp}/#{PROJECT}.git"
set :deploy_to, "/var/www/#{PROJECT}"
set :scm, :git
set :git_enable_submodules, 1
set :deploy_via, :remote_cache
set :git_shallow_clone, 1
set :group, "www-data"
role :app, domain
role :web, domain
role :db, domain, :primary => true
namespace :deploy do
%w|start restart|.each do |t|
task t do
run "touch #{"#"}{current_path}/tmp/restart.txt"
end
end
end
desc "Link production files"
task :after_symlink do
run "ln -nfs #{"#"}{shared_path}/system/database.yml #{"#"}{release_path}/config/database.yml"
run "ln -nfs #{"#"}{shared_path}/system/action_mailer_configs.rb #{"#"}{release_path}/config/initializers/action_mailer_configs.rb"
end
task :after_setup do
put File.read('config/database.yml'), "#{"#"}{shared_path}/system/database.yml"
put File.read('config/initializers/action_mailer_configs.rb'), "#{"#"}{shared_path}/system/action_mailer_configs.rb"
end
END
end
 
file 'app/helpers/application_helper.rb',
%q{module ApplicationHelper
def body_id
"#{controller.controller_name}"
end
end
}
 
file 'app/views/layouts/_flashes.html.erb',
%q{<div id="flash">
<% flash.each do |key, value| -%>
<div id="flash_<%= key %>"><%=h value %></div>
<% end -%>
</div>
}
 
file 'app/views/layouts/application.html.erb', <<LAYOUT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title><%= "#{"#"}{@title} | " if @title %>#{PROJECT.humanize}</title>
<meta name="description" content=""/>
<link rel="shortcut icon" href="/favicon.ico"/>
<%= stylesheet_link_tag "reset", :media => 'all', :cache => 'true' %>
<%= stylesheet_link_tag "style", :media => 'all', :cache => 'true' %>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
jQuery.ajaxSetup({
data: { authenticity_token: '<%= form_authenticity_token %>' }
});
</script>
</head>
<body id="<%= body_id %>">
<div id="page">
<%= render :partial => 'layouts/flashes' -%>
<%= yield %>
</div> <!-- #page -->
</body>
</html>
LAYOUT
 
initializer 'action_mailer_configs.rb', <<MAILER
require 'smtp-tls'
 
ActionMailer::Base.server_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "#{PROJECT}.com",
:authentication => :plain,
:user_name => "USER",
:password => "PASS"
}
MAILER
 
run "cp config/database.yml config/database.yml.example"
run "cp config/initializers/action_mailer_configs.rb config/initializers/action_mailer_configs.rb.example"
 
git :init
git :add => '.'
git :commit => "-a -m 'Initial Commit'"
 
puts "-" * 79
puts "Edit config/initializers/action_mailer_configs.rb with your gmail user/pass"
puts "-" * 79