Capcode 0.8.9 → 0.9.0

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.
Files changed (92) hide show
  1. data/README.rdoc +13 -1
  2. data/doc/rdoc/classes/Capcode.html +410 -545
  3. data/doc/rdoc/classes/Capcode/Configuration.html +263 -0
  4. data/doc/rdoc/classes/Capcode/Helpers.html +154 -345
  5. data/doc/rdoc/classes/Capcode/Helpers/Authorization.html +6 -6
  6. data/doc/rdoc/created.rid +1 -1
  7. data/doc/rdoc/files/README_rdoc.html +42 -2
  8. data/doc/rdoc/files/lib/capcode/configuration_rb.html +1 -1
  9. data/doc/rdoc/files/lib/capcode/render/text_rb.html +1 -1
  10. data/doc/rdoc/files/lib/capcode_rb.html +14 -1
  11. data/doc/rdoc/fr_class_index.html +1 -1
  12. data/doc/rdoc/fr_file_index.html +0 -13
  13. data/doc/rdoc/fr_method_index.html +12 -14
  14. data/examples/render-image.rb +1 -1
  15. data/examples/render-text.rb +4 -1
  16. data/examples/rest.rb +1 -0
  17. data/examples/sample.rb +5 -3
  18. data/examples/upload.rb +1 -0
  19. data/lib/capcode.rb +45 -61
  20. data/lib/capcode/configuration.rb +69 -34
  21. data/lib/capcode/render/text.rb +1 -1
  22. data/lib/capcode/version.rb +1 -1
  23. metadata +31 -106
  24. data/doc/rdoc/classes/Capcode/Mab.html +0 -118
  25. data/doc/rdoc/files/lib/capcode/render/binary_rb.html +0 -101
  26. data/doc/rdoc/files/lib/capcode/render/email_rb.html +0 -108
  27. data/doc/rdoc/files/lib/capcode/render/erb_rb.html +0 -108
  28. data/doc/rdoc/files/lib/capcode/render/haml_rb.html +0 -108
  29. data/doc/rdoc/files/lib/capcode/render/json_rb.html +0 -108
  30. data/doc/rdoc/files/lib/capcode/render/markaby_rb.html +0 -108
  31. data/doc/rdoc/files/lib/capcode/render/mustache_rb.html +0 -108
  32. data/doc/rdoc/files/lib/capcode/render/none_rb.html +0 -101
  33. data/doc/rdoc/files/lib/capcode/render/redirect_rb.html +0 -101
  34. data/doc/rdoc/files/lib/capcode/render/sass_rb.html +0 -108
  35. data/doc/rdoc/files/lib/capcode/render/static_rb.html +0 -101
  36. data/doc/rdoc/files/lib/capcode/render/webdav_rb.html +0 -124
  37. data/doc/rdoc/files/lib/capcode/render/xml_rb.html +0 -101
  38. data/examples/auth-webdav.rb +0 -29
  39. data/examples/blog-ar.rb +0 -81
  40. data/examples/blog-ar.yml +0 -3
  41. data/examples/blog-couchdb-run.rb +0 -10
  42. data/examples/blog-couchdb.rb +0 -314
  43. data/examples/blog-couchdb.ru +0 -12
  44. data/examples/blog-couchdb.yml +0 -2
  45. data/examples/blog-dm.rb +0 -63
  46. data/examples/blog-dm.yml +0 -2
  47. data/examples/blog-mongodb-run.rb +0 -10
  48. data/examples/blog-mongodb.rb +0 -304
  49. data/examples/blog-mongodb.yml +0 -3
  50. data/examples/blog-sq.rb +0 -82
  51. data/examples/blog-sq.yml +0 -3
  52. data/examples/mail/mail_html.rhtml +0 -1
  53. data/examples/mail/mail_text.rhtml +0 -1
  54. data/examples/mail/ok.rhtml +0 -1
  55. data/examples/mail/rubyfr.png +0 -0
  56. data/examples/mustache/with_class.mustache +0 -8
  57. data/examples/mustache/without_class.mustache +0 -1
  58. data/examples/render-binary.rb +0 -46
  59. data/examples/render-email.rb +0 -68
  60. data/examples/render-erb.rb +0 -19
  61. data/examples/render-haml_sass.rb +0 -26
  62. data/examples/render-json.rb +0 -13
  63. data/examples/render-markaby.rb +0 -29
  64. data/examples/render-mustache.rb +0 -30
  65. data/examples/render-redirect.rb +0 -19
  66. data/examples/render-static.rb +0 -21
  67. data/examples/render-static.ru +0 -19
  68. data/examples/render-use.rb +0 -32
  69. data/examples/render-webdav.rb +0 -26
  70. data/examples/render-xml.rb +0 -24
  71. data/examples/rss.rb +0 -48
  72. data/examples/static/coderay.css +0 -131
  73. data/examples/static/index.html +0 -24
  74. data/examples/test/index.html +0 -1
  75. data/lib/capcode/base/ar.rb +0 -54
  76. data/lib/capcode/base/couchdb.rb +0 -23
  77. data/lib/capcode/base/dm.rb +0 -33
  78. data/lib/capcode/base/mongodb.rb +0 -27
  79. data/lib/capcode/base/sq.rb +0 -58
  80. data/lib/capcode/render/binary.rb +0 -8
  81. data/lib/capcode/render/email.rb +0 -73
  82. data/lib/capcode/render/erb.rb +0 -59
  83. data/lib/capcode/render/haml.rb +0 -60
  84. data/lib/capcode/render/json.rb +0 -14
  85. data/lib/capcode/render/markaby.rb +0 -38
  86. data/lib/capcode/render/mustache.rb +0 -37
  87. data/lib/capcode/render/none.rb +0 -7
  88. data/lib/capcode/render/redirect.rb +0 -7
  89. data/lib/capcode/render/sass.rb +0 -48
  90. data/lib/capcode/render/static.rb +0 -14
  91. data/lib/capcode/render/webdav.rb +0 -49
  92. data/lib/capcode/render/xml.rb +0 -119
