camping 2.1 → 2.1.467

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,97 +1,38 @@
1
1
  $:.unshift 'extras'
2
2
  require 'rake'
3
3
  require 'rake/clean'
4
- require 'rake/gempackagetask'
5
4
  require 'rake/testtask'
6
5
  require 'tempfile'
7
6
  require 'open3'
8
7
 
9
- task :default => :check
10
-
11
- ## Constants
12
- NAME = "camping"
13
- BRANCH = "2.1"
14
- GIT = ENV['GIT'] || "git"
15
- REV = `#{GIT} rev-list HEAD`.strip.split.length
16
- VERS = ENV['VERSION'] || (REV.zero? ? BRANCH : [BRANCH, REV] * '.')
8
+ require File.expand_path('../constants', __FILE__)
17
9
 
18
10
  CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'test/test.log', '.*.pt']
19
- RDOC_OPTS = ["--line-numbers", "--quiet", "--main", "README"]
20
-
21
- ## Packaging
22
- spec =
23
- Gem::Specification.new do |s|
24
- s.name = NAME
25
- s.version = VERS
26
- s.platform = Gem::Platform::RUBY
27
- s.has_rdoc = true
28
- s.extra_rdoc_files = FileList["README", "CHANGELOG", "COPYING", "book/*"].to_a
29
- s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)\/', '--exclude', 'lib/camping.rb']
30
- s.summary = "minature rails for stay-at-home moms"
31
- s.author = "why the lucky stiff"
32
- s.email = 'why@ruby-lang.org'
33
- s.homepage = 'http://camping.rubyforge.org/'
34
- s.rubyforge_project = 'camping'
35
- s.executables = ['camping']
36
-
37
- s.add_dependency('rack', '>=1.0')
38
- s.required_ruby_version = '>= 1.8.2'
39
-
40
- s.files = %w(COPYING README Rakefile) +
41
- Dir.glob("{bin,doc,test,lib,extras,book}/**/*") +
42
- Dir.glob("ext/**/*.{h,c,rb}") +
43
- Dir.glob("examples/**/*.rb") +
44
- Dir.glob("tools/*.rb")
45
-
46
- s.require_path = "lib"
47
- s.bindir = "bin"
48
- end
49
-
50
- omni =
51
- Gem::Specification.new do |s|
52
- s.name = "camping-omnibus"
53
- s.version = VERS
54
- s.platform = Gem::Platform::RUBY
55
- s.summary = "the camping meta-package for updating ActiveRecord, Mongrel and SQLite3 bindings"
56
- %w[author email homepage rubyforge_project].each { |x| s.__send__("#{x}=", spec.__send__(x)) }
57
-
58
- s.add_dependency('camping', "=#{VERS}")
59
- s.add_dependency('activerecord')
60
- s.add_dependency('sqlite3-ruby', '>=1.1.0.1')
61
- s.add_dependency('mongrel')
62
- s.add_dependency('RedCloth')
63
- s.add_dependency('markaby')
64
- end
65
-
11
+
12
+ task :default => :check
13
+
66
14
  ## RDoc
67
15
 
68
16
  begin
69
- gem 'rdoc', '~> 2.4.0'
17
+ gem 'rdoc', '~>3.9.0'
70
18
  rescue LoadError
71
- # Don't complain yet.
72
- end
73
-
74
- require 'rdoc/rdoc'
75
- require 'rake/rdoctask'
76
-
77
- Rake::RDocTask.new(:docs) do |rdoc|
78
- if defined?(RDoc::VERSION) && RDoc::VERSION[0,3] == "2.4"
19
+ task :docs do
20
+ puts "** Camping needs RDoc 3.9 in order to use the Flipbook template."
21
+ end
22
+ else
23
+ require 'rdoc/task'
24
+ RDoc::Task.new(:docs) do |rdoc|
79
25
  # We have a recent version of RDoc, so let's use flipbook.
80
26
  require 'rdoc/generator/singledarkfish'
81
27
  rdoc.options += ['-f', 'singledarkfish', *RDOC_OPTS]
82
28
  rdoc.template = "flipbook"
83
- else
84
- # Use whatever template is available, and give a little warning.
85
- task :docs do
86
- puts "** Camping needs RDoc 2.4 in order to use the Flipbook template."
87
- end
29
+
30
+ rdoc.rdoc_dir = 'doc'
31
+ rdoc.title = "Camping, a Microframework"
32
+ rdoc.rdoc_files.add ['README', 'lib/camping-unabridged.rb', 'lib/camping/**/*.rb', 'book/*']
88
33
  end
