Capcode 0.9.8 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,199 @@
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>Class: Capcode::StaticFiles</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="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Capcode::StaticFiles</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/capcode_rb.html">
59
+ lib/capcode.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <p>
83
+ Static file loader
84
+ </p>
85
+ <p>
86
+ Use :
87
+ </p>
88
+ <pre>
89
+ set :static, &quot;path/to/static&quot;
90
+ </pre>
91
+
92
+ </div>
93
+
94
+
95
+ </div>
96
+
97
+ <div id="method-list">
98
+ <h3 class="section-bar">Methods</h3>
99
+
100
+ <div class="name-list">
101
+ <a href="#M000026">call</a>&nbsp;&nbsp;
102
+ <a href="#M000025">new</a>&nbsp;&nbsp;
103
+ </div>
104
+ </div>
105
+
106
+ </div>
107
+
108
+
109
+ <!-- if includes -->
110
+
111
+ <div id="section">
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+ <!-- if method_list -->
121
+ <div id="methods">
122
+ <h3 class="section-bar">Public Class methods</h3>
123
+
124
+ <div id="method-M000025" class="method-detail">
125
+ <a name="M000025"></a>
126
+
127
+ <div class="method-heading">
128
+ <a href="#M000025" class="method-signature">
129
+ <span class="method-name">new</span><span class="method-args">(app)</span>
130
+ </a>
131
+ </div>
132
+
133
+ <div class="method-description">
134
+ <p><a class="source-toggle" href="#"
135
+ onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
136
+ <div class="method-source-code" id="M000025-source">
137
+ <pre>
138
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 352</span>
139
+ 352: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">app</span>)
140
+ 353: <span class="ruby-ivar">@app</span> = <span class="ruby-identifier">app</span>
141
+ 354: <span class="ruby-keyword kw">end</span>
142
+ </pre>
143
+ </div>
144
+ </div>
145
+ </div>
146
+
147
+ <h3 class="section-bar">Public Instance methods</h3>
148
+
149
+ <div id="method-M000026" class="method-detail">
150
+ <a name="M000026"></a>
151
+
152
+ <div class="method-heading">
153
+ <a href="#M000026" class="method-signature">
154
+ <span class="method-name">call</span><span class="method-args">(env)</span>
155
+ </a>
156
+ </div>
157
+
158
+ <div class="method-description">
159
+ <p><a class="source-toggle" href="#"
160
+ onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
161
+ <div class="method-source-code" id="M000026-source">
162
+ <pre>
163
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 356</span>
164
+ 356: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
165
+ 357: <span class="ruby-identifier">static</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>( <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:root</span>), <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>) ) )
166
+ 358: <span class="ruby-identifier">file</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">static</span>, <span class="ruby-identifier">env</span>[<span class="ruby-value str">'REQUEST_PATH'</span>].<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;/&quot;</span>) )
167
+ 359: <span class="ruby-identifier">file</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">file</span>, <span class="ruby-value str">&quot;index.html&quot;</span> ) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">file</span>)
168
+ 360: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">file</span>)
169
+ 361: <span class="ruby-identifier">body</span> = [<span class="ruby-operator">::</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">file</span>)]
170
+ 362: <span class="ruby-identifier">header</span> = {
171
+ 363: <span class="ruby-value str">&quot;Last-Modified&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-operator">::</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">mtime</span>(<span class="ruby-identifier">file</span>).<span class="ruby-identifier">httpdate</span>,
172
+ 364: <span class="ruby-value str">&quot;Content-Type&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-operator">::</span><span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Mime</span>.<span class="ruby-identifier">mime_type</span>(<span class="ruby-operator">::</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-identifier">file</span>), <span class="ruby-value str">'text/plain'</span>),
173
+ 365: <span class="ruby-value str">&quot;Content-Length&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">body</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">size</span>.<span class="ruby-identifier">to_s</span>
174
+ 366: }
175
+ 367: <span class="ruby-keyword kw">return</span> [<span class="ruby-value">200</span>, <span class="ruby-identifier">header</span>, <span class="ruby-identifier">body</span>]
176
+ 368: <span class="ruby-keyword kw">else</span>
177
+ 369: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@app</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
178
+ 370: <span class="ruby-keyword kw">end</span>
179
+ 371:
180
+ 372: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@app</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
181
+ 373: <span class="ruby-keyword kw">end</span>
182
+ </pre>
183
+ </div>
184
+ </div>
185
+ </div>
186
+
187
+
188
+ </div>
189
+
190
+
191
+ </div>
192
+
193
+
194
+ <div id="validator-badges">
195
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
196
+ </div>
197
+
198
+ </body>
199
+ </html>
@@ -1 +1 @@
1
- Wed, 15 Sep 2010 14:22:01 +0200
1
+ Mon, 17 Jan 2011 12:12:30 +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 Sep 15 13:59:53 +0200 2010</td>
59
+ <td>Mon Jan 10 21:26:22 +0100 2011</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -91,6 +91,17 @@ 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.9</h3>
95
+ <ul>
96
+ <li>Better static files support <a
97
+ href="http://github.com/glejeune/Capcode/tree/master/examples/static.rb">See
98
+ example static.rb</a>
99
+
100
+ </li>
101
+ <li>Rewrite routes loader
102
+
103
+ </li>
104
+ </ul>
94
105
  <h3>0.9.8</h3>
