picnic 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/History.txt +10 -0
  2. data/Manifest.txt +27 -27
  3. data/lib/picnic.rb +1 -1
  4. data/lib/picnic/cli.rb +2 -0
  5. data/lib/picnic/conf.rb +30 -6
  6. data/lib/picnic/server.rb +18 -21
  7. data/lib/picnic/version.rb +1 -1
  8. data/picnic.gemspec +3 -3
  9. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/CHANGELOG +0 -0
  10. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/COPYING +0 -0
  11. data/vendor/zuk-camping-2.0.20090429/README +82 -0
  12. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/Rakefile +9 -3
  13. data/vendor/zuk-camping-2.0.20090429/bin/camping +97 -0
  14. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/doc/camping.1.gz +0 -0
  15. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/examples/README +0 -0
  16. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/examples/blog.rb +0 -0
  17. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/examples/campsh.rb +0 -0
  18. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/examples/tepee.rb +0 -0
  19. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/extras/Camping.gif +0 -0
  20. data/vendor/zuk-camping-2.0.20090429/extras/flipbook.rb +357 -0
  21. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/extras/permalink.gif +0 -0
  22. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping-unabridged.rb +53 -61
  23. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping.rb +23 -25
  24. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping/ar.rb +0 -0
  25. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping/ar/session.rb +0 -0
  26. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping/mab.rb +0 -0
  27. data/vendor/zuk-camping-2.0.20090429/lib/camping/reloader.rb +188 -0
  28. data/vendor/zuk-camping-2.0.20090429/lib/camping/server.rb +159 -0
  29. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/lib/camping/session.rb +1 -0
  30. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/setup.rb +0 -0
  31. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/test/apps/env_debug.rb +0 -0
  32. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/test/apps/forms.rb +0 -0
  33. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/test/apps/misc.rb +0 -0
  34. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/test/apps/sessions.rb +0 -0
  35. data/vendor/{camping-2.0.20090212 → zuk-camping-2.0.20090429}/test/test_camping.rb +0 -0
  36. metadata +29 -29
  37. data/vendor/camping-2.0.20090212/README +0 -119
  38. data/vendor/camping-2.0.20090212/bin/camping +0 -99
  39. data/vendor/camping-2.0.20090212/extras/flipbook_rdoc.rb +0 -491
  40. data/vendor/camping-2.0.20090212/lib/camping/reloader.rb +0 -163
  41. data/vendor/camping-2.0.20090212/lib/camping/server.rb +0 -158
