picnic 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/Manifest.txt +27 -27
- data/lib/picnic.rb +1 -1
- data/lib/picnic/cli.rb +2 -0
- data/lib/picnic/conf.rb +30 -6
- data/lib/picnic/server.rb +18 -21
- data/lib/picnic/version.rb +1 -1
- data/picnic.gemspec +3 -3
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/CHANGELOG +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/COPYING +0 -0
- data/vendor/zuk-camping-2.0.20090429/README +82 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/Rakefile +9 -3
- data/vendor/zuk-camping-2.0.20090429/bin/camping +97 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/doc/camping.1.gz +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/examples/README +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/examples/blog.rb +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/examples/campsh.rb +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/examples/tepee.rb +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/extras/Camping.gif +0 -0
- data/vendor/zuk-camping-2.0.20090429/extras/flipbook.rb +357 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/extras/permalink.gif +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping-unabridged.rb +53 -61
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping.rb +23 -25
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping/ar.rb +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping/ar/session.rb +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping/mab.rb +0 -0
- data/vendor/zuk-camping-2.0.20090429/lib/camping/reloader.rb +188 -0
- data/vendor/zuk-camping-2.0.20090429/lib/camping/server.rb +159 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping/session.rb +1 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/setup.rb +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/test/apps/env_debug.rb +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/test/apps/forms.rb +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/test/apps/misc.rb +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/test/apps/sessions.rb +0 -0
- data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/test/test_camping.rb +0 -0
- metadata +29 -29
- data/vendor/camping-2.0.20090212/README +0 -119
- data/vendor/camping-2.0.20090212/bin/camping +0 -99
- data/vendor/camping-2.0.20090212/extras/flipbook_rdoc.rb +0 -491
- data/vendor/camping-2.0.20090212/lib/camping/reloader.rb +0 -163
- data/vendor/camping-2.0.20090212/lib/camping/server.rb +0 -158
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 0.8.1 :: 2009-05-01
|
2
|
+
|
3
|
+
* The bundled version of camping has been updated so we are now compatible with
|
4
|
+
Passenger 2.2.
|
5
|
+
* We now attempt to check for app loading errors during startup, rather than
|
6
|
+
waiting for the first request. This should make debugging bad Camping apps
|
7
|
+
a bit easier.
|
8
|
+
* Mix bug fixes throughout.
|
9
|
+
|
10
|
+
|
1
11
|
=== 0.8.0 :: 2009-03-18
|
2
12
|
|
3
13
|
* Overhauled for Camping 2.0. Major changes throughout. Some things to
|
data/Manifest.txt
CHANGED
@@ -17,30 +17,30 @@ picnic.gemspec
|
|
17
17
|
setup.rb
|
18
18
|
test/picnic_test.rb
|
19
19
|
test/test_helper.rb
|
20
|
-
vendor/camping-2.0.
|
21
|
-
vendor/camping-2.0.
|
22
|
-
vendor/camping-2.0.
|
23
|
-
vendor/camping-2.0.
|
24
|
-
vendor/camping-2.0.
|
25
|
-
vendor/camping-2.0.
|
26
|
-
vendor/camping-2.0.
|
27
|
-
vendor/camping-2.0.
|
28
|
-
vendor/camping-2.0.
|
29
|
-
vendor/camping-2.0.
|
30
|
-
vendor/camping-2.0.
|
31
|
-
vendor/camping-2.0.
|
32
|
-
vendor/camping-2.0.
|
33
|
-
vendor/camping-2.0.
|
34
|
-
vendor/camping-2.0.
|
35
|
-
vendor/camping-2.0.
|
36
|
-
vendor/camping-2.0.
|
37
|
-
vendor/camping-2.0.
|
38
|
-
vendor/camping-2.0.
|
39
|
-
vendor/camping-2.0.
|
40
|
-
vendor/camping-2.0.
|
41
|
-
vendor/camping-2.0.
|
42
|
-
vendor/camping-2.0.
|
43
|
-
vendor/camping-2.0.
|
44
|
-
vendor/camping-2.0.
|
45
|
-
vendor/camping-2.0.
|
46
|
-
vendor/camping-2.0.
|
20
|
+
vendor/zuk-camping-2.0.20090429/CHANGELOG
|
21
|
+
vendor/zuk-camping-2.0.20090429/COPYING
|
22
|
+
vendor/zuk-camping-2.0.20090429/README
|
23
|
+
vendor/zuk-camping-2.0.20090429/Rakefile
|
24
|
+
vendor/zuk-camping-2.0.20090429/bin/camping
|
25
|
+
vendor/zuk-camping-2.0.20090429/doc/camping.1.gz
|
26
|
+
vendor/zuk-camping-2.0.20090429/examples/README
|
27
|
+
vendor/zuk-camping-2.0.20090429/examples/blog.rb
|
28
|
+
vendor/zuk-camping-2.0.20090429/examples/campsh.rb
|
29
|
+
vendor/zuk-camping-2.0.20090429/examples/tepee.rb
|
30
|
+
vendor/zuk-camping-2.0.20090429/extras/Camping.gif
|
31
|
+
vendor/zuk-camping-2.0.20090429/extras/flipbook.rb
|
32
|
+
vendor/zuk-camping-2.0.20090429/extras/permalink.gif
|
33
|
+
vendor/zuk-camping-2.0.20090429/lib/camping-unabridged.rb
|
34
|
+
vendor/zuk-camping-2.0.20090429/lib/camping.rb
|
35
|
+
vendor/zuk-camping-2.0.20090429/lib/camping/ar.rb
|
36
|
+
vendor/zuk-camping-2.0.20090429/lib/camping/ar/session.rb
|
37
|
+
vendor/zuk-camping-2.0.20090429/lib/camping/mab.rb
|
38
|
+
vendor/zuk-camping-2.0.20090429/lib/camping/reloader.rb
|
39
|
+
vendor/zuk-camping-2.0.20090429/lib/camping/server.rb
|
40
|
+
vendor/zuk-camping-2.0.20090429/lib/camping/session.rb
|
41
|
+
vendor/zuk-camping-2.0.20090429/setup.rb
|
42
|
+
vendor/zuk-camping-2.0.20090429/test/apps/env_debug.rb
|
43
|
+
vendor/zuk-camping-2.0.20090429/test/apps/forms.rb
|
44
|
+
vendor/zuk-camping-2.0.20090429/test/apps/misc.rb
|
45
|
+
vendor/zuk-camping-2.0.20090429/test/apps/sessions.rb
|
46
|
+
vendor/zuk-camping-2.0.20090429/test/test_camping.rb
|
data/lib/picnic.rb
CHANGED
data/lib/picnic/cli.rb
CHANGED
data/lib/picnic/conf.rb
CHANGED
@@ -25,18 +25,34 @@ module Picnic
|
|
25
25
|
# Read a configuration option.
|
26
26
|
#
|
27
27
|
# For example:
|
28
|
-
# puts
|
28
|
+
# puts conf[:server]
|
29
29
|
def [](key)
|
30
30
|
@conf[key]
|
31
31
|
end
|
32
32
|
|
33
|
-
#
|
33
|
+
# Set a configuration option.
|
34
|
+
#
|
35
|
+
# For example:
|
36
|
+
# conf[:server] = 'mongrel'
|
37
|
+
def []=(key, value)
|
38
|
+
@conf[key] = value
|
39
|
+
end
|
40
|
+
|
41
|
+
# Another way of reading or writing a configuration option.
|
34
42
|
#
|
35
43
|
# The following statements are equivalent:
|
36
|
-
# puts
|
37
|
-
# puts
|
44
|
+
# puts conf[:server]
|
45
|
+
# puts conf.server
|
46
|
+
#
|
47
|
+
# These are also equivalent:
|
48
|
+
# conf[:server] = 'mongrel'
|
49
|
+
# conf.server = 'mongrel'
|
38
50
|
def method_missing(method, *args)
|
39
|
-
|
51
|
+
if method.to_s =~ /(.*?)=$/
|
52
|
+
self[$~[1]] = args.first
|
53
|
+
else
|
54
|
+
self[method]
|
55
|
+
end
|
40
56
|
end
|
41
57
|
|
42
58
|
# Needs to be defined when we have a custom method_missing().
|
@@ -92,6 +108,11 @@ module Picnic
|
|
92
108
|
" suit your needs and then run #{app_name} again.\n"
|
93
109
|
exit 1
|
94
110
|
end
|
111
|
+
|
112
|
+
# Business logic for deriving the current config file name.
|
113
|
+
def determine_config_filename(app_name, app_root, config_file = nil)
|
114
|
+
config_file || "/etc/#{app_name.to_s.downcase}/config.yml"
|
115
|
+
end
|
95
116
|
|
96
117
|
# Loads the configuration from the YAML file for the given app.
|
97
118
|
#
|
@@ -101,7 +122,7 @@ module Picnic
|
|
101
122
|
#
|
102
123
|
# By default, the configuration will be loaded from <tt>/etc/<app_name>/config.yml</tt>.
|
103
124
|
def load_from_file(app_name, app_root, config_file = nil)
|
104
|
-
conf_file =
|
125
|
+
conf_file = determine_config_filename(app_name, app_root, config_file)
|
105
126
|
|
106
127
|
puts "Loading configuration for #{app_name.inspect} from #{conf_file.inspect}..."
|
107
128
|
|
@@ -131,5 +152,8 @@ module Picnic
|
|
131
152
|
def merge_defaults(defaults)
|
132
153
|
@conf = HashWithIndifferentAccess.new(HashWithIndifferentAccess.new(defaults).merge(@conf))
|
133
154
|
end
|
155
|
+
|
156
|
+
class Error < StandardError
|
157
|
+
end
|
134
158
|
end
|
135
159
|
end
|
data/lib/picnic/server.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'camping/server'
|
2
2
|
|
3
3
|
module Picnic::Server
|
4
|
-
class Base < Camping::Server
|
4
|
+
class Base < Camping::Server
|
5
5
|
def start
|
6
6
|
handler, conf = case @conf.server
|
7
7
|
when "console"
|
@@ -13,21 +13,31 @@ module Picnic::Server
|
|
13
13
|
when "webrick"
|
14
14
|
prep_webrick
|
15
15
|
end
|
16
|
-
|
17
|
-
|
16
|
+
|
17
|
+
# preload the apps in order to show any startup errors when
|
18
|
+
# the app is run from the command line (otherwise they would only
|
19
|
+
# show up after the first request to the web server)
|
20
|
+
reload!
|
21
|
+
|
22
|
+
handler.run(self, conf)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def app
|
27
|
+
reload!
|
28
|
+
|
29
|
+
rapp = apps.values.first
|
30
|
+
|
31
|
+
rapp = Rack::Static.new(rapp, @conf[:static]) if @conf[:static]
|
18
32
|
|
19
33
|
if @conf.uri_path
|
20
34
|
rapp = Rack::URLMap.new(@conf.uri_path => rapp)
|
21
35
|
end
|
22
|
-
|
23
|
-
rapp = Rack::Static.new(rapp, @conf[:static]) if @conf[:static]
|
36
|
+
|
24
37
|
rapp = Rack::ContentLength.new(rapp)
|
25
|
-
rapp = FixContentLength.new(rapp)
|
26
38
|
rapp = Rack::Lint.new(rapp)
|
27
39
|
rapp = Camping::Server::XSendfile.new(rapp)
|
28
40
|
rapp = Rack::ShowExceptions.new(rapp)
|
29
|
-
|
30
|
-
handler.run(rapp, conf)
|
31
41
|
end
|
32
42
|
|
33
43
|
|
@@ -83,17 +93,4 @@ module Picnic::Server
|
|
83
93
|
|
84
94
|
end
|
85
95
|
|
86
|
-
class FixContentLength
|
87
|
-
def initialize(app)
|
88
|
-
@app = app
|
89
|
-
end
|
90
|
-
|
91
|
-
def call(env)
|
92
|
-
status, headers, body = @app.call(env)
|
93
|
-
if headers.has_key?('Content-Length') && headers['Content-Length'].to_i == 0
|
94
|
-
headers['Content-Length'] = body.body.length.to_s
|
95
|
-
end
|
96
|
-
[status, headers, body]
|
97
|
-
end
|
98
|
-
end
|
99
96
|
end
|
data/lib/picnic/version.rb
CHANGED
data/picnic.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{picnic}
|
5
|
-
s.version = '0.8.
|
5
|
+
s.version = '0.8.1.' + Time.now.strftime('%Y%m%d')
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Matt Zukowski"]
|
9
9
|
s.date = Time.now.strftime('%Y-%m-%d')
|
10
10
|
s.description = %q{Camping for sissies}
|
11
11
|
s.email = %q{matt@roughest.net}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG.txt", "History.txt", "LICENSE.txt", "Manifest.txt", "README.
|
13
|
-
s.files = ["CHANGELOG.txt", "History.txt", "LICENSE.txt", "Manifest.txt", "README.
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG.txt", "History.txt", "LICENSE.txt", "Manifest.txt", "README.rdoc"]
|
13
|
+
s.files = ["CHANGELOG.txt", "History.txt", "LICENSE.txt", "Manifest.txt", "README.rdoc", "Rakefile", "lib/picnic.rb", "lib/picnic/authentication.rb", "lib/picnic/cli.rb", "lib/picnic/conf.rb", "lib/picnic/controllers.rb", "lib/picnic/logger.rb", "lib/picnic/server.rb", "lib/picnic/service_control.rb", "lib/picnic/version.rb", "setup.rb", "test/picnic_test.rb", "test/test_helper.rb", "vendor/zuk-camping-2.0.20090429/CHANGELOG", "vendor/zuk-camping-2.0.20090429/COPYING", "vendor/zuk-camping-2.0.20090429/README", "vendor/zuk-camping-2.0.20090429/Rakefile", "vendor/zuk-camping-2.0.20090429/bin/camping", "vendor/zuk-camping-2.0.20090429/doc/camping.1.gz", "vendor/zuk-camping-2.0.20090429/examples/README", "vendor/zuk-camping-2.0.20090429/examples/blog.rb", "vendor/zuk-camping-2.0.20090429/examples/campsh.rb", "vendor/zuk-camping-2.0.20090429/examples/tepee.rb", "vendor/zuk-camping-2.0.20090429/extras/Camping.gif", "vendor/zuk-camping-2.0.20090429/extras/permalink.gif", "vendor/zuk-camping-2.0.20090429/lib/camping-unabridged.rb", "vendor/zuk-camping-2.0.20090429/lib/camping.rb", "vendor/zuk-camping-2.0.20090429/lib/camping/ar.rb", "vendor/zuk-camping-2.0.20090429/lib/camping/ar/session.rb", "vendor/zuk-camping-2.0.20090429/lib/camping/mab.rb", "vendor/zuk-camping-2.0.20090429/lib/camping/reloader.rb", "vendor/zuk-camping-2.0.20090429/lib/camping/server.rb", "vendor/zuk-camping-2.0.20090429/lib/camping/session.rb", "vendor/zuk-camping-2.0.20090429/setup.rb", "vendor/zuk-camping-2.0.20090429/test/apps/env_debug.rb", "vendor/zuk-camping-2.0.20090429/test/apps/forms.rb", "vendor/zuk-camping-2.0.20090429/test/apps/misc.rb", "vendor/zuk-camping-2.0.20090429/test/apps/sessions.rb", "vendor/zuk-camping-2.0.20090429/test/test_camping.rb"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://picnic.rubyforge.org}
|
16
16
|
s.rdoc_options = ["--main", "README.txt"]
|
File without changes
|
File without changes
|
@@ -0,0 +1,82 @@
|
|
1
|
+
== Camping, a Microframework
|
2
|
+
|
3
|
+
Camping is a web framework which consistently stays at less than 3kb of code.
|
4
|
+
You can probably view the complete source code on a single page. But, you
|
5
|
+
know, it's so small that, if you think about it, what can it really do?
|
6
|
+
|
7
|
+
The idea here is to store a complete fledgling web application in a single
|
8
|
+
file like many small CGIs. But to organize it as a Model-View-Controller
|
9
|
+
application like Rails does. You can then easily move it to Rails once you've
|
10
|
+
got it going.
|
11
|
+
|
12
|
+
== A Camping Skeleton
|
13
|
+
|
14
|
+
A skeletal Camping blog could look like this:
|
15
|
+
|
16
|
+
require 'camping'
|
17
|
+
|
18
|
+
Camping.goes :Blog
|
19
|
+
|
20
|
+
module Blog::Models
|
21
|
+
class Post < Base; belongs_to :user; end
|
22
|
+
class Comment < Base; belongs_to :user; end
|
23
|
+
class User < Base; end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Blog::Controllers
|
27
|
+
class Index < R '/'
|
28
|
+
def get
|
29
|
+
@posts = Post.find :all
|
30
|
+
render :index
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module Blog::Views
|
36
|
+
def layout
|
37
|
+
html do
|
38
|
+
body do
|
39
|
+
self << yield
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def index
|
45
|
+
for post in @posts
|
46
|
+
h1 post.title
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
== Installation
|
52
|
+
|
53
|
+
Interested yet? Luckily it's quite easy to install Camping. We'll be using a tool called RubyGems, so if you don't have that installed yet, go grab it! Once that's sorted out, open up a Terminal or Command Line and enter:
|
54
|
+
|
55
|
+
* <tt>gem install camping</tt>
|
56
|
+
|
57
|
+
Or for the bleeding edge:
|
58
|
+
|
59
|
+
* <tt>gem install camping --source http://gems.judofyr.net</tt>
|
60
|
+
|
61
|
+
This will download everything you need and get you all set up. If you're installing camping manually, you'll need to make sure you have 'rack' installed as well, the interface Camping uses to talk to your web server. You'll also need 'markaby' for the views, and 'activerecord' if you're going to be using databases.
|
62
|
+
|
63
|
+
== Learning
|
64
|
+
|
65
|
+
* Start by reading the documentation in {the Camping module}[link:classes/Camping.html]
|
66
|
+
- it should get you started pretty quick.
|
67
|
+
* {The wiki}[http://wiki.github.com/why/camping] is the place for all tiny,
|
68
|
+
useful tricks that we've collected over the years. Don't be afraid to
|
69
|
+
share your own discoveries; the more, the better!
|
70
|
+
* Still wondering? Subscribe to {the mailing list}[http://rubyforge.org/mailman/listinfo/camping-list].
|
71
|
+
This is where it's all happening! Don't worry, though, the volume is just
|
72
|
+
as micro as Camping itself.
|
73
|
+
|
74
|
+
== Authors
|
75
|
+
|
76
|
+
Camping was originally started by{why the lucky stiff}[http://en.wikipedia.org/wiki/Why_the_lucky_stiff],
|
77
|
+
but is now maintained by the _community_. This simply means that if we like your
|
78
|
+
patch, it will be applied. Everything is managed through {the mailing list}[http://rubyforge.org/mailman/listinfo/camping-list],
|
79
|
+
so just subscribe and you'll become a contributor too. Remember: writing the
|
80
|
+
code is just half the job, without some serious thinking from you we won't get
|
81
|
+
any further.
|
82
|
+
|
@@ -4,6 +4,14 @@ require 'rake/gempackagetask'
|
|
4
4
|
require 'rake/rdoctask'
|
5
5
|
require 'rake/testtask'
|
6
6
|
require 'fileutils'
|
7
|
+
begin
|
8
|
+
gem 'rdoc', '~> 2.2.0'
|
9
|
+
require 'rdoc'
|
10
|
+
$:.unshift 'extras'
|
11
|
+
rescue Gem::LoadError
|
12
|
+
puts "RDoc 2.2 required to build docs"
|
13
|
+
puts "Please run `gem install rdoc --version 2.2`"
|
14
|
+
end
|
7
15
|
include FileUtils
|
8
16
|
|
9
17
|
NAME = "camping"
|
@@ -30,7 +38,7 @@ end
|
|
30
38
|
Rake::RDocTask.new do |rdoc|
|
31
39
|
rdoc.rdoc_dir = 'doc/rdoc'
|
32
40
|
rdoc.options += RDOC_OPTS
|
33
|
-
rdoc.template = "
|
41
|
+
rdoc.template = "flipbook"
|
34
42
|
rdoc.main = "README"
|
35
43
|
rdoc.title = "Camping, the Documentation"
|
36
44
|
rdoc.rdoc_files.add ['README', 'CHANGELOG', 'COPYING', 'lib/camping.rb', 'lib/camping/*.rb']
|
@@ -41,7 +49,6 @@ task :after_doc do
|
|
41
49
|
mv "lib/camping-mural.rb", "lib/camping.rb"
|
42
50
|
cp "extras/Camping.gif", "doc/rdoc/"
|
43
51
|
cp "extras/permalink.gif", "doc/rdoc/"
|
44
|
-
sh %{scp -r doc/rdoc/* #{ENV['USER']}@rubyforge.org:/var/www/gforge-projects/camping/}
|
45
52
|
end
|
46
53
|
|
47
54
|
spec =
|
@@ -61,7 +68,6 @@ spec =
|
|
61
68
|
|
62
69
|
s.add_dependency('markaby', '>=0.5')
|
63
70
|
s.add_dependency('rack', '>=0.3')
|
64
|
-
s.add_dependency('metaid')
|
65
71
|
s.required_ruby_version = '>= 1.8.2'
|
66
72
|
|
67
73
|
s.files = %w(COPYING README Rakefile) +
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
trap("INT") { exit }
|
4
|
+
require 'optparse'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'stringio'
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
$:.unshift File.dirname(__FILE__) + "/../lib"
|
10
|
+
require 'camping'
|
11
|
+
require 'camping/server'
|
12
|
+
|
13
|
+
conf = OpenStruct.new(:host => '0.0.0.0', :port => 3301)
|
14
|
+
|
15
|
+
# Setup paths
|
16
|
+
if home = ENV['HOME'] # POSIX
|
17
|
+
db_path = File.join(home, '.camping.db')
|
18
|
+
rc_path = File.join(home, '.campingrc')
|
19
|
+
elsif home = ENV['APPDATA'] # MSWIN
|
20
|
+
db_path = File.join(home, 'Camping.db')
|
21
|
+
rc_path = File.join(home, 'Campingrc')
|
22
|
+
end
|
23
|
+
|
24
|
+
# Parse options
|
25
|
+
opts = OptionParser.new do |opts|
|
26
|
+
opts.banner = "Usage: camping app1.rb, app2.rb..."
|
27
|
+
opts.define_head "#{File.basename($0)}, the microframework ON-button for ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
28
|
+
opts.separator ""
|
29
|
+
opts.separator "Specific options:"
|
30
|
+
|
31
|
+
opts.on("-h", "--host HOSTNAME", "Host for web server to bind to (default is all IPs)") { |conf.host| }
|
32
|
+
opts.on("-p", "--port NUM", "Port for web server (defaults to #{conf.port})") { |conf.port| }
|
33
|
+
opts.on("-d", "--database FILE", "SQLite3 database path (defaults to #{db_path ? db_path : '<none>'})") { |db_path| conf.database = {:adapter => 'sqlite3', :database => db_path} }
|
34
|
+
opts.on("-C", "--console", "Run in console mode with IRB") { conf.server = "console" }
|
35
|
+
server_list = ["mongrel", "webrick", "console"]
|
36
|
+
opts.on("-s", "--server NAME", server_list, "Server to force (#{server_list.join(', ')})") { |conf.server| }
|
37
|
+
|
38
|
+
opts.separator ""
|
39
|
+
opts.separator "Common options:"
|
40
|
+
|
41
|
+
# No argument, shows at tail. This will print an options summary.
|
42
|
+
# Try it and see!
|
43
|
+
opts.on_tail("-?", "--help", "Show this message") do
|
44
|
+
puts opts
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
|
48
|
+
# Another typical switch to print the version.
|
49
|
+
opts.on_tail("-v", "--version", "Show version") do
|
50
|
+
puts Gem.loaded_specs['camping'].version
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
opts.parse! ARGV
|
57
|
+
rescue OptionParser::ParseError => ex
|
58
|
+
STDERR.puts "!! #{ex.message}"
|
59
|
+
puts "** use `#{File.basename($0)} --help` for more details..."
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
|
63
|
+
if ARGV.length < 1
|
64
|
+
puts opts
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
# Load configuration if any
|
69
|
+
if rc_path and File.exists?(rc_path)
|
70
|
+
YAML.load_file(rc_path).each do |k,v|
|
71
|
+
conf.send("#{k}=", v) unless conf.send(k)
|
72
|
+
end
|
73
|
+
puts "** conf file #{rc_path} loaded"
|
74
|
+
end
|
75
|
+
|
76
|
+
# Default db
|
77
|
+
if conf.database.nil? and db_path
|
78
|
+
conf.database = { :adapter => 'sqlite3', :database => db_path }
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
# get a copy of the paths to pass to the server
|
83
|
+
paths = ARGV.dup
|
84
|
+
|
85
|
+
# Check that mongrel exists
|
86
|
+
if conf.server.nil? || conf.server == "mongrel"
|
87
|
+
begin
|
88
|
+
require 'mongrel'
|
89
|
+
conf.server = "mongrel"
|
90
|
+
rescue LoadError
|
91
|
+
puts "!! could not load mongrel. Falling back to webrick."
|
92
|
+
conf.server = "webrick"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
server = Camping::Server.new(conf, paths)
|
97
|
+
server.start
|