Capcode 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -111,7 +111,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
111
111
  <h3 class="section-bar">Methods</h3>
112
112
 
113
113
  <div class="name-list">
114
- <a href="#M000021">http_authentication</a>&nbsp;&nbsp;
114
+ <a href="#M000022">http_authentication</a>&nbsp;&nbsp;
115
115
  </div>
116
116
  </div>
117
117
 
@@ -133,11 +133,11 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
133
133
  <div id="methods">
134
134
  <h3 class="section-bar">Public Instance methods</h3>
135
135
 
136
- <div id="method-M000021" class="method-detail">
137
- <a name="M000021"></a>
136
+ <div id="method-M000022" class="method-detail">
137
+ <a name="M000022"></a>
138
138
 
139
139
  <div class="method-heading">
140
- <a href="#M000021" class="method-signature">
140
+ <a href="#M000022" class="method-signature">
141
141
  <span class="method-name">http_authentication</span><span class="method-args">( opts = {}, &amp;b )</span>
142
142
  </a>
143
143
  </div>
@@ -173,8 +173,8 @@ The block must return a Hash of username =&gt; password like that :
173
173
  }
174
174
  </pre>
175
175
  <p><a class="source-toggle" href="#"
176
- onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
177
- <div class="method-source-code" id="M000021-source">
176
+ onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
177
+ <div class="method-source-code" id="M000022-source">
178
178
  <pre>
179
179
  <span class="ruby-comment cmt"># File lib/capcode/helpers/auth.rb, line 105</span>
180
180
  105: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">http_authentication</span>( <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span> )
@@ -1 +1 @@
1
- Wed, 27 Jan 2010 20:49:26 +0100
1
+ Fri, 05 Feb 2010 19:23:09 +0100
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Wed Jan 27 14:01:28 +0100 2010</td>
59
+ <td>Thu Feb 04 15:27:28 +0100 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -71,7 +71,7 @@
71
71
  <div id="description">
72
72
  <h1><a href="../classes/Capcode.html">Capcode</a></h1>
73
73
  <p>
74
- Copyright (C) 2009 Gregoire Lejeune
74
+ Copyright (C) 2009, 2010 Gregoire Lejeune
75
75
  </p>
76
76
  <ul>
77
77
  <li>home : <a href="http://capcode.rubyforge.org">capcode.rubyforge.org</a>
@@ -91,6 +91,22 @@ href="http://www.algorithmique.net/capcode">www.algorithmique.net/capcode</a>/
91
91
  <a href="../classes/Capcode.html">Capcode</a> is a web microframework
92
92
  </p>
93
93
  <h2>FEATURES/PROBLEMS:</h2>
94
+ <h3>0.9.2</h3>
95
+ <ul>
96
+ <li>Remove JSON dependency
97
+
98
+ </li>
99
+ <li>Add the &quot;HTTP code&quot; renderer, so you can now use something like
100
+ this : render 200 =&gt; &quot;OK&quot;, :server =&gt; &quot;<a
101
+ href="../classes/Capcode.html">Capcode</a>&quot;, &#8230;
102
+
103
+ </li>
104
+ <li>Reintroduce before_filter. <a
105
+ href="http://github.com/glejeune/Capcode/tree/master/examples/filter.rb">See
106
+ example filter.rb</a>.
107
+
108
+ </li>
109
+ </ul>
94
110
  <h3>0.9.1</h3>
95
111
  <ul>
96
112
  <li>You don&#8216;t need to require the renderers. This will be done by <a
@@ -109,12 +125,10 @@ href="../classes/Capcode.html">Capcode</a> at use time.
109
125
  <li>THIS VERSION IS A MAJOR ENHANCEMENT : YOU MUST UNINSTALL ALL PREVIOUS
110
126
  VERSIONS !!!
111
127
 
128
+ <pre>
129
+ gem uninstall Capode --version '&lt; 0.9.0'
130
+ </pre>
112
131
  </li>
113
- </ul>
114
- <p>
115
- gem uninstall Capode &#8212;version &#8217;&lt; 0.9.0&#8216;
116
- </p>
117
- <ul>
118
132
  <li>Renderers and database accessors have been extracted and are now in the <a
119
133
  href="http://github.com/glejeune/Capcode.more">plugins repository</a>. Each
120
134
  plugin is a gem that&#8216;s can be installed separately.