@@ -1,163 +0,0 @@
1
- module Camping
2
- # == The Camping Reloader
3
- #
4
- # Camping apps are generally small and predictable. Many Camping apps are
5
- # contained within a single file. Larger apps are split into a handful of
6
- # other Ruby libraries within the same directory.
7
- #
8
- # Since Camping apps (and their dependencies) are loaded with Ruby's require
9
- # method, there is a record of them in $LOADED_FEATURES. Which leaves a
10
- # perfect space for this class to manage auto-reloading an app if any of its
11
- # immediate dependencies changes.
12
- #
13
- # == Wrapping Your Apps
14
- #
15
- # Since bin/camping and the Camping::FastCGI class already use the Reloader,
16
- # you probably don't need to hack it on your own. But, if you're rolling your
17
- # own situation, here's how.
18
- #
19
- # Rather than this:
20
- #
21
- # require 'yourapp'
22
- #
23
- # Use this:
24
- #
25
- # require 'camping/reloader'
26
- # Camping::Reloader.new('/path/to/yourapp.rb')
27
- #
28
- # The reloader will take care of requiring the app and monitoring all files
29
- # for alterations.
30
- class Reloader
31
- attr_accessor :klass, :mtime, :mount, :requires
32
-
33
- # Creates the reloader, assigns a +script+ to it and initially loads the
34
- # application. Pass in the full path to the script, otherwise the script
35
- # will be loaded relative to the current working directory.
36
- def initialize(script)
37
- @script = File.expand_path(script)
38
- @mount = File.basename(script, '.rb')
39
- @requires = nil
40
- load_app
41
- end
42
-
43
- # Find the application, based on the script name.
44
- def find_app(title)
45
- @klass = Object.const_get(Object.constants.grep(/^#{title}$/i)[0]) rescue nil
46
- end
47
-
48
- # If the file isn't found, if we need to remove the app from the global
49
- # namespace, this will be sure to do so and set @klass to nil.
50
- def remove_app
51
- if @klass
52
- Camping::Apps.delete(@klass)
53
- Object.send :remove_const, @klass.name
54
- @klass = nil
55
- end
56
- end
57
-
58
- # Loads (or reloads) the application. The reloader will take care of calling
59
- # this for you. You can certainly call it yourself if you feel it's warranted.
60
- def load_app
61
- title = File.basename(@script)[/^([\w_]+)/,1].gsub /_/,''
62
- begin
63
- all_requires = $LOADED_FEATURES.dup
64
- load @script
65
- @requires = ($LOADED_FEATURES - all_requires).select do |req|
66
- req.index(File.basename(@script) + "/") == 0 || req.index(title + "/") == 0
67
- end
68
- rescue Exception => e
69
- puts "!! trouble loading #{title.inspect}: [#{e.class}] #{e.message}"
70
- puts e.backtrace.join("\n")
71
- find_app title
72
- remove_app
73
- return
74
- end
75
-
76
- @mtime = mtime
77
- find_app title
78
- unless @klass and @klass.const_defined? :C
79
- puts "!! trouble loading #{title.inspect}: not a Camping app, no #{title.capitalize} module found"
80
- remove_app
81
- return
82
- end
83
-
84
- Reloader.conditional_connect
85
- @klass.create if @klass.respond_to? :create
86
- puts "** #{title.inspect} app loaded"
87
- @klass
88
- end
89
-
90
- # The timestamp of the most recently modified app dependency.
91
- def mtime
92
- ((@requires || []) + [@script]).map do |fname|
93
- fname = fname.gsub(/^#{Regexp::quote File.dirname(@script)}\//, '')
94
- begin
95
- File.mtime(File.join(File.dirname(@script), fname))
96
- rescue Errno::ENOENT
97
- remove_app
98
- @mtime
99
- end
100
- end.reject{|t| t > Time.now }.max
101
- end
102
-
103
- # Conditional reloading of the app. This gets called on each request and
104
- # only reloads if the modification times on any of the files is updated.
105
- def reload_app
106
- return if @klass and @mtime and mtime <= @mtime
107
-
108
- if @requires
109
- @requires.each { |req| $LOADED_FEATURES.delete(req) }
110
- end
111
- remove_app
112
- load_app
113
- end
114
-
115
- # Conditionally reloads (using reload_app.) Then passes the request through
116
- # to the wrapped Camping app.
117
- def call(*a)
118
- reload_app
119
- if @klass
120
- @klass.call(*a)
121
- else
122
- Camping.call(*a)
123
- end
124
- end
125
-
126
- # Returns source code for the main script in the application.
127
- def view_source
128
- File.read(@script)
129
- end
130
-
131
- class << self
132
- attr_writer :database, :log
133
-
134
- def conditional_connect
135
- # If database models are present, `autoload?` will return nil.
136
- unless Camping::Models.autoload? :Base
137
- if @database and @database[:adapter] == 'sqlite3'
138
- begin
139
- require 'sqlite3_api'
140
- rescue LoadError
141
- puts "!! Your SQLite3 adapter isn't a compiled extension."
142
- abort "!! Please check out http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for tips."
143
- end
144
- end
145
-
146
- case @log
147
- when Logger
148
- Camping::Models::Base.logger = @log
149
- when String
150
- require 'logger'
151
- Camping::Models::Base.logger = Logger.new(@log == "-" ? STDOUT : @log)
152
- end
153
-
154
- Camping::Models::Base.establish_connection @database if @database
155
-
156
- if Camping::Models.const_defined?(:Session)
157
- Camping::Models::Session.create_schema
158
- end
159
- end
160
- end
161
- end
162
- end
163
- end
@@ -1,158 +0,0 @@
1
- require 'irb'
2
- require 'rack'
3
- require 'camping/reloader'
4
-
5
- module Camping::Server
6
- class Base < Hash
7
- include Enumerable
8
-
9
- attr_reader :paths
10
- attr_accessor :conf
11
-
12
- def initialize(conf, paths = [])
13
- unless conf.database
14
- raise "!! No home directory found. Please specify a database file, see --help."
15
- end
16
-
17
- @conf = conf
18
- Camping::Reloader.database = conf.database
19
- Camping::Reloader.log = conf.log
20
-
21
- @paths = []
22
- paths.each { |script| add_app script }
23
- # TODO exception instead of abort()
24
- # abort("** No apps successfully loaded") unless self.detect { |app| app.klass }
25
-
26
- end
27
-
28
- def add_app(path)
29
- @paths << path
30
- if File.directory? path
31
- Dir[File.join(path, '*.rb')].each { |s| insert_app(s)}
32
- else
33
- insert_app(path)
34
- end
35
- # TODO check to see if the application is created or not... exception perhaps?
36
- end
37
-
38
- def find_new_scripts
39
- self.values.each { |app| app.reload_app }
40
- @paths.each do |path|
41
- Dir[File.join(path, '*.rb')].each do |script|
42
- smount = File.basename(script, '.rb')
43
- next if detect { |x| x.mount == smount }
44
-
45
- puts "** Discovered new #{script}"
46
- # TODO hmm. the next should be handled by the add_app thingy
47
- app = insert_app(script)
48
- next unless app
49
-
50
- yield app
51
-
52
- end
53
- end
54
- self.values.sort! { |x, y| x.mount <=> y.mount }
55
- end
56
- def index_page
57
- welcome = "You are Camping"
58
- apps = self
59
- <<-HTML
60
- <html>
61
- <head>
62
- <title>#{welcome}</title>
63
- <style type="text/css">
64
- body {
65
- font-family: verdana, arial, sans-serif;
66
- padding: 10px 40px;
67
- margin: 0;
68
- }
69
- h1, h2, h3, h4, h5, h6 {
70
- font-family: utopia, georgia, serif;
71
- }
72
- </style>
73
- </head>
74
- <body>
75
- <h1>#{welcome}</h1>
76
- <p>Good day. These are the Camping apps you've mounted.</p>
77
- <ul>
78
- #{apps.values.select{|app|app.klass}.map do |app|
79
- "<li><h3 style=\"display: inline\"><a href=\"/#{app.mount}\">#{app.klass.name}</a></h3><small> / <a href=\"/code/#{app.mount}\">View source</a></small></li>"
80
- end.join("\n")}
81
- </ul>
82
- </body>
83
- </html>
84
- HTML
85
- end
86
-
87
- def each(&b)
88
- self.values.each(&b)
89
- end
90
-
91
- # for RSpec tests
92
- def apps
93
- self.values
94
- end
95
-
96
- def start
97
- handler, conf = case @conf.server
98
- when "console"
99
- ARGV.clear
100
- IRB.start
101
- exit
102
- when "mongrel"
103
- puts "** Starting Mongrel on #{@conf.host}:#{@conf.port}"
104
- [Rack::Handler::Mongrel, {:Port => @conf.port, :Host => @conf.host}]
105
- when "webrick"
106
- [Rack::Handler::WEBrick, {:Port => @conf.port, :BindAddress => @conf.host}]
107
- end
108
-
109
- rapp = if apps.length > 1
110
- hash = {
111
- "/" => proc {|env|[200,{'Content-Type'=>'text/html'},index_page]}
112
- }
113
- apps.each do |app|
114
- hash["/#{app.mount}"] = app
115
- hash["/code/#{app.mount}"] = proc do |env|
116
- [200,{'Content-Type'=>'text/plain'},app.view_source]
117
- end
118
- end
119
- Rack::URLMap.new(hash)
120
- else
121
- apps.first
122
- end
123
- rapp = Rack::Lint.new(rapp)
124
- rapp = XSendfile.new(rapp)
125
- rapp = Rack::ShowExceptions.new(rapp)
126
- handler.run(rapp, conf)
127
- end
128
-
129
- private
130
-
131
- def insert_app(script)
132
- self[script] = Camping::Reloader.new(script)
133
- end
134
- end
135
-
136
- # A Rack middleware for reading X-Sendfile. Should only be used in
137
- # development.
138
- class XSendfile
139
-
140
- HEADERS = [
141
- "X-Sendfile",
142
- "X-Accel-Redirect",
143
- "X-LIGHTTPD-send-file"
144
- ]
145
-
146
- def initialize(app)
147
- @app = app
148
- end
149
-
150
- def call(env)
151
- status, headers, body = @app.call(env)
152
- if path = headers.values_at(*HEADERS).compact.first
153
- body = File.read(path)
154
- end
155
- [status, headers, body]
156
- end
157
- end
158
- end