whtt-eric-beet 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +12 -0
- data/Gemfile.lock +25 -0
- data/LICENSE +20 -0
- data/README.rdoc +13 -0
- data/Rakefile +59 -0
- data/TODO +25 -0
- data/VERSION +1 -0
- data/bin/beet +114 -0
- data/features/generating.feature +24 -0
- data/features/step_definitions/beet_steps.rb +7 -0
- data/features/step_definitions/common_steps.rb +172 -0
- data/features/support/common.rb +33 -0
- data/features/support/env.rb +25 -0
- data/lib/beet.rb +13 -0
- data/lib/beet/capistrano.rb +14 -0
- data/lib/beet/command_execution.rb +56 -0
- data/lib/beet/executor.rb +236 -0
- data/lib/beet/file_system.rb +163 -0
- data/lib/beet/files/swfupload/images/cancelbutton.gif +0 -0
- data/lib/beet/files/swfupload/images/header-bg.jpg +0 -0
- data/lib/beet/files/swfupload/images/logo.gif +0 -0
- data/lib/beet/files/swfupload/js/handlers.js +290 -0
- data/lib/beet/gem_location_map.rb +65 -0
- data/lib/beet/interaction.rb +47 -0
- data/lib/beet/logger.rb +44 -0
- data/lib/beet/rails.rb +175 -0
- data/lib/beet/recipes/passenger/vhost.rb +17 -0
- data/lib/beet/recipes/rack/middleware.rb +17 -0
- data/lib/beet/recipes/rails/auth/authlogic.rb +302 -0
- data/lib/beet/recipes/rails/auth/clearance.rb +22 -0
- data/lib/beet/recipes/rails/auth/devise.rb +22 -0
- data/lib/beet/recipes/rails/clean_files.rb +4 -0
- data/lib/beet/recipes/rails/cms/bcms_blog.rb +21 -0
- data/lib/beet/recipes/rails/cms/bcms_event.rb +24 -0
- data/lib/beet/recipes/rails/css/blueprint.rb +5 -0
- data/lib/beet/recipes/rails/css/compass.rb +35 -0
- data/lib/beet/recipes/rails/css/nifty_layout.rb +5 -0
- data/lib/beet/recipes/rails/css/reset.rb +10 -0
- data/lib/beet/recipes/rails/db/mongo.rb +57 -0
- data/lib/beet/recipes/rails/db/mysql.rb +47 -0
- data/lib/beet/recipes/rails/db/postgres.rb +52 -0
- data/lib/beet/recipes/rails/git.rb +23 -0
- data/lib/beet/recipes/rails/jquery.rb +11 -0
- data/lib/beet/recipes/rails/swfupload.rb +305 -0
- data/lib/beet/recipes/rails/testing/rspec.rb +3 -0
- data/lib/beet/recipes/rails/testing/shoulda.rb +1 -0
- data/lib/beet/recipes/rails3/admin_interface/active_scaffold.rb +10 -0
- data/lib/beet/recipes/rails3/admin_interface/rails_admin.rb +9 -0
- data/lib/beet/recipes/rails3/auth/devise.rb +17 -0
- data/lib/beet/recipes/rails3/clean_files.rb +3 -0
- data/lib/beet/recipes/rails3/css/boilerplate.rb +41 -0
- data/lib/beet/recipes/rails3/css/reset.rb +10 -0
- data/lib/beet/recipes/rails3/css/sass.rb +3 -0
- data/lib/beet/recipes/rails3/db/mysql.rb +35 -0
- data/lib/beet/recipes/rails3/file_uploads/paperclip.rb +29 -0
- data/lib/beet/recipes/rails3/git.rb +16 -0
- data/lib/beet/recipes/rails3/jammit.rb +26 -0
- data/lib/beet/recipes/rails3/js/jquery.rb +12 -0
- data/lib/beet/recipes/rails3/markup/haml.rb +3 -0
- data/lib/beet/recipes/rails3/testing/cucumber.rb +19 -0
- data/lib/beet/recipes/rails3/testing/rspec.rb +40 -0
- data/lib/beet/recipes/standalone/hades.rb +61 -0
- data/lib/beet/recipes/system/rvmrc.rb +15 -0
- data/lib/beet/scm.rb +36 -0
- data/lib/beet/scm/git.rb +15 -0
- data/lib/beet/scm/svn.rb +5 -0
- data/lib/beet/template_location_map.rb +15 -0
- data/test/executor_test.rb +24 -0
- data/test/file_system_test.rb +59 -0
- data/test/test_helper.rb +12 -0
- data/whtt-eric-beet.gemspec +120 -0
- metadata +203 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
gem 'thoughtbot-clearance', :lib => 'clearance',:source => 'http://gems.github.com', :version => '~> 0.6'
|
2
|
+
gem 'webrat'
|
3
|
+
gem 'cucumber'
|
4
|
+
gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source => "http://gems.github.com"
|
5
|
+
|
6
|
+
|
7
|
+
rake "gems:install", :sudo => true
|
8
|
+
rake "gems:unpack"
|
9
|
+
rake "db:create:all"
|
10
|
+
|
11
|
+
generate "clearance"
|
12
|
+
generate "cucumber"
|
13
|
+
generate "clearance_features"
|
14
|
+
rake "db:migrate"
|
15
|
+
|
16
|
+
environment "HOST = 'localhost'", :env => "development"
|
17
|
+
environment "HOST = 'localhost'", :env => "test"
|
18
|
+
environment "DO_NOT_REPLY = \"donotreply@example.com\""
|
19
|
+
route "map.root :controller => 'sessions', :action => 'new'"
|
20
|
+
|
21
|
+
run "cp -fr vendor/gems/thoughtbot-clearance*/app/views app/"
|
22
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# this is designed for rails 3
|
2
|
+
gem 'warden', :version => '0.9.3'
|
3
|
+
gem 'devise', :version => '1.0.2'
|
4
|
+
|
5
|
+
rake 'gems:install'
|
6
|
+
generate "devise_install"
|
7
|
+
generate "devise User"
|
8
|
+
generate "devise_views"
|
9
|
+
|
10
|
+
add_after 'config/routes.rb', '# root :to => "welcome#index"', "\n root :controller => 'home'\n"
|
11
|
+
|
12
|
+
rake "db:migrate"
|
13
|
+
|
14
|
+
file 'app/controllers/home_controller.rb' do
|
15
|
+
%{class HomeController < ApplicationController
|
16
|
+
def index
|
17
|
+
render :text => "Welcome from your HomeController!"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# install the gem
|
2
|
+
if `gem list bcms_blog | grep bcms_blog`.empty?
|
3
|
+
# Run this inside or outside your bcms_blog directory, otherwise download the code
|
4
|
+
git "clone git://github.com/browsermedia/bcms_blog.git" unless File.exists?('./bcms_blog') || File.basename(Dir.pwd) == 'bcms_blog'
|
5
|
+
FileUtils.chdir 'bcms_blog' do
|
6
|
+
system "gem build *.gemspec"
|
7
|
+
sudo "gem install bcms_blog*.gem"
|
8
|
+
end
|
9
|
+
if yes? "Should I delete bcms_blog/"
|
10
|
+
FileUtils.rm_rf('bcms_blog')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# add to project
|
15
|
+
add_after 'config/environment.rb', "config.gem 'browsercms'" do
|
16
|
+
"\tconfig.gem 'bcms_blog'"
|
17
|
+
end
|
18
|
+
|
19
|
+
add_before 'config/routes.rb', 'map.routes_for_browser_cms' do
|
20
|
+
"\tmap.routes_for_bcms_blog"
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# install the gem
|
2
|
+
if `gem list bcms_event | grep bcms_event`.empty?
|
3
|
+
# Run this inside or outside your bcms_event directory, otherwise download the code
|
4
|
+
git "clone git://github.com/browsermedia/bcms_event.git" unless File.exists?('./bcms_event') || File.basename(Dir.pwd) == 'bcms_event'
|
5
|
+
FileUtils.chdir 'bcms_event' do
|
6
|
+
system "gem build *.gemspec"
|
7
|
+
sudo "gem install bcms_event*.gem"
|
8
|
+
end
|
9
|
+
if yes? "Should I delete bcms_event/"
|
10
|
+
FileUtils.rm_rf('bcms_event')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# add to project
|
15
|
+
add_after 'config/environment.rb', "config.gem 'browsercms'" do
|
16
|
+
"\tconfig.gem 'bcms_event'"
|
17
|
+
end
|
18
|
+
|
19
|
+
add_before 'config/routes.rb', 'map.routes_for_browser_cms' do
|
20
|
+
"\tmap.routes_for_bcms_event\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
generate "browser_cms"
|
24
|
+
rake "db:migrate"
|
@@ -0,0 +1,5 @@
|
|
1
|
+
FileUtils.mkdir_p("public/stylesheets/blueprint")
|
2
|
+
%w(forms.css grid.css grid.png ie.css print.css reset.css typography.css).each do |file|
|
3
|
+
run "curl -L http://github.com/joshuaclayton/blueprint-css/blob/master/blueprint/src/#{file} \
|
4
|
+
> public/stylesheets/blueprint/#{file}"
|
5
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
framework = ask "What framework would you like to use (default: blueprint)?"
|
2
|
+
framework = 'blueprint' if framework.blank?
|
3
|
+
|
4
|
+
in_root do
|
5
|
+
if yes? "Install haml in vendor/plugins (hit 'n' if you use it as a gem)?"
|
6
|
+
run 'haml --rails .'
|
7
|
+
end
|
8
|
+
run "compass --rails -f #{framework} ."
|
9
|
+
end
|
10
|
+
|
11
|
+
layout_file = <<-FILE
|
12
|
+
!!! XML
|
13
|
+
!!!
|
14
|
+
%html{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en", :lang => "en"}
|
15
|
+
%head
|
16
|
+
%meta{'http-equiv' => "content-type", :content => "text/html;charset=UTF-8"}
|
17
|
+
%title= @browser_title || 'Default Browser Title'
|
18
|
+
= stylesheet_link_tag 'compiled/screen.css', :media => 'screen, projection'
|
19
|
+
= stylesheet_link_tag 'compiled/print.css', :media => 'print'
|
20
|
+
/[if IE]
|
21
|
+
= stylesheet_link_tag 'compiled/ie.css', :media => 'screen, projection'
|
22
|
+
= stylesheet_link_tag 'scaffold'
|
23
|
+
%body
|
24
|
+
#container
|
25
|
+
%h1 Welcome to Compass
|
26
|
+
= yield
|
27
|
+
FILE
|
28
|
+
|
29
|
+
gem 'compass'
|
30
|
+
|
31
|
+
unless File.exists?('app/views/layouts/application.html.haml')
|
32
|
+
file 'app/views/layouts/application.html.haml', layout_file
|
33
|
+
puts "We've added a simple layout for you as well which includes the css. Enjoy!"
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
reset_file_location = "http://developer.yahoo.com/yui/build/reset/reset.css"
|
2
|
+
unless File.exists?('public/stylesheets/reset.css')
|
3
|
+
begin
|
4
|
+
file "public/stylesheets/reset.css" do
|
5
|
+
open(reset_file_location).read
|
6
|
+
end
|
7
|
+
rescue
|
8
|
+
"Couldn't load #{reset_file_location}"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# based on jnunemaker's gist at http://gist.github.com/232953
|
2
|
+
file 'config/database.yml' do
|
3
|
+
%{
|
4
|
+
development: &global_settings
|
5
|
+
database: #{project_name}_development
|
6
|
+
host: 127.0.0.1
|
7
|
+
port: 27017
|
8
|
+
|
9
|
+
test:
|
10
|
+
database: #{project_name}_test
|
11
|
+
<<: *global_settings
|
12
|
+
|
13
|
+
production:
|
14
|
+
host: hostname
|
15
|
+
database: databasename
|
16
|
+
username: username
|
17
|
+
password: password
|
18
|
+
<<: *global_settings
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
file 'config/initializers/mongo.rb' do
|
23
|
+
%{
|
24
|
+
config = YAML.load_file(Rails.root + 'config' + 'database.yml')[Rails.env]
|
25
|
+
|
26
|
+
MongoMapper.connection = Mongo::Connection.new(config['host'], config['port'], {
|
27
|
+
:logger => Rails.logger
|
28
|
+
})
|
29
|
+
|
30
|
+
MongoMapper.database = config['database']
|
31
|
+
if config['username'].present?
|
32
|
+
MongoMapper.database.authenticate(config['username'], config['password'])
|
33
|
+
end
|
34
|
+
|
35
|
+
Dir[Rails.root + 'app/models/**/*.rb'].each do |model_path|
|
36
|
+
File.basename(model_path, '.rb').classify.constantize
|
37
|
+
end
|
38
|
+
MongoMapper.ensure_indexes!
|
39
|
+
|
40
|
+
if defined?(PhusionPassenger)
|
41
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
42
|
+
# if using older than 0.6.5 of MM then you want database instead of connection
|
43
|
+
# MongoMapper.database.connect_to_master if forked
|
44
|
+
MongoMapper.connection.connect_to_master if forked
|
45
|
+
end
|
46
|
+
end
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
# for those who don't like keeping database.yml in version control
|
51
|
+
# we slot in an example file to serve as reference
|
52
|
+
|
53
|
+
FileUtils.copy "config/database.yml", "config/database.yml.example"
|
54
|
+
|
55
|
+
environment 'config.frameworks -= [:active_record]'
|
56
|
+
|
57
|
+
gem 'mongo_mapper'
|
@@ -0,0 +1,47 @@
|
|
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
|
+
|
29
|
+
# Warning: The database defined as "test" will be erased and
|
30
|
+
# re-generated from your development database when you run "rake".
|
31
|
+
# Do not set this db to the same as development or production.
|
32
|
+
test:
|
33
|
+
<<: *defaults
|
34
|
+
database: #{project_name}_test
|
35
|
+
|
36
|
+
production:
|
37
|
+
<<: *defaults
|
38
|
+
database: #{project_name}_production
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
FileUtils.copy "config/database.yml", "config/database.yml.example"
|
43
|
+
|
44
|
+
if yes?("Create databases using rake db:create:all?")
|
45
|
+
rake "db:create:all"
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
file 'config/database.yml' do
|
2
|
+
%{
|
3
|
+
# PostgreSQL. Versions 7.4 and 8.x are supported.
|
4
|
+
#
|
5
|
+
# Install the ruby-postgres driver:
|
6
|
+
# gem install pg
|
7
|
+
# On Mac OS X:
|
8
|
+
# gem install ruby-postgres -- --include=/usr/local/pgsql
|
9
|
+
# On Windows:
|
10
|
+
# gem install ruby-postgres
|
11
|
+
# Choose the win32 build.
|
12
|
+
# Install PostgreSQL and put its /bin directory on your path.
|
13
|
+
|
14
|
+
development: &defaults
|
15
|
+
adapter: postgresql
|
16
|
+
encoding: unicode
|
17
|
+
database: #{project_name}_development
|
18
|
+
pool: 5
|
19
|
+
username: root
|
20
|
+
password:
|
21
|
+
|
22
|
+
# Connect on a TCP socket. Omitted by default since the client uses a
|
23
|
+
# domain socket that doesn't need configuration. Windows does not have
|
24
|
+
# domain sockets, so uncomment these lines.
|
25
|
+
#host: localhost
|
26
|
+
#port: 5432
|
27
|
+
|
28
|
+
# Schema search path. The server defaults to $user,public
|
29
|
+
#schema_search_path: myapp,sharedapp,public
|
30
|
+
|
31
|
+
# Minimum log levels, in increasing order:
|
32
|
+
# debug5, debug4, debug3, debug2, debug1,
|
33
|
+
# log, notice, warning, error, fatal, and panic
|
34
|
+
# The server defaults to notice.
|
35
|
+
#min_messages: warning
|
36
|
+
|
37
|
+
|
38
|
+
# Warning: The database defined as "test" will be erased and
|
39
|
+
# re-generated from your development database when you run "rake".
|
40
|
+
# Do not set this db to the same as development or production.
|
41
|
+
test:
|
42
|
+
<<: *defaults
|
43
|
+
database: #{project_name}_test
|
44
|
+
|
45
|
+
production:
|
46
|
+
<<: *defaults
|
47
|
+
database: #{project_name}_production
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
FileUtils.copy "config/database.yml", "config/database.yml.example"
|
52
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
["./tmp/pids", "./tmp/sessions", "./tmp/sockets", "./tmp/cache"].each do |f|
|
2
|
+
run("rmdir ./#{f}")
|
3
|
+
end
|
4
|
+
|
5
|
+
run("find . \\( -type d -empty \\) -and \\( -not -regex ./\\.git.* \\) -exec touch {}/.gitignore \\;")
|
6
|
+
|
7
|
+
git :init
|
8
|
+
|
9
|
+
file '.gitignore', <<-CODE
|
10
|
+
log/*.*
|
11
|
+
db/*.db
|
12
|
+
db/*.sqlite3
|
13
|
+
db/schema.rb
|
14
|
+
tmp/*
|
15
|
+
.DS_Store
|
16
|
+
doc/api
|
17
|
+
doc/app
|
18
|
+
config/database.yml
|
19
|
+
CODE
|
20
|
+
|
21
|
+
git :add => "."
|
22
|
+
|
23
|
+
git :commit => "-m 'Initial commit. Enjoy.'"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FileUtils.rm_r Dir.glob("public/javascripts/*.js")
|
2
|
+
|
3
|
+
run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js > public/javascripts/jquery.js"
|
4
|
+
run "curl -L http://jqueryjs.googlecode.com/svn/trunk/plugins/form/jquery.form.js > public/javascripts/jquery.form.js"
|
5
|
+
|
6
|
+
# Thanks to Chris Wanstrath and Doug Ramsay. The below will make it so that Rails recognizes form requests
|
7
|
+
file 'public/javascripts/application.js', <<-CODE
|
8
|
+
jQuery.ajaxSetup({
|
9
|
+
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
|
10
|
+
});
|
11
|
+
CODE
|
@@ -0,0 +1,305 @@
|
|
1
|
+
# lots of code and ideas borrowed from http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/
|
2
|
+
# setup directories to hold files
|
3
|
+
FileUtils.mkdir_p 'public/javascripts/swfupload'
|
4
|
+
FileUtils.mkdir_p 'public/flash/swfupload'
|
5
|
+
FileUtils.mkdir_p 'public/images/swfupload'
|
6
|
+
FileUtils.mkdir_p 'app/views/swfupload'
|
7
|
+
FileUtils.mkdir_p 'app/stylesheets'
|
8
|
+
|
9
|
+
# download plugin files
|
10
|
+
base_url = 'http://swfupload.googlecode.com/svn/swfupload/trunk/core/plugins'
|
11
|
+
|
12
|
+
js_files = %w(swfupload.cookies swfupload.queue swfupload.speed swfupload.swfobject handlers swfupload)
|
13
|
+
|
14
|
+
js_files.each do |js_file|
|
15
|
+
run "curl -L #{base_url}/#{js_file}.js > public/javascripts/swfupload/#{js_file}.js"
|
16
|
+
end
|
17
|
+
|
18
|
+
run "curl -L http://github.com/jackdempsey/beet/raw/master/lib/beet/files/swfupload/js/handlers.js > public/javascripts/swfupload/handlers.js"
|
19
|
+
run "curl -L http://swfupload.googlecode.com/svn/swfupload/trunk/core/swfupload.js > public/javascripts/swfupload/swfupload.js"
|
20
|
+
run "curl -L http://swfupload.googlecode.com/svn/swfupload/trunk/core/Flash/swfupload.swf > public/flash/swfupload/swfupload.swf"
|
21
|
+
run "chmod +x public/flash/swfupload/swfupload.swf"
|
22
|
+
run "curl -L http://github.com/jackdempsey/beet/raw/master/lib/beet/files/swfupload/images/cancelbutton.gif > public/images/swfupload/cancelbutton.gif"
|
23
|
+
|
24
|
+
file 'app/stylesheets/swfupload.sass', <<-FILE
|
25
|
+
divFileProgressContainer
|
26
|
+
height: 75px
|
27
|
+
|
28
|
+
#divFileProgress
|
29
|
+
|
30
|
+
.progressWrapper
|
31
|
+
width: 100%
|
32
|
+
overflow: hidden
|
33
|
+
|
34
|
+
.progressContainer
|
35
|
+
margin: 5px
|
36
|
+
padding: 4px
|
37
|
+
border: solid 1px #E8E8E8
|
38
|
+
background-color: #F7F7F7
|
39
|
+
overflow: hidden
|
40
|
+
|
41
|
+
.progressName
|
42
|
+
font-size: 8pt
|
43
|
+
font-weight: 700
|
44
|
+
color: #555
|
45
|
+
width: 100%
|
46
|
+
height: 14px
|
47
|
+
text-align: left
|
48
|
+
white-space: nowrap
|
49
|
+
overflow: hidden
|
50
|
+
|
51
|
+
.progressBarInProgress, .progressBarComplete, .progressBarError
|
52
|
+
font-size: 0
|
53
|
+
width: 0%
|
54
|
+
height: 2px
|
55
|
+
background-color: blue
|
56
|
+
margin-top: 2px
|
57
|
+
|
58
|
+
.progressBarComplete
|
59
|
+
width: 100%
|
60
|
+
background-color: green
|
61
|
+
visibility: hidden
|
62
|
+
|
63
|
+
.progressBarError
|
64
|
+
width: 100%
|
65
|
+
background-color: red
|
66
|
+
visibility: hidden
|
67
|
+
|
68
|
+
.progressBarStatus
|
69
|
+
margin-top: 2px
|
70
|
+
width: 337px
|
71
|
+
font-size: 7pt
|
72
|
+
font-family: Arial
|
73
|
+
text-align: left
|
74
|
+
white-space: nowrap
|
75
|
+
|
76
|
+
a.progressCancel
|
77
|
+
font-size: 0
|
78
|
+
display: block
|
79
|
+
height: 14px
|
80
|
+
width: 14px
|
81
|
+
background-image: url(/images/swfupload/cancelbutton.gif)
|
82
|
+
background-repeat: no-repeat
|
83
|
+
background-position: -14px 0px
|
84
|
+
float: right
|
85
|
+
|
86
|
+
a.progressCancel:hover
|
87
|
+
background-position: 0px 0px
|
88
|
+
FILE
|
89
|
+
|
90
|
+
# create upload partial
|
91
|
+
file 'app/views/swfupload/_upload.html.haml', %q{
|
92
|
+
- content_for :head do
|
93
|
+
= javascript_include_tag 'swfupload/swfupload', 'swfupload/swfupload.swfobject', 'swfupload/handlers'
|
94
|
+
= stylesheet_link_tag %w(compiled/swfupload)
|
95
|
+
- session_key_name = ActionController::Base.session_options[:key]
|
96
|
+
|
97
|
+
- upload_url = songs_path
|
98
|
+
- form_tag upload_url, :multipart => true do
|
99
|
+
#swfupload_degraded_container
|
100
|
+
%noscript= "You should have Javascript enabled for a nicer upload experience"
|
101
|
+
= file_field_tag :Filedata
|
102
|
+
= submit_tag "Add a File"
|
103
|
+
#swfupload_container{ :style => "display: none" }
|
104
|
+
%span#spanButtonPlaceholder
|
105
|
+
#divFileProgressContainer
|
106
|
+
|
107
|
+
|
108
|
+
:javascript
|
109
|
+
SWFUpload.onload = function() {
|
110
|
+
var swf_settings = {
|
111
|
+
|
112
|
+
// SWFObject settings
|
113
|
+
minimum_flash_version: "9.0.28",
|
114
|
+
swfupload_pre_load_handler: function() {
|
115
|
+
$('#swfupload_degraded_container').hide();
|
116
|
+
$('#swfupload_container').show();
|
117
|
+
},
|
118
|
+
swfupload_load_failed_handler: function() {
|
119
|
+
},
|
120
|
+
|
121
|
+
post_params: {
|
122
|
+
"#{session_key_name}": "#{cookies[session_key_name]}",
|
123
|
+
"authenticity_token": "#{form_authenticity_token}",
|
124
|
+
},
|
125
|
+
|
126
|
+
//upload_url: "#{upload_url}?#{session_key_name}="+encodeURIComponent("#{cookies[session_key_name]}")+"&authenticity_token="+encodeURIComponent("#{form_authenticity_token}"),
|
127
|
+
upload_url: "#{upload_url}",
|
128
|
+
flash_url: '/flash/swfupload/swfupload.swf',
|
129
|
+
|
130
|
+
//example below lets you scope to only allowing image uploads
|
131
|
+
//file_types: "*.jpg;*.jpeg;*.gif;*.png;",
|
132
|
+
file_types: "*",
|
133
|
+
file_types_description: "pictures",
|
134
|
+
file_size_limit: "20 MB",
|
135
|
+
|
136
|
+
button_placeholder_id: "spanButtonPlaceholder",
|
137
|
+
button_width: 380,
|
138
|
+
button_height: 32,
|
139
|
+
button_text : '<span class="button">Select Files <span class="buttonSmall">(10 MB Max)</span></span>',
|
140
|
+
button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 24pt; } .buttonSmall { font-size: 18pt; }',
|
141
|
+
button_text_top_padding: 0,
|
142
|
+
button_text_left_padding: 18,
|
143
|
+
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
|
144
|
+
button_cursor: SWFUpload.CURSOR.HAND,
|
145
|
+
file_queue_error_handler : fileQueueError,
|
146
|
+
file_dialog_complete_handler : fileDialogComplete,
|
147
|
+
upload_progress_handler : uploadProgress,
|
148
|
+
upload_error_handler : uploadError,
|
149
|
+
upload_success_handler : uploadSuccess,
|
150
|
+
upload_complete_handler : uploadComplete,
|
151
|
+
|
152
|
+
custom_settings : {
|
153
|
+
upload_target: "divFileProgressContainer"
|
154
|
+
}
|
155
|
+
}
|
156
|
+
var swf_upload = new SWFUpload(swf_settings);
|
157
|
+
};
|
158
|
+
}
|
159
|
+
|
160
|
+
append_file 'config/initializers/session_store.rb', <<-FILE
|
161
|
+
require 'rack/utils'
|
162
|
+
|
163
|
+
class FlashSessionCookieMiddleware
|
164
|
+
def initialize(app, session_key = '_session_id')
|
165
|
+
@app = app
|
166
|
+
@session_key = session_key
|
167
|
+
end
|
168
|
+
|
169
|
+
def call(env)
|
170
|
+
if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
|
171
|
+
params = ::Rack::Request.new(env).params
|
172
|
+
env['HTTP_COOKIE'] = [ @session_key, params[@session_key] ].join('=').freeze unless params[@session_key].nil?
|
173
|
+
end
|
174
|
+
@app.call(env)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, FlashSessionCookieMiddleware, ActionController::Base.session_options[:key])
|
179
|
+
FILE
|
180
|
+
|
181
|
+
# example Song resource for those who want it
|
182
|
+
controller_file = <<-FILE
|
183
|
+
class SongsController < ApplicationController
|
184
|
+
layout 'swfupload'
|
185
|
+
|
186
|
+
def index
|
187
|
+
@songs = Song.all
|
188
|
+
end
|
189
|
+
|
190
|
+
def create
|
191
|
+
require 'mime/types'
|
192
|
+
mp3_info = Mp3Info.new(params[:Filedata].path)
|
193
|
+
|
194
|
+
song = Song.new
|
195
|
+
song.artist = mp3_info.tag.artist
|
196
|
+
song.title = mp3_info.tag.title
|
197
|
+
song.length_in_seconds = mp3_info.length.to_i
|
198
|
+
|
199
|
+
params[:Filedata].content_type = MIME::Types.type_for(params[:Filedata].original_filename).to_s
|
200
|
+
song.track = params[:Filedata]
|
201
|
+
song.save
|
202
|
+
|
203
|
+
render :text => [song.artist, song.title, song.convert_seconds_to_time].join(" - ")
|
204
|
+
rescue Mp3InfoError => e
|
205
|
+
render :text => "File error"
|
206
|
+
rescue Exception => e
|
207
|
+
render :text => e.message
|
208
|
+
end
|
209
|
+
end
|
210
|
+
FILE
|
211
|
+
|
212
|
+
|
213
|
+
model_file = <<-FILE
|
214
|
+
class Song < ActiveRecord::Base
|
215
|
+
|
216
|
+
has_attached_file :track
|
217
|
+
|
218
|
+
# validates_presence_of :title, :artist, :length_in_seconds
|
219
|
+
validates_attachment_presence :track
|
220
|
+
validates_attachment_content_type :track, :content_type => [ 'application/mp3', 'application/x-mp3', 'audio/mpeg', 'audio/mp3' ]
|
221
|
+
validates_attachment_size :track, :less_than => 20.megabytes
|
222
|
+
|
223
|
+
attr_accessible :title, :artist, :length_in_seconds
|
224
|
+
|
225
|
+
def convert_seconds_to_time
|
226
|
+
total_minutes = length_in_seconds / 1.minutes
|
227
|
+
seconds_in_last_minute = length_in_seconds - total_minutes.minutes.seconds
|
228
|
+
"\#{total_minutes}m \#{seconds_in_last_minute}s"
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
end
|
233
|
+
FILE
|
234
|
+
|
235
|
+
view_file = <<-FILE
|
236
|
+
%h1 Songs
|
237
|
+
|
238
|
+
- @songs.each do |song|
|
239
|
+
%p= song.title
|
240
|
+
|
241
|
+
= render 'swfupload/upload'
|
242
|
+
FILE
|
243
|
+
|
244
|
+
migration_file = <<-FILE
|
245
|
+
class CreateSongs < ActiveRecord::Migration
|
246
|
+
def self.up
|
247
|
+
create_table :songs do |t|
|
248
|
+
t.string :artist
|
249
|
+
t.string :title
|
250
|
+
t.integer :length_in_seconds
|
251
|
+
t.string :track_file_name
|
252
|
+
t.string :track_content_type
|
253
|
+
t.integer :track_file_size
|
254
|
+
t.timestamps
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def self.down
|
259
|
+
drop_table :songs
|
260
|
+
end
|
261
|
+
end
|
262
|
+
FILE
|
263
|
+
|
264
|
+
layout_file = <<-FILE
|
265
|
+
!!! Strict
|
266
|
+
%html
|
267
|
+
%head
|
268
|
+
%title
|
269
|
+
= h(yield(:title) || "Untitled")
|
270
|
+
= '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>'
|
271
|
+
= '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery-ui.min.js"></script>'
|
272
|
+
= yield(:head)
|
273
|
+
%body
|
274
|
+
#container
|
275
|
+
= yield
|
276
|
+
FILE
|
277
|
+
|
278
|
+
puts '=' * 80
|
279
|
+
if yes? "Create an example resource using Paperclip? (y/n)"
|
280
|
+
FileUtils.mkdir_p 'app/views/songs'
|
281
|
+
FileUtils.mkdir_p 'public/stylesheets/compiled'
|
282
|
+
|
283
|
+
file 'app/views/layouts/swfupload.html.haml', layout_file
|
284
|
+
file 'app/controllers/songs_controller.rb', controller_file
|
285
|
+
file 'app/models/song.rb', model_file
|
286
|
+
file 'app/views/songs/index.html.haml', view_file
|
287
|
+
|
288
|
+
generate "migration", "create_songs"
|
289
|
+
filename = Dir['db/migrate/*create_songs.rb'].first
|
290
|
+
file filename, migration_file
|
291
|
+
rake "db:migrate"
|
292
|
+
|
293
|
+
gem 'paperclip'
|
294
|
+
gem 'haml'
|
295
|
+
gem 'ruby-mp3info', :lib => 'mp3info'
|
296
|
+
|
297
|
+
run "sass app/stylesheets/swfupload.sass > public/stylesheets/compiled/swfupload.css"
|
298
|
+
|
299
|
+
route 'map.resources :songs'
|
300
|
+
|
301
|
+
puts "Now fire up the app and go to /songs to test it out!"
|
302
|
+
else
|
303
|
+
puts "\nYour controller should have a create action that looks something like this:\n#{controller_file}"
|
304
|
+
puts "\nYou can create a model that looks like this:\n#{model_file}"
|
305
|
+
end
|