89
-
90
- rdoc.inline_source = false # --inline-source is deprecated
91
- rdoc.rdoc_dir = 'doc'
92
- rdoc.title = "Camping, a Microframework"
93
- rdoc.rdoc_files.add ['README', 'lib/camping-unabridged.rb', 'lib/camping/**/*.rb', 'book/*']
94
34
  end
35
+
95
36
 
96
37
  task :rubygems_docs do
97
38
  require 'rubygems/doc_manager'
@@ -105,29 +46,10 @@ end
105
46
  desc "Packages Camping."
106
47
  task :package => :clean
107
48
 
108
- Rake::GemPackageTask.new(spec) do |p|
109
- p.need_tar = true
110
- p.gem_spec = spec
111
- end
112
-
113
- Rake::GemPackageTask.new(omni) do |p|
114
- p.gem_spec = omni
115
- end
116
-
117
- task :install => :package do
118
- sh %{sudo gem install pkg/#{NAME}-#{VERS}}
119
- end
120
-
121
- task :uninstall => [:clean] do
122
- sh %{sudo gem uninstall #{NAME}}
123
- end
124
-
125
49
  ## Tests
126
50
  Rake::TestTask.new(:test) do |t|
127
51
  t.libs << "test"
128
52
  t.test_files = FileList['test/app_*.rb']
129
- # t.warning = true
130
- # t.verbose = true
131
53
  end
132
54
 
133
55
  ## Diff
@@ -153,11 +75,16 @@ end
153
75
  error = false
154
76
 
155
77
  ## Check
156
- task :check => ["test", "check:valid", "check:size", "check:lines", "check:exit"]
78
+ task :check => ["test", "check:valid", "check:equal", "check:size", "check:lines", "check:exit"]
157
79
  namespace :check do
158
80
 
159
81
  desc "Check source code validity"
160
82
  task :valid do
83
+ sh "ruby -c lib/camping.rb"
84
+ end
85
+
86
+ desc "Check equality between mural and unabridged"
87
+ task :equal do
161
88
  require 'ruby_parser'
162
89
  u = RubyParser.new.parse(File.read("lib/camping-unabridged.rb"))
163
90
  m = RubyParser.new.parse(File.read("lib/camping.rb"))
@@ -1,5 +1,16 @@
1
1
  // I know, I know.
2
2
  $(function() {
3
+ // #M0001 -> $(the section + the method body)
4
+ function m(name) {
5
+ var base = $(name);
6
+ return base.parent().add(base.next());
7
+ }
8
+
9
+ // #class-something -> $(the section below)
10
+ function s(name) {
11
+ return $(name).next();
12
+ }
13
+
3
14
  $('.source-link a').click(function() {
4
15
  var link = $(this);
5
16
  var code = link.parent().next();
@@ -64,16 +75,6 @@ $(function() {
64
75
  }
65
76
  });
66
77
 
67
- // #M0001 -> $(the section + the method body)
68
- function m(name) {
69
- var base = $(name);
70
- return base.parent().add(base.next());
71
- }
72
-
73
- // #class-something -> $(the section below)
74
- function s(name) {
75
- return $(name).next();
76
- }
77
78
  }
78
79
 
79
80
  });
@@ -82,6 +82,24 @@ module Camping
82
82
  end
83
83
  undef id, type if ?? == 63
84
84
  end
85
+
86
+ class Cookies < H
87
+ attr_accessor :_p
88
+ #
89
+ # Cookies that are set at this response
90
+ def _n; @n ||= {} end
91
+
92
+ alias _s []=
93
+
94
+ def set(k, v, o = {})
95
+ _s(j=k.to_s, v)
96
+ _n[j] = {:value => v, :path => _p}.update(o)
97
+ end
98
+
99
+ def []=(k, v)
100
+ set k, v, v.is_a?(Hash) ? v : {}
101
+ end
102
+ end
85
103
 
86
104
  # Helpers contains methods available in your controllers and views. You may
87
105
  # add methods of your own to this module, including many helper methods from
@@ -234,7 +252,7 @@ module Camping
234
252
  # it saves code for all the glue to stay in one place. Forgivable,
235
253
  # considering that it's only really a handful of methods and accessors.
236
254
  #
237
- # Everything in this module is accessable inside your controllers.
255
+ # Everything in this module is accessible inside your controllers.
238
256
  module Base
239
257
  attr_accessor :env, :request, :root, :input, :cookies, :state,
240
258
  :status, :headers, :body
@@ -250,6 +268,7 @@ module Camping
250
268
  def lookup(n)
251
269
  T.fetch(n.to_sym) do |k|
252
270
  t = Views.method_defined?(k) ||
271
+ (t = O[:_t].keys.grep(/^#{n}\./)[0]and Template[t].new{O[:_t][t]}) ||
253
272
  (f = Dir[[O[:views] || "views", "#{n}.*"]*'/'][0]) &&
254
273
  Template.new(f, O[f[/\.(\w+)$/, 1].to_sym] || {})
255
274
 
@@ -271,17 +290,17 @@ module Camping
271
290
  #
272
291
  def render(v, *a, &b)
273
292
  if t = lookup(v)
274
- o = Hash === a[-1] ? a.pop : {}
293
+ r, @_r = @_r, o = Hash === a[-1] ? a.pop : {}
275
294
  s = (t == true) ? mab{ send(v, *a, &b) } : t.render(self, o[:locals] || {}, &b)
276
- s = render(L, o.merge(L => false)) { s } if v.to_s[0] != ?_ && o[L] != false && lookup(L)
295
+ s = render(L, o.merge(L => false)) { s } if o[L] or o[L].nil? && lookup(L) && (!r && v.to_s[0] != ?_)
277
296
  s
278
297
  else
279
- raise "Can't find template #{v}"
298
+ raise "no template: #{v}"
280
299
  end
281
300
  end
282
301
 
283
- # You can directly return HTML form your controller for quick debugging
284
- # by calling this method and pass some Markaby to it.
302
+ # You can directly return HTML from your controller for quick debugging
303
+ # by calling this method and passing some Markaby to it.
285
304
  #
286
305
  # module Nuts::Controllers
287
306
  # class Info
@@ -367,6 +386,12 @@ module Camping
367
386
  def r501(m)
368
387
  P % "#{m.upcase} not implemented"
369
388
  end
389
+
390
+ # Serves the string +c+ with the MIME type of the filename +p+.
391
+ def serve(p, c)
392
+ t = Rack::Mime.mime_type(p[/\..*$/], nil) and @headers['Content-Type'] = t
393
+ c
394
+ end
370
395
 
371
396
  # Turn a controller into a Rack response. This is designed to be used to
372
397
  # pipe controllers into the <tt>r</tt> method. A great way to forward your
@@ -382,9 +407,7 @@ module Camping
382
407
  def to_a
383
408
  @env['rack.session'] = Hash[@state]
384
409
  r = Rack::Response.new(@body, @status, @headers)
385
- @cookies.each do |k, v|
386
- next if @old_cookies[k] == v
387
- v = { :value => v, :path => self / "/" } if String === v
410
+ @cookies._n.each do |k, v|
388
411
  r.set_cookie(k, v)
389
412
  end
390
413
  r.to_a
@@ -395,8 +418,9 @@ module Camping
395
418
  @root, @input, @cookies, @state,
396
419
  @headers, @status, @method =
397
420
  r.script_name.sub(/\/$/,''), n(r.params),
398
- H[@old_cookies = r.cookies], H[r.session],
421
+ Cookies[r.cookies], H[r.session.to_hash],
399
422
  {}, m =~ /r(\d+)/ ? $1.to_i : 200, m
423
+ @cookies._p = self/"/"
400
424
  end
401
425
 
402
426
  def n(h) # :nodoc:
@@ -504,11 +528,6 @@ module Camping
504
528
  module Controllers
505
529
  @r = []
506
530
  class << self
507
- # An array containing the various controllers available for dispatch.
508
- def r #:nodoc:
509
- @r
510
- end
511
-
512
531
  # Add routes to a controller class by piling them into the R method.
513
532
  #
514
533
  # The route is a regexp which will match the request path. Anything
@@ -544,7 +563,8 @@ module Camping
544
563
  # So, define your catch-all controllers last.
545
564
  def D(p, m, e)
546
565
  p = '/' if !p || !p[0]
547
- r.map { |k|
566
+ a=O[:_t].find{|n,_|n==p} and return [I, :serve, *a]
567
+ @r.map { |k|
548
568
  k.urls.map { |x|
549
569
  return (k.method_defined?(m)) ?
550
570
  [k, m, *$~[1..-1]] : [I, 'r501', m] if p =~ /^#{x}\/?$/
@@ -573,7 +593,7 @@ module Camping
573
593
  constants.map { |c|
574
594
  k = const_get(c)
575
595
  k.send :include,C,X,Base,Helpers,Models
576
- @r=[k]+r if r-[k]==r
596
+ @r=[k]+@r if @r-[k]==@r
577
597
  k.meta_def(:urls){["/#{c.to_s.scan(/.[^A-Z]*/).map(&N.method(:[]))*'/'}"]}if !k.respond_to?:urls
578
598
  }
579
599
  end
@@ -598,7 +618,11 @@ module Camping
598
618
  #
599
619
  # All the applications will be available in Camping::Apps.
600
620
  def goes(m)
601
- Apps << eval(S.gsub(/Camping/,m.to_s), TOPLEVEL_BINDING)
621
+ Apps << a = eval(S.gsub(/Camping/,m.to_s), TOPLEVEL_BINDING)
622
+ caller[0]=~/:/
623
+ IO.read(a.set:__FILE__,$`)=~/^__END__/ &&
624
+ (b=$'.split(/^@@\s*(.+?)\s*\r?\n/m)).shift rescue nil
625
+ a.set :_t,H[*b||[]]
602
626
  end
603
627
 
604
628
  # Ruby web servers use this method to enter the Camping realm. The +e+
@@ -732,8 +756,9 @@ module Camping
732
756
  # Models cannot be referred to in Views at this time.
733
757
  module Models
734
758
  autoload :Base,'camping/ar'
759
+ Helpers.send(:include, X, self)
735
760
  end
736
-
761
+
737
762
  autoload :Mab, 'camping/mab'
738
763
  autoload :Template, 'camping/template'
739
764
  C
@@ -2,44 +2,54 @@ 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
3
  )rescue nil;P="<h1>Cam\ping Problem!</h1><h2>%s</h2>";U=Rack::Utils;O={};Apps=[]
4
4
  class H<Hash;def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.
5
- to_s]:super end;undef id,type if ??==63;end;module Helpers;def R c,*g;p,h=
5
+ to_s]:super end;undef id,type if ??==63 end;class Cookies<H;attr_accessor :_p;
6
+ def _n;@n||={}end;alias :_s :[]=;def set k,v,o={};_s(j=k.to_s,v);_n[j]=
7
+ {:value=>v,:path=>_p}.update o;end;def []=(k,v)set(k,v,v.is_a?(Hash)?v:{})end
8
+ end;module Helpers;def R c,*g;p,h=
6
9
  /\(.+?\)/,g.grep(Hash);g-=h;raise"bad route"unless u=c.urls.find{|x|break x if
7
10
  x.scan(p).size==g.size&&/^#{x}\/?$/=~(x=g.inject(x){|x,a|x.sub p,U.escape((a.
8
- to_param rescue a))}.gsub(/\\(.)/){$1})};h.any?? u+"?"+U.build_query(h[0]):u end;def
9
- / p;p[0]==?/?@root + p : p end;def URL c='/',*a;c=R(c, *a) if c.respond_to?(
11
+ to_param rescue a))}.gsub(/\\(.)/){$1})};h.any?? u+"?"+U.build_query(h[0]):u
12
+ end;def / p;p[0]==?/?@root+p :p end;def URL c='/',*a;c=R(c,*a) if c.respond_to?(
10
13
  :urls);c=self/c;c=@request.url[/.{8,}?(?=\/)/]+c if c[0]==?/;URI c end end
11
14
  module Base;attr_accessor:env,:request,:root,:input,:cookies,:state,:status,
12
15
  :headers,:body;T={};L=:layout;def lookup n;T.fetch(n.to_sym){|k|t=Views.
13
- method_defined?(k)||(f=Dir[[O[:views]||"views","#{n}.*"]*'/'][0])&&Template.
16
+ method_defined?(k)||(t=O[:_t].keys.grep(/^#{n}\./)[0]and Template[t].new{
17
+ O[:_t][t]})||(f=Dir[[O[:views]||"views","#{n}.*"]*'/'][0])&&Template.
14
18
  new(f,O[f[/\.(\w+)$/,1].to_sym]||{});O[:dynamic_templates]?t:T[k]=t} end
15
- def render(v,*a,&b)if t=lookup(v);o=Hash===a[-1]?a.pop: {};s=(t==true)?mab{
19
+ def render v,*a,&b;if t=lookup(v);r,@_r=@_r,o=Hash===a[-1]?a.pop: {};s=(t==true)?mab{
16
20
  send v,*a,&b}: t.render(self,o[:locals]||{},&b);s=render(L,o.merge(L=>false)){s
17
- }if v.to_s[0]!=?_&&o[L]!=false&&lookup(L);s;else;raise"Can't find template #{v}"end
18
- end;def mab &b;(@mab||=Mab.new({},self)).capture(&b) end;def r s,b,h={};b,h=h,
19
- b if Hash===b;@status=s;@headers.merge!(h);@body=b;end;def redirect *a;r 302,'',
20
- 'Location'=>URL(*a).to_s;end;def r404 p;P%"#{p} not found"end;def r500 k,m,e
21
- raise e;end;def r501 m;P%"#{m.upcase} not implemented"end;def to_a;@env[
21
+ }if o[L]or o[L].nil?&&lookup(L)&&!r&&v.to_s[0]!=?_;s;else;raise"no template: #{v}"
22
+ end;end;def mab &b;(@mab||=Mab.new({},self)).capture(&b) end;def r s,b,h={};b,h=
23
+ h,b if Hash===b;@status=s;@headers.merge!(h);@body=b end;def redirect *a;r 302,
24
+ '','Location'=>URL(*a).to_s end;def r404 p;P%"#{p} not found"end;def r500 k,m,e
25
+ raise e end;def r501 m;P%"#{m.upcase} not implemented"end;def serve(p,c)
26
+ (t=Rack::Mime.mime_type p[/\..*$/],nil)&&@headers["Content-Type"]=t;c;end;def to_a;@env[
22
27
  'rack.session']=Hash[@state];r=Rack::Response.new(@body,@status,@headers)
23
- @cookies.each{|k,v|next if @old_cookies[k]==v;v={:value=>v,:path=>self/"/"} if
24
- String===v;r.set_cookie(k,v)};r.to_a;end;def initialize(env,m) r=@request=Rack::
25
- Request.new(@env=env);@root,@input,@cookies,@state,@headers,@status,@method=r.
26
- script_name.sub(/\/$/,''),n(r.params),H[@old_cookies = r.cookies],H[r.session],
27
- {},m=~/r(\d+)/?$1.to_i: 200,m end;def n h;Hash===h ?h.inject(H[]){|m,(k,v)|m[k]=
28
+ @cookies._n.each{|k,v|r.set_cookie k,v};r.to_a end;def initialize env,m
29
+ r=@request=Rack:: Request.new(@env=env);@root,@input,@cookies,@state,@headers,
30
+ @status,@method=r.script_name.sub(/\/$/,''),n(r.params),Cookies[r.cookies],
31
+ H[r.session.to_hash],{},m=~/r(\d+)/?$1.to_i: 200,m;@cookies._p=self/"/" end
32
+ def n h;Hash===h ?h.inject(H[]){|m,(k,v)|m[k]=
28
33
  n(v);m}: h end;def service *a;r=catch(:halt){send(@method,*a)};@body||=r;self
29
- end;end;module Controllers;@r=[];class<<self;def r;@r end;def R *u;r=@r;Class.
30
- new{meta_def(:urls){u};meta_def(:inherited){|x|r<<x}}end;def D p,m,e;p='/'if !p||
31
- !p[0];r.map{|k|k.urls.map{|x|return(k.method_defined? m)?[k,m,*$~[1..-1]]:[I,
32
- 'r501',m]if p=~/^#{x}\/?$/}};[I,'r404',p] end;N=H.new{|_,x|x.downcase}.merge!(
33
- "N"=>'(\d+)',"X"=>'([^/]+)',"Index"=>'');def M;def M;end;constants.map{|c|k=
34
- const_get(c);k.send:include,C,X,Base,Helpers,Models;@r=[k]+r if r-[k]==r
35
- k.meta_def(:urls){ [ "/#{c.to_s.scan(/.[^A-Z]*/).map(&N.method(:[]))*'/'}"]}if !k.
36
- respond_to?:urls}end end;I=R();end;X=Controllers;class<<self;def goes m;Apps<<
37
- eval(S.gsub(/Camping/,m.to_s),TOPLEVEL_BINDING) end;def call e;X.M
34
+ end end;module Controllers;@r=[];class<<self;def R *u;r=@r;Class.
35
+ new{meta_def(:urls){u};meta_def(:inherited){|x|r<<x}}end;def D p,m,e;p='/'if
36
+ !p||!p[0];(a=O[:_t].find{|n,_|n==p}) and return [I,:serve,*a]
37
+ @r.map{|k|k.urls.map{|x|return(k.method_defined? m)?[k,m,*$~[1..-1]]:
38
+ [I, 'r501',m]if p=~/^#{x}\/?$/}};[I,'r404',p] end;N=H.new{|_,x|x.downcase}.
39
+ merge!("N"=>'(\d+)',"X"=>'([^/]+)',"Index"=>'');def M;def M;end;constants.
40
+ map{|c|k=const_get(c);k.send:include,C,X,Base,Helpers,Models
41
+ @r=[k]+@r if @r-[k]==@r;k.meta_def(:urls){["/#{c.to_s.scan(/.[^A-Z]*/).map(&
42
+ N.method(:[]))*'/'}"]}if !k.respond_to?:urls}end end;I=R()end;X=
43
+ Controllers;class<<self;def
44
+ goes m;Apps<<a=eval(S.gsub(/Camping/,m.to_s),TOPLEVEL_BINDING);caller[0]=~/:/
45
+ IO.read(a.set:__FILE__,$`)=~/^__END__/&&(b=$'.split /^@@\s*(.+?)\s*\r?\n/m).shift rescue nil
46
+ a.set :_t,H[*b||[]];end;def call e;X.M
38
47
  p=e['PATH_INFO']=U.unescape(e['PATH_INFO']);k,m,*a=X.D p,e['REQUEST_METHOD'].
39
- downcase,e;k.new(e,m).service(*a).to_a;rescue;r500(:I,k,m,$!,:env=>e).to_a;end
48
+ downcase,e;k.new(e,m).service(*a).to_a;rescue;r500(:I,k,m,$!,:env=>e).to_a end
40
49
  def method_missing m,c,*a;X.M;h=Hash===a[-1]?a.pop: {};e=H[Rack::MockRequest.
41
50
  env_for('',h.delete(:env)||{})];k=X.const_get(c).new(e,m.to_s);h.each{|i,v|k.
42
- send"#{i}=",v};k.service(*a);end;def use*a,&b;m=a.shift.new(method(:call),*a,&b)
51
+ send"#{i}=",v};k.service(*a) end;def use*a,&b;m=a.shift.new(method(:call),*a,&b)
43
52
  meta_def(:call){|e|m.call(e)}end;def options;O end;def set k,v;O[k]=v end end
44
- module Views;include X,Helpers end;module Models;autoload:Base,'camping/ar';end
45
- autoload:Mab,'camping/mab';autoload:Template,'camping/template';C end
53
+ module Views;include X,Helpers end;module Models;autoload:Base,'camping/ar'
54
+ Helpers.send:include,X,self end;autoload:Mab,'camping/mab'
55
+ autoload:Template,'camping/template';C end
@@ -53,6 +53,10 @@ module Camping
53
53
  # Loads the apps availble in this script. Use <tt>apps</tt> to get
54
54
  # the loaded apps.
55
55
  def load_apps
56
+ @requires.each do |path|
57
+ $LOADED_FEATURES.delete(path)
58
+ end
59
+
56
60
  all_requires = $LOADED_FEATURES.dup
57
61
  all_apps = Camping::Apps.dup
58
62
 
@@ -122,7 +126,7 @@ module Camping
122
126
  def full_path(req)
123
127
  dir = $LOAD_PATH.detect { |l| File.exists?(File.join(l, req)) }
124
128
  if dir
125
- File.join(File.expand_path(dir), req)
129
+ File.expand_path(req, File.expand_path(dir))
126
130
  else
127
131
  req
128
132
  end
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+ require 'camping'
3
+
4
+ Camping.goes :Cookies
5
+
6
+ module Cookies::Controllers
7
+ class One
8
+ def get
9
+ @cookies.simple = '42'
10
+ @cookies.set :complex, '43'
11
+ @cookies.set :past, 'past', :expires => Time.now - 5
12
+ render :show
13
+ end
14
+ end
15
+
16
+ class Two
17
+ def get
18
+ render :show
19
+ end
20
+ end
21
+
22
+ class Old
23
+ def get
24
+ @cookies.simple = '42'
25
+ @cookies.complex = { :value => '43' }
26
+ @cookies.past = { :value => 'past', :expires => Time.now - 5 }
27
+ @cookies.past.class.name
28
+ end
29
+ end
30
+ end
31
+
32
+ module Cookies::Views
33
+ def show
34
+ @cookies.values_at('simple', 'complex', 'past').inspect
35
+ end
36
+ end
37
+
38
+ class Cookies::Test < TestCase
39
+ def test_cookies
40
+ get '/one'
41
+ assert_body '["42", "43", "past"]'
42
+
43
+ get '/two'
44
+ assert_body '["42", "43", nil]'
45
+ end
46
+
47
+ def test_backward_compatible
48
+ get '/old'
49
+ assert_body 'Hash'
50
+
51
+ get '/two'
52
+ assert_body '["42", "43", nil]'
53
+ end
54
+
55
+ def test_path
56
+ get '/one', {}, 'SCRIPT_NAME' => '/mnt'
57
+ assert_body '["42", "43", "past"]'
58
+ assert_equal 3, last_response.headers["Set-Cookie"].scan('path=/mnt/').size
59
+ end
60
+ end
61
+
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+ require 'camping'
3
+
4
+ Camping.goes :FileSource
5
+
6
+ module FileSource::Controllers
7
+ class Index
8
+ def get
9
+ FileSource.options[:__FILE__]
10
+ end
11
+ end
12
+ end
13
+
14
+ class FileSource::Test < TestCase
15
+ def test_source
16
+ get '/'
17
+ assert_body __FILE__
18
+ end
19
+
20
+ def test_file
21
+ get '/style.css'
22
+ assert_body "* { margin: 0; padding: 0 }"
23
+ assert_equal "text/css", last_response.headers['Content-Type']
24
+
25
+ get '/test.foo'
26
+ assert_body "Hello"
27
+ assert_equal "text/html", last_response.headers['Content-Type']
28
+
29
+ get '/test'
30
+ assert_body "No extension"
31
+ assert_equal "text/html", last_response.headers['Content-Type']
32
+ end
33
+ end
34
+
35
+ __END__
36
+
37
+ @@ /style.css
38
+ * { margin: 0; padding: 0 }
39
+
40
+ @@ /test.foo
41
+ Hello
42
+
43
+ @@ /test
44
+ No extension
45
+
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+ require 'camping'
3
+
4
+ Camping.goes :Helpers
5
+
6
+ module Helpers::Helpers
7
+ def frontpage
8
+ R(Index)
9
+ end
10
+
11
+ def current_user
12
+ User.new
13
+ end
14
+ end
15
+
16
+ module Helpers::Models
17
+ class User
18
+ def name
19
+ 'Bob'
20
+ end
21
+ end
22
+ end
23
+
24
+ module Helpers::Controllers
25
+ class Index
26
+ def get
27
+ current_user.name
28
+ end
29
+ end
30
+
31
+ class Users
32
+ def get
33
+ frontpage
34
+ end
35
+ end
36
+ end
37
+
38
+ class Helpers::Test < TestCase
39
+ def test_models
40
+ get '/'
41
+ assert_body "Bob"
42
+ end
43
+
44
+ def test_controllers
45
+ get '/users'
46
+ assert_body "/"
47
+ end
48
+ end
49
+
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+ require 'camping'
3
+
4
+ Camping.goes :Inline
5
+
6
+ module Inline::Controllers
7
+ class Index
8
+ def get
9
+ @world = "World"
10
+ render :index
11
+ end
12
+ end
13
+
14
+ class UserX
15
+ def get(name)
16
+ @name = name
17
+ render :user
18
+ end
19
+ end
20
+ end
21
+
22
+ class Inline::Test < TestCase
23
+ def test_inline
24
+ get '/'
25
+ assert_body "Hello World"
26
+
27
+ get '/user/Bluebie'
28
+ assert_body "My name is Bluebie"
29
+ end
30
+ end
31
+
32
+ __END__
33
+
34
+ @@ index.erb
35
+ Hello <%= @world %>
36
+
37
+ @@ user.erb
38
+ My name is <%= @name %>
39
+
@@ -0,0 +1,118 @@
1
+ require 'test_helper'
2
+ require 'camping'
3
+
4
+ Camping.goes :Partials
5
+ Camping.goes :TiltPartials
6
+
7
+ module Partials::Controllers
8
+ class Index
9
+ def get
10
+ render :index
11
+ end
12
+ end
13
+
14
+ class Partial
15
+ def get
16
+ render :_partial
17
+ end
18
+ end
19
+
20
+ class Nolayout
21
+ def get
22
+ render :index, :layout => false
23
+ end
24
+ end
25
+
26
+ class Forcelayout
27
+ def get
28
+ render :_partial, :layout => true
29
+ end
30
+ end
31
+
32
+ class Nested
33
+ def get
34
+ render :nested
35
+ end
36
+ end
37
+ end
38
+
39
+ # Copy over all controllers
40
+ module TiltPartials::Controllers
41
+ Partials::Controllers.constants.each do |const|
42
+ const_set(const, Partials::Controllers.const_get(const).dup)
43
+ end
44
+ end
45
+
46
+ module Partials::Views
47
+ def layout
48
+ body do
49
+ yield
50
+ end
51
+ end
52
+
53
+ def index
54
+ h1 "Index"
55
+ _partial
56
+ end
57
+
58
+ def _partial
59
+ p "Partial"
60
+ end
61
+
62
+ def nested
63
+ h1 "Nested"
64
+ regular
65
+ end
66
+
67
+ def regular
68
+ p "Regular"
69
+ end
70
+ end
71
+
72
+ class Partials::Test < TestCase
73
+ def test_underscore_partial
74
+ get '/'
75
+ assert_body "<body><h1>Index</h1><p>Partial</p></body>"
76
+ end
77
+
78
+ def test_underscore_partial_only
79
+ get '/partial'
80
+ assert_body "<p>Partial</p>"
81
+ end
82
+
83
+ def test_nolayout
84
+ get '/nolayout'
85
+ assert_body "<h1>Index</h1><p>Partial</p>"
86
+ end
87
+
88
+ def test_forcelayout
89
+ get '/forcelayout'
90
+ assert_body "<body><p>Partial</p></body>"
91
+ end
92
+
93
+ def test_netsted
94
+ get '/nested'
95
+ assert_body "<body><h1>Nested</h1><p>Regular</p></body>"
96
+ end
97
+ end
98
+
99
+ class TiltPartials::Test < Partials::Test
100
+ end
101
+
102
+
103
+ __END__
104
+ @@ layout.str
105
+ <body>#{yield.strip}</body>
106
+
107
+ @@ index.str
108
+ <h1>Index</h1>#{render(:_partial).strip}
109
+
110
+ @@ _partial.str
111
+ <p>Partial</p>
112
+
113
+ @@ nested.str
114
+ <h1>Nested</h1>#{render(:regular).strip}
115
+
116
+ @@ regular.str
117
+ <p>Regular</p>
118
+
@@ -36,11 +36,7 @@ class Sessions::Test < TestCase
36
36
  def test_session
37
37
  get '/one'
38
38
  follow_redirect!
39
-
40
- get '/two'
41
39
  follow_redirect!
42
-
43
- get '/three'
44
40
  assert_body "[42, 56, 99]"
45
41
  end
46
42
  end
@@ -5,7 +5,12 @@ begin
5
5
  rescue LoadError
6
6
  end
7
7
 
8
- require 'camping-unabridged'
8
+ if ENV['ABRIDGED']
9
+ require 'camping'
10
+ else
11
+ require 'camping-unabridged'
12
+ end
13
+
9
14
  require 'test/unit'
10
15
  require 'rack/test'
11
16
 
@@ -36,9 +41,9 @@ class TestCase < Test::Unit::TestCase
36
41
  def assert_body(str)
37
42
  case str
38
43
  when Regexp
39
- assert_match(str, last_response.body)
44
+ assert_match(str, last_response.body.strip)
40
45
  else
41
- assert_equal(str.to_s, last_response.body)
46
+ assert_equal(str.to_s, last_response.body.strip)
42
47
  end
43
48
  end
44
49
 
metadata CHANGED
@@ -1,11 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camping
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 2
7
- - 1
8
- version: "2.1"
4
+ version: 2.1.467
5
+ prerelease:
9
6
  platform: ruby
10
7
  authors:
11
8
  - why the lucky stiff
@@ -13,22 +10,41 @@ autorequire:
13
10
  bindir: bin
14
11
  cert_chain: []
15
12
 
16
- date: 2010-08-19 00:00:00 +02:00
17
- default_executable:
13
+ date: 2011-10-05 00:00:00 Z
18
14
  dependencies:
19
15
  - !ruby/object:Gem::Dependency
20
16
  name: rack
21
- prerelease: false
22
17
  requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
23
19
  requirements:
24
20
  - - ">="
25
21
  - !ruby/object:Gem::Version
26
- segments:
27
- - 1
28
- - 0
29
22
  version: "1.0"
30
23
  type: :runtime
24
+ prerelease: false
31
25
  version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - "="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.7
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rack-test
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
32
48
  description:
33
49
  email: why@ruby-lang.org
34
50
  executables:
@@ -47,7 +63,12 @@ files:
47
63
  - README
48
64
  - Rakefile
49
65
  - bin/camping
66
+ - test/app_cookies.rb
67
+ - test/app_file.rb
68
+ - test/app_helpers.rb
69
+ - test/app_inline_templates.rb
50
70
  - test/app_markup.rb
71
+ - test/app_partials.rb
51
72
  - test/app_route_generating.rb
52
73
  - test/app_sessions.rb
53
74
  - test/app_simple.rb
@@ -93,7 +114,6 @@ files:
93
114
  - book/51_upgrading
94
115
  - examples/blog.rb
95
116
  - CHANGELOG
96
- has_rdoc: true
97
117
  homepage: http://camping.rubyforge.org/
98
118
  licenses: []
99
119
 
@@ -110,25 +130,21 @@ rdoc_options:
110
130
  require_paths:
111
131
  - lib
112
132
  required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
113
134
  requirements:
114
135
  - - ">="
115
136
  - !ruby/object:Gem::Version
116
- segments:
117
- - 1
118
- - 8
119
- - 2
120
137
  version: 1.8.2
121
138
  required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
122
140
  requirements:
123
141
  - - ">="
124
142
  - !ruby/object:Gem::Version
125
- segments:
126
- - 0
127
143
  version: "0"
128
144
  requirements: []
129
145
 
130
146
  rubyforge_project: camping
131
- rubygems_version: 1.3.6
147
+ rubygems_version: 1.8.11
132
148
  signing_key:
133
149
  specification_version: 3
134
150
  summary: minature rails for stay-at-home moms