95
106
  <ul>
96
107
  <li>Add &quot;any&quot; to easly replace an <tt>alias_method :post, :get</tt>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sun Jun 20 13:09:06 +0200 2010</td>
59
+ <td>Tue Sep 21 09:36:19 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -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 Sep 15 14:11:05 +0200 2010</td>
59
+ <td>Mon Jan 10 21:24:39 +0100 2011</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -81,10 +81,10 @@ Please read the README.rdoc file !
81
81
  <div class="name-list">
82
82
  rubygems&nbsp;&nbsp;
83
83
  rack&nbsp;&nbsp;
84
+ rack/mime&nbsp;&nbsp;
84
85
  logger&nbsp;&nbsp;
85
86
  optparse&nbsp;&nbsp;
86
87
  irb&nbsp;&nbsp;
87
- active_support&nbsp;&nbsp;
88
88
  capcode/version&nbsp;&nbsp;
89
89
  capcode/core_ext&nbsp;&nbsp;
90
90
  capcode/helpers/auth&nbsp;&nbsp;
@@ -96,6 +96,7 @@ Please read the README.rdoc file !
96
96
  unicorn/launcher&nbsp;&nbsp;
97
97
  unicorn/launcher&nbsp;&nbsp;
98
98
  rainbows&nbsp;&nbsp;
99
+ control_tower&nbsp;&nbsp;
99
100
  </div>
100
101
  </div>
101
102
 
@@ -27,6 +27,7 @@
27
27
  <a href="classes/Capcode/Helpers.html">Capcode::Helpers</a><br />
28
28
  <a href="classes/Capcode/Helpers/Authorization.html">Capcode::Helpers::Authorization</a><br />
29
29
  <a href="classes/Capcode/Resource.html">Capcode::Resource</a><br />
30
+ <a href="classes/Capcode/StaticFiles.html">Capcode::StaticFiles</a><br />
30
31
  <a href="classes/Capcode/Views.html">Capcode::Views</a><br />
31
32
  </div>
32
33
  </div>
@@ -26,25 +26,27 @@
26
26
  <a href="classes/Capcode/Helpers.html#M000015">args (Capcode::Helpers)</a><br />
27
27
  <a href="classes/Capcode/Helpers.html#M000016">args= (Capcode::Helpers)</a><br />
28
28
  <a href="classes/Capcode.html#M000014">before_filter (Capcode)</a><br />
29
+ <a href="classes/Capcode/StaticFiles.html#M000026">call (Capcode::StaticFiles)</a><br />
29
30
  <a href="classes/Capcode/Helpers.html#M000021">content_for (Capcode::Helpers)</a><br />
