-
Notifications
You must be signed in to change notification settings - Fork 14
/
tog_template.rb
325 lines (262 loc) · 10.2 KB
/
tog_template.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
EDGE = "EDGE"
TOG_RELEASE = EDGE
#TOG_RELEASE = "v0.7"
APP_NAME = @root.split('/').last
module Colored
extend self
COLORS = { 'green' => 32, 'yellow' => 33,'blue' => 34}
EXTRAS = {'clear' => 0, 'bold' => 1}
COLORS.each do |color, value|
define_method(color) { colorize(self, :foreground => color) }
define_method("on_#{color}") { colorize(self, :background => color) }
COLORS.each do |highlight, value|
next if color == highlight
define_method("#{color}_on_#{highlight}") { colorize(self, :foreground => color, :background => highlight) }
end
end
EXTRAS.each do |extra, value|
next if extra == 'clear'
define_method(extra) { colorize(self, :extra => extra) }
end
define_method(:to_eol) do
tmp = sub(/^(\e\[[\[\e0-9;m]+m)/, "\\1\e[2K")
if tmp == self
return "\e[2K" << self
end
tmp
end
def colorize(string, options = {})
colored = [color(options[:foreground]), color("on_#{options[:background]}"), extra(options[:extra])].compact * ''
colored << string
colored << extra(:clear)
end
def colors
@@colors ||= COLORS.keys.sort
end
def extra(extra_name)
extra_name = extra_name.to_s
"\e[#{EXTRAS[extra_name]}m" if EXTRAS[extra_name]
end
def color(color_name)
background = color_name.to_s =~ /on_/
color_name = color_name.to_s.sub('on_', '')
return unless color_name && COLORS[color_name]
"\e[#{COLORS[color_name] + (background ? 10 : 0)}m"
end
end unless Object.const_defined? :Colored
String.send(:include, Colored)
require 'open3'
def silence!
# Rails::Generator::Base.logger.quiet = true
end
def verbum!
# Rails::Generator::Base.logger.quiet = false
end
def add_desert_require
sentinel = 'Rails::Initializer.run do |config|'
gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi, "\nrequire 'desert'\n\\1"
end
def install_require_gems
run "gem sources -a http://gems.github.com"
gem 'desert', :lib => 'desert', :version => '0.5.2'
gem 'i18n', :version => '0.4.1'
gem 'mislav-will_paginate', :lib => 'will_paginate', :version => '~> 2.3.6'
gem 'thoughtbot-factory_girl', :lib => 'factory_girl'
gem 'jackdempsey-acts_as_commentable', :lib => 'acts_as_commentable', :version => '2.0.1'
gem "mreinsch-acts_as_rateable", :lib => "acts_as_rateable", :version => '2.0.1'
gem 'RedCloth', :lib => 'redcloth', :version => '4.2.0'
gem "mbleigh-acts-as-taggable-on", :lib => "acts-as-taggable-on", :version => '1.0.5'
gem "linkingpaths-acts_as_abusable", :lib => "acts_as_abusable", :version => '0.0.2'
gem 'rubyist-aasm', :version => '~> 2.1.1', :lib => 'aasm'
gem 'oauth', :version => '0.4.1'
puts "\n"
if yes?("Install required gems as root? (y/n). If you are using Windows, please, answer 'n'. If installing gems as superuser you could be asked to enter your password.")
rake "gems:install", :sudo => true
else
rake "gems:install", :sudo => false
end
end
def install_tog_core_plugins
quiet_git_install('tog_core', "git://github.com/tog/tog_core.git", TOG_RELEASE )
quiet_git_install('tog_social', "git://github.com/tog/tog_social.git", TOG_RELEASE )
quiet_git_install('tog_mail', "git://github.com/tog/tog_mail.git", TOG_RELEASE )
route "map.routes_from_plugin 'tog_core'"
puts "* adding tog_core routes to host app... #{"added".green.bold}";
route "map.routes_from_plugin 'tog_social'"
puts "* adding tog_tog_social routes to host app... #{"added".green.bold}";
route "map.routes_from_plugin 'tog_mail'"
puts "* adding tog_mail routes to host app... #{"added".green.bold}";
generate "update_tog_migration"
puts "* generating tog_core migration... #{"generated".green.bold}";
end
def install_acts_as_commentable
generate "comment"
puts "* acts_as_commentable installed... #{"generated".green.bold}";
end
def install_preferences
generate "preferences"
puts "* preferences installed... #{"generated".green.bold}";
end
def generate_acts_as_rateable_migration
generate "acts_as_rateable_migration "
puts "* acts_as_rateable migration... #{"generated".green.bold}";
end
def generate_acts_as_shareable_migration
generate "share_migration"
puts "* acts_as_shareable migration... #{"generated".green.bold}";
end
def generate_acts_as_abusable_migration
generate "acts_as_abusable_migration"
puts "* acts_as_abusable migration... #{"generated".green.bold}";
end
def generate_acts_as_taggable_migration
generate "acts_as_taggable_on_migration"
puts "* acts_as_taggable migration... #{"generated".green.bold}";
end
def generate_acts_as_scribe_migration
generate "acts_as_scribe_migration"
puts "* acts_as_scribe migration... #{"generated".green.bold}";
end
def install_tog_user_plugin
verbum!
if STDIN.gets.strip == ""
silence!
quiet_git_install("restful_authentication", "git://github.com/technoweenie/restful-authentication.git")
File.rename "vendor/plugins/restful-authentication", "vendor/plugins/restful_authentication"
rake "auth:gen:site_key"
quiet_git_install('tog_user', "git://github.com/tog/tog_user.git", TOG_RELEASE)
route "map.routes_from_plugin 'tog_user'"
puts "* adding routes to host app... #{"added".green.bold}";
else
silence!
end
end
def introduction_banner
puts %q{
This installer will guide you through the tog integration process. The installer
downloads a few plugins over the internet so the time it takes depends in a great
measure of your bandwidth, but usually it should take a few minutes.
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
4. The host app will be a working tog instance after the installation.
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.}
STDIN.gets
end
def tog_user_banner
puts <<-eos
Tog includes its own user authentication library: tog_user. It's based
on the great restful-authentication plugin and well suited to work out-the-box.
If you're creating a new app #{"it's definitely recommended to install this plugin".green.bold}.
If you've already using a user library in the host app you can skip this step.
Press Enter to install tog_user, or 'n' to skip this step
eos
end
def gem_banner
puts <<-eos
We are going to install the required gems. This could be done as super user in a host-wide manner of just for your user.
eos
end
def congratulations_banner
puts <<-eos
Hurrah!... everything should be fine now. Some things you could try:
* Run the tests. Just run: '#{"rake db:test:prepare && rake tog:plugins:test".green.bold}'.
* Start the app in your favorite server and check your new, shiny tog installation.
* Visit http://wiki.github.com/tog/tog if you need technical read about the platform.
* You can install more tog plugins. For a list of available plugins check
http://www.toghq.com/tog_plugins
eos
end
def installation_step(title, &block)
puts "\n-------------------------------------------- \n\n"
puts "#{title.yellow_on_blue.bold} \n\n"
yield
end
def install_svn_plugins(plugins)
plugins.each_pair do |name, url|
print "* #{name}... "; STDOUT.flush
plugin name, :svn => url
puts "installed".green.bold
end
end
def install_git_plugins(plugins)
plugins.each_pair do |name, url|
quiet_git_install(name, url)
end
end
def install_jquery_support
puts "\n"
if yes?("Replace javascript library 'prototype' with 'jquery' (via jquery plugin)? (y/n)")
install_git_plugins({
'jrails' => "http://github.com/aaronchi/jrails.git"
})
end
end
def quiet_git_install(name, url, tag=nil)
tag = tag && tag != EDGE ? "-r tag #{tag}'": ""
print "* #{name} #{tag if tag}... ";
plugin name, :git => "#{tag} #{url}"
# Open3 doesn't work on windows, so no quiet install
# resolution = "installed".green
# command = "script/plugin install #{url}"
# command << " -r 'tag #{tag}'" if tag && tag != EDGE
# Open3.popen3(command) { |stdin, stdout, stderr|
# stdout.each { |line| resolution = "already installed -> skipped".yellow if line =~ /already installed/; STDOUT.flush }
# }
# puts resolution.bold
end
silence!
installation_step "Welcome to the Tog installer #{TOG_RELEASE}" do
introduction_banner
end
installation_step "Installing gem dependencies..." do
gem_banner
install_require_gems
end
installation_step "Installing plugin dependencies..." do
install_svn_plugins({
'seo_urls' => "http://svn.redshiftmedia.com/svn/plugins/seo_urls"
})
#also installed restful_authentication by tog_user optional part
install_git_plugins({
'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",
'acts_as_shareable' => "git://github.com/molpe/acts_as_shareable.git",
'preferences' => "http://github.com/pluginaweek/preferences.git"
})
install_jquery_support
end
installation_step "Generating dependencies migrations..." do
install_acts_as_commentable
install_preferences
generate_acts_as_rateable_migration
generate_acts_as_abusable_migration
generate_acts_as_taggable_migration
generate_acts_as_scribe_migration
generate_acts_as_shareable_migration
end
installation_step "Installing tog_user plugin..." do
tog_user_banner
install_tog_user_plugin
end
installation_step "Installing tog core plugins..." do
install_tog_core_plugins
end
installation_step "Updating the host app files..." do
add_desert_require
environment( "config.reload_plugins = true if RAILS_ENV == 'development'" )
append_file 'Rakefile', "require 'tasks/tog'\n"
puts "* including tog rake tasks... #{"done".green.bold}";
rake "tog:plugins:copy_resources"
puts "* copy tog plugins resources... #{"done".green.bold}";
rake "db:migrate"
puts "* run migrations... #{"done".green.bold}";
File.delete 'public/index.html'
puts "* removing index.html... #{"done".green.bold}";
end
installation_step "Tog #{TOG_RELEASE} installed" do
congratulations_banner
end