aitor (owner)

Revisions

gist: 130641 Download_button fork
public
Public Clone URL: git://gist.github.com/130641.git
Embed All Files: show embed
Ruby #
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
require 'colored'
 
def add_desert_require
  sentinel = 'Rails::Initializer.run do |config|'
  gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
    "\nrequire 'desert'\n#{match}"
  end
end
 
def gsub_file(path, regexp, *args, &block)
  content = File.read(path).gsub(regexp, *args, &block)
  File.open(path, 'wb') { |file| file.write(content) }
end
               
def install_require_gems
  run "gem sources -a http://gems.github.com"
 
  gem 'desert', :version => '0.5', :lib => 'desert'
  gem 'mislav-will_paginate', :version => '~> 2.3.6', :lib => 'will_paginate', :source => 'http://gems.github.com'
  gem 'tog-tog', :version => '0.5', :lib => 'tog'
  gem 'mocha'
  gem 'thoughtbot-factory_girl', :lib => 'factory_girl'
  rake "gems:install", :sudo => true
end
 
def install_tog_core_plugins
  plugin 'tog_core', :git => "git://github.com/tog/tog_core.git"
  plugin 'tog_social', :git => "git://github.com/tog/tog_social.git"
  plugin 'tog_mail', :git => "git://github.com/tog/tog_mail.git"
 
  route "map.routes_from_plugin 'tog_core'"
  route "map.routes_from_plugin 'tog_mail'"
  route "map.routes_from_plugin 'tog_social'"
 
  file "db/migrate/" + Time.now.strftime("%Y%m%d%H%M%S") + "_install_tog.rb",
  %q{class InstallTog < ActiveRecord::Migration
def self.up
migrate_plugin "tog_core", 6
migrate_plugin "tog_social", 5
migrate_plugin "tog_mail", 2
end
 
def self.down
migrate_plugin "tog_mail", 0
migrate_plugin "tog_social", 0
migrate_plugin "tog_core", 0
end
end
}
end
 
def generate_acts_as_commentable_migration
  file "db/migrate/" + Time.now.strftime("%Y%m%d%H%M%S") + "_acts_as_commentable.rb",
  %q{class ActsAsCommentable < 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
}
end
 
def generate_acts_as_rateable_migration
  file "db/migrate/" + Time.now.strftime("%Y%m%d%H%M%S") + "_add_ratings.rb",
  %q{class AddRatings < ActiveRecord::Migration
def self.up
create_table :ratings do |t|
t.column :rating, :integer # You can add a default value here if you wish
t.column :rateable_id, :integer, :null => false
t.column :rateable_type, :string, :null => false
end
add_index :ratings, [:rateable_id, :rating] # Not required, but should help more than it hurts
end
 
def self.down
drop_table :ratings
end
end
}
end
 
def install_tog_user_plugin
  if yes?("Install tog_user?")
 
    plugin 'tog_user', :git => "git://github.com/tog/tog_user.git"
 
    route "map.routes_from_plugin 'tog_user'"
 
    file "db/migrate/" + Time.now.strftime("%Y%m%d%H%M%S") + "_install_tog_user.rb",
    %q{class InstallTogUser < ActiveRecord::Migration
def self.up
migrate_plugin "tog_user", 1
end
 
def self.down
migrate_plugin "tog_user", 0
end
end
}
 
    if yes?("Create a default admin user?")
      name = ask("username?")
      pwd = ask("password?")
      puts "nothing yet, sorry :("
    end
  end
end
 
def run_tog_tests
  if yes?("Run tog's tests?")
    rake "db:test:prepare"
    rake "tog:plugins:test"
  end
end
 
def introduction_banner
  puts %q{
#{"Welcome to the Tog installer, v0.5.1".yellow_on_blue.bold} "
}
  puts %q{
This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.
 
Here's what you can expect from the installation process:
 
1. All the tog's dependencies will be installed for you.
2. The installer will generate a few migrations required by the dependencies
3. You will be able to install tog_user.
4. You will be able to create an initial admin user.
 
Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.
 
Press Enter to continue, or Ctrl-C to abort.
}
  gets
end
 
introduction_banner
add_desert_require
install_require_gems
 
{
  'acts_as_commentable' => "http://juixe.com/svn/acts_as_commentable",
  'acts_as_state_machine' => "http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk",
  'seo_urls' => "http://svn.redshiftmedia.com/svn/plugins/seo_urls"
}.each_pair { |name, url| plugin name, :svn => url }
 
{
  'acts_as_taggable_on_steroids' => "git://github.com/jviney/acts_as_taggable_on_steroids.git",
  'acts_as_rateable' => "git://github.com/andry1/acts_as_rateable.git",
  'acts_as_abusable' => "git://github.com/linkingpaths/acts_as_abusable.git",
  'acts_as_scribe' => "git://github.com/linkingpaths/acts_as_scribe.git",
  'paperclip' => "git://github.com/thoughtbot/paperclip.git",
  'viking' => "git://github.com/technoweenie/viking.git"
}.each_pair { |name, url| plugin name, :git => url }
 
generate_acts_as_commentable_migration
generate_acts_as_rateable_migration
generate "acts_as_abusable_migration"
generate "acts_as_taggable_migration"
generate "acts_as_scribe_migration"
 
install_tog_user_plugin
install_tog_core_plugins
 
run "echo \"require 'tasks/tog'\" >> Rakefile"
rake "tog:plugins:copy_resources"
rake "db:migrate"
run 'rm public/index.html'
 
run_tog_tests