tog (owner)

Revisions

gist: 15496 Download_button fork
public
Public Clone URL: git://gist.github.com/15496.git
app_for_togify.rb
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
#!/usr/bin/env ruby
require 'rubygems'
$COLORED_ENABLED = false
 
begin
  require 'colored'
  $COLORED_ENABLED = true
rescue LoadError
end
 
def log(text)
  puts text unless text.empty?
  text
end
 
def colored(text, color=:green )
  $COLORED_ENABLED ? text.send(color) : text
end
 
def run (command)
  log colored("[RUNNING] #{command}")
  system("#{command}")
end
 
def rm (file)
  log colored("[DELETING] #{file}", :yellow)
  FileUtils.rm_rf(file)
end
 
begin
  require 'redcloth'
rescue Exception => e
  log colored("[ERROR] You've to install redcloth. Run `[sudo] gem install RedCloth` and try again.", :red)
  exit -1
end
 
begin
  require 'aasm'
rescue Exception => e
  log colored("[ERROR] You've to install aasm. Run `gem sources -a http://gems.github.com` and `[sudo] gem install rubyist-aasm` and try again.", :red)
  exit -1
end
 
 
def with_migration_tpl_file(tpl_file)
  File.open(tpl_file, 'w') {|file|
    file.write <<-eos
class CreateComments < ActiveRecord::Migration
def self.up
create_table "comments", :force => true do |t|
t.column "title", :string, :limit => 50, :default => ""
t.column "comment", :text, :default => ""
t.column "created_at", :datetime, :null => false
t.column "commentable_id", :integer, :default => 0, :null => false
t.column "commentable_type", :string, :limit => 15, :default => "", :null => false
t.column "user_id", :integer, :default => 0, :null => false
end
 
add_index "comments", ["user_id"], :name => "fk_comments_user"
end
 
def self.down
drop_table :comments
end
end
eos
  }
  yield tpl_file
  rm tpl_file
end
 
app = ARGV.first || "app_for_togify"
 
rm (app)
run "git clone git://github.com/tog/app_for_togify.git #{app}"
 
Dir.chdir app do
  run 'rake db:migrate'
  run 'rake league:db:rebuild'
 
  run "ruby script/plugin install http://juixe.com/svn/acts_as_commentable"
  run 'ruby script/generate migration create_comments'
  pattern = File.join Dir.pwd, "db" , "migrate", "*create_comments.rb"
  create_migration = Dir.glob(pattern).first
 
  with_migration_tpl_file("tmp_tpl.rb") do |file|
    FileUtils.cp file, create_migration
  end
 
 
  run "ruby script/plugin install git://github.com/linkingpaths/acts_as_scribe.git"
  run "ruby script/generate acts_as_scribe_migration"
 
  run "ruby script/plugin install git://github.com/linkingpaths/acts_as_abusable.git"
  run "ruby script/generate acts_as_abusable_migration"
 
  run "ruby script/plugin install http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids"
  run "ruby script/generate acts_as_taggable_migration"
 
  run "ruby script/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk"
  run "ruby script/plugin install http://svn.redshiftmedia.com/svn/plugins/seo_urls"
  run "ruby script/plugin install http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk"
 
  run "togify . --skip-tog_user"
  run "rake tog:plugins:copy_resources"
  run "rake db:migrate"
 
end