Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 4484 Bytes
1 | require 'rbconfig' |
2 | |
3 | class InstanceGenerator < Rails::Generator::Base |
4 | DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], |
5 | Config::CONFIG['ruby_install_name']) |
6 | |
7 | DATABASES = %w( mysql postgresql sqlite3 sqlserver db2 ) |
8 | |
9 | MYSQL_SOCKET_LOCATIONS = [ |
10 | "/tmp/mysql.sock", # default |
11 | "/var/run/mysqld/mysqld.sock", # debian/gentoo |
12 | "/var/tmp/mysql.sock", # freebsd |
13 | "/var/lib/mysql/mysql.sock", # fedora |
14 | "/opt/local/lib/mysql/mysql.sock", # fedora |
15 | "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql |
16 | "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4 |
17 | "/opt/local/var/run/mysql5/mysqld.sock" # mac + darwinports + mysql5 |
18 | ] |
19 | |
20 | default_options :db => "mysql", :shebang => DEFAULT_SHEBANG, :freeze => false |
21 | |
22 | def initialize(runtime_args, runtime_options = {}) |
23 | super |
24 | usage if args.empty? |
25 | usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db])) |
26 | @destination_root = args.shift |
27 | end |
28 | |
29 | def manifest |
30 | # The absolute location of the Radiant files |
31 | root = File.expand_path(RADIANT_ROOT) |
32 | |
33 | # Use /usr/bin/env if no special shebang was specified |
34 | script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] } |
35 | dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] } |
36 | |
37 | record do |m| |
38 | # Root directory |
39 | m.directory "" |
40 | |
41 | # Standard files and directories |
42 | base_dirs = %w(config config/environments config/initializers db log script public vendor/plugins vendor/extensions) |
43 | text_files = %w(CHANGELOG CONTRIBUTORS LICENSE INSTALL README) |
44 | environments = Dir["#{root}/config/environments/*.rb"] |
45 | initializers = Dir["#{root}/config/initializers/*.rb"] |
46 | scripts = Dir["#{root}/script/**/*"].reject { |f| f =~ /(destroy|generate|plugin)$/ } |
47 | public_files = ["public/.htaccess"] + Dir["#{root}/public/**/*"] |
48 | |
49 | files = base_dirs + text_files + environments + initializers + scripts + public_files |
50 | files.map! { |f| f = $1 if f =~ %r{^#{root}/(.+)$}; f } |
51 | files.sort! |
52 | |
53 | files.each do |file| |
54 | case |
55 | when File.directory?("#{root}/#{file}") |
56 | m.directory file |
57 | when file =~ %r{^script/} |
58 | m.file radiant_root(file), file, script_options |
59 | when file =~ %r{^public/dispatch} |
60 | m.file radiant_root(file), file, dispatcher_options |
61 | else |
62 | m.file radiant_root(file), file |
63 | end |
64 | end |
65 | |
66 | # script/generate |
67 | m.file "instance_generate", "script/generate", script_options |
68 | |
69 | # database.yml and .htaccess |
70 | m.template "databases/#{options[:db]}.yml", "config/database.yml", :assigns => { |
71 | :app_name => File.basename(File.expand_path(@destination_root)), |
72 | :socket => options[:db] == "mysql" ? mysql_socket_location : nil |
73 | } |
74 | |
75 | # Instance Rakefile |
76 | m.file "instance_rakefile", "Rakefile" |
77 | |
78 | # Instance Configurations |
79 | m.file "instance_routes.rb", "config/routes.rb" |
80 | m.template "instance_environment.rb", "config/environment.rb", :assigns => { |
81 | :radiant_environment => File.join(File.dirname(__FILE__), 'templates', radiant_root("config/environment.rb")), |
82 | :app_name => File.basename(File.expand_path(@destination_root)) |
83 | } |
84 | m.template "instance_boot.rb", "config/boot.rb" |
85 | |
86 | # Install Readme |
87 | m.readme radiant_root("INSTALL") |
88 | end |
89 | end |
90 | |
91 | protected |
92 | |
93 | def banner |
94 | "Usage: #{$0} /path/to/radiant/app [options]" |
95 | end |
96 | |
97 | def add_options!(opt) |
98 | opt.separator '' |
99 | opt.separator 'Options:' |
100 | opt.on("-r", "--ruby=path", String, |
101 | "Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).", |
102 | "Default: #{DEFAULT_SHEBANG}") { |v| options[:shebang] = v } |
103 | opt.on("-d", "--database=name", String, |
104 | "Preconfigure for selected database (options: #{DATABASES.join(", ")}).", |
105 | "Default: mysql") { |v| options[:db] = v } |
106 | end |
107 | |
108 | def mysql_socket_location |
109 | RUBY_PLATFORM =~ /mswin32/ ? MYSQL_SOCKET_LOCATIONS.find { |f| File.exists?(f) } : nil |
110 | end |
111 | |
112 | private |
113 | |
114 | def radiant_root(filename = '') |
115 | File.join("..", "..", "..", "..", filename) |
116 | end |
117 | |
118 | end |