jackdempsey-beet 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/beet.gemspec +4 -3
- data/lib/beet/executor.rb +12 -7
- data/lib/beet/logger.rb +44 -0
- data/lib/beet/templates/rails/authlogic.rb +286 -5
- data/lib/beet/templates/rails/db/mysql.rb +43 -0
- data/lib/beet.rb +0 -1
- metadata +4 -3
- data/lib/beet/logging.rb +0 -14
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/beet.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{beet}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Jack Dempsey"]
|
9
|
-
s.date = %q{2009-05-
|
9
|
+
s.date = %q{2009-05-21}
|
10
10
|
s.default_executable = %q{beet}
|
11
11
|
s.email = %q{jack.dempsey@gmail.com}
|
12
12
|
s.executables = ["beet"]
|
@@ -28,13 +28,14 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/beet/executor.rb",
|
29
29
|
"lib/beet/file_system.rb",
|
30
30
|
"lib/beet/interaction.rb",
|
31
|
-
"lib/beet/
|
31
|
+
"lib/beet/logger.rb",
|
32
32
|
"lib/beet/rails.rb",
|
33
33
|
"lib/beet/scm.rb",
|
34
34
|
"lib/beet/scm/git.rb",
|
35
35
|
"lib/beet/scm/svn.rb",
|
36
36
|
"lib/beet/templates/rails/authlogic.rb",
|
37
37
|
"lib/beet/templates/rails/clean_files.rb",
|
38
|
+
"lib/beet/templates/rails/db/mysql.rb",
|
38
39
|
"lib/beet/templates/rails/git.rb",
|
39
40
|
"lib/beet/templates/rails/jquery.rb",
|
40
41
|
"spec/beet_spec.rb",
|
data/lib/beet/executor.rb
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
require 'open-uri'
|
2
|
+
require 'beet/logger'
|
2
3
|
module Beet
|
3
4
|
class Executor
|
4
5
|
include Beet::Execution
|
5
6
|
include Beet::FileSystem
|
6
7
|
include Beet::Interaction
|
7
|
-
include Beet::Logging
|
8
8
|
|
9
9
|
# TODO create a better way to mixin things from rails/whatever as needed
|
10
10
|
include Beet::Rails
|
11
11
|
include Beet::Capistrano
|
12
12
|
include Beet::SCM
|
13
13
|
|
14
|
-
attr_reader :root
|
15
|
-
|
16
|
-
attr_accessor :templates, :app_name
|
14
|
+
attr_reader :root, :logger
|
15
|
+
attr_accessor :templates, :project_name
|
17
16
|
|
18
|
-
def initialize(templates,
|
19
|
-
@root = File.expand_path(File.join(Dir.pwd,
|
17
|
+
def initialize(templates, project_name) # :nodoc:
|
18
|
+
@root = File.expand_path(File.join(Dir.pwd, project_name))
|
19
|
+
@project_name = project_name
|
20
|
+
@logger = Beet::Logger.new
|
20
21
|
@templates = []
|
21
22
|
templates.split(/[\s,]+/).each do |template|
|
22
23
|
if file = template_location(template)
|
@@ -36,13 +37,17 @@ module Beet
|
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
40
|
+
def log(*args)
|
41
|
+
logger.log(*args)
|
42
|
+
end
|
43
|
+
|
39
44
|
private
|
40
45
|
|
41
46
|
def template_location(template)
|
42
47
|
return template if File.exists?(template) or template.include?('http://')
|
43
48
|
locations = []
|
44
|
-
locations << File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
45
49
|
locations << File.expand_path(ENV['BEET_TEMPLATES_DIR']) if ENV['BEET_TEMPLATES_DIR']
|
50
|
+
locations << File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
46
51
|
locations.each do |location|
|
47
52
|
filename = File.join(location, "#{template}.rb")
|
48
53
|
return filename if File.exists?(filename)
|
data/lib/beet/logger.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Beet
|
2
|
+
class Logger # :nodoc:
|
3
|
+
attr_reader :out
|
4
|
+
attr_accessor :quiet
|
5
|
+
|
6
|
+
def initialize(out = $stdout)
|
7
|
+
@out = out
|
8
|
+
@quiet = false
|
9
|
+
@level = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def log(status, message, &block)
|
13
|
+
@out.print("%12s %s%s\n" % [status, ' ' * @level, message]) unless quiet
|
14
|
+
indent(&block) if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def indent(&block)
|
18
|
+
@level += 1
|
19
|
+
if block_given?
|
20
|
+
begin
|
21
|
+
block.call
|
22
|
+
ensure
|
23
|
+
outdent
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def outdent
|
29
|
+
@level -= 1
|
30
|
+
if block_given?
|
31
|
+
begin
|
32
|
+
block.call
|
33
|
+
ensure
|
34
|
+
indent
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def method_missing(method, *args, &block)
|
41
|
+
log(method.to_s, args.first, &block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,8 +1,289 @@
|
|
1
|
-
# app/models/user_session.rb
|
2
1
|
file "app/models/user_session.rb" do
|
3
|
-
%
|
4
|
-
|
5
|
-
|
2
|
+
%{
|
3
|
+
class UserSession < Authlogic::Session::Base
|
4
|
+
logout_on_timeout true # default is false
|
5
|
+
end
|
6
|
+
}
|
7
|
+
end
|
8
|
+
|
9
|
+
file "app/models/user.rb" do
|
10
|
+
%{
|
11
|
+
class User < ActiveRecord::Base
|
12
|
+
acts_as_authentic do |c|
|
13
|
+
c.logged_in_timeout = 10.minutes # default is 10.minutes
|
14
|
+
end
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
file "app/controllers/user_sessions_controller.rb" do
|
20
|
+
%{
|
21
|
+
class UserSessionsController < ApplicationController
|
22
|
+
before_filter :require_no_user, :only => [:new, :create]
|
23
|
+
before_filter :require_user, :only => :destroy
|
24
|
+
|
25
|
+
def new
|
26
|
+
@user_session = UserSession.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
@user_session = UserSession.new(params[:user_session])
|
31
|
+
if @user_session.save
|
32
|
+
flash[:notice] = "Login successful!"
|
33
|
+
redirect_back_or_default account_url
|
34
|
+
else
|
35
|
+
render :action => :new
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy
|
40
|
+
current_user_session.destroy
|
41
|
+
flash[:notice] = "Logout successful!"
|
42
|
+
redirect_back_or_default new_user_session_url
|
43
|
+
end
|
44
|
+
end
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
file "app/views/user_sessions/new.html.erb" do
|
50
|
+
%{
|
51
|
+
<h1>Login</h1>
|
52
|
+
|
53
|
+
<% form_for @user_session, :url => user_session_path do |f| %>
|
54
|
+
<%= f.error_messages %>
|
55
|
+
<%= f.label :email %><br />
|
56
|
+
<%= f.text_field :email %><br />
|
57
|
+
<br />
|
58
|
+
<%= f.label :password %><br />
|
59
|
+
<%= f.password_field :password %><br />
|
60
|
+
<br />
|
61
|
+
<%= f.check_box :remember_me %><%= f.label :remember_me %><br />
|
62
|
+
<br />
|
63
|
+
<%= f.submit "Login" %>
|
64
|
+
<% end %>
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
# Setup some routes
|
69
|
+
route 'map.resource :user_session'
|
70
|
+
route 'map.resource :account, :controller => "users"'
|
71
|
+
route 'map.resources :users'
|
72
|
+
route 'map.register "/register", :controller => "users", :action => "new"'
|
73
|
+
route 'map.login "/login", :controller => "user_sessions", :action => "new"'
|
74
|
+
route 'map.logout "/logout", :controller => "user_sessions", :action => "destroy"'
|
75
|
+
|
76
|
+
file "app/controllers/application_controller.rb" do
|
77
|
+
%{
|
78
|
+
# Filters added to this controller apply to all controllers in the application.
|
79
|
+
# Likewise, all the methods added will be available for all controllers.
|
80
|
+
|
81
|
+
class ApplicationController < ActionController::Base
|
82
|
+
helper :all
|
83
|
+
helper_method :current_user_session, :current_user
|
84
|
+
filter_parameter_logging :password, :password_confirmation
|
85
|
+
|
86
|
+
private
|
87
|
+
def current_user_session
|
88
|
+
return @current_user_session if defined?(@current_user_session)
|
89
|
+
@current_user_session = UserSession.find
|
90
|
+
end
|
91
|
+
|
92
|
+
def current_user
|
93
|
+
return @current_user if defined?(@current_user)
|
94
|
+
@current_user = current_user_session && current_user_session.record
|
95
|
+
end
|
96
|
+
|
97
|
+
def require_user
|
98
|
+
unless current_user
|
99
|
+
store_location
|
100
|
+
flash[:notice] = "You must be logged in to access this page"
|
101
|
+
redirect_to new_user_session_url
|
102
|
+
return false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def require_no_user
|
107
|
+
if current_user
|
108
|
+
store_location
|
109
|
+
flash[:notice] = "You must be logged out to access this page"
|
110
|
+
redirect_to account_url
|
111
|
+
return false
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def store_location
|
116
|
+
session[:return_to] = request.request_uri
|
117
|
+
end
|
118
|
+
|
119
|
+
def redirect_back_or_default(default)
|
120
|
+
redirect_to(session[:return_to] || default)
|
121
|
+
session[:return_to] = nil
|
6
122
|
end
|
7
|
-
}
|
8
123
|
end
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
file "app/controllers/users_controller.rb" do
|
128
|
+
%{
|
129
|
+
class UsersController < ApplicationController
|
130
|
+
before_filter :require_no_user, :only => [:new, :create]
|
131
|
+
before_filter :require_user, :only => [:show, :edit, :update]
|
132
|
+
|
133
|
+
def new
|
134
|
+
@user = User.new
|
135
|
+
end
|
136
|
+
|
137
|
+
def create
|
138
|
+
@user = User.new(params[:user])
|
139
|
+
if @user.save
|
140
|
+
flash[:notice] = "Account registered!"
|
141
|
+
redirect_back_or_default account_url
|
142
|
+
else
|
143
|
+
render :action => :new
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def show
|
148
|
+
@user = @current_user
|
149
|
+
end
|
150
|
+
|
151
|
+
def edit
|
152
|
+
@user = @current_user
|
153
|
+
end
|
154
|
+
|
155
|
+
def update
|
156
|
+
@user = @current_user # makes our views "cleaner" and more consistent
|
157
|
+
if @user.update_attributes(params[:user])
|
158
|
+
flash[:notice] = "Account updated!"
|
159
|
+
redirect_to account_url
|
160
|
+
else
|
161
|
+
render :action => :edit
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
file "app/views/users/_form.html.erb" do
|
169
|
+
%{
|
170
|
+
<%= form.label :email %><br />
|
171
|
+
<%= form.text_field :email %><br />
|
172
|
+
<br />
|
173
|
+
<%= form.label :password, form.object.new_record? ? nil : "Change password" %><br />
|
174
|
+
<%= form.password_field :password %><br />
|
175
|
+
<br />
|
176
|
+
<%= form.label :password_confirmation %><br />
|
177
|
+
<%= form.password_field :password_confirmation %><br />
|
178
|
+
}
|
179
|
+
end
|
180
|
+
|
181
|
+
file "app/views/users/edit.html.erb" do
|
182
|
+
%{
|
183
|
+
<h1>Edit My Account</h1>
|
184
|
+
|
185
|
+
<% form_for @user, :url => account_path do |f| %>
|
186
|
+
<%= f.error_messages %>
|
187
|
+
<%= render :partial => "form", :object => f %>
|
188
|
+
<%= f.submit "Update" %>
|
189
|
+
<% end %>
|
190
|
+
|
191
|
+
<br /><%= link_to "My Profile", account_path %>
|
192
|
+
}
|
193
|
+
end
|
194
|
+
|
195
|
+
file "app/views/users/new.html.erb" do
|
196
|
+
%{
|
197
|
+
<h1>Register</h1>
|
198
|
+
|
199
|
+
<% form_for @user, :url => account_path do |f| %>
|
200
|
+
<%= f.error_messages %>
|
201
|
+
<%= render :partial => "form", :object => f %>
|
202
|
+
<%= f.submit "Register" %>
|
203
|
+
<% end %>
|
204
|
+
}
|
205
|
+
end
|
206
|
+
|
207
|
+
file "app/views/users/show.html.erb" do
|
208
|
+
%{
|
209
|
+
<p>
|
210
|
+
<b>Email:</b>
|
211
|
+
<%=h @user.email %>
|
212
|
+
</p>
|
213
|
+
|
214
|
+
<p>
|
215
|
+
<b>Login count:</b>
|
216
|
+
<%=h @user.login_count %>
|
217
|
+
</p>
|
218
|
+
|
219
|
+
<p>
|
220
|
+
<b>Last request at:</b>
|
221
|
+
<%=h @user.last_request_at %>
|
222
|
+
</p>
|
223
|
+
|
224
|
+
<p>
|
225
|
+
<b>Last login at:</b>
|
226
|
+
<%=h @user.last_login_at %>
|
227
|
+
</p>
|
228
|
+
|
229
|
+
<p>
|
230
|
+
<b>Current login at:</b>
|
231
|
+
<%=h @user.current_login_at %>
|
232
|
+
</p>
|
233
|
+
|
234
|
+
<p>
|
235
|
+
<b>Last login ip:</b>
|
236
|
+
<%=h @user.last_login_ip %>
|
237
|
+
</p>
|
238
|
+
|
239
|
+
<p>
|
240
|
+
<b>Current login ip:</b>
|
241
|
+
<%=h @user.current_login_ip %>
|
242
|
+
</p>
|
243
|
+
|
244
|
+
|
245
|
+
<%= link_to 'Edit', edit_account_path %>
|
246
|
+
}
|
247
|
+
end
|
248
|
+
|
249
|
+
# can't rely on internal rails migration generation, so we do it this way
|
250
|
+
run "script/generate migration beet_authlogic_create_user"
|
251
|
+
|
252
|
+
#now open it
|
253
|
+
file(Dir.glob('db/migrate/*beet_authlogic_create_user*').first) do
|
254
|
+
%{
|
255
|
+
class BeetAuthlogicCreateUser < ActiveRecord::Migration
|
256
|
+
def self.up
|
257
|
+
unless table_exists?(:users)
|
258
|
+
create_table :users do |t|
|
259
|
+
t.string :email, :null => false # optional, you can use login instead, or both
|
260
|
+
t.string :crypted_password, :null => false # optional, see below
|
261
|
+
t.string :password_salt, :null => false # optional, but highly recommended
|
262
|
+
t.string :persistence_token, :null => false # required
|
263
|
+
t.string :single_access_token, :null => false # optional, see Authlogic::Session::Params
|
264
|
+
t.string :perishable_token, :null => false # optional, see Authlogic::Session::Perishability
|
265
|
+
|
266
|
+
# Magic columns, just like ActiveRecord's created_at and updated_at. These are automatically maintained by Authlogic if they are present.
|
267
|
+
t.integer :login_count, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
|
268
|
+
t.integer :failed_login_count, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
|
269
|
+
t.datetime :last_request_at # optional, see Authlogic::Session::MagicColumns
|
270
|
+
t.datetime :current_login_at # optional, see Authlogic::Session::MagicColumns
|
271
|
+
t.datetime :last_login_at # optional, see Authlogic::Session::MagicColumns
|
272
|
+
t.string :current_login_ip # optional, see Authlogic::Session::MagicColumns
|
273
|
+
t.string :last_login_ip # optional, see Authlogic::Session::MagicColumns
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def self.down
|
279
|
+
drop_table :users
|
280
|
+
end
|
281
|
+
end
|
282
|
+
}
|
283
|
+
end
|
284
|
+
|
285
|
+
gem 'authlogic'
|
286
|
+
|
287
|
+
rake "gems:install", :sudo => true
|
288
|
+
rake "db:create:all"
|
289
|
+
rake "db:migrate"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
file 'config/database.yml' do
|
2
|
+
%{
|
3
|
+
# MySQL. Versions 4.1 and 5.0 are recommended.
|
4
|
+
#
|
5
|
+
# Install the MySQL driver:
|
6
|
+
# gem install mysql
|
7
|
+
# On Mac OS X:
|
8
|
+
# sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
|
9
|
+
# On Mac OS X Leopard:
|
10
|
+
# sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
11
|
+
# This sets the ARCHFLAGS environment variable to your native architecture
|
12
|
+
# On Windows:
|
13
|
+
# gem install mysql
|
14
|
+
# Choose the win32 build.
|
15
|
+
# Install MySQL and put its /bin directory on your path.
|
16
|
+
#
|
17
|
+
# And be sure to use new-style password hashing:
|
18
|
+
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
|
19
|
+
---
|
20
|
+
development: &defaults
|
21
|
+
adapter: mysql
|
22
|
+
encoding: utf8
|
23
|
+
reconnect: false
|
24
|
+
database: #{project_name}_development
|
25
|
+
pool: 5
|
26
|
+
username: root
|
27
|
+
password:
|
28
|
+
socket: /tmp/mysql.sock
|
29
|
+
|
30
|
+
# Warning: The database defined as "test" will be erased and
|
31
|
+
# re-generated from your development database when you run "rake".
|
32
|
+
# Do not set this db to the same as development or production.
|
33
|
+
test:
|
34
|
+
<<: *defaults
|
35
|
+
database: #{project_name}_test
|
36
|
+
|
37
|
+
production:
|
38
|
+
<<: *defaults
|
39
|
+
database: #{project_name}_production
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
FileUtils.copy "config/database.yml", "config/database.yml.example"
|
data/lib/beet.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jackdempsey-beet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Dempsey
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-21 00:00:00 -07:00
|
13
13
|
default_executable: beet
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -36,13 +36,14 @@ files:
|
|
36
36
|
- lib/beet/executor.rb
|
37
37
|
- lib/beet/file_system.rb
|
38
38
|
- lib/beet/interaction.rb
|
39
|
-
- lib/beet/
|
39
|
+
- lib/beet/logger.rb
|
40
40
|
- lib/beet/rails.rb
|
41
41
|
- lib/beet/scm.rb
|
42
42
|
- lib/beet/scm/git.rb
|
43
43
|
- lib/beet/scm/svn.rb
|
44
44
|
- lib/beet/templates/rails/authlogic.rb
|
45
45
|
- lib/beet/templates/rails/clean_files.rb
|
46
|
+
- lib/beet/templates/rails/db/mysql.rb
|
46
47
|
- lib/beet/templates/rails/git.rb
|
47
48
|
- lib/beet/templates/rails/jquery.rb
|
48
49
|
- spec/beet_spec.rb
|