@@ -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="#M000026">http_authentication</a>&nbsp;&nbsp;
114
+ <a href="#M000021">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-M000026" class="method-detail">
137
- <a name="M000026"></a>
136
+ <div id="method-M000021" class="method-detail">
137
+ <a name="M000021"></a>
138
138
 
139
139
  <div class="method-heading">
140
- <a href="#M000026" class="method-signature">
140
+ <a href="#M000021" 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('M000026-source');return false;">[Source]</a></p>
177
- <div class="method-source-code" id="M000026-source">
176
+ onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
177
+ <div class="method-source-code" id="M000021-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
- Mon, 21 Dec 2009 19:39:41 +0100
1
+ Thu, 07 Jan 2010 00:27:00 +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>Mon Dec 21 15:36:14 +0100 2009</td>
59
+ <td>Thu Jan 07 00:23:27 +0100 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -91,6 +91,46 @@ 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.0</h3>
95
+ <ul>
96
+ <li><b>IMPORTANT</b>
97
+
98
+ <ul>
99
+ <li>THIS VERSION IS A MAJOR ENHANCEMENT : YOU MUST UNINSTALL ALL PREVIOUS
100
+ VERSIONS !!!
101
+
102
+ </li>
103
+ </ul>
104
+ <p>
105
+ gem uninstall Capode &#8212;version &#8217;&lt; 0.9.0&#8216;
106
+ </p>
107
+ <ul>
108
+ <li>Renderers and database accessors have been extracted and are now in the <a
109
+ href="http://github.com/glejeune/Capcode.more">plugins repository</a>. Each
110
+ plugin is a gem that&#8216;s can be installed separately.
111
+
112
+ </li>
113
+ </ul>
114
+ </li>
115
+ <li><b>Important, but less!</b>
116
+
117
+ <ul>
118
+ <li>Add <a href="http://jashkenas.github.com/coffee-script/">Coffee-Script</a>
119
+ renderer
120
+
121
+ </li>
122
+ <li>Update renderers options
123
+
124
+ </li>
125
+ <li>Rewrite configuration
126
+
127
+ </li>
128
+ <li>Bug corrections in all DB modules
129
+
130
+ </li>
131
+ </ul>
132
+ </li>
133
+ </ul>
94
134
  <h3>0.8.9</h3>
95
135
  <ul>
96
136
  <li>Add Thin support
@@ -556,7 +596,7 @@ for complete examples.
556
596
  # !!! Render file from /Users/greg/temp !!!
557
597
  class WebDav &lt; Route '/temp'
558
598
  def get
