rails 0.8.5 → 8.1.3
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +2 -2
- data/README.md +102 -0
- metadata +227 -127
- data/CHANGELOG +0 -187
- data/README +0 -121
- data/Rakefile +0 -271
- data/bin/rails +0 -28
- data/configs/apache.conf +0 -44
- data/configs/database.yml +0 -13
- data/dispatches/dispatch.fcgi +0 -7
- data/dispatches/dispatch.rb +0 -10
- data/dispatches/dispatch.servlet +0 -45
- data/doc/README_FOR_APP +0 -2
- data/doc/apache_protection +0 -3
- data/doc/index.html +0 -94
- data/environments/production.rb +0 -6
- data/environments/shared.rb +0 -27
- data/environments/shared_for_gem.rb +0 -17
- data/environments/test.rb +0 -6
- data/fresh_rakefile +0 -101
- data/gem_snapshot +0 -14
- data/generators/new_controller.rb +0 -43
- data/generators/new_crud.rb +0 -34
- data/generators/new_mailer.rb +0 -43
- data/generators/new_model.rb +0 -31
- data/generators/templates/controller.erb +0 -24
- data/generators/templates/controller_test.erb +0 -17
- data/generators/templates/controller_view.rhtml +0 -10
- data/generators/templates/helper.erb +0 -2
- data/generators/templates/mailer.erb +0 -15
- data/generators/templates/mailer_action.rhtml +0 -3
- data/generators/templates/mailer_fixture.rhtml +0 -4
- data/generators/templates/mailer_test.erb +0 -37
- data/generators/templates/model.erb +0 -4
- data/generators/templates/model_test.erb +0 -11
- data/helpers/abstract_application.rb +0 -7
- data/helpers/application_helper.rb +0 -3
- data/helpers/test_helper.rb +0 -15
- data/html/404.html +0 -6
- data/html/500.html +0 -6
- data/html/index.html +0 -1
- data/lib/code_statistics.rb +0 -71
- data/lib/dispatcher.rb +0 -46
- data/lib/generator.rb +0 -112
- data/lib/webrick_server.rb +0 -158
data/lib/generator.rb
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
require 'fileutils'
|
|
2
|
-
require 'active_record/support/inflector'
|
|
3
|
-
|
|
4
|
-
module Generator
|
|
5
|
-
class GeneratorError < StandardError; end
|
|
6
|
-
|
|
7
|
-
class Base
|
|
8
|
-
@@template_root = File.dirname(__FILE__) + '/../generators/templates'
|
|
9
|
-
cattr_accessor :template_root
|
|
10
|
-
|
|
11
|
-
attr_reader :rails_root, :class_name, :file_name, :table_name,
|
|
12
|
-
:actions, :options
|
|
13
|
-
|
|
14
|
-
def initialize(rails_root, object_name, actions = [], options = {})
|
|
15
|
-
@rails_root = rails_root
|
|
16
|
-
@class_name = Inflector.camelize(object_name)
|
|
17
|
-
@file_name = Inflector.underscore(@class_name)
|
|
18
|
-
@table_name = Inflector.pluralize(@file_name)
|
|
19
|
-
@actions = actions
|
|
20
|
-
@options = options
|
|
21
|
-
|
|
22
|
-
# Use local templates if rails_root/generators directory exists.
|
|
23
|
-
local_template_root = File.join(@rails_root, 'generators')
|
|
24
|
-
if File.directory?(local_template_root)
|
|
25
|
-
self.class.template_root = local_template_root
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
protected
|
|
30
|
-
|
|
31
|
-
# Generate a file in a fresh Rails app from an ERB template.
|
|
32
|
-
# Takes a template path relative to +template_root+, a
|
|
33
|
-
# destination path relative to +rails_root+, evaluates the template,
|
|
34
|
-
# and writes the result to the destination.
|
|
35
|
-
def generate_file(template_file_path, rails_file_path, eval_binding = nil)
|
|
36
|
-
# Determine full paths for source and destination files.
|
|
37
|
-
template_path = File.join(template_root, template_file_path)
|
|
38
|
-
rails_path = File.join(rails_root, rails_file_path)
|
|
39
|
-
|
|
40
|
-
# Create destination directories.
|
|
41
|
-
FileUtils.mkdir_p(File.dirname(rails_path))
|
|
42
|
-
|
|
43
|
-
# Render template and write result.
|
|
44
|
-
eval_binding ||= binding
|
|
45
|
-
contents = ERB.new(File.read(template_path), nil, '-').result(eval_binding)
|
|
46
|
-
File.open(rails_path, 'w') { |file| file.write(contents) }
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Generate controller, helper, functional test, and views.
|
|
51
|
-
class Controller < Base
|
|
52
|
-
def generate
|
|
53
|
-
options[:scaffold] = file_name if options[:scaffold]
|
|
54
|
-
|
|
55
|
-
# Controller class.
|
|
56
|
-
generate_file "controller.erb", "app/controllers/#{file_name}_controller.rb"
|
|
57
|
-
|
|
58
|
-
# Helper class.
|
|
59
|
-
generate_file "helper.erb", "app/helpers/#{file_name}_helper.rb"
|
|
60
|
-
|
|
61
|
-
# Function test.
|
|
62
|
-
generate_file "controller_test.erb", "test/functional/#{file_name}_controller_test.rb"
|
|
63
|
-
|
|
64
|
-
# View template for each action.
|
|
65
|
-
@actions.each do |action|
|
|
66
|
-
generate_file "controller_view.rhtml",
|
|
67
|
-
"app/views/#{file_name}/#{action}.rhtml",
|
|
68
|
-
binding
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# Generate model, unit test, and fixtures.
|
|
74
|
-
class Model < Base
|
|
75
|
-
def generate
|
|
76
|
-
|
|
77
|
-
# Model class.
|
|
78
|
-
generate_file "model.erb", "app/models/#{file_name}.rb"
|
|
79
|
-
|
|
80
|
-
# Model unit test.
|
|
81
|
-
generate_file "model_test.erb", "test/unit/#{file_name}_test.rb"
|
|
82
|
-
|
|
83
|
-
# Test fixtures directory.
|
|
84
|
-
FileUtils.mkdir_p("test/fixtures/#{table_name}")
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Generate mailer, helper, functional test, and views.
|
|
89
|
-
class Mailer < Base
|
|
90
|
-
def generate
|
|
91
|
-
|
|
92
|
-
# Mailer class.
|
|
93
|
-
generate_file "mailer.erb", "app/models/#{file_name}.rb"
|
|
94
|
-
|
|
95
|
-
# Mailer unit test.
|
|
96
|
-
generate_file "mailer_test.erb", "test/unit/#{file_name}_test.rb"
|
|
97
|
-
|
|
98
|
-
# Test fixtures directory.
|
|
99
|
-
FileUtils.mkdir_p("test/fixtures/#{table_name}")
|
|
100
|
-
|
|
101
|
-
# View template and fixture for each action.
|
|
102
|
-
@actions.each do |action|
|
|
103
|
-
generate_file "mailer_action.rhtml",
|
|
104
|
-
"app/views/#{file_name}/#{action}.rhtml",
|
|
105
|
-
binding
|
|
106
|
-
generate_file "mailer_fixture.rhtml",
|
|
107
|
-
"test/fixtures/#{table_name}/#{action}",
|
|
108
|
-
binding
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
data/lib/webrick_server.rb
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
# Donated by Florian Gross
|
|
2
|
-
|
|
3
|
-
require 'webrick'
|
|
4
|
-
require 'cgi'
|
|
5
|
-
require 'stringio'
|
|
6
|
-
|
|
7
|
-
include WEBrick
|
|
8
|
-
|
|
9
|
-
class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
10
|
-
def self.dispatch(options = {})
|
|
11
|
-
Socket.do_not_reverse_lookup = true # patch for OS X
|
|
12
|
-
|
|
13
|
-
server = WEBrick::HTTPServer.new(:Port => options[:port].to_i, :ServerType => options[:server_type], :BindAddress => options[:ip])
|
|
14
|
-
server.mount('/', DispatchServlet, options)
|
|
15
|
-
|
|
16
|
-
trap("INT") { server.shutdown }
|
|
17
|
-
server.start
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def initialize(server, options)
|
|
21
|
-
@server_options = options
|
|
22
|
-
@file_handler = WEBrick::HTTPServlet::FileHandler.new(server, options[:server_root], {:FancyIndexing => true })
|
|
23
|
-
super
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def do_GET(req, res)
|
|
27
|
-
unless handle_index(req, res)
|
|
28
|
-
unless handle_dispatch(req, res)
|
|
29
|
-
unless handle_file(req, res)
|
|
30
|
-
unless handle_mapped(req, res)
|
|
31
|
-
raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found."
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
alias :do_POST :do_GET
|
|
39
|
-
|
|
40
|
-
def handle_index(req, res)
|
|
41
|
-
if req.request_uri.path == "/"
|
|
42
|
-
if @server_options[:index_controller]
|
|
43
|
-
res.set_redirect WEBrick::HTTPStatus::MovedPermanently, "/#{@server_options[:index_controller]}/"
|
|
44
|
-
else
|
|
45
|
-
res.set_redirect WEBrick::HTTPStatus::MovedPermanently, "/_doc/index.html"
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
return true
|
|
49
|
-
else
|
|
50
|
-
return false
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def handle_file(req, res)
|
|
55
|
-
begin
|
|
56
|
-
@file_handler.send(:do_GET, req, res)
|
|
57
|
-
return true
|
|
58
|
-
rescue HTTPStatus::PartialContent, HTTPStatus::NotModified => err
|
|
59
|
-
res.set_error(err)
|
|
60
|
-
return true
|
|
61
|
-
rescue => err
|
|
62
|
-
p err
|
|
63
|
-
return false
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def handle_mapped(req, res)
|
|
68
|
-
parsed_ok, controller, action, id = DispatchServlet.parse_uri(req.request_uri.path)
|
|
69
|
-
if parsed_ok
|
|
70
|
-
query = "controller=#{controller}&action=#{action}&id=#{id}"
|
|
71
|
-
query << "&#{req.request_uri.query}" if req.request_uri.query
|
|
72
|
-
origin = req.request_uri.path + "?" + query
|
|
73
|
-
req.request_uri.path = "/dispatch.rb"
|
|
74
|
-
req.request_uri.query = query
|
|
75
|
-
handle_dispatch(req, res, origin)
|
|
76
|
-
else
|
|
77
|
-
return false
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def handle_dispatch(req, res, origin = nil)
|
|
82
|
-
return false unless /^\/dispatch\.(?:cgi|rb|fcgi)$/.match(req.request_uri.path)
|
|
83
|
-
|
|
84
|
-
env = req.meta_vars.clone
|
|
85
|
-
env["QUERY_STRING"] = req.request_uri.query
|
|
86
|
-
env["REQUEST_URI"] = origin if origin
|
|
87
|
-
|
|
88
|
-
data = nil
|
|
89
|
-
if @server_options[:cache_classes]
|
|
90
|
-
old_stdin, old_stdout = $stdin, $stdout
|
|
91
|
-
$stdin, $stdout = StringIO.new(req.body || ""), StringIO.new
|
|
92
|
-
|
|
93
|
-
begin
|
|
94
|
-
require 'cgi'
|
|
95
|
-
CGI.send(:define_method, :env_table) { env }
|
|
96
|
-
|
|
97
|
-
load File.join(@server_options[:server_root], "dispatch.rb")
|
|
98
|
-
|
|
99
|
-
$stdout.rewind
|
|
100
|
-
data = $stdout.read
|
|
101
|
-
ensure
|
|
102
|
-
$stdin, $stdout = old_stdin, old_stdout
|
|
103
|
-
end
|
|
104
|
-
else
|
|
105
|
-
begin
|
|
106
|
-
require 'rbconfig'
|
|
107
|
-
ruby_interpreter = Config::CONFIG['ruby_install_name'] || 'ruby'
|
|
108
|
-
rescue Object
|
|
109
|
-
ruby_interpreter = 'ruby'
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
dispatch_rb_path = File.expand_path(File.join(@server_options[:server_root], "dispatch.rb"))
|
|
113
|
-
IO.popen(ruby_interpreter, "rb+") do |ruby|
|
|
114
|
-
ruby.puts <<-END
|
|
115
|
-
require 'cgi'
|
|
116
|
-
require 'stringio'
|
|
117
|
-
env = #{env.inspect}
|
|
118
|
-
CGI.send(:define_method, :env_table) { env }
|
|
119
|
-
$stdin = StringIO.new(#{(req.body || "").inspect})
|
|
120
|
-
|
|
121
|
-
eval "load '#{dispatch_rb_path}'", binding, #{dispatch_rb_path.inspect}
|
|
122
|
-
END
|
|
123
|
-
ruby.close_write
|
|
124
|
-
data = ruby.read
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
raw_header, body = *data.split(/^[\xd\xa]+/on, 2)
|
|
129
|
-
header = WEBrick::HTTPUtils::parse_header(raw_header)
|
|
130
|
-
if /^(\d+)/ =~ header['status'][0]
|
|
131
|
-
res.status = $1.to_i
|
|
132
|
-
header.delete('status')
|
|
133
|
-
end
|
|
134
|
-
header.each { |key, val| res[key] = val.join(", ") }
|
|
135
|
-
|
|
136
|
-
res.body = body
|
|
137
|
-
return true
|
|
138
|
-
rescue => err
|
|
139
|
-
p err, err.backtrace
|
|
140
|
-
return false
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
def self.parse_uri(path)
|
|
144
|
-
component = /([-_a-zA-Z0-9]+)/
|
|
145
|
-
|
|
146
|
-
case path.sub(%r{^/(?:fcgi|mruby|cgi)/}, "/")
|
|
147
|
-
when %r{^/#{component}/?$} then
|
|
148
|
-
[true, $1, "index", nil]
|
|
149
|
-
when %r{^/#{component}/#{component}/?$} then
|
|
150
|
-
[true, $1, $2, nil]
|
|
151
|
-
when %r{^/#{component}/#{component}/#{component}/?$} then
|
|
152
|
-
[true, $1, $2, $3]
|
|
153
|
-
else
|
|
154
|
-
[false, nil, nil, nil]
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
end
|