@@ -0,0 +1,101 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: filters.rb</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>filters.rb</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>lib/capcode/filters.rb
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Thu Feb 04 16:06:55 +0100 2010</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+
72
+
73
+ </div>
74
+
75
+
76
+ </div>
77
+
78
+
79
+ <!-- if includes -->
80
+
81
+ <div id="section">
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+ <!-- if method_list -->
91
+
92
+
93
+ </div>
94
+
95
+
96
+ <div id="validator-badges">
97
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
98
+ </div>
99
+
100
+ </body>
101
+ </html>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Wed Jan 27 14:00:59 +0100 2010</td>
59
+ <td>Thu Feb 04 15:36:48 +0100 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -81,7 +81,6 @@ Please read the README.rdoc file !
81
81
  <div class="name-list">
82
82
  rubygems&nbsp;&nbsp;
83
83
  rack&nbsp;&nbsp;
84
- json&nbsp;&nbsp;
85
84
  logger&nbsp;&nbsp;
86
85
  optparse&nbsp;&nbsp;
87
86
  irb&nbsp;&nbsp;
@@ -91,6 +90,7 @@ Please read the README.rdoc file !
91
90
  capcode/helpers/auth&nbsp;&nbsp;
92
91
  capcode/render/text&nbsp;&nbsp;
93
92
  capcode/configuration&nbsp;&nbsp;
93
+ capcode/filters&nbsp;&nbsp;
94
94
  mongrel&nbsp;&nbsp;
95
95
  </div>
96
96
  </div>
@@ -26,6 +26,7 @@
26
26
  <a href="files/lib/capcode_rb.html">lib/capcode.rb</a><br />
27
27
  <a href="files/lib/capcode/base/db_rb.html">lib/capcode/base/db.rb</a><br />
28
28
  <a href="files/lib/capcode/configuration_rb.html">lib/capcode/configuration.rb</a><br />
29
+ <a href="files/lib/capcode/filters_rb.html">lib/capcode/filters.rb</a><br />
29
30
  <a href="files/lib/capcode/helpers/auth_rb.html">lib/capcode/helpers/auth.rb</a><br />
30
31
  <a href="files/lib/capcode/render/text_rb.html">lib/capcode/render/text.rb</a><br />
31
32
  </div>
@@ -21,28 +21,29 @@
21
21
  <h1 class="section-bar">Methods</h1>
22
22
  <div id="index-entries">
23
23
  <a href="classes/Capcode.html#M000001">Route (Capcode)</a><br />
24
- <a href="classes/Capcode/Helpers.html#M000018">URL (Capcode::Helpers)</a><br />
24
+ <a href="classes/Capcode/Helpers.html#M000019">URL (Capcode::Helpers)</a><br />
25
25
  <a href="classes/Capcode.html#M000010">application (Capcode)</a><br />
26
- <a href="classes/Capcode/Helpers.html#M000013">args (Capcode::Helpers)</a><br />
27
- <a href="classes/Capcode/Helpers.html#M000014">args= (Capcode::Helpers)</a><br />
28
- <a href="classes/Capcode/Helpers.html#M000019">content_for (Capcode::Helpers)</a><br />
26
+ <a href="classes/Capcode/Helpers.html#M000014">args (Capcode::Helpers)</a><br />
27
+ <a href="classes/Capcode/Helpers.html#M000015">args= (Capcode::Helpers)</a><br />
28
+ <a href="classes/Capcode.html#M000013">before_filter (Capcode)</a><br />
29
+ <a href="classes/Capcode/Helpers.html#M000020">content_for (Capcode::Helpers)</a><br />
29
30
  <a href="classes/Capcode.html#M000003">env (Capcode)</a><br />
30
- <a href="classes/Capcode/Configuration.html#M000023">get (Capcode::Configuration)</a><br />
31
+ <a href="classes/Capcode/Configuration.html#M000024">get (Capcode::Configuration)</a><br />
31
32
  <a href="classes/Capcode.html#M000009">http_authentication (Capcode)</a><br />
32
- <a href="classes/Capcode/Helpers/Authorization.html#M000021">http_authentication (Capcode::Helpers::Authorization)</a><br />
33
- <a href="classes/Capcode/Helpers.html#M000016">json (Capcode::Helpers)</a><br />
33
+ <a href="classes/Capcode/Helpers/Authorization.html#M000022">http_authentication (Capcode::Helpers::Authorization)</a><br />
34
+ <a href="classes/Capcode/Helpers.html#M000017">json (Capcode::Helpers)</a><br />
34
35
  <a href="classes/Capcode.html#M000007">map (Capcode)</a><br />
35
- <a href="classes/Capcode/Configuration.html#M000024">options (Capcode::Configuration)</a><br />
36
+ <a href="classes/Capcode/Configuration.html#M000025">options (Capcode::Configuration)</a><br />
36
37
  <a href="classes/Capcode.html#M000002">params (Capcode)</a><br />