559
- render :webdav =&gt; &quot;/Users/greg&quot;
599
+ render :webdav =&gt; &quot;/Users/greg/temp&quot;
560
600
  end
561
601
 
562
602
  def method_missing(id, *a, &amp;b)
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Thu Dec 03 14:22:22 +0100 2009</td>
59
+ <td>Tue Jan 05 17:04:58 +0100 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>Mon Oct 19 10:33:08 +0200 2009</td>
59
+ <td>Mon Dec 28 14:01:05 +0100 2009</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>Fri Dec 11 21:04:01 +0100 2009</td>
59
+ <td>Tue Jan 05 17:03:42 +0100 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -107,6 +107,19 @@ Please read the README.rdoc file !
107
107
 
108
108
 
109
109
 
110
+ <div id="aliases-list">
111
+ <h3 class="section-bar">External Aliases</h3>
112
+
113
+ <div class="name-list">
114
+ <table summary="aliases">
115
+ <tr class="top-aligned-row context-row">
116
+ <td class="context-item-name">"<<"</td>
117
+ <td>-&gt;</td>
118
+ <td class="context-item-value">write</td>
119
+ </tr>
120
+ </table>
121
+ </div>
122
+ </div>
110
123
 
111
124
 
112
125
 
@@ -22,10 +22,10 @@
22
22
  <div id="index-entries">
23
23
  <a href="classes/Capcode.html">Capcode</a><br />
24
24
  <a href="classes/Capcode/Base.html">Capcode::Base</a><br />
25
+ <a href="classes/Capcode/Configuration.html">Capcode::Configuration</a><br />
25
26
  <a href="classes/Capcode/HTTPError.html">Capcode::HTTPError</a><br />
26
27
  <a href="classes/Capcode/Helpers.html">Capcode::Helpers</a><br />
27
28
  <a href="classes/Capcode/Helpers/Authorization.html">Capcode::Helpers::Authorization</a><br />
28
- <a href="classes/Capcode/Mab.html">Capcode::Mab</a><br />
29
29
  <a href="classes/Capcode/Resource.html">Capcode::Resource</a><br />
30
30
  <a href="classes/Capcode/Views.html">Capcode::Views</a><br />
31
31
  </div>
@@ -27,20 +27,7 @@
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
29
  <a href="files/lib/capcode/helpers/auth_rb.html">lib/capcode/helpers/auth.rb</a><br />
30
- <a href="files/lib/capcode/render/binary_rb.html">lib/capcode/render/binary.rb</a><br />
31
- <a href="files/lib/capcode/render/email_rb.html">lib/capcode/render/email.rb</a><br />
32
- <a href="files/lib/capcode/render/erb_rb.html">lib/capcode/render/erb.rb</a><br />
33
- <a href="files/lib/capcode/render/haml_rb.html">lib/capcode/render/haml.rb</a><br />
34
- <a href="files/lib/capcode/render/json_rb.html">lib/capcode/render/json.rb</a><br />
35
- <a href="files/lib/capcode/render/markaby_rb.html">lib/capcode/render/markaby.rb</a><br />
36
- <a href="files/lib/capcode/render/mustache_rb.html">lib/capcode/render/mustache.rb</a><br />
37
- <a href="files/lib/capcode/render/none_rb.html">lib/capcode/render/none.rb</a><br />
38
- <a href="files/lib/capcode/render/redirect_rb.html">lib/capcode/render/redirect.rb</a><br />
39
- <a href="files/lib/capcode/render/sass_rb.html">lib/capcode/render/sass.rb</a><br />
40
- <a href="files/lib/capcode/render/static_rb.html">lib/capcode/render/static.rb</a><br />
41
30
  <a href="files/lib/capcode/render/text_rb.html">lib/capcode/render/text.rb</a><br />
42
- <a href="files/lib/capcode/render/webdav_rb.html">lib/capcode/render/webdav.rb</a><br />
43
- <a href="files/lib/capcode/render/xml_rb.html">lib/capcode/render/xml.rb</a><br />
44
31
  </div>
45
32
  </div>
46
33
  </body>
@@ -21,30 +21,28 @@
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#M000019">URL (Capcode::Helpers)</a><br />
24
+ <a href="classes/Capcode/Helpers.html#M000018">URL (Capcode::Helpers)</a><br />
25
25
  <a href="classes/Capcode.html#M000010">application (Capcode)</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">config (Capcode)</a><br />
