camping 2.1.523 → 2.1.531
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/camping-unabridged.rb +24 -7
- data/lib/camping.rb +6 -6
- data/test/app_simple.rb +1 -0
- metadata +31 -12
data/lib/camping-unabridged.rb
CHANGED
@@ -50,6 +50,7 @@ module Camping
|
|
50
50
|
U = Rack::Utils
|
51
51
|
O = {}
|
52
52
|
Apps = []
|
53
|
+
SK = :camping #Key for r.session
|
53
54
|
# An object-like Hash.
|
54
55
|
# All Camping query string and cookie variables are loaded as this.
|
55
56
|
#
|
@@ -389,8 +390,9 @@ module Camping
|
|
389
390
|
end
|
390
391
|
|
391
392
|
# Serves the string +c+ with the MIME type of the filename +p+.
|
393
|
+
# Default text/html
|
392
394
|
def serve(p, c)
|
393
|
-
t = Rack::Mime.mime_type(p[/\..*$/],
|
395
|
+
t = Rack::Mime.mime_type(p[/\..*$/], "text/html") and @headers['Content-Type'] = t
|
394
396
|
c
|
395
397
|
end
|
396
398
|
|
@@ -406,7 +408,7 @@ module Camping
|
|
406
408
|
# end
|
407
409
|
# end
|
408
410
|
def to_a
|
409
|
-
@env['rack.session'] = Hash[@state]
|
411
|
+
@env['rack.session'][SK] = Hash[@state]
|
410
412
|
r = Rack::Response.new(@body, @status, @headers)
|
411
413
|
@cookies._n.each do |k, v|
|
412
414
|
r.set_cookie(k, v)
|
@@ -419,8 +421,8 @@ module Camping
|
|
419
421
|
@root, @input, @cookies, @state,
|
420
422
|
@headers, @status, @method =
|
421
423
|
r.script_name.sub(/\/$/,''), n(r.params),
|
422
|
-
Cookies[r.cookies], H[r.session
|
423
|
-
{}, m =~ /r(\d+)/ ? $1.to_i : 200, m
|
424
|
+
Cookies[r.cookies], H[r.session[SK]||{}],
|
425
|
+
{'Content-Type'=>'text/html'}, m =~ /r(\d+)/ ? $1.to_i : 200, m
|
424
426
|
@cookies._p = self/"/"
|
425
427
|
end
|
426
428
|
|
@@ -615,11 +617,26 @@ module Camping
|
|
615
617
|
#
|
616
618
|
# module Nuts::Controllers; ... end
|
617
619
|
# module Nuts::Models; ... end
|
618
|
-
# module Nuts::Views; ... end
|
620
|
+
# module Nuts::Views; ... end
|
621
|
+
#
|
622
|
+
# Additionally, you can pass a Binding as the second parameter,
|
623
|
+
# which enables you to create a Camping-based application within
|
624
|
+
# another module, for example to namespace your web interface and
|
625
|
+
# code for a worker process together:
|
626
|
+
#
|
627
|
+
# module YourApplication
|
628
|
+
# Camping.goes :Web, binding()
|
629
|
+
# module Web
|
630
|
+
# ...
|
631
|
+
# end
|
632
|
+
# module Worker
|
633
|
+
# ...
|
634
|
+
# end
|
635
|
+
# end
|
619
636
|
#
|
620
637
|
# All the applications will be available in Camping::Apps.
|
621
|
-
def goes(m)
|
622
|
-
Apps << a = eval(S.gsub(/Camping/,m.to_s),
|
638
|
+
def goes(m, g=TOPLEVEL_BINDING)
|
639
|
+
Apps << a = eval(S.gsub(/Camping/,m.to_s), g)
|
623
640
|
caller[0]=~/:/
|
624
641
|
IO.read(a.set:__FILE__,$`)=~/^__END__/ &&
|
625
642
|
(b=$'.split(/^@@\s*(.+?)\s*\r?\n/m)).shift rescue nil
|
data/lib/camping.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "uri";require "rack";class Object;def meta_def m,&b;(class<<self;self
|
2
2
|
end).send:define_method,m,&b end end;module Camping;C=self;S=IO.read(__FILE__
|
3
|
-
)rescue nil;P="<h1>Cam\ping Problem!</h1><h2>%s</h2>";U=Rack::Utils;O={};Apps=[]
|
4
|
-
class H<Hash;def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.
|
3
|
+
)rescue nil;P="<h1>Cam\ping Problem!</h1><h2>%s</h2>";U=Rack::Utils;O={};Apps=[];
|
4
|
+
SK=:camping;class H<Hash;def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.
|
5
5
|
to_s]:super end;undef id,type if ??==63 end;class Cookies<H;attr_accessor :_p;
|
6
6
|
def _n;@n||={}end;alias :_s :[]=;def set k,v,o={};_s(j=k.to_s,v);_n[j]=
|
7
7
|
{:value=>v,:path=>_p}.update o;end;def []=(k,v)set(k,v,v.is_a?(Hash)?v:{})end
|
@@ -23,12 +23,12 @@ end;end;def mab &b;extend(Mab);mab(&b) end;def r s,b,h={};b,h=
|
|
23
23
|
h,b if Hash===b;@status=s;@headers.merge!(h);@body=b end;def redirect *a;r 302,
|
24
24
|
'','Location'=>URL(*a).to_s end;def r404 p;P%"#{p} not found"end;def r500 k,m,e
|
25
25
|
raise e end;def r501 m;P%"#{m.upcase} not implemented"end;def serve(p,c)
|
26
|
-
(t=Rack::Mime.mime_type p[/\..*$/],
|
27
|
-
'rack.session']=Hash[@state];r=Rack::Response.new(@body,@status,@headers)
|
26
|
+
(t=Rack::Mime.mime_type p[/\..*$/],"text/html")&&@headers["Content-Type"]=t;c;end;def to_a;@env[
|
27
|
+
'rack.session'][SK]=Hash[@state];r=Rack::Response.new(@body,@status,@headers)
|
28
28
|
@cookies._n.each{|k,v|r.set_cookie k,v};r.to_a end;def initialize env,m
|
29
29
|
r=@request=Rack:: Request.new(@env=env);@root,@input,@cookies,@state,@headers,
|
30
30
|
@status,@method=r.script_name.sub(/\/$/,''),n(r.params),Cookies[r.cookies],
|
31
|
-
H[r.session
|
31
|
+
H[r.session[SK]||{}],{'Content-Type'=>'text/html'},m=~/r(\d+)/?$1.to_i: 200,m;@cookies._p=self/"/" end
|
32
32
|
def n h;Hash===h ?h.inject(H[]){|m,(k,v)|m[k]=
|
33
33
|
n(v);m}: h end;def service *a;r=catch(:halt){send(@method,*a)};@body||=r;self
|
34
34
|
end end;module Controllers;@r=[];class<<self;def R *u;r=@r;Class.
|
@@ -41,7 +41,7 @@ map{|c|k=const_get(c);k.send:include,C,X,Base,Helpers,Models
|
|
41
41
|
@r=[k]+@r if @r-[k]==@r;k.meta_def(:urls){["/#{c.to_s.scan(/.[^A-Z]*/).map(&
|
42
42
|
N.method(:[]))*'/'}"]}if !k.respond_to?:urls}end end;I=R()end;X=
|
43
43
|
Controllers;class<<self;def
|
44
|
-
goes m;Apps<<a=eval(S.gsub(/Camping/,m.to_s),
|
44
|
+
goes m,g=TOPLEVEL_BINDING;Apps<<a=eval(S.gsub(/Camping/,m.to_s),g);caller[0]=~/:/
|
45
45
|
IO.read(a.set:__FILE__,$`)=~/^__END__/&&(b=$'.split /^@@\s*(.+?)\s*\r?\n/m).shift rescue nil
|
46
46
|
a.set :_t,H[*b||[]];end;def call e;X.M
|
47
47
|
k,m,*a=X.D e["PATH_INFO"],e['REQUEST_METHOD'].
|
data/test/app_simple.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.531
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: mab
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rake
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rack-test
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,7 +69,12 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
description:
|
59
79
|
email: why@ruby-lang.org
|
60
80
|
executables:
|
@@ -156,9 +176,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
176
|
version: '0'
|
157
177
|
requirements: []
|
158
178
|
rubyforge_project: camping
|
159
|
-
rubygems_version: 1.8.
|
179
|
+
rubygems_version: 1.8.23
|
160
180
|
signing_key:
|
161
181
|
specification_version: 3
|
162
182
|
summary: minature rails for stay-at-home moms
|
163
183
|
test_files: []
|
164
|
-
has_rdoc: true
|