ginatra 2.0.2 → 2.1.0
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.
- data/.gitignore +3 -0
- data/README.md +51 -44
- data/VERSION +1 -1
- data/ginatra.gemspec +6 -18
- data/lib/ginatra/config.rb +41 -1
- data/lib/ginatra/helpers.rb +130 -9
- data/lib/ginatra/repo.rb +40 -4
- data/lib/ginatra/repo_list.rb +42 -1
- data/lib/ginatra.rb +93 -2
- metadata +3 -16
- data/vendor/vegas/History.txt +0 -18
- data/vendor/vegas/LICENSE +0 -22
- data/vendor/vegas/Manifest.txt +0 -5
- data/vendor/vegas/README.rdoc +0 -45
- data/vendor/vegas/Rakefile +0 -32
- data/vendor/vegas/lib/vegas/runner.rb +0 -270
- data/vendor/vegas/lib/vegas.rb +0 -16
- data/vendor/vegas/test/test_app/bin/test_app +0 -9
- data/vendor/vegas/test/test_app/test_app.rb +0 -10
- data/vendor/vegas/test/test_apps.rb +0 -22
- data/vendor/vegas/test/test_helper.rb +0 -59
- data/vendor/vegas/test/test_vegas_runner.rb +0 -8
- data/vendor/vegas/vegas.gemspec +0 -45
data/lib/ginatra.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
+
# We only want Rubygems if it exists. Else, we assume they know what they're doing.
|
2
|
+
begin
|
3
|
+
require 'rubygems'
|
4
|
+
rescue LoadError
|
5
|
+
end
|
1
6
|
require 'sinatra/base'
|
2
7
|
require 'grit'
|
3
8
|
require 'coderay'
|
4
9
|
|
5
10
|
current_path = File.expand_path(File.dirname(__FILE__))
|
6
11
|
|
12
|
+
# The Ginatra Namespace Module
|
7
13
|
module Ginatra; end
|
8
14
|
|
9
15
|
# Loading in reverse because RepoList needs to be loaded before MultiRepoList
|
@@ -14,9 +20,16 @@ require "#{current_path}/sinatra/partials"
|
|
14
20
|
# Written myself. i know, what the hell?!
|
15
21
|
module Ginatra
|
16
22
|
|
23
|
+
# A standard error class for inheritance.
|
24
|
+
# @todo Look for a refactor.
|
17
25
|
class Error < StandardError; end
|
26
|
+
|
27
|
+
# An error related to a commit somewhere.
|
28
|
+
# @todo Look for a refactor.
|
18
29
|
class CommitsError < Error; end
|
19
|
-
|
30
|
+
|
31
|
+
# Error raised when commit ref passed in parameters
|
32
|
+
# does not exist in repository
|
20
33
|
class InvalidCommit < Error
|
21
34
|
def initialize(id)
|
22
35
|
super("Could not find a commit with the id of #{id}")
|
@@ -24,8 +37,13 @@ module Ginatra
|
|
24
37
|
end
|
25
38
|
|
26
39
|
current_path = File.expand_path(File.dirname(__FILE__))
|
40
|
+
# @todo look for a refactor that is rip compatible
|
27
41
|
VERSION = File.new("#{current_path}/../VERSION").read
|
28
42
|
|
43
|
+
# The main application class.
|
44
|
+
#
|
45
|
+
# This class contains all the core application logic
|
46
|
+
# and is what is mounted by the +rackup.ru+ files.
|
29
47
|
class App < Sinatra::Base
|
30
48
|
|
31
49
|
configure do
|
@@ -42,18 +60,36 @@ module Ginatra
|
|
42
60
|
end
|
43
61
|
|
44
62
|
helpers do
|
63
|
+
|
64
|
+
# Ginatra::Helpers module full of goodness
|
45
65
|
include Helpers
|
66
|
+
|
67
|
+
# My Sinatra Partials implementation.
|
68
|
+
#
|
69
|
+
# check out http://gist.github.com/119874
|
70
|
+
# for more details
|
46
71
|
include ::Sinatra::Partials
|
47
72
|
end
|
48
73
|
|
74
|
+
# Let's handle a CommitsError.
|
75
|
+
#
|
76
|
+
# @todo prettify
|
49
77
|
error CommitsError do
|
50
78
|
'No commits were returned for ' + request.uri
|
51
79
|
end
|
52
80
|
|
81
|
+
# The root route
|
82
|
+
#
|
83
|
+
# @todo how does this work?
|
53
84
|
get '/' do
|
54
85
|
erb :index
|
55
86
|
end
|
56
87
|
|
88
|
+
# The atom feed of recent commits to a +repo+.
|
89
|
+
#
|
90
|
+
# This only returns commits to the +master+ branch.
|
91
|
+
#
|
92
|
+
# @param [String] repo the repository url-sanitised-name
|
57
93
|
get '/:repo.atom' do
|
58
94
|
@repo = RepoList.find(params[:repo])
|
59
95
|
@commits = @repo.commits
|
@@ -62,6 +98,11 @@ module Ginatra
|
|
62
98
|
builder :atom, :layout => nil
|
63
99
|
end
|
64
100
|
|
101
|
+
# The html page for a +repo+.
|
102
|
+
#
|
103
|
+
# Shows the most recent commits in a log format
|
104
|
+
#
|
105
|
+
# @param [String] repo the repository url-sanitised-name
|
65
106
|
get '/:repo' do
|
66
107
|
@repo = RepoList.find(params[:repo])
|
67
108
|
@commits = @repo.commits
|
@@ -69,6 +110,10 @@ module Ginatra
|
|
69
110
|
erb :log
|
70
111
|
end
|
71
112
|
|
113
|
+
# The atom feed of recent commits to a certain branch of a +repo+.
|
114
|
+
#
|
115
|
+
# @param [String] repo the repository url-sanitised-name
|
116
|
+
# @param [String] ref the repository ref
|
72
117
|
get '/:repo/:ref.atom' do
|
73
118
|
@repo = RepoList.find(params[:repo])
|
74
119
|
@commits = @repo.commits(params[:ref])
|
@@ -77,6 +122,12 @@ module Ginatra
|
|
77
122
|
builder :atom, :layout => nil
|
78
123
|
end
|
79
124
|
|
125
|
+
# The html page for a given +ref+ of a +repo+.
|
126
|
+
#
|
127
|
+
# Shows the most recent commits in a log format
|
128
|
+
#
|
129
|
+
# @param [String] repo the repository url-sanitised-name
|
130
|
+
# @param [String] ref the repository ref
|
80
131
|
get '/:repo/:ref' do
|
81
132
|
params[:page] = 1
|
82
133
|
@repo = RepoList.find(params[:repo])
|
@@ -85,12 +136,20 @@ module Ginatra
|
|
85
136
|
erb :log
|
86
137
|
end
|
87
138
|
|
139
|
+
# The patch file for a given commit to a +repo+.
|
140
|
+
#
|
141
|
+
# @param [String] repo the repository url-sanitised-name
|
142
|
+
# @param [String] commit the repository commit
|
88
143
|
get '/:repo/commit/:commit.patch' do
|
89
144
|
response['Content-Type'] = "text/plain"
|
90
145
|
@repo = RepoList.find(params[:repo])
|
91
146
|
@repo.git.format_patch({}, "--stdout", "-1", params[:commit])
|
92
147
|
end
|
93
148
|
|
149
|
+
# The html representation of a commit.
|
150
|
+
#
|
151
|
+
# @param [String] repo the repository url-sanitised-name
|
152
|
+
# @param [String] commit the repository commit
|
94
153
|
get '/:repo/commit/:commit' do
|
95
154
|
@repo = RepoList.find(params[:repo])
|
96
155
|
@commit = @repo.commit(params[:commit]) # can also be a ref
|
@@ -98,12 +157,21 @@ module Ginatra
|
|
98
157
|
erb(:commit)
|
99
158
|
end
|
100
159
|
|
160
|
+
# Download an archive of a given tree!
|
161
|
+
#
|
162
|
+
# @param [String] repo the repository url-sanitised-name
|
163
|
+
# @param [String] tree the repository tree
|
101
164
|
get '/:repo/archive/:tree.tar.gz' do
|
102
165
|
response['Content-Type'] = "application/x-tar-gz"
|
103
166
|
@repo = RepoList.find(params[:repo])
|
104
167
|
@repo.archive_tar_gz(params[:tree])
|
105
168
|
end
|
106
169
|
|
170
|
+
# HTML page for a given tree in a given +repo+
|
171
|
+
#
|
172
|
+
# @todo cleanup!
|
173
|
+
# @param [String] repo the repository url-sanitised-name
|
174
|
+
# @param [String] tree the repository tree
|
107
175
|
get '/:repo/tree/:tree' do
|
108
176
|
@repo = RepoList.find(params[:repo])
|
109
177
|
|
@@ -121,6 +189,13 @@ module Ginatra
|
|
121
189
|
erb(:tree)
|
122
190
|
end
|
123
191
|
|
192
|
+
# HTML page for a given tree in a given +repo+.
|
193
|
+
#
|
194
|
+
# This one supports a splat parameter so you can specify a path
|
195
|
+
#
|
196
|
+
# @todo cleanup!
|
197
|
+
# @param [String] repo the repository url-sanitised-name
|
198
|
+
# @param [String] tree the repository tree
|
124
199
|
get '/:repo/tree/:tree/*' do # for when we specify a path
|
125
200
|
@repo = RepoList.find(params[:repo])
|
126
201
|
@tree = @repo.tree(params[:tree])/params[:splat].first # can also be a ref (i think)
|
@@ -137,6 +212,10 @@ module Ginatra
|
|
137
212
|
end
|
138
213
|
end
|
139
214
|
|
215
|
+
# HTML page for a given blob in a given +repo+
|
216
|
+
#
|
217
|
+
# @param [String] repo the repository url-sanitised-name
|
218
|
+
# @param [String] tree the repository tree
|
140
219
|
get '/:repo/blob/:blob' do
|
141
220
|
@repo = RepoList.find(params[:repo])
|
142
221
|
@blob = @repo.blob(params[:blob])
|
@@ -144,6 +223,13 @@ module Ginatra
|
|
144
223
|
erb(:blob)
|
145
224
|
end
|
146
225
|
|
226
|
+
# HTML page for a given blob in a given repo.
|
227
|
+
#
|
228
|
+
# Uses a splat param to specify a blob path.
|
229
|
+
#
|
230
|
+
# @todo cleanup!
|
231
|
+
# @param [String] repo the repository url-sanitised-name
|
232
|
+
# @param [String] tree the repository tree
|
147
233
|
get '/:repo/blob/:tree/*' do
|
148
234
|
@repo = RepoList.find(params[:repo])
|
149
235
|
@blob = @repo.tree(params[:tree])/params[:splat].first
|
@@ -167,13 +253,18 @@ module Ginatra
|
|
167
253
|
end
|
168
254
|
end
|
169
255
|
|
256
|
+
# pagination route for the commits to a given ref in a +repo+.
|
257
|
+
#
|
258
|
+
# @todo cleanup!
|
259
|
+
# @param [String] repo the repository url-sanitised-name
|
260
|
+
# @param [String] ref the repository ref
|
170
261
|
get '/:repo/:ref/:page' do
|
171
262
|
pass unless params[:page] =~ /^(\d)+$/
|
172
263
|
params[:page] = params[:page].to_i
|
173
264
|
@repo = RepoList.find(params[:repo])
|
174
265
|
@commits = @repo.commits(params[:ref], 10, (params[:page] - 1) * 10)
|
175
266
|
@next_commits = !@repo.commits(params[:ref], 10, params[:page] * 10).empty?
|
176
|
-
if params[:page] - 1 > 0
|
267
|
+
if params[:page] - 1 > 0
|
177
268
|
@previous_commits = !@repo.commits(params[:ref], 10, (params[:page] - 1) * 10).empty?
|
178
269
|
end
|
179
270
|
@separator = @next_commits && @previous_commits
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ginatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Elliott
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-12-28 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -101,19 +101,6 @@ files:
|
|
101
101
|
- spec/repo_list_spec.rb
|
102
102
|
- spec/repo_spec.rb
|
103
103
|
- spec/spec_helper.rb
|
104
|
-
- vendor/vegas/History.txt
|
105
|
-
- vendor/vegas/LICENSE
|
106
|
-
- vendor/vegas/Manifest.txt
|
107
|
-
- vendor/vegas/README.rdoc
|
108
|
-
- vendor/vegas/Rakefile
|
109
|
-
- vendor/vegas/lib/vegas.rb
|
110
|
-
- vendor/vegas/lib/vegas/runner.rb
|
111
|
-
- vendor/vegas/test/test_app/bin/test_app
|
112
|
-
- vendor/vegas/test/test_app/test_app.rb
|
113
|
-
- vendor/vegas/test/test_apps.rb
|
114
|
-
- vendor/vegas/test/test_helper.rb
|
115
|
-
- vendor/vegas/test/test_vegas_runner.rb
|
116
|
-
- vendor/vegas/vegas.gemspec
|
117
104
|
- views/_actor_box.erb
|
118
105
|
- views/_commit_info_box.erb
|
119
106
|
- views/_header.erb
|
@@ -149,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
136
|
requirements: []
|
150
137
|
|
151
138
|
rubyforge_project:
|
152
|
-
rubygems_version: 1.3.
|
139
|
+
rubygems_version: 1.3.5
|
153
140
|
signing_key:
|
154
141
|
specification_version: 3
|
155
142
|
summary: A Gitweb Clone in Sinatra and Grit
|
data/vendor/vegas/History.txt
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
== 0.0.4 2009-08-09
|
2
|
-
|
3
|
-
* new -L (--skip-launch) option doesn't launch the web browser (thanks bmabey!)
|
4
|
-
* rubygems is required only on LoadError
|
5
|
-
|
6
|
-
== 0.0.3 2009-07-06
|
7
|
-
|
8
|
-
* Vegas::Runner is now Windows compatible (require win32-process gem)
|
9
|
-
* Includes daemon-ization
|
10
|
-
* PID tracking
|
11
|
-
* Vegas::WINDOWS is a top level boolean
|
12
|
-
* Vegas is no longer dependent on Launchy
|
13
|
-
* launching browser is done simply with open/start depending on platform
|
14
|
-
|
15
|
-
== 0.0.1 2009-04-13
|
16
|
-
|
17
|
-
* 1 major enhancement:
|
18
|
-
* Initial release
|
data/vendor/vegas/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
(The MIT License)
|
2
|
-
|
3
|
-
Copyright (c) 2009 Aaron Quint, Quirkey NYC, LLC.
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
'Software'), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/vendor/vegas/Manifest.txt
DELETED
data/vendor/vegas/README.rdoc
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
= vegas
|
2
|
-
|
3
|
-
http://code.quirkey.com/vegas
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps.
|
8
|
-
|
9
|
-
== FEATURES/PROBLEMS:
|
10
|
-
|
11
|
-
Currently, Vegas just includes a single class Vegas::Runner which wraps your Sinatra app to give it command line options, daemonization, PID/URL tracking, and browser launching (using Launchy).
|
12
|
-
|
13
|
-
Lets say you have a gem with a sinatra application. With Vegas you can create a bin that looks like
|
14
|
-
|
15
|
-
#!/usr/bin/env ruby
|
16
|
-
# ./bin/myapp
|
17
|
-
|
18
|
-
require File.expand_path(File.dirname(__FILE__) + "/../lib/myapp")
|
19
|
-
require 'vegas'
|
20
|
-
|
21
|
-
Vegas::Runner.new(Sinatra::Application, 'myapp')
|
22
|
-
|
23
|
-
|
24
|
-
See the website: http://code.quirkey.com/vegas for full usage/options.
|
25
|
-
|
26
|
-
=== WINDOWS:
|
27
|
-
|
28
|
-
Using vegas (and gems that depend on it) on Windows works but isn't 100% the same.
|
29
|
-
Daemon-ization and browser launching work, but you will see duplicate messages.
|
30
|
-
|
31
|
-
If you see a warning like:
|
32
|
-
|
33
|
-
`expand_path': couldn't find HOME environment -- expanding `~/.vegas' (ArgumentError)
|
34
|
-
|
35
|
-
You have to set your HOME path:
|
36
|
-
|
37
|
-
c:\> set HOME=%HOMEPATH%
|
38
|
-
|
39
|
-
== INSTALL:
|
40
|
-
|
41
|
-
sudo gem install vegas
|
42
|
-
|
43
|
-
== LICENSE:
|
44
|
-
|
45
|
-
MIT LICENSE, see LICENSE for details
|
data/vendor/vegas/Rakefile
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
%w[rubygems rake rake/clean hoe fileutils newgem rubigen].each { |f| require f }
|
2
|
-
require File.dirname(__FILE__) + '/lib/vegas'
|
3
|
-
|
4
|
-
# Generate all the Rake tasks
|
5
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
-
$hoe = Hoe.spec('vegas') do |p|
|
7
|
-
p.version = Vegas::VERSION
|
8
|
-
p.developer('Aaron Quint', 'aaron@quirkey.com')
|
9
|
-
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
10
|
-
p.summary = "Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps."
|
11
|
-
p.description = %{Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps. It includes a class Vegas::Runner that wraps Rack/Sinatra applications and provides a simple command line interface and launching mechanism.}
|
12
|
-
p.rubyforge_name = 'quirkey'
|
13
|
-
p.extra_deps = [
|
14
|
-
['sinatra','>= 0.9.1']
|
15
|
-
]
|
16
|
-
p.extra_dev_deps = [
|
17
|
-
['newgem', ">= #{::Newgem::VERSION}"],
|
18
|
-
['nokogiri', ">= 1.0.6"],
|
19
|
-
['bacon', ">= 1.1.0"]
|
20
|
-
]
|
21
|
-
|
22
|
-
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
23
|
-
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
24
|
-
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
25
|
-
p.rsync_args = '-av --delete --ignore-errors'
|
26
|
-
end
|
27
|
-
|
28
|
-
require 'newgem/tasks' # load /tasks/*.rake
|
29
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
30
|
-
|
31
|
-
# TODO - want other tests/tasks run by default? Add them to the list
|
32
|
-
# task :default => [:spec, :features]
|
@@ -1,270 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'logger'
|
3
|
-
require 'optparse'
|
4
|
-
|
5
|
-
if Vegas::WINDOWS
|
6
|
-
begin
|
7
|
-
require 'win32/process'
|
8
|
-
rescue
|
9
|
-
puts "Sorry, in order to use Vegas on Windows you need the win32-process gem:\n gem install win32-process"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module Vegas
|
14
|
-
class Runner
|
15
|
-
attr_reader :app, :app_name, :rack_handler, :port, :host, :options
|
16
|
-
|
17
|
-
ROOT_DIR = File.expand_path(File.join('~', '.vegas'))
|
18
|
-
PORT = 5678
|
19
|
-
HOST = WINDOWS ? 'localhost' : '0.0.0.0'
|
20
|
-
|
21
|
-
def initialize(app, app_name, set_options = {}, &block)
|
22
|
-
# initialize
|
23
|
-
@app = app
|
24
|
-
@app_name = app_name
|
25
|
-
@options = set_options || {}
|
26
|
-
@rack_handler = @app.send :detect_rack_handler
|
27
|
-
# load options from opt parser
|
28
|
-
define_options do |opts|
|
29
|
-
if block_given?
|
30
|
-
opts.separator ''
|
31
|
-
opts.separator "#{app_name} options:"
|
32
|
-
yield(self, opts, app)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
# set app options
|
36
|
-
@host = options[:host] || HOST
|
37
|
-
@app.set options
|
38
|
-
# initialize app dir
|
39
|
-
FileUtils.mkdir_p(app_dir)
|
40
|
-
|
41
|
-
return if options[:start] === false
|
42
|
-
|
43
|
-
logger.info "Running with Windows Settings" if WINDOWS
|
44
|
-
logger.info "Starting #{app_name}"
|
45
|
-
|
46
|
-
check_for_running
|
47
|
-
find_port
|
48
|
-
write_url
|
49
|
-
start
|
50
|
-
end
|
51
|
-
|
52
|
-
def app_dir
|
53
|
-
File.join(ROOT_DIR, app_name)
|
54
|
-
end
|
55
|
-
|
56
|
-
def pid_file
|
57
|
-
File.join(app_dir, "#{app_name}.pid")
|
58
|
-
end
|
59
|
-
|
60
|
-
def url_file
|
61
|
-
File.join(app_dir, "#{app_name}.url")
|
62
|
-
end
|
63
|
-
|
64
|
-
def url
|
65
|
-
"http://#{host}:#{port}"
|
66
|
-
end
|
67
|
-
|
68
|
-
def log_file
|
69
|
-
File.join(app_dir, "#{app_name}.log")
|
70
|
-
end
|
71
|
-
|
72
|
-
def handler_name
|
73
|
-
rack_handler.name.gsub(/.*::/, '')
|
74
|
-
end
|
75
|
-
|
76
|
-
def find_port
|
77
|
-
if @port = options[:port]
|
78
|
-
if !port_open?
|
79
|
-
logger.warn "Port #{port} is already in use. Please try another or don't use -P, for auto-port"
|
80
|
-
end
|
81
|
-
else
|
82
|
-
@port = PORT
|
83
|
-
logger.info "Trying to start #{app_name} on Port #{port}"
|
84
|
-
while !port_open?
|
85
|
-
@port += 1
|
86
|
-
logger.info "Trying to start #{app_name} on Port #{port}"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def port_open?(check_url = nil)
|
92
|
-
begin
|
93
|
-
open(check_url || url)
|
94
|
-
false
|
95
|
-
rescue Errno::ECONNREFUSED => e
|
96
|
-
true
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def write_url
|
101
|
-
File.open(url_file, 'w') {|f| f << url }
|
102
|
-
end
|
103
|
-
|
104
|
-
def check_for_running
|
105
|
-
if File.exists?(pid_file) && File.exists?(url_file)
|
106
|
-
running_url = File.read(url_file)
|
107
|
-
if !port_open?(running_url)
|
108
|
-
logger.warn "#{app_name} is already running at #{running_url}"
|
109
|
-
launch!(running_url)
|
110
|
-
exit!
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def run!
|
116
|
-
rack_handler.run app, :Host => host, :Port => port do |server|
|
117
|
-
trap(kill_command) do
|
118
|
-
## Use thins' hard #stop! if available, otherwise just #stop
|
119
|
-
server.respond_to?(:stop!) ? server.stop! : server.stop
|
120
|
-
logger.info "#{app_name} received INT ... stopping"
|
121
|
-
delete_pid!
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# Adapted from Rackup
|
127
|
-
def daemonize!
|
128
|
-
if RUBY_VERSION < "1.9"
|
129
|
-
logger.debug "Parent Process: #{Process.pid}"
|
130
|
-
exit! if fork
|
131
|
-
logger.debug "Child Process: #{Process.pid}"
|
132
|
-
Dir.chdir "/"
|
133
|
-
File.umask 0000
|
134
|
-
FileUtils.touch(log_file)
|
135
|
-
STDIN.reopen log_file
|
136
|
-
STDOUT.reopen log_file, "a"
|
137
|
-
STDERR.reopen log_file, "a"
|
138
|
-
else
|
139
|
-
Process.daemon
|
140
|
-
end
|
141
|
-
logger.debug "Child Process: #{Process.pid}"
|
142
|
-
|
143
|
-
File.open(pid_file, 'w') {|f| f.write("#{Process.pid}") }
|
144
|
-
at_exit { delete_pid! }
|
145
|
-
end
|
146
|
-
|
147
|
-
def launch!(specific_url = nil)
|
148
|
-
return if options[:skip_launch]
|
149
|
-
cmd = WINDOWS ? "start" : "sleep 2 && open"
|
150
|
-
system "#{cmd} #{specific_url || url}"
|
151
|
-
end
|
152
|
-
|
153
|
-
def kill!
|
154
|
-
pid = File.read(pid_file)
|
155
|
-
logger.warn "Sending INT to #{pid.to_i}"
|
156
|
-
Process.kill(kill_command, pid.to_i)
|
157
|
-
rescue => e
|
158
|
-
logger.warn "pid not found at #{pid_file} : #{e}"
|
159
|
-
end
|
160
|
-
|
161
|
-
def start
|
162
|
-
begin
|
163
|
-
launch!
|
164
|
-
daemonize! unless options[:foreground]
|
165
|
-
run!
|
166
|
-
rescue RuntimeError => e
|
167
|
-
logger.warn "There was an error starting #{app_name}: #{e}"
|
168
|
-
exit
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def status
|
173
|
-
if File.exists?(pid_file)
|
174
|
-
logger.info "#{app_name} running"
|
175
|
-
logger.info "PID #{File.read(pid_file)}"
|
176
|
-
logger.info "URL #{File.read(url_file)}" if File.exists?(url_file)
|
177
|
-
else
|
178
|
-
logger.info "#{app_name} not running!"
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
def logger
|
183
|
-
return @logger if @logger
|
184
|
-
@logger = Logger.new(STDOUT)
|
185
|
-
@logger.level = options[:debug] ? Logger::DEBUG : Logger::INFO
|
186
|
-
@logger.formatter = Proc.new {|s, t, n, msg| "[#{t}] #{msg}\n"}
|
187
|
-
@logger
|
188
|
-
end
|
189
|
-
|
190
|
-
private
|
191
|
-
def define_options
|
192
|
-
OptionParser.new("", 24, ' ') { |opts|
|
193
|
-
opts.banner = "Usage: #{app_name} [options]"
|
194
|
-
|
195
|
-
opts.separator ""
|
196
|
-
opts.separator "Vegas options:"
|
197
|
-
|
198
|
-
opts.on("-s", "--server SERVER", "serve using SERVER (webrick/mongrel)") { |s|
|
199
|
-
@rack_handler = Rack::Handler.get(s)
|
200
|
-
}
|
201
|
-
|
202
|
-
opts.on("-o", "--host HOST", "listen on HOST (default: #{HOST})") { |host|
|
203
|
-
@options[:host] = host
|
204
|
-
}
|
205
|
-
|
206
|
-
opts.on("-p", "--port PORT", "use PORT (default: #{PORT})") { |port|
|
207
|
-
@options[:port] = port
|
208
|
-
}
|
209
|
-
|
210
|
-
opts.on("-e", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
|
211
|
-
@options[:environment] = e
|
212
|
-
}
|
213
|
-
|
214
|
-
opts.on("-F", "--foreground", "don't daemonize, run in the foreground") { |f|
|
215
|
-
@options[:foreground] = true
|
216
|
-
}
|
217
|
-
|
218
|
-
opts.on("-L", "--no-launch", "don't launch the browser") { |f|
|
219
|
-
@options[:skip_launch] = true
|
220
|
-
}
|
221
|
-
|
222
|
-
opts.on('-K', "--kill", "kill the running process and exit") {|k|
|
223
|
-
kill!
|
224
|
-
exit
|
225
|
-
}
|
226
|
-
|
227
|
-
opts.on('-S', "--status", "display the current running PID and URL then quit") {|s|
|
228
|
-
status
|
229
|
-
exit!
|
230
|
-
}
|
231
|
-
|
232
|
-
opts.on('-d', "--debug", "raise the log level to :debug (default: :info)") {|s|
|
233
|
-
@options[:debug] = true
|
234
|
-
}
|
235
|
-
|
236
|
-
yield opts if block_given?
|
237
|
-
|
238
|
-
opts.separator ""
|
239
|
-
opts.separator "Common options:"
|
240
|
-
|
241
|
-
opts.on_tail("-h", "--help", "Show this message") do
|
242
|
-
puts opts
|
243
|
-
exit
|
244
|
-
end
|
245
|
-
|
246
|
-
opts.on_tail("--version", "Show version") do
|
247
|
-
if app.respond_to?(:version)
|
248
|
-
puts "#{app_name} #{app.version}"
|
249
|
-
end
|
250
|
-
puts "sinatra #{Sinatra::VERSION}"
|
251
|
-
puts "vegas #{Vegas::VERSION}"
|
252
|
-
exit
|
253
|
-
end
|
254
|
-
|
255
|
-
opts.parse! ARGV
|
256
|
-
}
|
257
|
-
rescue OptionParser::MissingArgument => e
|
258
|
-
logger.warn "#{e}, run -h for options"
|
259
|
-
exit
|
260
|
-
end
|
261
|
-
|
262
|
-
def kill_command
|
263
|
-
WINDOWS ? 1 : :INT
|
264
|
-
end
|
265
|
-
|
266
|
-
def delete_pid!
|
267
|
-
File.delete(pid_file) if File.exist?(pid_file)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
data/vendor/vegas/lib/vegas.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'sinatra'
|
3
|
-
rescue LoadError
|
4
|
-
require 'rubygems'
|
5
|
-
require 'sinatra'
|
6
|
-
end
|
7
|
-
|
8
|
-
$LOAD_PATH.unshift File.dirname(__FILE__)
|
9
|
-
|
10
|
-
module Vegas
|
11
|
-
VERSION = "0.0.4.1"
|
12
|
-
WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i)
|
13
|
-
|
14
|
-
autoload :Runner, 'vegas/runner'
|
15
|
-
end
|
16
|
-
|
@@ -1,9 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# Created on 2009-2-27.
|
4
|
-
# Copyright (c) 2009. All rights reserved.
|
5
|
-
|
6
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_app.rb'))
|
7
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib','vegas.rb'))
|
8
|
-
|
9
|
-
Vegas::Runner.new(TestApp, 'test_app')
|