29
- <a href="classes/Capcode/Helpers.html#M000020">content_for (Capcode::Helpers)</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 />
30
29
  <a href="classes/Capcode.html#M000003">env (Capcode)</a><br />
31
- <a href="classes/Capcode/Helpers.html#M000022">erb_path= (Capcode::Helpers)</a><br />
32
- <a href="classes/Capcode/Helpers.html#M000023">haml_path= (Capcode::Helpers)</a><br />
30
+ <a href="classes/Capcode/Configuration.html#M000023">get (Capcode::Configuration)</a><br />
33
31
  <a href="classes/Capcode.html#M000009">http_authentication (Capcode)</a><br />
34
- <a href="classes/Capcode/Helpers/Authorization.html#M000026">http_authentication (Capcode::Helpers::Authorization)</a><br />
35
- <a href="classes/Capcode/Helpers.html#M000017">json (Capcode::Helpers)</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 />
36
34
  <a href="classes/Capcode.html#M000007">map (Capcode)</a><br />
35
+ <a href="classes/Capcode/Configuration.html#M000024">options (Capcode::Configuration)</a><br />
37
36
  <a href="classes/Capcode.html#M000002">params (Capcode)</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 />
40
- <a href="classes/Capcode/Helpers.html#M000025">render_webdav (Capcode::Helpers)</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 />
41
39
  <a href="classes/Capcode.html#M000005">request (Capcode)</a><br />
42
40
  <a href="classes/Capcode.html#M000006">response (Capcode)</a><br />
43
41
  <a href="classes/Capcode.html#M000011">run (Capcode)</a><br />
44
- <a href="classes/Capcode/Helpers.html#M000024">sass_path= (Capcode::Helpers)</a><br />
45
42
  <a href="classes/Capcode.html#M000004">session (Capcode)</a><br />
43
+ <a href="classes/Capcode/Configuration.html#M000022">set (Capcode::Configuration)</a><br />
46
44
  <a href="classes/Capcode.html#M000012">set (Capcode)</a><br />
47
- <a href="classes/Capcode/Helpers.html#M000021">static (Capcode::Helpers)</a><br />
45
+ <a href="classes/Capcode/Helpers.html#M000020">static (Capcode::Helpers)</a><br />
48
46
  <a href="classes/Capcode.html#M000008">use (Capcode)</a><br />
49
47
  </div>
50
48
  </div>
@@ -1,7 +1,7 @@
1
1
  $:.unshift( "../lib" )
2
2
  require 'capcode'
3
- require 'capcode/render/markaby'
4
3
  require 'rubygems'
4
+ require 'capcode/render/markaby'
5
5
  require 'graphviz'
6
6
  require 'base64'
7
7
 
@@ -2,6 +2,9 @@ $:.unshift( "../lib" )
2
2
  require 'capcode'
3
3
 
4
4
  module Capcode
5
+ set :server, :webrick
6
+ set :port, 1111
7
+
5
8
  class Index < Route '/'
6
9
  def get
7
10
  render "Hello World"
@@ -9,4 +12,4 @@ module Capcode
9
12
  end
10
13
  end
11
14
 
12
- Capcode.run( )
15
+ Capcode.run( :port => 2222 )
@@ -1,5 +1,6 @@
1
1
  $:.unshift( "../lib" )
2
2
  require 'capcode'
3
+ require 'rubygems'
3
4
  require 'capcode/render/markaby'
4
5
 
5
6
  module Capcode
@@ -1,12 +1,10 @@
1
1
  $:.unshift( "../lib" )
2
- require 'rubygems'
3
2
  require 'capcode'
3
+ require 'rubygems'
4
4
  require 'capcode/render/markaby'
5
5
  require 'capcode/render/haml'
6
- Capcode::Helpers.haml_path = "haml"
7
6
  require 'capcode/render/json'
8
7
  require 'capcode/render/erb'
9
- Capcode::Helpers.erb_path = "erb"
10
8
 
11
9
  module Capcode
12
10
  module Helpers
@@ -17,6 +15,9 @@ module Capcode
17
15
  end
18
16
 
19
17
  module Capcode
18
+ set :haml, "haml"
19
+ set :erb, "erb"
20
+
20
21
  class HTTPError
21
22
  def r404(f)
22
23
  "Pas glop !!! #{f} est inconnu !!!"
