camping 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,6 +22,7 @@ module Camping::Controllers
22
22
  def get
23
23
  if cookies.user_id
24
24
  @session = User.find cookies.user_id
25
+ @post = Post.new
25
26
  end
26
27
  render :add
27
28
  end
@@ -1,29 +1,28 @@
1
1
  %w[rubygems active_record markaby metaid ostruct].each {|lib| require lib}
2
- module Camping;module Models;Base = ActiveRecord::Base;end;module Views;end
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 = markaview(m);str = markaview(:layout){ str }rescue nil;r(200, 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 = c.urls.first;c.gsub!(/\(.+?\)/) do;((a = args.
10
- shift).respond_to?(:primary_key) ? a.method(a.primary_key) : a).to_s;end
11
- end;r(302,'','Location' => c);end;def r(s, b, h = {});@status = s;@headers.
12
- merge!(h);@body = b;end;def service(e, m, a);@status, @headers = 200,
13
- {'Content-Type' => 'text/html'};@cookies=Camping.cookie_parse(e['COOKIE']||
14
- e['HTTP_COOKIE']);cook = @cookies.marshal_dump.dup;if (e['REQUEST_METHOD']==
15
- 'POST')and %r|\Amultipart/form-data.*boundary=\"?.+?\"?|n=~e['CONTENT_TYPE']
16
- return r(500, "Urgh, multipart/form-data not yet supported.");else;@input =
17
- Camping.qs_parse(e['REQUEST_METHOD']!="POST" ? e['QUERY_STRING'] : $stdin.
18
- read(e['CONTENT_LENGTH'].to_i));end;@body = method( m.downcase ).call(*a)
19
- @headers['Set-Cookie'] = @cookies.marshal_dump.map { |k,v| "#{k}=#{Camping.
20
- escape(v)}; path=/"if v != cook[k]}.compact;self;end;def to_s;"Status: #{
21
- @status}\n#{@headers.map{|k,v|v.to_a.map{|v2|"#{k}: #{v2}"}}.flatten.join(
22
- "\n")}\n\n#{@body}";end;private;def markaby;Markaby::Builder.new(
23
- instance_variables.map{|iv|[iv[1..-1].intern, instance_variable_get(iv)] },
24
- {});end;def markaview(m,*args,&blk);markaby.instance_eval{Views.
25
- instance_method(m).bind(self).call(*args, &blk); self }.to_s;end;end;class R
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'])+[ENV['REQUEST_METHOD']||
39
- "GET"];k.class_eval{include Controllers::RM};o=k.new;o.class.class_eval do
40
- Models.constants.each{|c|g=Models.const_get(c);remove_const c if
41
- const_defined? c;const_set c,g};end;puts o.service(ENV, m, a);rescue=>e
42
- puts Response.new(200){@headers['Content-Type']='text/html';@body=Markaby::
43
- Builder.new({},{}){h1'Camping Problem!';h2"#{k}.#{m}";h3"#{e.class} \
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
@@ -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
- c.gsub!(/\(.+?\)/) do
25
- ((a = args.shift).respond_to?(:primary_key) ? a.method(a.primary_key) : a).to_s
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
- $stdin.read(e['CONTENT_LENGTH'].to_i) : e['QUERY_STRING'])
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
- puts o.service(ENV, m, a)
99
+ w << o.service(r, ENV, m, a)
100
100
  rescue => e
101
- puts 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 }
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.0"
7
- date: 2006-01-18 00:00:00 -07:00
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
- - lib
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
- - !ruby/object:Gem::Version
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
- - why the lucky stiff
29
+ - why the lucky stiff
31
30
  files:
32
- - examples/blog
33
- - examples/blog/blog.sqlite3
34
- - examples/blog/blog.rb
35
- - examples/blog/camping.log
36
- - examples/blog/start
37
- - examples/blog/blog3.db
38
- - examples/blog/styles.css
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
- - !ruby/object:Gem::Dependency
49
- name: activerecord
50
- version_requirement:
51
- version_requirements: !ruby/object:Gem::Version::Requirement
52
- requirements:
53
- -
54
- - ">"
55
- - !ruby/object:Gem::Version
56
- version: 0.0.0
57
- version:
58
- - !ruby/object:Gem::Dependency
59
- name: markaby
60
- version_requirement:
61
- version_requirements: !ruby/object:Gem::Version::Requirement
62
- requirements:
63
- -
64
- - ">"
65
- - !ruby/object:Gem::Version
66
- version: 0.0.0
67
- version:
68
- - !ruby/object:Gem::Dependency
69
- name: metaid
70
- version_requirement:
71
- version_requirements: !ruby/object:Gem::Version::Requirement
72
- requirements:
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:
Binary file
@@ -1,16 +0,0 @@
1
- # Logfile created on Tue Jan 17 22:57:14 MST 2006 by logger.rb/1.5.2.4
2
- Camping::Models::Post Load (0.000000) SQLite3::SQLException: no such table: posts: SELECT * FROM posts 
3
- Camping::Models::Post Load (0.000764) SELECT * FROM posts 
4
- Camping::Models::Post Load (0.000776) SELECT * FROM posts 
5
- Camping::Models::Post Load (0.000781) SELECT * FROM posts 
6
- Camping::Models::Post Load (0.000803) SELECT * FROM posts WHERE (posts.id = '1') LIMIT 1
7
- Camping::Models::Post Load (0.000873) SELECT * FROM posts 
8
- Camping::Models::Post Load (0.000825) SELECT * FROM posts 
9
- Camping::Models::Post Load (0.000806) SELECT * FROM posts 
10
- Camping::Models::Post Load (0.000824) SELECT * FROM posts 
11
- Camping::Models::Post Load (0.000832) SELECT * FROM posts 
12
- Camping::Models::Post Load (0.000816) SELECT * FROM posts 
13
- Camping::Models::Post Load (0.000824) SELECT * FROM posts 
14
- Camping::Models::Post Load (0.000813) SELECT * FROM posts 
15
- Camping::Models::Post Load (0.000828) SELECT * FROM posts 
16
- Camping::Models::User Load (0.000831) SELECT * FROM users WHERE (username = '_why' AND password = 'hacky') LIMIT 1