37
- <a href="classes/Capcode/Helpers.html#M000017">redirect (Capcode::Helpers)</a><br />
38
- <a href="classes/Capcode/Helpers.html#M000015">render (Capcode::Helpers)</a><br />
38
+ <a href="classes/Capcode/Helpers.html#M000018">redirect (Capcode::Helpers)</a><br />
39
+ <a href="classes/Capcode/Helpers.html#M000016">render (Capcode::Helpers)</a><br />
39
40
  <a href="classes/Capcode.html#M000005">request (Capcode)</a><br />
40
41
  <a href="classes/Capcode.html#M000006">response (Capcode)</a><br />
41
42
  <a href="classes/Capcode.html#M000011">run (Capcode)</a><br />
42
43
  <a href="classes/Capcode.html#M000004">session (Capcode)</a><br />
43
- <a href="classes/Capcode/Configuration.html#M000022">set (Capcode::Configuration)</a><br />
44
44
  <a href="classes/Capcode.html#M000012">set (Capcode)</a><br />
45
- <a href="classes/Capcode/Helpers.html#M000020">static (Capcode::Helpers)</a><br />
45
+ <a href="classes/Capcode/Configuration.html#M000023">set (Capcode::Configuration)</a><br />
46
+ <a href="classes/Capcode/Helpers.html#M000021">static (Capcode::Helpers)</a><br />
46
47
  <a href="classes/Capcode.html#M000008">use (Capcode)</a><br />
47
48
  </div>
48
49
  </div>
@@ -0,0 +1,105 @@
1
+ $:.unshift( "../lib" )
2
+ require 'capcode'
3
+
4
+ module Capcode
5
+ before_filter :for_all, :except => [:SecretPage]
6
+ before_filter :only_one, :only => [:One]
7
+ before_filter :except_three, :except => [:Three, :SecretPage]
8
+ before_filter :you_will_never_see_this_page, :only => [:SecretPage]
9
+
10
+ def for_all
11
+ @was ||= ""
12
+ @was << "for_all "
13
+
14
+ return nil
15
+ end
16
+
17
+ def only_one
18
+ @was ||= ""
19
+ @was << "only_one "
20
+
21
+ return nil
22
+ end
23
+
24
+ def except_three
25
+ @was ||= ""
26
+ @was << "except_three "
27
+
28
+ return nil
29
+ end
30
+
31
+ def you_will_never_see_this_page
32
+ redirect Capcode::Index
33
+ end
34
+
35
+ class Index < Route "/"
36
+ def get
37
+ render :markaby => :index
38
+ end
39
+ end
40
+
41
+ class One < Route "/one"
42
+ def get
43
+ @value = Time.now
44
+ @wwas = @was
45
+ @was = ""
46
+ render :markaby => :count
47
+ end
48
+ end
49
+
50
+ class Two < Route "/two"
51
+ def get
52
+ @value = Time.now
53
+ @wwas = @was
54
+ @was = ""
55
+ render :markaby => :count
56
+ end
57
+ end
58
+
59
+ class Three < Route "/three"
60
+ def get
61
+ @value = Time.now
62
+ @wwas = @was
63
+ @was = ""
64
+ render :markaby => :count
65
+ end
66
+ end
67
+
68
+ class SecretPage < Route "/secret"
69
+ def get
70
+ render :markaby => :secret
71
+ end
72
+ end
73
+ end
74
+
75
+ module Capcode::Views
76
+ def index
77
+ html do
78
+ body do
79
+ a "One", :href => URL(Capcode::One); br
80
+ a "Two", :href => URL(Capcode::Two); br
81
+ a "Three", :href => URL(Capcode::Three); br
82
+ a "SecretPage", :href => URL(Capcode::SecretPage); br
83
+ end
84
+ end
85
+ end
86
+
87
+ def count
88
+ html do
89
+ body do
90
+ span "I was in : #{@wwas}"; br
91
+ span "It's #{@value}"
92
+ end
93
+ end
94
+ end
95
+
96
+ def secret
97
+ html do
98
+ body do
99
+ span "If you see this page, there is a "; b "bug !!!"
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ Capcode.run()
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'rack'
5
- require 'json' ## DELETE THIS IN 1.0.0
6
5
  require 'logger'
7
6
  Logger.class_eval { alias :write :<< } unless Logger.instance_methods.include? "write"
8
7
  require 'optparse'
@@ -13,6 +12,7 @@ require 'capcode/core_ext'
13
12
  require 'capcode/helpers/auth'
14
13
  require 'capcode/render/text'
15
14
  require 'capcode/configuration'
15
+ require 'capcode/filters'
16
16
 
17
17
  module Capcode
18
18
  #@@__ROUTES = {}
@@ -25,7 +25,6 @@ module Capcode
25
25
  # @@__FILTERS << opts