@@ -63,6 +64,7 @@ module Capcode
63
64
 
64
65
  class ContentFor < Route '/cf'
65
66
  def get
67
+ @time = Time.now
66
68
  render( :erb => :cf, :layout => :cf_layout )
67
69
  end
68
70
  end
@@ -1,5 +1,6 @@
1
1
  $:.unshift( "../lib" )
2
2
  require 'capcode'
3
+ require 'rubygems'
3
4
  require 'capcode/render/markaby'
4
5
  require 'capcode/render/static'
5
6
  require 'fileutils'
@@ -4,6 +4,7 @@ require 'rubygems'
4
4
  require 'rack'
5
5
  require 'json' ## DELETE THIS IN 1.0.0
6
6
  require 'logger'
7
+ Logger.class_eval { alias :write :"<<" } unless Logger.instance_methods.include? "write"
7
8
  require 'optparse'
8
9
  require 'irb'
9
10
  require 'mime/types'
@@ -527,30 +528,13 @@ module Capcode
527
528
  end
528
529
  end
529
530
 
530
- def configuration( args = {} ) #:nodoc:
531
- {
532
- :port => args[:port]||Capcode.get(:port)||3000,
533
- :host => args[:host]||Capcode.get(:host)||"0.0.0.0",
534
- :server => args[:server]||Capcode.get(:server)||nil,
535
- :log => args[:log]||Capcode.get(:log)||$stdout,
536
- :session => args[:session]||Capcode.get(:session)||{},
537
- :pid => args[:pid]||Capcode.get(:pid)||"#{$0}.pid",
538
- :daemonize => args[:daemonize]||Capcode.get(:daemonize)||false,
539
- :db_config => File.expand_path(args[:db_config]||Capcode.get(:db_config)||"database.yml"),
540
- :root => args[:root]||Capcode.get(:root)||File.expand_path(File.dirname($0)),
541
- :static => args[:static]||Capcode.get(:static)||args[:root]||File.expand_path(File.dirname($0)),
542
- :verbose => args[:verbose]||Capcode.get(:verbose)||false,
543
- :console => false
544
- }
545
- end
546
-
547
531
  # Return the Rack App.
548
532
  #
549
- # Options : see Capcode.set
533
+ # Options : see Capcode::Configuration.set
550
534
  #
551
535
  # Options set here replace the ones set globally
552
536
  def application( args = {} )
553
- conf = configuration(args)
537
+ Capcode::Configuration.configuration(args)
554
538
 
555
539
  Capcode.constants.each do |k|
556
540
  begin
@@ -570,21 +554,21 @@ module Capcode
570
554
 
571
555
  # Set Static directory
572
556
  #@@__STATIC_DIR = (conf[:static][0].chr == "/")?conf[:static]:"/"+conf[:static] unless conf[:static].nil?
573
- Capcode.static = (conf[:static][0].chr == "/")?conf[:static]:"/"+conf[:static] unless conf[:static].nil?
557
+ Capcode.static = (Capcode::Configuration.get(:static)[0].chr == "/")?Capcode::Configuration.get(:static):"/"+Capcode::Configuration.get(:static) unless Capcode::Configuration.get(:static).nil?
574
558
 
575
559
  # Initialize Rack App
576
- puts "** Map routes." if conf[:verbose]
560
+ puts "** Map routes." if Capcode::Configuration.get(:verbose)
577
561
  #app = Rack::URLMap.new(@@__ROUTES)
578
562
  app = Rack::URLMap.new(Capcode.routes)
579
- puts "** Initialize static directory (#{conf[:static]})" if conf[:verbose]
563
+ puts "** Initialize static directory (#{Capcode::Configuration.get(:static)})" if Capcode::Configuration.get(:verbose)
580
564
  app = Rack::Static.new(
581
565
  app,
582
566
  #:urls => [@@__STATIC_DIR],
583
567
  :urls => [Capcode.static],
584
- :root => File.expand_path(conf[:root])
585
- ) unless conf[:static].nil?
586
- puts "** Initialize session" if conf[:verbose]
587
- app = Rack::Session::Cookie.new( app, conf[:session] )
568
+ :root => File.expand_path(Capcode::Configuration.get(:root))
569
+ ) unless Capcode::Configuration.get(:static).nil?
570
+ puts "** Initialize session" if Capcode::Configuration.get(:verbose)
571
+ app = Rack::Session::Cookie.new( app, Capcode::Configuration.get(:session) )
588
572
  app = Capcode::HTTPError.new(app)
