camping 1.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/blog/blog.rb +1 -0
- data/lib/camping-mural.rb +26 -27
- data/lib/camping.rb +8 -8
- metadata +47 -47
- data/examples/blog/blog3.db +0 -0
- data/examples/blog/camping.log +0 -16
data/examples/blog/blog.rb
CHANGED
data/lib/camping-mural.rb
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
%w[rubygems active_record markaby metaid ostruct].each {|lib| require lib}
|
2
|
-
module Camping;module Models;Base
|
3
|
-
Markaby::Builder.class_eval{include Views};module Controllers;module RM
|
2
|
+
module Camping;C=self;module Models;Base=ActiveRecord::Base;end;module Views
|
3
|
+
end;Markaby::Builder.class_eval{include Views};module Controllers;module RM
|
4
4
|
attr_accessor :input,:cookies,:headers,:body,:status;def method_missing(m,
|
5
5
|
*args, &blk);str=eval("markaby.#{m}(*args, &blk)");str=markaview(:layout){
|
6
6
|
str}rescue nil;r(200,str.to_s,'Content-Type'=>'text/html');end;def render(m)
|
7
|
-
str
|
7
|
+
str=markaview(m);str=markaview(:layout){ str }rescue nil;r(200, str,
|
8
8
|
"Content-Type" => 'text/html');end;def redirect(*args);c, *args = args;if \
|
9
|
-
c.respond_to? :urls;c
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
include RM end;class NotFound < R;def get;r(404,h1('Camping Problem!')+h2(
|
9
|
+
c.respond_to? :urls;c=c.urls.first.gsub(/\(.+?\)/){a=args.shift;a.
|
10
|
+
method(a.class.primary_key)[] rescue a};end;r(302,'','Location' => c);end
|
11
|
+
def r(s,b,h={});@status=s;@headers.merge!(h);@body = b;end;def service(
|
12
|
+
r,e,m,a);@status,@headers=200,{'Content-Type' => 'text/html'};@cookies=
|
13
|
+
C.cookie_parse(e['COOKIE']||e['HTTP_COOKIE']);cook=@cookies.marshal_dump.
|
14
|
+
dup;if (e['REQUEST_METHOD']=='POST')and %r|\Amultipart/form-data.*boundar\
|
15
|
+
y=\"?.+?\"?|n=~e['CONTENT_TYPE'];return r(500, "Urgh, multipart/form-data\
|
16
|
+
not yet supported.");else;@input=C.qs_parse(e['REQUEST_METHOD']!="POST" ?
|
17
|
+
e['QUERY_STRING']:r.read(e['CONTENT_LENGTH'].to_i));end;@body=method(m.
|
18
|
+
downcase).call(*a);@headers['Set-Cookie']=@cookies.marshal_dump.map{|k,v|
|
19
|
+
"#{k}=#{C.escape(v)};path=/"if v != cook[k]}.compact;self;end;def to_s;
|
20
|
+
"Status: #{@status}\n#{@headers.map{|k,v|v.to_a.map{|v2|"#{k}: #{v2}"}}.
|
21
|
+
flatten.join("\n")}\n\n#{@body}";end;private;def markaby;Markaby::Builder.
|
22
|
+
new( instance_variables.map{|iv|[iv[1..-1].intern,instance_variable_get(
|
23
|
+
iv)]},{});end;def markaview(m,*args,&blk);markaby.instance_eval{Views.
|
24
|
+
instance_method(m).bind(self).call(*args, &blk);self}.to_s;end;end;class R
|
25
|
+
include RM end;class NotFound < R;def get;r(404,h1('#{C} Problem!')+h2(
|
27
26
|
'Not Found'))end end;class<<self;def R(*urls);Class.new(R){meta_def(
|
28
27
|
:inherited){|c|c.meta_def(:urls){urls}}}end;def D(path);constants.each{|c|
|
29
28
|
k=const_get(c);return k,$~[1..-1]if (k.urls rescue "/#{c.downcase}").find{
|
@@ -35,10 +34,10 @@ end;def unescape(s);s.tr('+',' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){[$1.delete(
|
|
35
34
|
'%')].pack('H*')}end;def qs_parse(qs,d='&;');OpenStruct.new((qs||'').split(
|
36
35
|
/[#{d}] */n).inject({}){|hsh, p|k,v=p.split('=',2).map{|v|unescape(v)};hsh[
|
37
36
|
k]=v unless v.empty?;hsh}) end;def cookie_parse(s);c=qs_parse(s,';,') end
|
38
|
-
def run;begin;k,a,m=Controllers.D(ENV['PATH_INFO'])+[
|
39
|
-
"GET"];k.class_eval{include Controllers::RM};o=k.new
|
40
|
-
Models.constants.each{|c|g=Models.const_get(c)
|
41
|
-
const_defined? c;const_set c,g};
|
42
|
-
|
43
|
-
Builder.new({},{}){h1'
|
37
|
+
def run(r=$stdin,w=$stdout);begin;k,a,m=Controllers.D(ENV['PATH_INFO'])+[
|
38
|
+
ENV['REQUEST_METHOD']||"GET"];k.class_eval{include Controllers::RM};o=k.new
|
39
|
+
o.class.class_eval{Models.constants.each{|c|g=Models.const_get(c)
|
40
|
+
remove_const c if const_defined? c;const_set c,g}};w<<o.service(r,ENV,m,a)
|
41
|
+
rescue=>e;w<<Response.new(200){@headers['Content-Type']='text/html';@body=
|
42
|
+
Markaby::Builder.new({},{}){h1'#{C} Problem!';h2"#{k}.#{m}";h3"#{e.class} \
|
44
43
|
#{e.message}:";ul{e.backtrace.each{|bt|li bt}}}.to_s};end end end end
|
data/lib/camping.rb
CHANGED
@@ -20,15 +20,15 @@ module Camping
|
|
20
20
|
def redirect(*args)
|
21
21
|
c, *args = args
|
22
22
|
if c.respond_to? :urls
|
23
|
-
c = c.urls.first
|
24
|
-
|
25
|
-
|
23
|
+
c = c.urls.first.gsub(/\(.+?\)/) do
|
24
|
+
a = args.shift
|
25
|
+
a.method(a.class.primary_key)[] rescue a
|
26
26
|
end
|
27
27
|
end
|
28
28
|
r(302, '', 'Location' => c)
|
29
29
|
end
|
30
30
|
def r(s, b, h = {}); @status = s; @headers.merge!(h); @body = b; end
|
31
|
-
def service(e, m, a)
|
31
|
+
def service(r, e, m, a)
|
32
32
|
@status, @headers = 200, {'Content-Type' => 'text/html'}
|
33
33
|
@cookies = Camping.cookie_parse(e['HTTP_COOKIE'] || e['COOKIE'])
|
34
34
|
cook = @cookies.marshal_dump.dup
|
@@ -37,7 +37,7 @@ module Camping
|
|
37
37
|
return r(500, "Urgh, multipart/form-data not yet supported.")
|
38
38
|
else
|
39
39
|
@input = Camping.qs_parse(e['REQUEST_METHOD'] == "POST" ?
|
40
|
-
|
40
|
+
r.read(e['CONTENT_LENGTH'].to_i) : e['QUERY_STRING'])
|
41
41
|
end
|
42
42
|
|
43
43
|
@body = method( m.downcase ).call(*a)
|
@@ -84,7 +84,7 @@ module Camping
|
|
84
84
|
def qs_parse(qs, d = '&;'); OpenStruct.new((qs||'').split(/[#{d}] */n).
|
85
85
|
inject({}){|hsh, p|k, v = p.split('=',2).map {|v| unescape(v)}; hsh[k] = v unless v.empty?; hsh}) end
|
86
86
|
def cookie_parse(s); c = qs_parse(s, ';,'); end
|
87
|
-
def run
|
87
|
+
def run(r=$stdin,w=$stdout)
|
88
88
|
begin
|
89
89
|
k, a, m = Controllers.D(ENV['PATH_INFO']) + [ENV['REQUEST_METHOD'] || "GET"]
|
90
90
|
k.class_eval { include Controllers::RM }
|
@@ -96,9 +96,9 @@ module Camping
|
|
96
96
|
const_set c, g
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
99
|
+
w << o.service(r, ENV, m, a)
|
100
100
|
rescue => e
|
101
|
-
|
101
|
+
w << Response.new(200) { @headers['Content-Type'] = 'text/html'; @body = Markaby::Builder.new({}, {}) { h1 'Camping Problem!'; h2 "#{k}.#{m}"; h3 "#{e.class} #{e.message}:"; ul { e.backtrace.each { |bt| li bt } } }.to_s }
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
metadata
CHANGED
@@ -3,11 +3,11 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: camping
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "1.
|
7
|
-
date: 2006-01-
|
6
|
+
version: "1.1"
|
7
|
+
date: 2006-01-19 00:00:00 -07:00
|
8
8
|
summary: miniature rails for stay-at-home moms
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
11
|
email: why@ruby-lang.org
|
12
12
|
homepage: http://whytheluckystiff.net/camping/
|
13
13
|
rubyforge_project: hobix
|
@@ -18,60 +18,60 @@ bindir: bin
|
|
18
18
|
has_rdoc: false
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
20
|
requirements:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
25
24
|
version:
|
26
25
|
platform: ruby
|
27
26
|
signing_key:
|
28
27
|
cert_chain:
|
29
28
|
authors:
|
30
|
-
|
29
|
+
- why the lucky stiff
|
31
30
|
files:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
- lib/camping-mural.rb
|
40
|
-
- lib/camping.rb
|
31
|
+
- examples/blog
|
32
|
+
- examples/blog/blog.sqlite3
|
33
|
+
- examples/blog/blog.rb
|
34
|
+
- examples/blog/styles.css
|
35
|
+
- examples/blog/start
|
36
|
+
- lib/camping-mural.rb
|
37
|
+
- lib/camping.rb
|
41
38
|
test_files: []
|
39
|
+
|
42
40
|
rdoc_options: []
|
41
|
+
|
43
42
|
extra_rdoc_files: []
|
43
|
+
|
44
44
|
executables: []
|
45
|
+
|
45
46
|
extensions: []
|
47
|
+
|
46
48
|
requirements: []
|
49
|
+
|
47
50
|
dependencies:
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 0.0.0
|
77
|
-
version:
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: activerecord
|
53
|
+
version_requirement:
|
54
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">"
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 0.0.0
|
59
|
+
version:
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: markaby
|
62
|
+
version_requirement:
|
63
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.0.0
|
68
|
+
version:
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: metaid
|
71
|
+
version_requirement:
|
72
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.0.0
|
77
|
+
version:
|
data/examples/blog/blog3.db
DELETED
Binary file
|
data/examples/blog/camping.log
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# Logfile created on Tue Jan 17 22:57:14 MST 2006 by logger.rb/1.5.2.4
|
2
|
-
[4;36;1mCamping::Models::Post Load (0.000000)[0m [0;1mSQLite3::SQLException: no such table: posts: SELECT * FROM posts [0m
|
3
|
-
[4;36;1mCamping::Models::Post Load (0.000764)[0m [0;1mSELECT * FROM posts [0m
|
4
|
-
[4;36;1mCamping::Models::Post Load (0.000776)[0m [0;1mSELECT * FROM posts [0m
|
5
|
-
[4;36;1mCamping::Models::Post Load (0.000781)[0m [0;1mSELECT * FROM posts [0m
|
6
|
-
[4;36;1mCamping::Models::Post Load (0.000803)[0m [0;1mSELECT * FROM posts WHERE (posts.id = '1') LIMIT 1[0m
|
7
|
-
[4;36;1mCamping::Models::Post Load (0.000873)[0m [0;1mSELECT * FROM posts [0m
|
8
|
-
[4;36;1mCamping::Models::Post Load (0.000825)[0m [0;1mSELECT * FROM posts [0m
|
9
|
-
[4;36;1mCamping::Models::Post Load (0.000806)[0m [0;1mSELECT * FROM posts [0m
|
10
|
-
[4;36;1mCamping::Models::Post Load (0.000824)[0m [0;1mSELECT * FROM posts [0m
|
11
|
-
[4;36;1mCamping::Models::Post Load (0.000832)[0m [0;1mSELECT * FROM posts [0m
|
12
|
-
[4;36;1mCamping::Models::Post Load (0.000816)[0m [0;1mSELECT * FROM posts [0m
|
13
|
-
[4;36;1mCamping::Models::Post Load (0.000824)[0m [0;1mSELECT * FROM posts [0m
|
14
|
-
[4;36;1mCamping::Models::Post Load (0.000813)[0m [0;1mSELECT * FROM posts [0m
|
15
|
-
[4;36;1mCamping::Models::Post Load (0.000828)[0m [0;1mSELECT * FROM posts [0m
|
16
|
-
[4;36;1mCamping::Models::User Load (0.000831)[0m [0;1mSELECT * FROM users WHERE (username = '_why' AND password = 'hacky') LIMIT 1[0m
|