26
26
  # end
27
27
 
28
-
29
28
  class ParameterError < ArgumentError #:nodoc: all
30
29
  end
31
30
 
@@ -68,6 +67,10 @@ module Capcode
68
67
  # * :xml => :my_func : :my_func must be defined in Capcode::Views
69
68
  # * :webdav => /path/to/root
70
69
  #
70
+ # Or you can use a "HTTP code" renderer :
71
+ #
72
+ # render 200 => "Ok", :server => "Capcode #{Capcode::CAPCOD_VERION}", ...
73
+ #
71
74
  # If you want to use a specific layout, you can specify it with option
72
75
  # :layout
73
76
  #
@@ -80,6 +83,7 @@ module Capcode
80
83
  def render( hash )
81
84
  if hash.class == Hash
82
85
  render_type = nil
86
+ possible_code_renderer = nil
83
87
 
84
88
  if render_type.nil?
85
89
  hash.keys.each do |key|
@@ -98,26 +102,41 @@ module Capcode
98
102
  end
99
103
  render_type = key
100
104
  end
105
+
106
+ if key.class == Fixnum
107
+ possible_code_renderer = key
108
+ end
101
109
  end
102
110
 
103
- if render_type.nil?
111
+ if render_type.nil? and possible_code_renderer.nil?
104
112
  raise Capcode::RenderError, "Renderer type not specified!", caller
105
113
  end
106
114
  end
107
115
  unless self.respond_to?("render_#{render_type.to_s}")
108
- raise Capcode::RenderError, "#{render_type} renderer not present ! please require 'capcode/render/#{render_type}'", caller
109
- end
110
-
111
- render_name = hash.delete(render_type)
112
- content_type = hash.delete(:content_type)
113
- unless content_type.nil?
114
- @response['Content-Type'] = content_type
115
- end
116
-
117
- begin
118
- self.send( "render_#{render_type.to_s}", render_name, hash )
119
- rescue => e
120
- raise Capcode::RenderError, "Error rendering `#{render_type.to_s}' : #{e.message}", caller
116
+ if possible_code_renderer.nil?
117
+ raise Capcode::RenderError, "#{render_type} renderer not present ! please require 'capcode/render/#{render_type}'", caller
118
+ else
119
+ code = possible_code_renderer
120
+ body = hash.delete(possible_code_renderer)
121
+ header = {}
122
+ hash.each do |k, v|
123
+ k = k.to_s.split(/_/).map{|e| e.capitalize}.join("-")
124
+ header[k] = v
125
+ end
126
+ [code, hash, body]
127
+ end
128
+ else
129
+ render_name = hash.delete(render_type)
130
+ content_type = hash.delete(:content_type)
131
+ unless content_type.nil?
132
+ @response['Content-Type'] = content_type
133
+ end
134
+
135
+ begin
136
+ self.send( "render_#{render_type.to_s}", render_name, hash )
137
+ rescue => e
138
+ raise Capcode::RenderError, "Error rendering `#{render_type.to_s}' : #{e.message}", caller
139
+ end
121
140
  end
122
141
  else
123
142
  render( :text => hash )
@@ -137,8 +156,7 @@ module Capcode
137
156
  # <b>DEPRECATED</b>, please use <tt>render( :json => o )</tt>
138
157
  def json( d ) ## DELETE THIS IN 1.0.0
139
158
  warn( "json is deprecated and will be removed in version 1.0, please use `render( :json => ... )'" )
140
- @response['Content-Type'] = 'application/json'
141
- d.to_json
159
+ render :json => d
142
160
  end
143
161
 
144
162
  # Send a redirect response
@@ -446,15 +464,21 @@ module Capcode
446
464
  args << nil
447
465
  end
448
466
 
449
- case @env["REQUEST_METHOD"]
450
- when "GET"
451
- get( *args )
452
- when "POST"
453
- _method = params.delete( "_method" ) { |_| "post" }
454
- send( _method.downcase.to_sym, *args )
455
- else
456
- _method = @env["REQUEST_METHOD"]
457
- send( _method.downcase.to_sym, *args )
467
+ filter_output = Capcode::Filter.execute( self )
468
+
469
+ if( filter_output.nil? )
470
+ case @env["REQUEST_METHOD"]
471
+ when "GET"
472
+ get( *args )
473
+ when "POST"
474
+ _method = params.delete( "_method" ) { |_| "post" }
475
+ send( _method.downcase.to_sym, *args )
476
+ else
477
+ _method = @env["REQUEST_METHOD"]
478
+ send( _method.downcase.to_sym, *args )
479
+ end
480
+ else
481
+ filter_output
458
482
  end
459
483
  }
460
484
  if r.respond_to?(:to_ary)