589
573
  app = Rack::ContentLength.new(app)
590
574
  app = Rack::Lint.new(app)
@@ -594,7 +578,7 @@ module Capcode
594
578
 
595
579
  middlewares.each do |mw|
596
580
  middleware, args, block = mw
597
- puts "** Load middleware #{middleware}" if conf[:verbose]
581
+ puts "** Load middleware #{middleware}" if Capcode::Configuration.get(:verbose)
598
582
  if block
599
583
  app = middleware.new( app, *args, &block )
600
584
  else
@@ -604,7 +588,7 @@ module Capcode
604
588
 
605
589
  # Start database
606
590
  if self.methods.include? "db_connect"
607
- db_connect( conf[:db_config], conf[:log] )
591
+ db_connect( Capcode::Configuration.get(:db_config), Capcode::Configuration.get(:log) )
608
592
  end
609
593
 
610
594
  if block_given?
@@ -616,11 +600,11 @@ module Capcode
616
600
 
617
601
  # Start your application.
618
602
  #
619
- # Options : see Capcode.set
603
+ # Options : see Capcode::Configuration.set
620
604
  #
621
605
  # Options set here replace the ones set globally
622
606
  def run( args = {} )
623
- conf = configuration(args)
607
+ Capcode::Configuration.configuration(args)
624
608
 
625
609
  # Parse options
626
610
  opts = OptionParser.new do |opts|
@@ -629,22 +613,22 @@ module Capcode
629
613
  opts.separator "Specific options:"
630
614
 
631
615
  opts.on( "-C", "--console", "Run in console mode with IRB (default: false)" ) {
632
- conf[:console] = true
616
+ Capcode::Configuration.set :console, true
633
617
  }