30
31
  <a href="classes/Capcode.html#M000003">env (Capcode)</a><br />
31
- <a href="classes/Capcode/Configuration.html#M000027">get (Capcode::Configuration)</a><br />
32
+ <a href="classes/Capcode/Configuration.html#M000029">get (Capcode::Configuration)</a><br />
32
33
  <a href="classes/Capcode.html#M000009">http_authentication (Capcode)</a><br />
33
34
  <a href="classes/Capcode/Helpers/Authorization.html#M000024">http_authentication (Capcode::Helpers::Authorization)</a><br />
34
35
  <a href="classes/Capcode/Helpers.html#M000018">json (Capcode::Helpers)</a><br />
35
36
  <a href="classes/Capcode/Helpers.html#M000023">log (Capcode::Helpers)</a><br />
36
37
  <a href="classes/Capcode.html#M000012">logger (Capcode)</a><br />
37
38
  <a href="classes/Capcode.html#M000007">map (Capcode)</a><br />
38
- <a href="classes/Capcode/Configuration.html#M000028">options (Capcode::Configuration)</a><br />
39
+ <a href="classes/Capcode/StaticFiles.html#M000025">new (Capcode::StaticFiles)</a><br />
40
+ <a href="classes/Capcode/Configuration.html#M000030">options (Capcode::Configuration)</a><br />
39
41
  <a href="classes/Capcode.html#M000002">params (Capcode)</a><br />
40
- <a href="classes/Capcode/Configuration.html#M000025">print_debug (Capcode::Configuration)</a><br />
42
+ <a href="classes/Capcode/Configuration.html#M000027">print_debug (Capcode::Configuration)</a><br />
41
43
  <a href="classes/Capcode/Helpers.html#M000019">redirect (Capcode::Helpers)</a><br />
42
44
  <a href="classes/Capcode/Helpers.html#M000017">render (Capcode::Helpers)</a><br />
43
45
  <a href="classes/Capcode.html#M000005">request (Capcode)</a><br />
44
46
  <a href="classes/Capcode.html#M000006">response (Capcode)</a><br />
45
47
  <a href="classes/Capcode.html#M000011">run (Capcode)</a><br />
46
48
  <a href="classes/Capcode.html#M000004">session (Capcode)</a><br />
47
- <a href="classes/Capcode/Configuration.html#M000026">set (Capcode::Configuration)</a><br />
49
+ <a href="classes/Capcode/Configuration.html#M000028">set (Capcode::Configuration)</a><br />
48
50
  <a href="classes/Capcode.html#M000013">set (Capcode)</a><br />
49
51
  <a href="classes/Capcode/Helpers.html#M000022">static (Capcode::Helpers)</a><br />
50
52
  <a href="classes/Capcode.html#M000008">use (Capcode)</a><br />
@@ -0,0 +1,26 @@
1
+ $:.unshift( "../lib" )
2
+ require 'capcode'
3
+ require 'rubygems'
4
+
5
+ module Capcode
6
+ set :static, "static"
7
+
8
+ class Index < Route '/'
9
+ def get
10
+ render :markaby => :index
11
+ end
12
+ end
13
+ end
14
+
15
+ module Capcode::Views
16
+ def index
17
+ html do
18
+ body do
19
+ h1 "Hello World!"
20
+ a "Show me static", :href => "/static-index.html"
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ Capcode.run( )
@@ -0,0 +1,6 @@
1
+ <html>
2
+ <body>
3
+ Bye bye World !<br />
4
+ <a href="/">Back !</a>
5
+ </body>
6
+ </html>
@@ -0,0 +1,6 @@
1
+ <html>
2
+ <body>
3
+ Hello Index !<br />
4
+ <a href="/bye.html">Bye !</a>
5
+ </body>
6
+ </html>
@@ -2,18 +2,17 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'rack'
5
+ require 'rack/mime'
5
6
  require 'logger'
