ramaze 2011.01.30 → 2011.07.25
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.mailmap +2 -0
- data/.rvmrc +1 -0
- data/README.md +119 -197
- data/Rakefile +14 -97
- data/bin/ramaze +6 -14
- data/doc/AUTHORS +8 -4
- data/doc/CHANGELOG +3784 -3339
- data/examples/app/chat/start.rb +2 -2
- data/lib/proto/app.rb +2 -3
- data/lib/proto/config.ru +4 -5
- data/lib/proto/controller/init.rb +11 -4
- data/lib/proto/controller/main.rb +12 -7
- data/lib/proto/layout/default.xhtml +56 -23
- data/lib/proto/model/init.rb +3 -1
- data/lib/proto/public/css/grid.css +107 -0
- data/lib/proto/public/css/layout.css +81 -0
- data/lib/proto/public/css/reset.css +123 -0
- data/lib/proto/public/css/text.css +109 -0
- data/lib/proto/public/images/bg.png +0 -0
- data/lib/proto/spec/main.rb +2 -2
- data/lib/proto/start.rb +11 -1
- data/lib/proto/view/index.xhtml +27 -23
- data/lib/ramaze.rb +0 -1
- data/lib/ramaze/app.rb +85 -12
- data/lib/ramaze/app_graph.rb +107 -0
- data/lib/ramaze/bin/console.rb +87 -0
- data/lib/ramaze/bin/create.rb +94 -0
- data/lib/ramaze/bin/helper.rb +107 -0
- data/lib/ramaze/bin/restart.rb +95 -0
- data/lib/ramaze/bin/runner.rb +141 -0
- data/lib/ramaze/bin/start.rb +206 -0
- data/lib/ramaze/bin/status.rb +152 -0
- data/lib/ramaze/bin/stop.rb +112 -0
- data/lib/ramaze/cache.rb +9 -4
- data/lib/ramaze/cache/localmemcache.rb +10 -13
- data/lib/ramaze/cache/lru.rb +49 -7
- data/lib/ramaze/cache/memcache.rb +170 -92
- data/lib/ramaze/cache/sequel.rb +301 -118
- data/lib/ramaze/controller.rb +108 -9
- data/lib/ramaze/controller/default.rb +15 -2
- data/lib/ramaze/current.rb +14 -2
- data/lib/ramaze/dependencies.rb +46 -0
- data/lib/ramaze/files.rb +38 -3
- data/lib/ramaze/gestalt.rb +12 -12
- data/lib/ramaze/helper.rb +0 -2
- data/lib/ramaze/helper/auth.rb +30 -23
- data/lib/ramaze/helper/blue_form.rb +175 -126
- data/lib/ramaze/helper/csrf.rb +76 -91
- data/lib/ramaze/helper/email.rb +105 -0
- data/lib/ramaze/helper/erector.rb +16 -15
- data/lib/ramaze/helper/gestalt.rb +2 -2
- data/lib/ramaze/helper/layout.rb +89 -73
- data/lib/ramaze/helper/link.rb +7 -6
- data/lib/ramaze/helper/localize.rb +6 -5
- data/lib/ramaze/helper/markaby.rb +25 -23
- data/lib/ramaze/helper/maruku.rb +3 -3
- data/lib/ramaze/helper/paginate.rb +19 -27
- data/lib/ramaze/helper/remarkably.rb +3 -3
- data/lib/ramaze/helper/request_accessor.rb +3 -3
- data/lib/ramaze/helper/send_file.rb +12 -8
- data/lib/ramaze/helper/simple_captcha.rb +5 -6
- data/lib/ramaze/helper/stack.rb +7 -4
- data/lib/ramaze/helper/tagz.rb +10 -11
- data/lib/ramaze/helper/thread.rb +19 -16
- data/lib/ramaze/helper/ultraviolet.rb +7 -4
- data/lib/ramaze/helper/user.rb +40 -21
- data/lib/ramaze/helper/xhtml.rb +29 -20
- data/lib/ramaze/log.rb +3 -11
- data/lib/ramaze/log/analogger.rb +5 -4
- data/lib/ramaze/log/growl.rb +9 -7
- data/lib/ramaze/log/hub.rb +3 -5
- data/lib/ramaze/log/informer.rb +15 -12
- data/lib/ramaze/log/knotify.rb +3 -5
- data/lib/ramaze/log/logger.rb +3 -5
- data/lib/ramaze/log/logging.rb +6 -8
- data/lib/ramaze/log/rotatinginformer.rb +27 -17
- data/lib/ramaze/log/syslog.rb +7 -7
- data/lib/ramaze/log/xosd.rb +3 -5
- data/lib/ramaze/middleware_compiler.rb +27 -4
- data/lib/ramaze/reloader.rb +50 -12
- data/lib/ramaze/reloader/watch_inotify.rb +4 -5
- data/lib/ramaze/reloader/watch_stat.rb +3 -3
- data/lib/ramaze/request.rb +18 -8
- data/lib/ramaze/response.rb +38 -7
- data/lib/ramaze/rest.rb +36 -0
- data/lib/ramaze/setup.rb +101 -31
- data/lib/ramaze/spec.rb +1 -1
- data/lib/ramaze/spec/bacon.rb +6 -3
- data/lib/ramaze/spec/helper/bacon.rb +0 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +2 -11
- data/lib/ramaze/view/erector.rb +46 -31
- data/lib/ramaze/view/erubis.rb +7 -3
- data/lib/ramaze/view/ezamar.rb +7 -3
- data/lib/ramaze/view/gestalt.rb +9 -3
- data/lib/ramaze/view/haml.rb +7 -3
- data/lib/ramaze/view/liquid.rb +3 -3
- data/lib/ramaze/view/lokar.rb +7 -3
- data/lib/ramaze/view/mustache.rb +11 -5
- data/lib/ramaze/view/nagoro.rb +3 -3
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/slippers.rb +40 -13
- data/lib/ramaze/view/tagz.rb +9 -5
- data/ramaze.gemspec +23 -128
- data/spec/helper.rb +5 -0
- data/spec/ramaze/bin/app/config.ru +11 -0
- data/spec/ramaze/bin/create.rb +28 -0
- data/spec/ramaze/bin/runner.rb +30 -0
- data/spec/ramaze/bin/start.rb +38 -0
- data/spec/ramaze/cache/memcache.rb +10 -3
- data/spec/ramaze/cache/sequel.rb +7 -0
- data/spec/ramaze/controller/provide_inheritance.rb +0 -10
- data/spec/ramaze/dispatcher/file.rb +19 -15
- data/spec/ramaze/helper/auth.rb +10 -9
- data/spec/ramaze/helper/blue_form.rb +121 -68
- data/spec/ramaze/helper/email.rb +69 -0
- data/spec/ramaze/helper/layout.rb +12 -15
- data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
- data/spec/ramaze/helper/user.rb +2 -0
- data/spec/ramaze/log/growl.rb +14 -1
- data/spec/{contrib → ramaze}/rest.rb +1 -1
- data/spec/ramaze/session/memcache.rb +2 -2
- data/spec/ramaze/view/sass.rb +1 -1
- data/tasks/bacon.rake +3 -3
- data/tasks/gem.rake +17 -18
- data/tasks/rcov.rake +2 -3
- data/tasks/release.rake +8 -65
- data/tasks/setup.rake +10 -8
- data/tasks/todo.rake +9 -5
- data/tasks/yard.rake +3 -2
- metadata +105 -397
- data/MANIFEST +0 -532
- data/TODO.md +0 -19
- data/benchmark/bench_templates/bench.rb +0 -67
- data/benchmark/bench_templates/view/large.erb +0 -79
- data/benchmark/bench_templates/view/large.haml +0 -41
- data/benchmark/bench_templates/view/large.lok +0 -79
- data/benchmark/bench_templates/view/large.xhtml +0 -79
- data/benchmark/bench_templates/view/small.erb +0 -21
- data/benchmark/bench_templates/view/small.haml +0 -12
- data/benchmark/bench_templates/view/small.lok +0 -21
- data/benchmark/bench_templates/view/small.xhtml +0 -21
- data/benchmark/results.txt +0 -131
- data/benchmark/run.rb +0 -355
- data/benchmark/suite/minimal.rb +0 -11
- data/benchmark/suite/no_informer.rb +0 -7
- data/benchmark/suite/no_sessions.rb +0 -9
- data/benchmark/suite/no_template.rb +0 -7
- data/benchmark/suite/simple.rb +0 -5
- data/benchmark/suite/template_erubis.rb +0 -8
- data/benchmark/suite/template_etanni.rb +0 -8
- data/benchmark/suite/template_ezamar.rb +0 -8
- data/benchmark/suite/template_haml.rb +0 -13
- data/benchmark/suite/template_liquid.rb +0 -11
- data/benchmark/suite/template_markaby.rb +0 -9
- data/benchmark/suite/template_nagoro.rb +0 -8
- data/benchmark/suite/template_redcloth.rb +0 -13
- data/benchmark/suite/template_tenjin.rb +0 -8
- data/benchmark/test.rb +0 -35
- data/doc/FAQ +0 -92
- data/doc/INSTALL +0 -92
- data/doc/TODO +0 -29
- data/doc/meta/announcement.txt +0 -119
- data/doc/meta/configuration.txt +0 -163
- data/doc/meta/internals.txt +0 -278
- data/doc/meta/users.kml +0 -64
- data/doc/tutorial/todolist.html +0 -1512
- data/doc/tutorial/todolist.txt +0 -920
- data/examples/app/sourceview/public/coderay.css +0 -104
- data/examples/app/sourceview/public/images/file.gif +0 -0
- data/examples/app/sourceview/public/images/folder.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item.gif +0 -0
- data/examples/app/sourceview/public/jquery.js +0 -11
- data/examples/app/sourceview/public/jquery.treeview.css +0 -48
- data/examples/app/sourceview/public/jquery.treeview.js +0 -223
- data/examples/app/sourceview/public/sourceview.js +0 -52
- data/examples/app/sourceview/start.rb +0 -79
- data/examples/app/sourceview/view/index.haml +0 -59
- data/examples/helpers/httpdigest.rb +0 -107
- data/lib/proto/public/css/screen.css +0 -30
- data/lib/proto/public/js/jquery.js +0 -7179
- data/lib/ramaze/contrib/addressable_route.rb +0 -56
- data/lib/ramaze/contrib/app_graph.rb +0 -64
- data/lib/ramaze/contrib/email.rb +0 -88
- data/lib/ramaze/contrib/facebook.rb +0 -23
- data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
- data/lib/ramaze/contrib/gettext.rb +0 -113
- data/lib/ramaze/contrib/gettext/mo.rb +0 -155
- data/lib/ramaze/contrib/gettext/parser.rb +0 -46
- data/lib/ramaze/contrib/gettext/po.rb +0 -109
- data/lib/ramaze/contrib/gzip_filter.rb +0 -1
- data/lib/ramaze/contrib/maruku_uv.rb +0 -59
- data/lib/ramaze/contrib/profiling.rb +0 -36
- data/lib/ramaze/contrib/rest.rb +0 -23
- data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
- data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
- data/lib/ramaze/contrib/sequel/image.rb +0 -196
- data/lib/ramaze/contrib/sequel/relation.rb +0 -98
- data/lib/ramaze/helper/httpdigest.rb +0 -96
- data/lib/ramaze/tool/bin.rb +0 -340
- data/lib/ramaze/tool/create.rb +0 -48
- data/lib/ramaze/tool/project_creator.rb +0 -120
- data/lib/ramaze/view/less.rb +0 -12
- data/lib/ramaze/view/maruku.rb +0 -15
- data/lib/ramaze/view/redcloth.rb +0 -21
- data/spec/contrib/addressable_route.rb +0 -30
- data/spec/examples/helpers/httpdigest.rb +0 -64
- data/spec/examples/templates/template_redcloth.rb +0 -13
- data/spec/ramaze/bin/ramaze.rb +0 -96
- data/spec/ramaze/helper/httpdigest.rb +0 -176
- data/spec/ramaze/view/less.rb +0 -60
- data/spec/ramaze/view/less/file.css.less +0 -8
- data/spec/ramaze/view/redcloth.rb +0 -66
- data/spec/ramaze/view/redcloth/external.redcloth +0 -8
- data/tasks/copyright.rake +0 -21
- data/tasks/gem_setup.rake +0 -112
- data/tasks/git.rake +0 -46
- data/tasks/grancher.rake +0 -12
- data/tasks/jquery.rake +0 -15
- data/tasks/manifest.rake +0 -4
- data/tasks/metric_changes.rake +0 -24
- data/tasks/reversion.rake +0 -8
- data/tasks/traits.rake +0 -21
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'irb'
|
2
|
+
require 'irb/completion'
|
3
|
+
|
4
|
+
module Ramaze
|
5
|
+
#:nodoc:
|
6
|
+
module Bin
|
7
|
+
##
|
8
|
+
# Allows the user to enter an IRB like session that takes advantage of
|
9
|
+
# everything provided by Ramaze.
|
10
|
+
#
|
11
|
+
# == Usage
|
12
|
+
#
|
13
|
+
# ramaze console
|
14
|
+
# ramaze console /path/to/app/start.rb
|
15
|
+
#
|
16
|
+
# @author Yorick Peterse
|
17
|
+
# @since 21-07-2011
|
18
|
+
#
|
19
|
+
class Console
|
20
|
+
# String containing the description of this command.
|
21
|
+
Description = 'Starts an IRB session with Ramaze loaded into the session'
|
22
|
+
|
23
|
+
# The banner that is displayed when the -h or --help option is specified.
|
24
|
+
Banner = <<-TXT.strip
|
25
|
+
Starts an IRB session and loads Ramaze into the session. All specified Rack
|
26
|
+
options are ignored and environment variables are passed to IRB.
|
27
|
+
|
28
|
+
Usage:
|
29
|
+
ramaze console [DIR] [OPTIONS]
|
30
|
+
|
31
|
+
Example:
|
32
|
+
ramaze console
|
33
|
+
ramaze console /home/foobar/ramaze/start.rb
|
34
|
+
TXT
|
35
|
+
|
36
|
+
##
|
37
|
+
# Creates a new instance of the command and sets all the options.
|
38
|
+
#
|
39
|
+
# @author Yorick Peterse
|
40
|
+
# @since 21-07-2011
|
41
|
+
#
|
42
|
+
def initialize
|
43
|
+
@options = OptionParser.new do |opt|
|
44
|
+
opt.banner = Banner
|
45
|
+
opt.summary_indent = ' '
|
46
|
+
|
47
|
+
opt.separator "\nOptions:\n"
|
48
|
+
|
49
|
+
opt.on('-h', '--help', 'Shows this help message') do
|
50
|
+
puts @options
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Runs the command based on the given command line arguments.
|
58
|
+
#
|
59
|
+
# @author Yorick Peterse
|
60
|
+
# @since 21-07-2011
|
61
|
+
# @param [Array] argv An array of command line arguments.
|
62
|
+
#
|
63
|
+
def run(argv = [])
|
64
|
+
@options.parse!(argv)
|
65
|
+
|
66
|
+
start_file = argv.delete_at(0)
|
67
|
+
start_file = File.join(Dir.pwd, 'start.rb') if start_file.nil?
|
68
|
+
|
69
|
+
if File.directory?(start_file)
|
70
|
+
start_file = File.join(start_file, 'start.rb')
|
71
|
+
end
|
72
|
+
|
73
|
+
if !File.exist?(start_file)
|
74
|
+
abort "The file #{start_file} does not exist"
|
75
|
+
end
|
76
|
+
|
77
|
+
start_file = Pathname.new(start_file).realpath.to_s
|
78
|
+
Ramaze.options.started = true
|
79
|
+
|
80
|
+
require(start_file)
|
81
|
+
|
82
|
+
IRB.start
|
83
|
+
puts 'Ramazement has ended, go in peace.'
|
84
|
+
end
|
85
|
+
end # Console
|
86
|
+
end # Bin
|
87
|
+
end # Ramaze
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Ramaze
|
4
|
+
#:nodoc:
|
5
|
+
module Bin
|
6
|
+
##
|
7
|
+
# Simple command that allows users to easily create a new application based
|
8
|
+
# on the prototype that ships with Ramaze.
|
9
|
+
#
|
10
|
+
# == Usage
|
11
|
+
#
|
12
|
+
# ramaze create blog
|
13
|
+
#
|
14
|
+
# @author Yorick Peterse
|
15
|
+
# @since 21-07-2011
|
16
|
+
#
|
17
|
+
class Create
|
18
|
+
# The description of this command as shown in the global help message.
|
19
|
+
Description = 'Allows developers to easily create new Ramaze applications.'
|
20
|
+
|
21
|
+
# The banner of this command.
|
22
|
+
Banner = <<-TXT.strip
|
23
|
+
Allows developers to easily create new Ramaze applications based on the
|
24
|
+
prototype that ships with Ramaze.
|
25
|
+
|
26
|
+
Usage:
|
27
|
+
ramaze create [NAME] [OPTIONS]
|
28
|
+
|
29
|
+
Example:
|
30
|
+
ramaze create blog
|
31
|
+
TXT
|
32
|
+
|
33
|
+
##
|
34
|
+
# Creates a new instance of the command and sets the options for
|
35
|
+
# OptionParser.
|
36
|
+
#
|
37
|
+
# @author Yorick Peterse
|
38
|
+
# @since 21-07-2011
|
39
|
+
#
|
40
|
+
def initialize
|
41
|
+
@options = {
|
42
|
+
:force => false
|
43
|
+
}
|
44
|
+
|
45
|
+
@opts = OptionParser.new do |opt|
|
46
|
+
opt.banner = Banner
|
47
|
+
opt.summary_indent = ' '
|
48
|
+
|
49
|
+
opt.separator "\nOptions:\n"
|
50
|
+
|
51
|
+
opt.on('-f', '--force', 'Overwrites existing directories') do
|
52
|
+
@options[:force] = true
|
53
|
+
end
|
54
|
+
|
55
|
+
opt.on('-h', '--help', 'Shows this help message') do
|
56
|
+
puts @opts
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Runs the command based on the specified command line arguments.
|
64
|
+
#
|
65
|
+
# @author Yorick Peterse
|
66
|
+
# @since 21-07-2011
|
67
|
+
# @param [Array] argv Array containing all command line arguments.
|
68
|
+
#
|
69
|
+
def run(argv = [])
|
70
|
+
@opts.parse!(argv)
|
71
|
+
|
72
|
+
path = argv.delete_at(0)
|
73
|
+
proto = __DIR__('../../proto')
|
74
|
+
|
75
|
+
abort 'You need to specify a name for your application' if path.nil?
|
76
|
+
|
77
|
+
if File.directory?(path) and @options[:force] === false
|
78
|
+
abort 'The specified application already exists, use -f to overwrite it'
|
79
|
+
end
|
80
|
+
|
81
|
+
if File.directory?(path) and @options[:force] === true
|
82
|
+
FileUtils.rm_rf(path)
|
83
|
+
end
|
84
|
+
|
85
|
+
begin
|
86
|
+
FileUtils.cp_r(proto, path)
|
87
|
+
puts "The application has been generated and saved in #{path}"
|
88
|
+
rescue
|
89
|
+
abort 'The application could not be generated'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end # Create
|
93
|
+
end # Bin
|
94
|
+
end # Ramaze
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module Ramaze
|
2
|
+
#:nodoc:
|
3
|
+
module Bin
|
4
|
+
##
|
5
|
+
# Module containing various helper methods useful for most commands.
|
6
|
+
#
|
7
|
+
# @author Yorick Peterse
|
8
|
+
# @author TJ Vanderpoel
|
9
|
+
# @since 21-07-2011
|
10
|
+
#
|
11
|
+
module Helper
|
12
|
+
##
|
13
|
+
# Checks if the specified PID points to a process that's already running.
|
14
|
+
#
|
15
|
+
# @author TJ Vanderpoel
|
16
|
+
# @since 21-07-2011
|
17
|
+
# @param [String] pid The path to the PID.
|
18
|
+
# @return [TrueClass|FalseClass]
|
19
|
+
#
|
20
|
+
def is_running?(pid)
|
21
|
+
return false if !File.exist?(pid)
|
22
|
+
|
23
|
+
pid = File.read(pid).to_i
|
24
|
+
|
25
|
+
if is_windows?
|
26
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
27
|
+
processes, ours = wmi.ExecQuery(
|
28
|
+
"select * from win32_process where ProcessId = #{pid}"
|
29
|
+
), []
|
30
|
+
|
31
|
+
processes.each { |process| ours << process.Name }
|
32
|
+
|
33
|
+
return ours.first.nil?
|
34
|
+
else
|
35
|
+
begin
|
36
|
+
prio = Process.getpriority(Process::PRIO_PROCESS, pid)
|
37
|
+
return true
|
38
|
+
rescue Errno::ESRCH
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Checks if the system the user is using is Windows.
|
46
|
+
#
|
47
|
+
# @author TJ Vanderpoel
|
48
|
+
# @since 21-07-2011
|
49
|
+
# @return [TrueClass|FalseClass]
|
50
|
+
#
|
51
|
+
def is_windows?
|
52
|
+
return @is_win if @is_win
|
53
|
+
|
54
|
+
begin; require "win32ole"; rescue LoadError; end
|
55
|
+
|
56
|
+
@is_win ||= Object.const_defined?("WIN32OLE")
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Tries to extract the path to the Rackup executable.
|
61
|
+
#
|
62
|
+
# @author TJ Vanderpoel
|
63
|
+
# @since 21-07-2001
|
64
|
+
# @return [String]
|
65
|
+
#
|
66
|
+
def rackup_path
|
67
|
+
return @rackup_path if @rackup_path
|
68
|
+
|
69
|
+
# Check with 'which' on platforms which support it
|
70
|
+
unless is_windows?
|
71
|
+
@rackup_path = %x{which rackup}.to_s.chomp
|
72
|
+
|
73
|
+
if @rackup_path.size > 0 and File.file?(@rackup_path)
|
74
|
+
return @rackup_path
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# check for rackup in RUBYLIB
|
79
|
+
libs = ENV["RUBYLIB"].to_s.split(is_windows? ? ";" : ":")
|
80
|
+
|
81
|
+
if rack_lib = libs.detect { |r| r.match %r<(\\|/)rack\1> }
|
82
|
+
require "pathname"
|
83
|
+
@rackup_path = Pathname.new(rack_lib).parent.join("bin").join(
|
84
|
+
"rackup"
|
85
|
+
).expand_path
|
86
|
+
|
87
|
+
return @rackup_path if File.file?(@rackup_path)
|
88
|
+
end
|
89
|
+
|
90
|
+
begin
|
91
|
+
require "rubygems"
|
92
|
+
require "rack"
|
93
|
+
require "pathname"
|
94
|
+
|
95
|
+
@rackup_path = Pathname.new(Gem.bindir).join("rackup").to_s
|
96
|
+
|
97
|
+
return @rackup_path if File.file?(@rackup_path)
|
98
|
+
rescue LoadError
|
99
|
+
nil
|
100
|
+
end
|
101
|
+
|
102
|
+
@rackup_path = nil
|
103
|
+
abort "Cannot find the path to the Rackup executable"
|
104
|
+
end
|
105
|
+
end # Helper
|
106
|
+
end # Bin
|
107
|
+
end # Ramaze
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Ramaze
|
2
|
+
#:nodoc:
|
3
|
+
module Bin
|
4
|
+
##
|
5
|
+
# Restarts an application based on a specified directory/rackup file and
|
6
|
+
# PID. The PID is used to kill the process, the Rackup file is used to start
|
7
|
+
# the process again after it has been killed.
|
8
|
+
#
|
9
|
+
# == Usage
|
10
|
+
#
|
11
|
+
# ramaze restart
|
12
|
+
# ramaze restart /home/foobar/projects/ramaze/ \
|
13
|
+
# -P /home/foobar/projects/ramaze/ramaze.pid
|
14
|
+
#
|
15
|
+
# @author Yorick Peterse
|
16
|
+
# @since 21-07-2011
|
17
|
+
#
|
18
|
+
class Restart
|
19
|
+
# The description of this command, displayed in the global help message.
|
20
|
+
Description = 'Restarts an application'
|
21
|
+
|
22
|
+
# The banner, displayed when the -h or --help option is specified.
|
23
|
+
Banner = <<-TXT.strip
|
24
|
+
Restarts an active Ramaze application.
|
25
|
+
|
26
|
+
Usage:
|
27
|
+
ramaze restart [RACKUP] [OPTIONS]
|
28
|
+
|
29
|
+
Example:
|
30
|
+
ramaze restart config.ru -P ramaze.pid
|
31
|
+
TXT
|
32
|
+
|
33
|
+
##
|
34
|
+
# Creates a new instance of the command and sets all the options.
|
35
|
+
#
|
36
|
+
# @author Yorick Peterse
|
37
|
+
# @since 21-07-2011
|
38
|
+
#
|
39
|
+
def initialize
|
40
|
+
@options = OptionParser.new do |opt|
|
41
|
+
opt.banner = Banner
|
42
|
+
opt.summary_indent = ' '
|
43
|
+
|
44
|
+
opt.separator "\nOptions:\n"
|
45
|
+
|
46
|
+
opt.on('-h', '--help', 'Shows this help message') do
|
47
|
+
puts @options
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
opt.on(
|
52
|
+
'-P',
|
53
|
+
'--pid FILE',
|
54
|
+
'Uses the PID to kill the application'
|
55
|
+
) do |pid|
|
56
|
+
@pid = pid
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Runs the command based on the specified command line arguments.
|
63
|
+
#
|
64
|
+
# @author Yorick Peterse
|
65
|
+
# @since 21-07-2011
|
66
|
+
# @param [Array] argv An array containing all command line arguments.
|
67
|
+
#
|
68
|
+
def run(argv = [])
|
69
|
+
@options.parse!(argv)
|
70
|
+
|
71
|
+
@rackup = argv.delete_at(0)
|
72
|
+
@rackup = File.join(Dir.pwd, 'config.ru') if @rackup.nil?
|
73
|
+
|
74
|
+
if File.directory?(@rackup)
|
75
|
+
@rackup = File.join(@rackup, 'config.ru')
|
76
|
+
end
|
77
|
+
|
78
|
+
if !File.exist?(@rackup)
|
79
|
+
abort "The Rackup file #{@rackup} does not exist"
|
80
|
+
end
|
81
|
+
|
82
|
+
stop = Ramaze::Bin::Runner::Commands[:stop].new
|
83
|
+
start = Ramaze::Bin::Runner::Commands[:start].new
|
84
|
+
params = [@rackup]
|
85
|
+
|
86
|
+
unless @pid.nil?
|
87
|
+
params.push("-P #{@pid}")
|
88
|
+
end
|
89
|
+
|
90
|
+
stop.run([@pid])
|
91
|
+
start.run(params)
|
92
|
+
end
|
93
|
+
end # Restart
|
94
|
+
end # Bin
|
95
|
+
end # Ramaze
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
require __DIR__('helper')
|
5
|
+
require __DIR__('start')
|
6
|
+
require __DIR__('restart')
|
7
|
+
require __DIR__('stop')
|
8
|
+
require __DIR__('create')
|
9
|
+
require __DIR__('status')
|
10
|
+
require __DIR__('console')
|
11
|
+
|
12
|
+
module Ramaze
|
13
|
+
#:nodoc:
|
14
|
+
module Bin
|
15
|
+
##
|
16
|
+
# Module used for running a particular command based on the specified
|
17
|
+
# command line arguments.
|
18
|
+
#
|
19
|
+
# == Usage
|
20
|
+
#
|
21
|
+
# ramaze --help # Shows a help message
|
22
|
+
# ramaze -h # Shows a help message as well
|
23
|
+
# ramaze -v # Shows the version of Ramaze
|
24
|
+
#
|
25
|
+
# ramaze [COMMAND] # Runs [COMMAND]
|
26
|
+
#
|
27
|
+
# @author Yorick Peterse
|
28
|
+
# @since 21-07-2011
|
29
|
+
#
|
30
|
+
module Runner
|
31
|
+
# Hash containing all the available commands, their names and their
|
32
|
+
# classes.
|
33
|
+
Commands = {
|
34
|
+
:start => Ramaze::Bin::Start,
|
35
|
+
:stop => Ramaze::Bin::Stop,
|
36
|
+
:restart => Ramaze::Bin::Restart,
|
37
|
+
:status => Ramaze::Bin::Status,
|
38
|
+
:create => Ramaze::Bin::Create,
|
39
|
+
:console => Ramaze::Bin::Console,
|
40
|
+
}
|
41
|
+
|
42
|
+
# String containing the banner of the main command.
|
43
|
+
Banner = <<-TXT.strip
|
44
|
+
Ramaze is a simple, light and modular open-source web application
|
45
|
+
framework written in Ruby.
|
46
|
+
|
47
|
+
Usage:
|
48
|
+
ramaze [COMMAND] [OPTIONS]
|
49
|
+
|
50
|
+
Example:
|
51
|
+
ramaze create blog
|
52
|
+
TXT
|
53
|
+
|
54
|
+
##
|
55
|
+
# Runs a particular command based on the specified array.
|
56
|
+
#
|
57
|
+
# @example
|
58
|
+
# Ramaze::Bin::Runner.run(ARGV)
|
59
|
+
# Ramaze::Bin::Runner.run(['start', '--help'])
|
60
|
+
#
|
61
|
+
# @author Yorick Peterse
|
62
|
+
# @since 21-07-2011
|
63
|
+
# @param [Array] argv An array containing command line arguments, set to
|
64
|
+
# ARGV by default.
|
65
|
+
#
|
66
|
+
def self.run(argv=ARGV)
|
67
|
+
op = OptionParser.new do |opt|
|
68
|
+
opt.banner = Banner
|
69
|
+
opt.summary_indent = ' '
|
70
|
+
|
71
|
+
opt.separator "\nCommands:\n #{commands_info.join("\n ")}"
|
72
|
+
|
73
|
+
# Show all the common options
|
74
|
+
opt.separator "\nOptions:\n"
|
75
|
+
|
76
|
+
# Show the version of Ramaze
|
77
|
+
opt.on('-v', '--version', 'Shows the version of Ramaze') do
|
78
|
+
puts Ramaze::VERSION
|
79
|
+
exit
|
80
|
+
end
|
81
|
+
|
82
|
+
opt.on('-h', '--help', 'Shows this help message') do
|
83
|
+
puts op
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
op.order!(argv)
|
89
|
+
|
90
|
+
# Show a help message if no command has been specified
|
91
|
+
if !argv[0]
|
92
|
+
puts op.to_s
|
93
|
+
exit
|
94
|
+
end
|
95
|
+
|
96
|
+
cmd = argv.delete_at(0).to_sym
|
97
|
+
|
98
|
+
if Commands.key?(cmd)
|
99
|
+
cmd = Commands[cmd].new
|
100
|
+
cmd.run(argv)
|
101
|
+
else
|
102
|
+
abort 'The specified command is invalid'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Generates an array of "rows" where each row contains the name and
|
108
|
+
# description of a command. The descriptions of all commands are aligned
|
109
|
+
# based on the length of the longest command name.
|
110
|
+
#
|
111
|
+
# @author Yorick Peterse
|
112
|
+
# @since 21-07-2011
|
113
|
+
# @return [Array]
|
114
|
+
#
|
115
|
+
def self.commands_info
|
116
|
+
cmds = []
|
117
|
+
longest = Commands.map { |name, klass| name.to_s }.sort[0].size
|
118
|
+
|
119
|
+
Commands.each do |name, klass|
|
120
|
+
name = name.to_s
|
121
|
+
desc = ''
|
122
|
+
|
123
|
+
# Try to extract the command description
|
124
|
+
if klass.respond_to?(:const_defined?) \
|
125
|
+
and klass.const_defined?(:Description)
|
126
|
+
desc = klass.const_get(:Description)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Align the description based on the length of the name
|
130
|
+
while name.size <= longest do
|
131
|
+
name += ' '
|
132
|
+
end
|
133
|
+
|
134
|
+
cmds.push(["#{name} #{desc}"])
|
135
|
+
end
|
136
|
+
|
137
|
+
return cmds
|
138
|
+
end
|
139
|
+
end # Runner
|
140
|
+
end # Bin
|
141
|
+
end # Ramaze
|