634
- opts.on( "-h", "--host HOSTNAME", "Host for web server to bind to (default: #{conf[:host]})" ) { |h|
635
- conf[:host] = h
618
+ opts.on( "-h", "--host HOSTNAME", "Host for web server to bind to (default: #{Capcode::Configuration.get(:host)})" ) { |h|
619
+ Capcode::Configuration.set :host, h
636
620
  }
637
- opts.on( "-p", "--port NUM", "Port for web server (default: #{conf[:port]})" ) { |p|
638
- conf[:port] = p
621
+ opts.on( "-p", "--port NUM", "Port for web server (default: #{Capcode::Configuration.get(:port)})" ) { |p|
622
+ Capcode::Configuration.set :port, p
639
623
  }
640
- opts.on( "-d", "--daemonize [true|false]", "Daemonize (default: #{conf[:daemonize]})" ) { |d|
641
- conf[:daemonize] = d
624
+ opts.on( "-d", "--daemonize [true|false]", "Daemonize (default: #{Capcode::Configuration.get(:daemonize)})" ) { |d|
625
+ Capcode::Configuration.set :daemonize, d
642
626
  }
643
- opts.on( "-r", "--root PATH", "Working directory (default: #{conf[:root]})" ) { |w|
644
- conf[:root] = w
627
+ opts.on( "-r", "--root PATH", "Working directory (default: #{Capcode::Configuration.get(:root)})" ) { |w|
628
+ Capcode::Configuration.set :root, w
645
629
  }
646
- opts.on( "-s", "--static PATH", "Static directory -- relative to the root directory (default: #{conf[:static]})" ) { |r|
647
- conf[:static] = r
630
+ opts.on( "-s", "--static PATH", "Static directory -- relative to the root directory (default: #{Capcode::Configuration.get(:static)})" ) { |r|
631
+ Capcode::Configuration.set :static, r
648
632
  }
649
633
 
650
634
  opts.separator ""
@@ -659,7 +643,7 @@ module Capcode
659
643
  exit
660
644
  end
661
645
  opts.on_tail( "-V", "--verbose", "Run in verbose mode" ) do
662
- conf[:verbose] = true
646
+ Capcode::Configuration.set :verbose, true
663
647
  end
664
648
  end
665
649
 
@@ -672,22 +656,22 @@ module Capcode
672
656
  end
673
657
 
674
658
  # Run in the Working directory
675
- puts "** Go on root directory (#{File.expand_path(conf[:root])})" if conf[:verbose]
676
- Dir.chdir( conf[:root] ) do
659
+ puts "** Go on root directory (#{File.expand_path(Capcode::Configuration.get(:root))})" if Capcode::Configuration.get(:verbose)
660
+ Dir.chdir( Capcode::Configuration.get(:root) ) do
677
661
 
678
662
  # Check that mongrel exists
679
- if conf[:server].nil? || conf[:server] == "mongrel"
663
+ if Capcode::Configuration.get(:server).nil? || Capcode::Configuration.get(:server) == "mongrel"
680
664
  begin
681
665
  require 'mongrel'
682
- conf[:server] = "mongrel"
666
+ Capcode::Configuration.set :server, :mongrel
683
667
  rescue LoadError
684
668
  puts "!! could not load mongrel. Falling back to webrick."
685
- conf[:server] = "webrick"
669
+ Capcode::Configuration.set :server, :webrick
686
670
  end
687
671
  end
688
672
 
689
673
  # From rackup !!!
690
- if conf[:daemonize]
674
+ if Capcode::Configuration.get(:daemonize)
691
675
  if /java/.match(RUBY_PLATFORM).nil?
692
676
  if RUBY_VERSION < "1.9"
693
677
  exit if fork
@@ -705,39 +689,39 @@ module Capcode
705
689
  puts "!! daemonize option unavailable on #{RUBY_PLATFORM} platform."
706
690
  end
707
691
 
708
- File.open(conf[:pid], 'w'){ |f| f.write("#{Process.pid}") }
709
- at_exit { File.delete(conf[:pid]) if File.exist?(conf[:pid]) }
692
+ File.open(Capcode::Configuration.get(:pid), 'w'){ |f| f.write("#{Process.pid}") }
693
+ at_exit { File.delete(Capcode::Configuration.get(:pid)) if File.exist?(Capcode::Configuration.get(:pid)) }
710
694
  end
711
695
 
712
696
  app = nil
713
697
  if block_given?
714
- app = application(conf) { yield( self ) }
698
+ app = application(Capcode::Configuration.get) { yield( self ) }
715
699
  else
716
- app = application(conf)
700
+ app = application(Capcode::Configuration.get)
717
701
  end
718
- app = Rack::CommonLogger.new( app, Logger.new(conf[:log]) )
702
+ app = Rack::CommonLogger.new( app, Logger.new(Capcode::Configuration.get(:log)) )
719
703
 
720
- if conf[:console]
704
+ if Capcode::Configuration.get(:console)
721
705
  puts "Run console..."
722
706
  IRB.start
723
707
  exit
724
708
  end
725
709
 
726
710
  # Start server
727
- case conf[:server].to_s
711
+ case Capcode::Configuration.get(:server).to_s
728
712
  when "mongrel"
729
- puts "** Starting Mongrel on #{conf[:host]}:#{conf[:port]}"
730
- Rack::Handler::Mongrel.run( app, {:Port => conf[:port], :Host => conf[:host]} ) { |server|
713
+ puts "** Starting Mongrel on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"
714
+ Rack::Handler::Mongrel.run( app, {:Port => Capcode::Configuration.get(:port), :Host => Capcode::Configuration.get(:host)} ) { |server|
731
715
  trap "SIGINT", proc { server.stop }
732
716
  }
733
717
  when "webrick"
734
- puts "** Starting WEBrick on #{conf[:host]}:#{conf[:port]}"
735
- Rack::Handler::WEBrick.run( app, {:Port => conf[:port], :BindAddress => conf[:host]} ) { |server|
718
+ puts "** Starting WEBrick on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"
719
+ Rack::Handler::WEBrick.run( app, {:Port => Capcode::Configuration.get(:port), :BindAddress => Capcode::Configuration.get(:host)} ) { |server|
736
720
  trap "SIGINT", proc { server.shutdown }
737
721
  }
738
722
  when "thin"
739
- puts "** Starting Thin on #{conf[:host]}:#{conf[:port]}"
740
- Rack::Handler::Thin.run( app, {:Port => conf[:port], :Host => conf[:host]} ) { |server|
723
+ puts "** Starting Thin on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"
724
+ Rack::Handler::Thin.run( app, {:Port => Capcode::Configuration.get(:port), :Host => Capcode::Configuration.get(:host)} ) { |server|
741
725
  trap "SIGINT", proc { server.stop }
742
726
  }
743
727
  end