6
7
  Logger.class_eval { alias :write :<< } unless Logger.instance_methods.include? "write"
7
8
  require 'optparse'
8
9
  require 'irb'
9
- require 'active_support'
10
10
  require 'capcode/version'
11
11
  require 'capcode/core_ext'
12
12
  require 'capcode/helpers/auth'
13
13
  require 'capcode/render/text'
14
14
  require 'capcode/configuration'
15
15
  require 'capcode/filters'
16
-
17
16
  require 'capcode/ext/rack/urlmap'
18
17
 
19
18
  module Capcode
@@ -126,7 +125,7 @@ module Capcode
126
125
  begin
127
126
  self.send( "render_#{render_type.to_s}", render_name, hash )
128
127
  rescue => e
129
- raise Capcode::RenderError, "Error rendering `#{render_type.to_s}' : #{e.message}", caller
128
+ raise Capcode::RenderError, "Error rendering `#{render_type.to_s}' : #{e.message}"#, caller
130
129
  end
131
130
  end
132
131
  else
@@ -208,22 +207,22 @@ module Capcode
208
207
  a = a.delete_if{ |x| x.nil? }
209
208
 
210
209
  if klass.class == Class
211
- klass.__urls__[0].each do |cpath, regexp|
212
- data = a.clone
210
+ klass.__urls__[0].each do |cpath, data|
211
+ args = a.clone
213
212
 
214
- n = Regexp.new( regexp ).number_of_captures
213
+ n = Regexp.new( data[:regexp] ).number_of_captures
215
214
  equart = (a.size - n).abs
216
215
 
217
- rtable = regexp.dup.gsub( /\\\(/, "" ).gsub( /\\\)/, "" ).split( /\([^\)]*\)/ )
216
+ rtable = data[:regexp].dup.gsub( /\\\(/, "" ).gsub( /\\\)/, "" ).split( /\([^\)]*\)/ )
218
217
  rtable.each do |r|
219
218
  if r == ""
220
- cpath = cpath + "/#{data.shift}"
219
+ cpath = cpath + "/#{args.shift}"
221
220
  else
222
221
  cpath = cpath + "/#{r}"
223
222
  end
224
223
  end
225
224
 
226
- cpath = (cpath + "/" + data.join( "/" )) if data.size > 0
225
+ cpath = (cpath + "/" + args.join( "/" )) if args.size > 0
227
226
  cpath = cpath.gsub( /(\/){2,}/, "/" )
228
227
  result[equart] = cpath
229
228
  end
@@ -344,6 +343,35 @@ module Capcode
344
343
  [status, headers, body]
345
344
  end
346
345
  end
346
+
347
+ # Static file loader
348
+ #
349
+ # Use :
350
+ # set :static, "path/to/static"
351
+ class StaticFiles
352
+ def initialize(app)
353
+ @app = app
354
+ end
355
+
356
+ def call(env)
357
+ static = File.expand_path( File.join(Capcode::Configuration.get(:root), Capcode::Configuration.get(:static) ) )
358
+ file = File.join(static, env['REQUEST_PATH'].split("/") )
359
+ file = File.join(file, "index.html" ) if File.directory?(file)
360
+ if File.exist?(file)
361
+ body = [::File.read(file)]
362
+ header = {
363
+ "Last-Modified" => ::File.mtime(file).httpdate,
364
+ "Content-Type" => ::Rack::Mime.mime_type(::File.extname(file), 'text/plain'),
365
+ "Content-Length" => body.first.size.to_s
366
+ }
367
+ return [200, header, body]
368
+ else
369
+ return @app.call(env)
370
+ end
371
+
372
+ return @app.call(env)
373
+ end
374
+ end
347
375
 
348
376
  class << self
349
377
  attr :__auth__, true #:nodoc:
@@ -371,7 +399,18 @@ module Capcode
371
399
  meta_def(:__urls__) {
372
400
  routes_paths = ['/'+self.to_s.gsub( /^Capcode::/, "" ).underscore] if create_path == true
373
401
  # < Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent => /Songbird (\d\.\d)[\d\/]*?/
374
- # # => [ {'/hello/world' => '([^\/]*)/id(\d*)', '/hello' => '(.*)'},
402
+ # # => [ {
403
+ # '/hello/world' => {
404
+ # :regexp => '([^\/]*)/id(\d*)',
405
+ # :route => '/hello/world/([^\/]*)/id(\d*)',
406
+ # :nargs => 2
407
+ # },
408
+ # '/hello/world' => {
409
+ # :regexp => '(.*)',
410
+ # :route => '/hello/(.*)',
411
+ # :nargs => 1
412
+ # }
413
+ # },
375
414
  # 2,
376
415
  # <Capcode::Klass>,
377
416
  # {:agent => /Songbird (\d\.\d)[\d\/]*?/} ]
@@ -382,13 +421,23 @@ module Capcode
382
421
  m = /\/([^\/]*\(.*)/.match( current_route_path )
383
422
  if m.nil?
384
423
  raise Capcode::RouteError, "Route `#{current_route_path}' already defined with regexp `#{hash_of_routes[current_route_path]}' !", caller if hash_of_routes.keys.include?(current_route_path)
385
- hash_of_routes[current_route_path] = ''
424
+ hash_of_routes[current_route_path] = {
425
+ :regexp => '',
426
+ :route => current_route_path,
427
+ :nargs => 0
428
+ }
386
429
  else
387
430
  _pre = m.pre_match
388
431
  _pre = "/" if _pre.size == 0
389
432
  raise Capcode::RouteError, "Route `#{_pre}' already defined with regexp `#{hash_of_routes[_pre]}' !", caller if hash_of_routes.keys.include?(_pre)
390
- hash_of_routes[_pre] = m.captures[0]
391
- max_captures_for_routes = Regexp.new(m.captures[0]).number_of_captures if max_captures_for_routes < Regexp.new(m.captures[0]).number_of_captures
433
+ captures_for_routes = Regexp.new(m.captures[0]).number_of_captures
434
+
435
+ hash_of_routes[_pre] = {
436
+ :regexp => m.captures[0],
437
+ :route => current_route_path,
438
+ :nargs => captures_for_routes
439
+ }
440
+ max_captures_for_routes = captures_for_routes if max_captures_for_routes < captures_for_routes
392
441
  end
393
442
  else
394
443
  raise Capcode::ParameterError, "Bad route declaration !", caller
@@ -453,40 +502,40 @@ module Capcode
453
502
  }
454
503
  end
455
504
 
456
- finalPath = nil
457
- finalArgs = nil
458
- finalNArgs = nil
459
-
460
- aPath = @request.path.gsub( /^\//, "" ).split( "/" )
461
- self.class.__urls__[0].each do |p, r|
462
- xPath = p.gsub( /^\//, "" ).split( "/" )
463
- if (xPath - aPath).size == 0
464
- diffArgs = aPath - xPath
465
- diffNArgs = diffArgs.size - 1
466
- if finalNArgs.nil? or finalNArgs > diffNArgs
467
- finalPath = p
468
- finalNArgs = diffNArgs
469
- finalArgs = diffArgs
470
- end
505
+ max_match_size = self.class.__urls__[1]
506
+ match_distance = self.class.__urls__[1]
507
+
508
+ result_route = nil
509
+ result_nargs = nil
510
+ result_args = []
511
+
512
+ self.class.__urls__[0].each do |route, data|
513
+ regexp = Regexp.new("^"+data[:route]+"$")
514
+
515
+ matching = regexp.match(@request.path)
516
+ next if matching.nil?
517
+
518
+ result_args = matching.to_a
519
+ result_args.shift
520
+ match_size = matching.size - 1
521
+
522
+ if match_size == max_match_size
523
+ # OK Terminé
524
+ result_route = data[:route]
525
+ result_nargs = data[:nargs]
526
+
527
+ break
528
+ elsif max_match_size > match_size and match_distance > max_match_size - match_size
529
+ match_distance = max_match_size - match_size
530
+
531
+ result_route = data[:route]
532
+ result_nargs = data[:nargs]
471
533
  end
472
534
  end
473
535
 
474
- if finalNArgs > self.class.__urls__[1]
475
- return [404, {'Content-Type' => 'text/plain'}, "Not Found: #{@request.path}"]
476
- end
477
-
478
- nargs = self.class.__urls__[1]
479
- regexp = Regexp.new( self.class.__urls__[0][finalPath] )
480
- args = regexp.match( Rack::Utils.unescape(@request.path).gsub( Regexp.new( "^#{finalPath}" ), "" ).gsub( /^\//, "" ) )
481
- if args.nil?
482
- raise Capcode::ParameterError, "Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'"
483
- else
484
- args = args.captures.map { |x| (x.size == 0)?nil:x }
485
- end
486
-
487
- while args.size < nargs
488
- args << nil
489
- end
536
+ return [404, {'Content-Type' => 'text/plain'}, "Not Found: #{@request.path}"] if result_route.nil?
537
+
538
+ result_args = result_args + Array.new(max_match_size - result_nargs)
490
539
 
491
540
  filter_output = Capcode::Filter.execute( self )
492
541
 
@@ -504,9 +553,11 @@ module Capcode
504
553
  begin
505
554
  _method = params.delete( "_method" ) { |_| @env["REQUEST_METHOD"] }
506
555
  if self.class.method_defined?( _method.downcase.to_sym )
507
- send( _method.downcase.to_sym, *args )
556
+ # send( _method.downcase.to_sym, *args )
557
+ send( _method.downcase.to_sym, *result_args )
508
558
  else
509
- any( *args )
559
+ # any( *args )
560
+ any( *result_args )
510
561
  end
511
562
  rescue => e
512
563
  raise e.class, e.to_s
@@ -614,6 +665,7 @@ module Capcode
614
665
  "Views",
615
666
  "ParameterError",
616
667
  "HTTPError",
668
+ "StaticFiles",
617
669
  "Configuration",
618
670
  "MissingLibrary",
619
671
  "Route",
@@ -624,9 +676,7 @@ module Capcode
624
676
  if eval "Capcode::#{k}.public_methods(true).include?( '__urls__' )"
625
677
  hash_of_routes, max_captures_for_routes, klass = eval "Capcode::#{k}.__urls__"
626
678
  hash_of_routes.keys.each do |current_route_path|
627
- #raise Capcode::RouteError, "Route `#{current_route_path}' already define !", caller if @@__ROUTES.keys.include?(current_route_path)
628
679
  raise Capcode::RouteError, "Route `#{current_route_path}' already define !", caller if Capcode.routes.keys.include?(current_route_path)
629
- # Capcode.routes[current_route_path] = klass.new
630
680
  Capcode.routes[current_route_path] = klass
631
681
  end
632
682
  end
@@ -651,6 +701,7 @@ module Capcode
651
701
  ) unless Capcode::Configuration.get(:static).nil?
652
702
  puts "** Initialize session" if Capcode::Configuration.get(:verbose)
653
703
  app = Rack::Session::Cookie.new( app, Capcode::Configuration.get(:session) )
704
+ app = Capcode::StaticFiles.new(app)
654
705
  app = Capcode::HTTPError.new(app)
655
706
  app = Rack::ContentLength.new(app)
656
707
  app = Rack::Lint.new(app)
@@ -818,6 +869,10 @@ module Capcode
818
869
  require 'rainbows'
819
870
  puts "** Starting Rainbow on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"
820
871
  Rainbows.run( app, {:listeners => ["#{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"]} )
872
+ when "control_tower"
873
+ require 'control_tower'
874
+ puts "** Starting ControlTower on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"
875
+ ControlTower::Server.new( app, {:host => Capcode::Configuration.get(:host), :port => Capcode::Configuration.get(:port)} ).start
821
876
  end
822
877
  end
823
878
  end