zuk-picnic 0.7.999.20090212
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +1 -0
- data/History.txt +68 -0
- data/LICENSE.txt +165 -0
- data/Manifest.txt +29 -0
- data/README.txt +31 -0
- data/Rakefile +62 -0
- data/lib/picnic/authentication.rb +218 -0
- data/lib/picnic/cli.rb +165 -0
- data/lib/picnic/conf.rb +135 -0
- data/lib/picnic/controllers.rb +4 -0
- data/lib/picnic/logger.rb +41 -0
- data/lib/picnic/server.rb +98 -0
- data/lib/picnic/service_control.rb +274 -0
- data/lib/picnic/version.rb +9 -0
- data/lib/picnic.rb +48 -0
- data/setup.rb +1585 -0
- data/test/picnic_test.rb +11 -0
- data/test/test_helper.rb +2 -0
- data/vendor/camping-2.0.20090212/CHANGELOG +118 -0
- data/vendor/camping-2.0.20090212/COPYING +18 -0
- data/vendor/camping-2.0.20090212/README +119 -0
- data/vendor/camping-2.0.20090212/Rakefile +174 -0
- data/vendor/camping-2.0.20090212/bin/camping +99 -0
- data/vendor/camping-2.0.20090212/doc/camping.1.gz +0 -0
- data/vendor/camping-2.0.20090212/examples/README +5 -0
- data/vendor/camping-2.0.20090212/examples/blog.rb +375 -0
- data/vendor/camping-2.0.20090212/examples/campsh.rb +629 -0
- data/vendor/camping-2.0.20090212/examples/tepee.rb +242 -0
- data/vendor/camping-2.0.20090212/extras/Camping.gif +0 -0
- data/vendor/camping-2.0.20090212/extras/flipbook_rdoc.rb +491 -0
- data/vendor/camping-2.0.20090212/extras/permalink.gif +0 -0
- data/vendor/camping-2.0.20090212/lib/camping/ar/session.rb +132 -0
- data/vendor/camping-2.0.20090212/lib/camping/ar.rb +78 -0
- data/vendor/camping-2.0.20090212/lib/camping/mab.rb +26 -0
- data/vendor/camping-2.0.20090212/lib/camping/reloader.rb +163 -0
- data/vendor/camping-2.0.20090212/lib/camping/server.rb +158 -0
- data/vendor/camping-2.0.20090212/lib/camping/session.rb +74 -0
- data/vendor/camping-2.0.20090212/lib/camping-unabridged.rb +638 -0
- data/vendor/camping-2.0.20090212/lib/camping.rb +54 -0
- data/vendor/camping-2.0.20090212/setup.rb +1551 -0
- data/vendor/camping-2.0.20090212/test/apps/env_debug.rb +65 -0
- data/vendor/camping-2.0.20090212/test/apps/forms.rb +95 -0
- data/vendor/camping-2.0.20090212/test/apps/misc.rb +86 -0
- data/vendor/camping-2.0.20090212/test/apps/sessions.rb +38 -0
- data/vendor/camping-2.0.20090212/test/test_camping.rb +54 -0
- metadata +128 -0
data/test/picnic_test.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
= 1.6
|
2
|
+
=== ???, 2007
|
3
|
+
|
4
|
+
* Camping::Apps removed, it wasn't reliable.
|
5
|
+
* bin/camping server kinds splitted in various files.
|
6
|
+
* NotFound and ServerError controllers changed to methods :
|
7
|
+
|
8
|
+
r404 : called when a controller was not found
|
9
|
+
r500 : called on uncaught exception
|
10
|
+
r501 : called on undefined method
|
11
|
+
|
12
|
+
All of those can be overridden at your taste.
|
13
|
+
|
14
|
+
* Markaby no longer required. Like AR, is it autoloaded on (Mab) usage.
|
15
|
+
* Camping::H is now inheriting from Hash instead of HashWithIndifferentAccess.
|
16
|
+
* Which made possible to remove the last strict dependency : active_support
|
17
|
+
* #errors_for removed, it wasn't really used
|
18
|
+
* Bug fixes !
|
19
|
+
|
20
|
+
= 1.5
|
21
|
+
=== 3rd Oct, 2006
|
22
|
+
|
23
|
+
* Camping::Apps stores an array of classes for all loaded apps.
|
24
|
+
* bin/camping can be given a directory. Like: <tt>camping examples/</tt>
|
25
|
+
* Console mode -- thank zimbatm. Use: camping -C yourapp.rb
|
26
|
+
* Call controllers with Camping.method_missing.
|
27
|
+
|
28
|
+
Tepee.get(:Index) #=> (Response)
|
29
|
+
Blog.post(:Delete, id) #=> (Response)
|
30
|
+
|
31
|
+
Blog.post(:Login, :input => {'username' => 'admin', 'password' => 'camping'})
|
32
|
+
#=> #<Blog::Controllers::Login @user=... >
|
33
|
+
|
34
|
+
Blog.get(:Info, :env => {:HTTP_HOST => 'wagon'})
|
35
|
+
#=> #<Blog::Controllers::Info @env={'HTTP_HOST'=>'wagon'} ...>
|
36
|
+
|
37
|
+
* Using \r\n instead of \n on output. FastCGI has these needs.
|
38
|
+
* ActiveRecord no longer required or installed.
|
39
|
+
* If you refer to Models::Base, however, ActiveRecord will be loaded with autoload. (see lib/camping/db.rb)
|
40
|
+
* new Camping::FastCGI.serve which will serve a whole directory of apps
|
41
|
+
(see http://code.whytheluckystiff.net/camping/wiki/TheCampingServer)
|
42
|
+
* ~/.campingrc can contain database connection info if you want your default to be something other than SQLite.
|
43
|
+
|
44
|
+
database:
|
45
|
+
adapter: mysql
|
46
|
+
username: camping
|
47
|
+
socket: /tmp/mysql.sock
|
48
|
+
password: NOFORESTFIRES
|
49
|
+
database: camping
|
50
|
+
|
51
|
+
* controllers are now *ordered*. uses the inherited hook to keep track of all
|
52
|
+
classes created with R. those classes are scanned, in order, when a request is
|
53
|
+
made. any other controllers are handled first. so if you plan on overriding the
|
54
|
+
urls method, be sure to subclass from R().
|
55
|
+
* Console mode will load .irbrc in the working directory, if present.
|
56
|
+
(for example, in my ~/git/balloon directory, i have this in the .irbrc:
|
57
|
+
include Balloon::Models
|
58
|
+
when camping -C balloon.rb gets run, the models all get included in main.)
|
59
|
+
* And, of course, many other bugfixes from myself and the loyal+kind zimbatm...
|
60
|
+
* Markaby updated to 0.5. (See its CHANGELOG.)
|
61
|
+
|
62
|
+
= 1.4.2
|
63
|
+
=== 18th May, 2006
|
64
|
+
|
65
|
+
* Efficient file uploads for multipart/form-data POSTs.
|
66
|
+
* Camping tool now uses Mongrel, if available. If not, sticks with WEBrick.
|
67
|
+
* Multiple apps can be loaded with the camping tool, each mounted according to their file name.
|
68
|
+
|
69
|
+
= 1.4.1
|
70
|
+
=== 3rd May, 2006
|
71
|
+
|
72
|
+
* Streaming HTTP support. If body is IO, will simply pass to the controller. Mongrel, in particular, supports this nicely.
|
73
|
+
|
74
|
+
= 1.4
|
75
|
+
=== 11th April, 2006
|
76
|
+
|
77
|
+
* Moved Camping::Controllers::Base to Camping::Base.
|
78
|
+
* Moved Camping::Controllers::R to Camping::R.
|
79
|
+
* New session library (lib/camping/session.rb).
|
80
|
+
* WEBrick handler (lib/camping/webrick.rb) and Mongrel handler (lib/camping/mongrel.rb).
|
81
|
+
* Helpers#URL, builds a complete URL for a route. Returns a URI object. This way relative links could just return self.URL.path.
|
82
|
+
* Base#initialize takes over some of Base#service's duties.
|
83
|
+
* ENV now available as @env in controllers and views.
|
84
|
+
* Beautiful multi-page docs without frames!
|
85
|
+
|
86
|
+
= 1.3
|
87
|
+
=== 28th January, 2006
|
88
|
+
|
89
|
+
* bin/camping: an application launcher.
|
90
|
+
* <tt>Camping.run(request, response)</tt> now changed to <tt>controller = Camping.run(request, env)</tt>
|
91
|
+
* This means outputting the response is the wrapper/server's job. See bin/camping, you can do a controller.to_s at the least.
|
92
|
+
* <tt>Controllers::Base.env</tt> is the new thread-safe home for <tt>ENV</tt>.
|
93
|
+
* The input hash now works more like Rails params. You can call keys
|
94
|
+
like methods or with symbols or strings.
|
95
|
+
* Queries are now parsed more like PHP/Rails, in that you can denote
|
96
|
+
structure with brackets: post[user]=_why;post[id]=2
|
97
|
+
* Auto-prefix table names, to help prevent name clash.
|
98
|
+
* Helpers.errors_for simple validation.
|
99
|
+
* Lots of empty :href and :action attributes, a bug.
|
100
|
+
* New single-page flipbook RDoc template.
|
101
|
+
|
102
|
+
= 1.2
|
103
|
+
=== 23rd January, 2006
|
104
|
+
|
105
|
+
* Camping.goes allows fresh modules build from all Camping parts.
|
106
|
+
* File uploads now supported (multipart/form-data).
|
107
|
+
* Helpers.R can rebuild routes.
|
108
|
+
* Helpers./ for tracing paths from the root.
|
109
|
+
|
110
|
+
= 1.1
|
111
|
+
=== 19th January, 2006
|
112
|
+
|
113
|
+
* Allowed request and response streams to be passed in, to allow WEBrick and FastCGI support.
|
114
|
+
|
115
|
+
= 1.0
|
116
|
+
=== 17th January, 2006
|
117
|
+
|
118
|
+
* Initial checkin, see announcement at http://redhanded.hobix.com/bits/campingAMicroframework.html.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2006 why the lucky stiff
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,119 @@
|
|
1
|
+
== Camping, a Microframework
|
2
|
+
|
3
|
+
Camping is a web framework which consistently stays at less than 4kb of code.
|
4
|
+
You can probably view the complete source code on a single page. But, you know,
|
5
|
+
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 file
|
8
|
+
like many small CGIs. But to organize it as a Model-View-Controller application
|
9
|
+
like Rails does. You can then easily move it to Rails once you've got it going.
|
10
|
+
|
11
|
+
== A Camping Skeleton
|
12
|
+
|
13
|
+
A skeletal Camping blog could look like this:
|
14
|
+
|
15
|
+
require 'camping'
|
16
|
+
|
17
|
+
Camping.goes :Blog
|
18
|
+
|
19
|
+
module Blog::Models
|
20
|
+
class Post < Base; belongs_to :user; end
|
21
|
+
class Comment < Base; belongs_to :user; end
|
22
|
+
class User < Base; end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Blog::Controllers
|
26
|
+
class Index < R '/'
|
27
|
+
def get
|
28
|
+
@posts = Post.find :all
|
29
|
+
render :index
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module Blog::Views
|
35
|
+
def layout
|
36
|
+
html do
|
37
|
+
body do
|
38
|
+
self << yield
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def index
|
44
|
+
for post in @posts
|
45
|
+
h1 post.title
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Some things you might have noticed:
|
51
|
+
|
52
|
+
* Camping::Models uses ActiveRecord to do its work. We love ActiveRecord!
|
53
|
+
* Camping::Controllers can be assigned URLs in the class definition. Neat?
|
54
|
+
* Camping::Views describes HTML using pure Ruby. Markup as Ruby, which we
|
55
|
+
call Markaby.
|
56
|
+
* You use Camping::goes to make a copy of the Camping framework under your
|
57
|
+
own module name (in this case: <tt>Blog</tt>.)
|
58
|
+
|
59
|
+
<b>NOTE:</b> Camping auto-prefixes table names. If your class is named
|
60
|
+
<tt>Blog::Models::Post</tt>, your table will be called <b>blog_posts</b>.
|
61
|
+
Since many Camping apps can be attached to a database at once, this helps
|
62
|
+
prevent name clash.
|
63
|
+
|
64
|
+
(If you want to see the full blog example, check out <tt>examples/blog/blog.rb</tt>
|
65
|
+
for the complete code.)
|
66
|
+
|
67
|
+
If you want to write larger applications with Camping, you are encouraged to
|
68
|
+
split the application into distinct parts which can be mounted at URLs on your
|
69
|
+
web server. You might have a blog at /blog and a wiki at /wiki. Each
|
70
|
+
self-contained. But you can certainly share layouts and models by storing them
|
71
|
+
in plain Ruby scripts.
|
72
|
+
|
73
|
+
Interested yet? Okay, okay, one step at a time.
|
74
|
+
|
75
|
+
== Installation
|
76
|
+
|
77
|
+
* <tt>gem install camping</tt>
|
78
|
+
|
79
|
+
Or for the bleeding edge:
|
80
|
+
|
81
|
+
* <tt>gem install camping --source http://code.whytheluckystiff.net</tt>
|
82
|
+
|
83
|
+
You are encourage to install Camping and SQLite3, since it is a small database
|
84
|
+
which fits perfectly with our compact bylaws, works well with the examples.
|
85
|
+
|
86
|
+
* See http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for instructions.
|
87
|
+
|
88
|
+
== Running Camping Apps
|
89
|
+
|
90
|
+
The blog example above and most Camping applications look a lot like CGI scripts.
|
91
|
+
If you run them from the commandline, you'll probably just see a pile of HTML.
|
92
|
+
|
93
|
+
Camping comes with an tool for launching apps from the commandline:
|
94
|
+
|
95
|
+
* Run: <tt>camping blog.rb</tt>
|
96
|
+
* Visit http://localhost:3301/ to use the app.
|
97
|
+
|
98
|
+
== How the Camping Tool Works
|
99
|
+
|
100
|
+
If your application isn't working with the <tt>camping</tt> tool, keep in mind
|
101
|
+
that the tool expects the following conventions to be used:
|
102
|
+
|
103
|
+
1. You must have SQLite3 and SQLite3-ruby installed. (Once again, please see
|
104
|
+
http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for instructions.)
|
105
|
+
2. If your script is called <tt>test.rb</tt>, Camping expects your application to
|
106
|
+
be stored in a module called <tt>Test</tt>. Case is not imporant, though. The
|
107
|
+
module can be called <tt>TeSt</tt> or any other permutation.
|
108
|
+
3. Your script's postamble (anything enclosed in <tt>if __FILE__ == $0</tt>) will be
|
109
|
+
ignored by the tool, since the tool will create an SQLite3 database at
|
110
|
+
<tt>~/.camping.db</tt>. Or, on Windows, <tt>$USER/Application Data/Camping.db</tt>.
|
111
|
+
4. If your application's module has a <tt>create</tt> method, it will be executed before
|
112
|
+
the web server starts up.
|
113
|
+
|
114
|
+
== The Rules of Thumb
|
115
|
+
|
116
|
+
Once you've started writing your own Camping app, I'd highly recommend that you become familiar
|
117
|
+
with the Camping Rules of Thumb which are listed on the wiki:
|
118
|
+
http://code.whytheluckystiff.net/camping/wiki/CampingRulesOfThumb
|
119
|
+
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'fileutils'
|
7
|
+
include FileUtils
|
8
|
+
|
9
|
+
NAME = "camping"
|
10
|
+
REV = (`#{ENV['GIT'] || "git"} rev-list HEAD`.split.length + 1).to_s rescue nil
|
11
|
+
VERS = ENV['VERSION'] || ("1.9" + (REV ? ".#{REV}" : ""))
|
12
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'test/test.log', '.*.pt']
|
13
|
+
RDOC_OPTS = ['--quiet', '--title', "Camping, the Documentation",
|
14
|
+
"--opname", "index.html",
|
15
|
+
"--line-numbers",
|
16
|
+
"--main", "README",
|
17
|
+
"--inline-source"]
|
18
|
+
|
19
|
+
desc "Packages up Camping."
|
20
|
+
task :default => [:check]
|
21
|
+
task :package => [:clean]
|
22
|
+
|
23
|
+
task :doc => [:before_doc, :rdoc, :after_doc]
|
24
|
+
|
25
|
+
task :before_doc do
|
26
|
+
mv "lib/camping.rb", "lib/camping-mural.rb"
|
27
|
+
mv "lib/camping-unabridged.rb", "lib/camping.rb"
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
rdoc.rdoc_dir = 'doc/rdoc'
|
32
|
+
rdoc.options += RDOC_OPTS
|
33
|
+
rdoc.template = "extras/flipbook_rdoc.rb"
|
34
|
+
rdoc.main = "README"
|
35
|
+
rdoc.title = "Camping, the Documentation"
|
36
|
+
rdoc.rdoc_files.add ['README', 'CHANGELOG', 'COPYING', 'lib/camping.rb', 'lib/camping/*.rb']
|
37
|
+
end
|
38
|
+
|
39
|
+
task :after_doc do
|
40
|
+
mv "lib/camping.rb", "lib/camping-unabridged.rb"
|
41
|
+
mv "lib/camping-mural.rb", "lib/camping.rb"
|
42
|
+
cp "extras/Camping.gif", "doc/rdoc/"
|
43
|
+
cp "extras/permalink.gif", "doc/rdoc/"
|
44
|
+
sh %{scp -r doc/rdoc/* #{ENV['USER']}@rubyforge.org:/var/www/gforge-projects/camping/}
|
45
|
+
end
|
46
|
+
|
47
|
+
spec =
|
48
|
+
Gem::Specification.new do |s|
|
49
|
+
s.name = NAME
|
50
|
+
s.version = VERS
|
51
|
+
s.platform = Gem::Platform::RUBY
|
52
|
+
s.has_rdoc = true
|
53
|
+
s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
|
54
|
+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)\/', '--exclude', 'lib/camping.rb']
|
55
|
+
s.summary = "minature rails for stay-at-home moms"
|
56
|
+
s.description = s.summary
|
57
|
+
s.author = "why the lucky stiff"
|
58
|
+
s.email = 'why@ruby-lang.org'
|
59
|
+
s.homepage = 'http://code.whytheluckystiff.net/camping/'
|
60
|
+
s.executables = ['camping']
|
61
|
+
|
62
|
+
s.add_dependency('markaby', '>=0.5')
|
63
|
+
s.add_dependency('rack', '>=0.3')
|
64
|
+
s.add_dependency('metaid')
|
65
|
+
s.required_ruby_version = '>= 1.8.2'
|
66
|
+
|
67
|
+
s.files = %w(COPYING README Rakefile) +
|
68
|
+
Dir.glob("{bin,doc,test,lib,extras}/**/*") +
|
69
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
70
|
+
Dir.glob("examples/**/*.rb") +
|
71
|
+
Dir.glob("tools/*.rb")
|
72
|
+
|
73
|
+
s.require_path = "lib"
|
74
|
+
# s.extensions = FileList["ext/**/extconf.rb"].to_a
|
75
|
+
s.bindir = "bin"
|
76
|
+
end
|
77
|
+
|
78
|
+
omni =
|
79
|
+
Gem::Specification.new do |s|
|
80
|
+
s.name = "camping-omnibus"
|
81
|
+
s.version = VERS
|
82
|
+
s.platform = Gem::Platform::RUBY
|
83
|
+
s.summary = "the camping meta-package for updating ActiveRecord, Mongrel and SQLite3 bindings"
|
84
|
+
s.description = s.summary
|
85
|
+
%w[author email homepage].each { |x| s.__send__("#{x}=", spec.__send__(x)) }
|
86
|
+
|
87
|
+
s.add_dependency('camping', "=#{VERS}")
|
88
|
+
s.add_dependency('activerecord')
|
89
|
+
s.add_dependency('sqlite3-ruby', '>=1.1.0.1')
|
90
|
+
s.add_dependency('mongrel')
|
91
|
+
s.add_dependency('acts_as_versioned')
|
92
|
+
s.add_dependency('RedCloth')
|
93
|
+
end
|
94
|
+
|
95
|
+
Rake::GemPackageTask.new(spec) do |p|
|
96
|
+
p.need_tar = true
|
97
|
+
p.gem_spec = spec
|
98
|
+
end
|
99
|
+
|
100
|
+
Rake::GemPackageTask.new(omni) do |p|
|
101
|
+
p.gem_spec = omni
|
102
|
+
end
|
103
|
+
|
104
|
+
task :install do
|
105
|
+
sh %{rake package}
|
106
|
+
sh %{sudo gem install pkg/#{NAME}-#{VERS}}
|
107
|
+
end
|
108
|
+
|
109
|
+
task :uninstall => [:clean] do
|
110
|
+
sh %{sudo gem uninstall #{NAME}}
|
111
|
+
end
|
112
|
+
|
113
|
+
Rake::TestTask.new(:test) do |t|
|
114
|
+
t.test_files = FileList['test/test_*.rb']
|
115
|
+
# t.warning = true
|
116
|
+
# t.verbose = true
|
117
|
+
end
|
118
|
+
|
119
|
+
desc "Compare camping and camping-unabridged parse trees"
|
120
|
+
task :diff do
|
121
|
+
if `which parse_tree_show`.strip.empty?
|
122
|
+
STDERR.puts "ERROR: parse_tree_show missing : `gem install ParseTree`"
|
123
|
+
exit 1
|
124
|
+
end
|
125
|
+
|
126
|
+
sh "parse_tree_show lib/camping.rb > .camping.pt"
|
127
|
+
sh "parse_tree_show lib/camping-unabridged.rb > .camping-unabridged.pt"
|
128
|
+
sh "diff -u .camping-unabridged.pt .camping.pt | less"
|
129
|
+
end
|
130
|
+
|
131
|
+
task :ruby_diff do
|
132
|
+
require 'ruby2ruby'
|
133
|
+
c = Ruby2Ruby.translate(File.read("lib/camping.rb"))
|
134
|
+
n = Ruby2Ruby.translate(File.read("lib/camping-unabridged.rb"))
|
135
|
+
|
136
|
+
File.open(".camping-unabridged.rb.rb","w"){|f|f<<c}
|
137
|
+
File.open(".camping.rb.rb","w"){|f|f<<n}
|
138
|
+
|
139
|
+
sh "diff -u .camping-unabridged.rb.rb .camping.rb.rb | less"
|
140
|
+
end
|
141
|
+
|
142
|
+
task :check => ["check:valid", "check:size", "check:lines"]
|
143
|
+
namespace :check do
|
144
|
+
|
145
|
+
desc "Check source code validity"
|
146
|
+
task :valid do
|
147
|
+
ruby "-rubygems", "-w", "lib/camping-unabridged.rb"
|
148
|
+
ruby "-rubygems", "-w", "lib/camping.rb"
|
149
|
+
end
|
150
|
+
|
151
|
+
SIZE_LIMIT = 4096
|
152
|
+
desc "Compare camping sizes to unabridged"
|
153
|
+
task :size do
|
154
|
+
FileList["lib/camping*.rb"].each do |path|
|
155
|
+
s = File.size(path)
|
156
|
+
puts "%21s : % 6d % 4d%" % [File.basename(path), s, (100 * s / SIZE_LIMIT)]
|
157
|
+
end
|
158
|
+
if File.size("lib/camping.rb") > SIZE_LIMIT
|
159
|
+
STDERR.puts "lib/camping.rb: file is too big (> #{SIZE_LIMIT})"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
desc "Verify that line lenght doesn't exceed 80 chars for camping.rb"
|
164
|
+
task :lines do
|
165
|
+
i = 1
|
166
|
+
File.open("lib/camping.rb").each_line do |line|
|
167
|
+
if line.size > 81 # 1 added for \n
|
168
|
+
STDERR.puts "lib/camping.rb:#{i}: line too long (#{line[-10..-1].inspect})"
|
169
|
+
end
|
170
|
+
i += 1
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
@@ -0,0 +1,99 @@
|
|
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("-l", "--log FILE", "Start a database log ('-' for STDOUT)") { |conf.log| }
|
35
|
+
opts.on("-C", "--console", "Run in console mode with IRB") { conf.server = "console" }
|
36
|
+
server_list = ["mongrel", "webrick", "console"]
|
37
|
+
opts.on("-s", "--server NAME", server_list, "Server to force (#{server_list.join(', ')})") { |conf.server| }
|
38
|
+
|
39
|
+
opts.separator ""
|
40
|
+
opts.separator "Common options:"
|
41
|
+
|
42
|
+
# No argument, shows at tail. This will print an options summary.
|
43
|
+
# Try it and see!
|
44
|
+
opts.on_tail("-?", "--help", "Show this message") do
|
45
|
+
puts opts
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
|
49
|
+
# Another typical switch to print the version.
|
50
|
+
opts.on_tail("-v", "--version", "Show version") do
|
51
|
+
class << Gem; attr_accessor :loaded_specs; end
|
52
|
+
puts Gem.loaded_specs['camping'].version
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
begin
|
58
|
+
opts.parse! ARGV
|
59
|
+
rescue OptionParser::ParseError => ex
|
60
|
+
STDERR.puts "!! #{ex.message}"
|
61
|
+
puts "** use `#{File.basename($0)} --help` for more details..."
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
|
65
|
+
if ARGV.length < 1
|
66
|
+
puts opts
|
67
|
+
exit 1
|
68
|
+
end
|
69
|
+
|
70
|
+
# Load configuration if any
|
71
|
+
if rc_path and File.exists?( rc_path )
|
72
|
+
YAML.load_file(rc_path).each do |k,v|
|
73
|
+
conf.send("#{k}=", v) unless conf.send(k)
|
74
|
+
end
|
75
|
+
puts "** conf file #{rc_path} loaded"
|
76
|
+
end
|
77
|
+
|
78
|
+
# Default db
|
79
|
+
if conf.database.nil? and db_path
|
80
|
+
conf.database = {:adapter => 'sqlite3', :database => db_path} if db_path
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
# get a copy of the paths to pass to the server
|
85
|
+
paths = ARGV.dup
|
86
|
+
|
87
|
+
# Check that mongrel exists
|
88
|
+
if conf.server.nil? || conf.server == "mongrel"
|
89
|
+
begin
|
90
|
+
require 'mongrel'
|
91
|
+
conf.server = "mongrel"
|
92
|
+
rescue LoadError
|
93
|
+
puts "!! could not load mongrel. Falling back to webrick."
|
94
|
+
conf.server = "webrick"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
server = Camping::Server::Base.new(conf, paths)
|
99
|
+
server.start
|
Binary file
|