Capcode 0.8.2 → 0.8.4
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.
- data/{README → README.rdoc} +12 -1
- data/examples/haml/cf_layout.haml +1 -0
- data/examples/haml/style.sass +2 -0
- data/examples/render-erb.rb +14 -0
- data/examples/render-haml_sass.rb +22 -0
- data/examples/render-json.rb +13 -0
- data/examples/render-markaby.rb +27 -0
- data/examples/render-static.rb +18 -0
- data/examples/render-text.rb +12 -0
- data/examples/render-xml.rb +24 -0
- data/examples/rest.rb +77 -0
- data/examples/upload.rb +4 -4
- data/lib/capcode.rb +118 -44
- data/lib/capcode/base/db.rb +23 -0
- data/lib/capcode/base/dm.rb +11 -11
- data/lib/capcode/render/erb.rb +5 -3
- data/lib/capcode/render/haml.rb +3 -2
- data/lib/capcode/render/json.rb +1 -1
- data/lib/capcode/render/markaby.rb +5 -5
- data/lib/capcode/render/sass.rb +4 -2
- data/lib/capcode/render/static.rb +6 -2
- data/lib/capcode/render/text.rb +1 -1
- data/lib/capcode/render/xml.rb +3 -5
- data/lib/capcode/version.rb +1 -1
- metadata +25 -55
- data/doc/rdoc/classes/Capcode.html +0 -605
- data/doc/rdoc/classes/Capcode/HTTPError.html +0 -129
- data/doc/rdoc/classes/Capcode/Helpers.html +0 -342
- data/doc/rdoc/classes/Capcode/RenderError.html +0 -129
- data/doc/rdoc/classes/Capcode/Views.html +0 -108
- data/doc/rdoc/created.rid +0 -1
- data/doc/rdoc/files/AUTHORS.html +0 -103
- data/doc/rdoc/files/COPYING.html +0 -527
- data/doc/rdoc/files/README.html +0 -478
- data/doc/rdoc/files/lib/capcode_rb.html +0 -541
- data/doc/rdoc/index.html +0 -10
- data/doc/rdoc/permalink.gif +0 -0
- data/doc/rdoc/rdoc-style.css +0 -106
- data/doc/rdoc/rubyfr.png +0 -0
- data/doc/rdoc_iphone/classes/Capcode.html +0 -175
- data/doc/rdoc_iphone/classes/Capcode/HTTPError.html +0 -21
- data/doc/rdoc_iphone/classes/Capcode/Helpers.html +0 -153
- data/doc/rdoc_iphone/classes/Capcode/RenderError.html +0 -21
- data/doc/rdoc_iphone/classes/Capcode/Views.html +0 -21
- data/doc/rdoc_iphone/classes_index.html +0 -10
- data/doc/rdoc_iphone/created.rid +0 -1
- data/doc/rdoc_iphone/files/AUTHORS.html +0 -11
- data/doc/rdoc_iphone/files/COPYING.html +0 -435
- data/doc/rdoc_iphone/files/README.html +0 -325
- data/doc/rdoc_iphone/files/lib/capcode_rb.html +0 -435
- data/doc/rdoc_iphone/files_index.html +0 -7
- data/doc/rdoc_iphone/index.html +0 -51
- data/doc/rdoc_iphone/iui/backButton.png +0 -0
- data/doc/rdoc_iphone/iui/blueButton.png +0 -0
- data/doc/rdoc_iphone/iui/cancel.png +0 -0
- data/doc/rdoc_iphone/iui/grayButton.png +0 -0
- data/doc/rdoc_iphone/iui/iui-logo-touch-icon.png +0 -0
- data/doc/rdoc_iphone/iui/iui.css +0 -386
- data/doc/rdoc_iphone/iui/iui.js +0 -442
- data/doc/rdoc_iphone/iui/iuix.css +0 -1
- data/doc/rdoc_iphone/iui/iuix.js +0 -1
- data/doc/rdoc_iphone/iui/listArrow.png +0 -0
- data/doc/rdoc_iphone/iui/listArrowSel.png +0 -0
- data/doc/rdoc_iphone/iui/listGroup.png +0 -0
- data/doc/rdoc_iphone/iui/loading.gif +0 -0
- data/doc/rdoc_iphone/iui/pinstripes.png +0 -0
- data/doc/rdoc_iphone/iui/selection.png +0 -0
- data/doc/rdoc_iphone/iui/thumb.png +0 -0
- data/doc/rdoc_iphone/iui/toggle.png +0 -0
- data/doc/rdoc_iphone/iui/toggleOn.png +0 -0
- data/doc/rdoc_iphone/iui/toolButton.png +0 -0
- data/doc/rdoc_iphone/iui/toolbar.png +0 -0
- data/doc/rdoc_iphone/iui/whiteButton.png +0 -0
- data/doc/rdoc_iphone/rdoc-style.css +0 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
module Capcode
|
2
|
+
# This module contains the resources needed in a model
|
3
|
+
module Resource
|
4
|
+
end
|
5
|
+
|
6
|
+
# This class allow you to define models
|
7
|
+
#
|
8
|
+
# class Story < Capcode::Base
|
9
|
+
# include Capcode::Resource
|
10
|
+
#
|
11
|
+
# property :id, Integer, :serial => true
|
12
|
+
# property :title, String
|
13
|
+
# property :body, String
|
14
|
+
# property :date, String
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# If you want to use DataMapper, you need to require "capcode/base/dm", if
|
18
|
+
# you want to use CouchDB (via couch_foo), you need to require "capcode/base/couchdb".
|
19
|
+
#
|
20
|
+
# Please, refer to the DataMapper or couch_foo documentation for more information.
|
21
|
+
class Base
|
22
|
+
end
|
23
|
+
end
|
data/lib/capcode/base/dm.rb
CHANGED
@@ -3,18 +3,18 @@ require 'dm-core'
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'logger'
|
5
5
|
|
6
|
-
|
7
|
-
#
|
8
|
-
# class Story < Capcode::Base
|
9
|
-
# include Capcode::Base
|
10
|
-
# property :id, Integer, :serial => true
|
11
|
-
# property :title, String
|
12
|
-
# property :body, String
|
13
|
-
# property :date, String
|
14
|
-
# end
|
15
|
-
module Capcode
|
6
|
+
module Capcode
|
16
7
|
Resource = DataMapper::Resource
|
17
|
-
|
8
|
+
|
9
|
+
# use DataMapper
|
10
|
+
#
|
11
|
+
# class Story < Capcode::Base
|
12
|
+
# include Capcode::Base
|
13
|
+
# property :id, Integer, :serial => true
|
14
|
+
# property :title, String
|
15
|
+
# property :body, String
|
16
|
+
# property :date, String
|
17
|
+
# end
|
18
18
|
class Base
|
19
19
|
end
|
20
20
|
|
data/lib/capcode/render/erb.rb
CHANGED
@@ -3,17 +3,19 @@ require 'erb'
|
|
3
3
|
module Capcode
|
4
4
|
module Helpers
|
5
5
|
@@__ERB_PATH__ = "."
|
6
|
-
|
6
|
+
|
7
|
+
# Set the path to ERB files. If this path is not set, Capcode will search in the static path.
|
8
|
+
def self.erb_path=( p ) #:nodoc:
|
7
9
|
@@__ERB_PATH__ = p
|
8
10
|
end
|
9
11
|
|
10
|
-
def get_binding
|
12
|
+
def get_binding #:nodoc:
|
11
13
|
binding
|
12
14
|
end
|
13
15
|
|
14
16
|
def render_erb( f, opts ) #:nodoc:
|
15
17
|
if @@__ERB_PATH__.nil?
|
16
|
-
@@__ERB_PATH__ = "." + (Capcode.static.nil? == false)?Capcode.static:''
|
18
|
+
@@__ERB_PATH__ = "." + (Capcode.static.nil? == false)?Capcode.static():''
|
17
19
|
end
|
18
20
|
|
19
21
|
f = f.to_s
|
data/lib/capcode/render/haml.rb
CHANGED
@@ -3,13 +3,14 @@ require "haml"
|
|
3
3
|
module Capcode
|
4
4
|
module Helpers
|
5
5
|
@@__HAML_PATH__ = nil
|
6
|
-
|
6
|
+
# Set the path to Haml files. If this path is not set, Capcode will search in the static path.
|
7
|
+
def self.haml_path=( p ) #:nodoc:
|
7
8
|
@@__HAML_PATH__ = p
|
8
9
|
end
|
9
10
|
|
10
11
|
def render_haml( f, opts ) #:nodoc:
|
11
12
|
if @@__HAML_PATH__.nil?
|
12
|
-
@@__HAML_PATH__ = "." + (Capcode.static.nil? == false)?Capcode.static:''
|
13
|
+
@@__HAML_PATH__ = "." + (Capcode.static.nil? == false)?Capcode.static():''
|
13
14
|
end
|
14
15
|
|
15
16
|
f = f.to_s
|
data/lib/capcode/render/json.rb
CHANGED
@@ -3,7 +3,7 @@ require "markaby"
|
|
3
3
|
Markaby::Builder.set(:indent, 2)
|
4
4
|
|
5
5
|
module Capcode
|
6
|
-
class Markaby::Builder
|
6
|
+
class Mab < Markaby::Builder
|
7
7
|
include Views
|
8
8
|
end
|
9
9
|
|
@@ -11,8 +11,8 @@ module Capcode
|
|
11
11
|
def render_markaby( f, opts ) #:nodoc:
|
12
12
|
f = f.to_s
|
13
13
|
layout = opts.delete(:layout)||:layout
|
14
|
-
|
15
|
-
|
14
|
+
|
15
|
+
__mab = Mab.new({}, self) {
|
16
16
|
if self.respond_to?(layout)
|
17
17
|
self.send(layout.to_s) { |*args|
|
18
18
|
@@__ARGS__ = args
|
@@ -22,7 +22,7 @@ module Capcode
|
|
22
22
|
self.send(f)
|
23
23
|
end
|
24
24
|
}
|
25
|
-
|
25
|
+
__mab.to_s
|
26
26
|
end
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
data/lib/capcode/render/sass.rb
CHANGED
@@ -3,13 +3,15 @@ require "sass"
|
|
3
3
|
module Capcode
|
4
4
|
module Helpers
|
5
5
|
@@__SASS_PATH__ = "."
|
6
|
-
|
6
|
+
|
7
|
+
# Set the path to Sass files. If this path is not set, Capcode will search in the static path.
|
8
|
+
def self.sass_path=( p ) #:nodoc:
|
7
9
|
@@__SASS_PATH__ = p
|
8
10
|
end
|
9
11
|
|
10
12
|
def render_sass( f, _ ) #:nodoc:
|
11
13
|
if @@__SASS_PATH__.nil?
|
12
|
-
@@__SASS_PATH__ = "." + (Capcode.static.nil? == false)?Capcode.static:''
|
14
|
+
@@__SASS_PATH__ = "." + (Capcode.static.nil? == false)?Capcode.static():''
|
13
15
|
end
|
14
16
|
|
15
17
|
f = f.to_s
|
@@ -1,10 +1,14 @@
|
|
1
1
|
module Capcode
|
2
2
|
module Helpers
|
3
|
-
def render_static( f,
|
3
|
+
def render_static( f, opts = { :exact_path => true } ) #:nodoc:
|
4
4
|
if Capcode.static.nil? or f.include? '..'
|
5
5
|
return [403, {}, '403 - Invalid path']
|
6
6
|
end
|
7
|
-
|
7
|
+
if !opts.keys.include?(:exact_path) or opts[:exact_path] == true
|
8
|
+
redirect File.join( static[:uri], f )
|
9
|
+
else
|
10
|
+
File.read( File.join( static[:path], f ) ).to_s
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
data/lib/capcode/render/text.rb
CHANGED
data/lib/capcode/render/xml.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class XML #:nodoc:
|
4
|
-
class TagError < ArgumentError #:nodoc:
|
1
|
+
class XML #:nodoc: all
|
2
|
+
class TagError < ArgumentError
|
5
3
|
end
|
6
4
|
|
7
|
-
class DSL
|
5
|
+
class DSL
|
8
6
|
def initialize( helper, &block )
|
9
7
|
@__x_d_level = 0
|
10
8
|
@__x_d_helper = helper
|
data/lib/capcode/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Capcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Gr\xC3\xA9goire Lejeune"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-05 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -39,65 +39,26 @@ executables: []
|
|
39
39
|
extensions: []
|
40
40
|
|
41
41
|
extra_rdoc_files:
|
42
|
-
- README
|
42
|
+
- README.rdoc
|
43
43
|
- AUTHORS
|
44
44
|
- COPYING
|
45
45
|
- lib/capcode.rb
|
46
|
+
- lib/capcode/base/db.rb
|
47
|
+
- lib/capcode/render/erb.rb
|
48
|
+
- lib/capcode/render/haml.rb
|
49
|
+
- lib/capcode/render/json.rb
|
50
|
+
- lib/capcode/render/markaby.rb
|
51
|
+
- lib/capcode/render/sass.rb
|
52
|
+
- lib/capcode/render/static.rb
|
53
|
+
- lib/capcode/render/text.rb
|
54
|
+
- lib/capcode/render/xml.rb
|
46
55
|
files:
|
47
56
|
- COPYING
|
48
|
-
- README
|
57
|
+
- README.rdoc
|
49
58
|
- AUTHORS
|
50
59
|
- setup.rb
|
51
|
-
- doc/rdoc/classes/Capcode/Helpers.html
|
52
|
-
- doc/rdoc/classes/Capcode/HTTPError.html
|
53
|
-
- doc/rdoc/classes/Capcode/RenderError.html
|
54
|
-
- doc/rdoc/classes/Capcode/Views.html
|
55
|
-
- doc/rdoc/classes/Capcode.html
|
56
|
-
- doc/rdoc/created.rid
|
57
|
-
- doc/rdoc/files/AUTHORS.html
|
58
|
-
- doc/rdoc/files/COPYING.html
|
59
|
-
- doc/rdoc/files/lib/capcode_rb.html
|
60
|
-
- doc/rdoc/files/README.html
|
61
|
-
- doc/rdoc/index.html
|
62
|
-
- doc/rdoc/permalink.gif
|
63
|
-
- doc/rdoc/rdoc-style.css
|
64
|
-
- doc/rdoc/rubyfr.png
|
65
|
-
- doc/rdoc_iphone/classes/Capcode/Helpers.html
|
66
|
-
- doc/rdoc_iphone/classes/Capcode/HTTPError.html
|
67
|
-
- doc/rdoc_iphone/classes/Capcode/RenderError.html
|
68
|
-
- doc/rdoc_iphone/classes/Capcode/Views.html
|
69
|
-
- doc/rdoc_iphone/classes/Capcode.html
|
70
|
-
- doc/rdoc_iphone/classes_index.html
|
71
|
-
- doc/rdoc_iphone/created.rid
|
72
|
-
- doc/rdoc_iphone/files/AUTHORS.html
|
73
|
-
- doc/rdoc_iphone/files/COPYING.html
|
74
|
-
- doc/rdoc_iphone/files/lib/capcode_rb.html
|
75
|
-
- doc/rdoc_iphone/files/README.html
|
76
|
-
- doc/rdoc_iphone/files_index.html
|
77
|
-
- doc/rdoc_iphone/index.html
|
78
|
-
- doc/rdoc_iphone/iui/backButton.png
|
79
|
-
- doc/rdoc_iphone/iui/blueButton.png
|
80
|
-
- doc/rdoc_iphone/iui/cancel.png
|
81
|
-
- doc/rdoc_iphone/iui/grayButton.png
|
82
|
-
- doc/rdoc_iphone/iui/iui-logo-touch-icon.png
|
83
|
-
- doc/rdoc_iphone/iui/iui.css
|
84
|
-
- doc/rdoc_iphone/iui/iui.js
|
85
|
-
- doc/rdoc_iphone/iui/iuix.css
|
86
|
-
- doc/rdoc_iphone/iui/iuix.js
|
87
|
-
- doc/rdoc_iphone/iui/listArrow.png
|
88
|
-
- doc/rdoc_iphone/iui/listArrowSel.png
|
89
|
-
- doc/rdoc_iphone/iui/listGroup.png
|
90
|
-
- doc/rdoc_iphone/iui/loading.gif
|
91
|
-
- doc/rdoc_iphone/iui/pinstripes.png
|
92
|
-
- doc/rdoc_iphone/iui/selection.png
|
93
|
-
- doc/rdoc_iphone/iui/thumb.png
|
94
|
-
- doc/rdoc_iphone/iui/toggle.png
|
95
|
-
- doc/rdoc_iphone/iui/toggleOn.png
|
96
|
-
- doc/rdoc_iphone/iui/toolbar.png
|
97
|
-
- doc/rdoc_iphone/iui/toolButton.png
|
98
|
-
- doc/rdoc_iphone/iui/whiteButton.png
|
99
|
-
- doc/rdoc_iphone/rdoc-style.css
|
100
60
|
- lib/capcode/base/couchdb.rb
|
61
|
+
- lib/capcode/base/db.rb
|
101
62
|
- lib/capcode/base/dm.rb
|
102
63
|
- lib/capcode/core_ext.rb
|
103
64
|
- lib/capcode/render/erb.rb
|
@@ -122,7 +83,16 @@ files:
|
|
122
83
|
- examples/haml/cf_layout.haml
|
123
84
|
- examples/haml/layout.haml
|
124
85
|
- examples/haml/m_hello.haml
|
86
|
+
- examples/haml/style.sass
|
125
87
|
- examples/my_blog.db
|
88
|
+
- examples/render-erb.rb
|
89
|
+
- examples/render-haml_sass.rb
|
90
|
+
- examples/render-json.rb
|
91
|
+
- examples/render-markaby.rb
|
92
|
+
- examples/render-static.rb
|
93
|
+
- examples/render-text.rb
|
94
|
+
- examples/render-xml.rb
|
95
|
+
- examples/rest.rb
|
126
96
|
- examples/rss.rb
|
127
97
|
- examples/sample.rb
|
128
98
|
- examples/session.rb
|
@@ -154,7 +124,7 @@ rdoc_options:
|
|
154
124
|
- index.html
|
155
125
|
- --line-numbers
|
156
126
|
- --main
|
157
|
-
- README
|
127
|
+
- README.rdoc
|
158
128
|
- --inline-source
|
159
129
|
- --exclude
|
160
130
|
- ^(examples|extras|test|lib)\/
|
@@ -175,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
145
|
requirements: []
|
176
146
|
|
177
147
|
rubyforge_project: capcode
|
178
|
-
rubygems_version: 1.3.
|
148
|
+
rubygems_version: 1.3.5
|
179
149
|
signing_key:
|
180
150
|
specification_version: 3
|
181
151
|
summary: Capcode is a web microframework
|
@@ -1,605 +0,0 @@
|
|
1
|
-
|
2
|
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
3
|
-
<html>
|
4
|
-
<head>
|
5
|
-
<title>
|
6
|
-
Capcode, the Documentation » Module: Capcode
|
7
|
-
</title>
|
8
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
9
|
-
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
10
|
-
<script language="JavaScript" type="text/javascript">
|
11
|
-
// <![CDATA[
|
12
|
-
|
13
|
-
function toggleSource( id )
|
14
|
-
{
|
15
|
-
var elem
|
16
|
-
var link
|
17
|
-
|
18
|
-
if( document.getElementById )
|
19
|
-
{
|
20
|
-
elem = document.getElementById( id )
|
21
|
-
link = document.getElementById( "l_" + id )
|
22
|
-
}
|
23
|
-
else if ( document.all )
|
24
|
-
{
|
25
|
-
elem = eval( "document.all." + id )
|
26
|
-
link = eval( "document.all.l_" + id )
|
27
|
-
}
|
28
|
-
else
|
29
|
-
return false;
|
30
|
-
|
31
|
-
if( elem.style.display == "block" )
|
32
|
-
{
|
33
|
-
elem.style.display = "none"
|
34
|
-
link.innerHTML = "show source"
|
35
|
-
}
|
36
|
-
else
|
37
|
-
{
|
38
|
-
elem.style.display = "block"
|
39
|
-
link.innerHTML = "hide source"
|
40
|
-
}
|
41
|
-
}
|
42
|
-
|
43
|
-
function openCode( url )
|
44
|
-
{
|
45
|
-
window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
|
46
|
-
}
|
47
|
-
// ]]>
|
48
|
-
</script>
|
49
|
-
</head>
|
50
|
-
<body>
|
51
|
-
<!--
|
52
|
-
<div id="menu">
|
53
|
-
<h3 class="title">Module: Capcode</h3>
|
54
|
-
</div>
|
55
|
-
-->
|
56
|
-
<div id="fullpage">
|
57
|
-
<div id="pager">
|
58
|
-
<table>
|
59
|
-
<tr><td><img src="../rubyfr.png" /></td>
|
60
|
-
<td id="pagertd">
|
61
|
-
<strong># Module: Capcode<br />
|
62
|
-
[
|
63
|
-
"<a href="../files/README.html" value="File: README">README</a>",
|
64
|
-
"<a href="../files/AUTHORS.html" value="File: AUTHORS">AUTHORS</a>",
|
65
|
-
"<a href="../files/COPYING.html" value="File: COPYING">COPYING</a>",
|
66
|
-
"<a href="../files/lib/capcode_rb.html" value="File: capcode.rb">lib/capcode.rb</a>",
|
67
|
-
<a href="http://greg.rubyfr.net">nil</a>].each do<br />
|
68
|
-
<a href="../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
|
69
|
-
<a href="../classes/Capcode/Views.html" title="Module: Capcode::Views">Capcode::Views</a>.view_html<br />
|
70
|
-
<a href="../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
|
71
|
-
<a href="../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
|
72
|
-
<a href="../classes/Capcode/RenderError.html" title="Class: Capcode::RenderError">Capcode::RenderError</a>.view_html<br />
|
73
|
-
<a href="../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
|
74
|
-
<a href="../classes/Capcode/ParameterError.html" title="Class: Capcode::ParameterError">Capcode::ParameterError</a>.view_html<br />
|
75
|
-
end</strong>
|
76
|
-
</td></tr>
|
77
|
-
</table>
|
78
|
-
</ul>
|
79
|
-
</div>
|
80
|
-
|
81
|
-
|
82
|
-
<div id="Capcode" class="page_shade">
|
83
|
-
<div class="page">
|
84
|
-
<h3>Module Capcode</h3>
|
85
|
-
|
86
|
-
(in files
|
87
|
-
<a href="../files/lib/capcode_rb.html">lib/capcode.rb</a>
|
88
|
-
)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
<h4>Includes</h4>
|
94
|
-
<ul>
|
95
|
-
<li>Rack</li>
|
96
|
-
<li><a href="Capcode/Helpers.html">Capcode::Helpers</a></li>
|
97
|
-
<li><a href="Capcode/Views.html">Capcode::Views</a></li>
|
98
|
-
</ul>
|
99
|
-
|
100
|
-
<h2 class="ruled">Methods</h2>
|
101
|
-
<h4 class="ruled">Public Class method:
|
102
|
-
<strong><a name="M000001">Route(*u)</a></strong> <a href="#M000001"><img src="../permalink.gif" border="0" title="Permalink to Public Class method: Route" /></a></h4>
|
103
|
-
|
104
|
-
<p>
|
105
|
-
Add routes to a controller class
|
106
|
-
</p>
|
107
|
-
<pre>
|
108
|
-
module Capcode
|
109
|
-
class Hello < Route '/hello/(.*)', '/hello/([^#]*)#(.*)'
|
110
|
-
def get( arg1, arg2 )
|
111
|
-
...
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
</pre>
|
116
|
-
<p>
|
117
|
-
In the <tt>get</tt> method, you will receive the maximum of parameters
|
118
|
-
declared by the routes. In this example, you will receive 2 parameters. So
|
119
|
-
if you go to <tt>/hello/world#friend</tt> then <tt>arg1</tt> will be set to
|
120
|
-
<tt>world</tt> and <tt>arg2</tt> will be set to <tt>friend</tt>. Now if you
|
121
|
-
go to <tt>/hello/you</tt>, then <tt>arg1</tt> will be set to <tt>you</tt>
|
122
|
-
and <tt>arg2</tt> will be set to <tt>nil</tt>
|
123
|
-
</p>
|
124
|
-
<p>
|
125
|
-
If the regexp in the route does not match, all arguments will be
|
126
|
-
<tt>nil</tt>
|
127
|
-
</p>
|
128
|
-
|
129
|
-
<div class="sourcecode">
|
130
|
-
<p class="source-link">[ <a href="javascript:toggleSource('M000001_source')" id="l_M000001_source">show source</a> ]</p>
|
131
|
-
<div id="M000001_source" class="dyn-source">
|
132
|
-
<pre>
|
133
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line 210</span>
|
134
|
-
210: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Route</span> <span class="ruby-operator">*</span><span class="ruby-identifier">u</span>
|
135
|
-
211: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
|
136
|
-
212: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>){
|
137
|
-
213: <span class="ruby-comment cmt"># < Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)'</span>
|
138
|
-
214: <span class="ruby-comment cmt"># # => [ {'/hello/world' => '([^\/]*)/id(\d*)', '/hello' => '(.*)'}, 2, <Capcode::Klass> ]</span>
|
139
|
-
215: <span class="ruby-identifier">h</span> = {}
|
140
|
-
216: <span class="ruby-identifier">max</span> = <span class="ruby-value">0</span>
|
141
|
-
217: <span class="ruby-identifier">u</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">_u</span><span class="ruby-operator">|</span>
|
142
|
-
218: <span class="ruby-identifier">m</span> = <span class="ruby-regexp re">/\/([^\/]*\(.*)/</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">_u</span> )
|
143
|
-
219: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
|
144
|
-
220: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">"Route `#{_u}' already defined with regexp `#{h[_u]}' !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">h</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_u</span>)
|
145
|
-
221: <span class="ruby-identifier">h</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-value str">''</span>
|
146
|
-
222: <span class="ruby-keyword kw">else</span>
|
147
|
-
223: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
|
148
|
-
224: <span class="ruby-identifier">_pre</span> = <span class="ruby-value str">"/"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">_pre</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
149
|
-
225: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">"Route `#{_pre}' already defined with regexp `#{h[_pre]}' !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">h</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_pre</span>)
|
150
|
-
226: <span class="ruby-identifier">h</span>[<span class="ruby-identifier">_pre</span>] = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]
|
151
|
-
227: <span class="ruby-identifier">max</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">number_of_captures</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">max</span> <span class="ruby-operator"><</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">number_of_captures</span>
|
152
|
-
228: <span class="ruby-keyword kw">end</span>
|
153
|
-
229: <span class="ruby-keyword kw">end</span>
|
154
|
-
230: [<span class="ruby-identifier">h</span>, <span class="ruby-identifier">max</span>, <span class="ruby-keyword kw">self</span>]
|
155
|
-
231: }
|
156
|
-
232:
|
157
|
-
233: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
|
158
|
-
234: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
159
|
-
235: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
160
|
-
236: <span class="ruby-keyword kw">end</span>
|
161
|
-
237:
|
162
|
-
238: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
|
163
|
-
239: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
164
|
-
240: <span class="ruby-ivar">@env</span>
|
165
|
-
241: <span class="ruby-keyword kw">end</span>
|
166
|
-
242:
|
167
|
-
243: <span class="ruby-comment cmt"># Hash session</span>
|
168
|
-
244: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
169
|
-
245: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
170
|
-
246: <span class="ruby-keyword kw">end</span>
|
171
|
-
247:
|
172
|
-
248: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
|
173
|
-
249: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
174
|
-
250: <span class="ruby-ivar">@request</span>
|
175
|
-
251: <span class="ruby-keyword kw">end</span>
|
176
|
-
252:
|
177
|
-
253: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
|
178
|
-
254: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
179
|
-
255: <span class="ruby-ivar">@response</span>
|
180
|
-
256: <span class="ruby-keyword kw">end</span>
|
181
|
-
257:
|
182
|
-
258: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>( <span class="ruby-identifier">e</span> ) <span class="ruby-comment cmt">#:nodoc:</span>
|
183
|
-
259: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
|
184
|
-
260: <span class="ruby-ivar">@response</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Response</span>.<span class="ruby-identifier">new</span>
|
185
|
-
261: <span class="ruby-ivar">@request</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Request</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@env</span>)
|
186
|
-
262:
|
187
|
-
263: <span class="ruby-comment cmt"># __k = self.class.to_s.split( /::/ )[-1].downcase.to_sym</span>
|
188
|
-
264: <span class="ruby-comment cmt"># @@__FILTERS.each do |f|</span>
|
189
|
-
265: <span class="ruby-comment cmt"># proc = f.delete(:action)</span>
|
190
|
-
266: <span class="ruby-comment cmt"># __run = true</span>
|
191
|
-
267: <span class="ruby-comment cmt"># if f[:only]</span>
|
192
|
-
268: <span class="ruby-comment cmt"># __run = f[:only].include?(__k)</span>
|
193
|
-
269: <span class="ruby-comment cmt"># end</span>
|
194
|
-
270: <span class="ruby-comment cmt"># if f[:except]</span>
|
195
|
-
271: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
|
196
|
-
272: <span class="ruby-comment cmt"># end</span>
|
197
|
-
273: <span class="ruby-comment cmt"># </span>
|
198
|
-
274: <span class="ruby-comment cmt"># # proc.call(self) if __run</span>
|
199
|
-
275: <span class="ruby-comment cmt"># puts "call #{proc} for #{__k}"</span>
|
200
|
-
276: <span class="ruby-comment cmt"># end</span>
|
201
|
-
277:
|
202
|
-
278: <span class="ruby-identifier">r</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>]
|
203
|
-
279: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"GET"</span>
|
204
|
-
280: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
|
205
|
-
281: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
|
206
|
-
282: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
|
207
|
-
283:
|
208
|
-
284: <span class="ruby-identifier">aPath</span> = <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">""</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-value str">"/"</span> )
|
209
|
-
285: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
210
|
-
286: <span class="ruby-identifier">xPath</span> = <span class="ruby-identifier">p</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">""</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-value str">"/"</span> )
|
211
|
-
287: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">xPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">aPath</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
212
|
-
288: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
|
213
|
-
289: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
|
214
|
-
290: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">finalNArgs</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">finalNArgs</span> <span class="ruby-operator">></span> <span class="ruby-identifier">diffNArgs</span>
|
215
|
-
291: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
|
216
|
-
292: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
|
217
|
-
293: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
|
218
|
-
294: <span class="ruby-keyword kw">end</span>
|
219
|
-
295: <span class="ruby-keyword kw">end</span>
|
220
|
-
296:
|
221
|
-
297: <span class="ruby-keyword kw">end</span>
|
222
|
-
298:
|
223
|
-
299: <span class="ruby-identifier">nargs</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">1</span>]
|
224
|
-
300: <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>][<span class="ruby-identifier">finalPath</span>] )
|
225
|
-
301: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>( <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span>.<span class="ruby-identifier">unescape</span>(<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>).<span class="ruby-identifier">gsub</span>( <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-node">"^#{finalPath}"</span> ), <span class="ruby-value str">""</span> ).<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">""</span> ) )
|
226
|
-
302: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
|
227
|
-
303: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">ParameterError</span>, <span class="ruby-node">"Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'"</span>
|
228
|
-
304: <span class="ruby-keyword kw">else</span>
|
229
|
-
305: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">captures</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">x</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>)<span class="ruby-operator">?</span><span class="ruby-keyword kw">nil</span><span class="ruby-operator">:</span><span class="ruby-identifier">x</span> }
|
230
|
-
306: <span class="ruby-keyword kw">end</span>
|
231
|
-
307:
|
232
|
-
308: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">nargs</span>
|
233
|
-
309: <span class="ruby-identifier">args</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">nil</span>
|
234
|
-
310: <span class="ruby-keyword kw">end</span>
|
235
|
-
311:
|
236
|
-
312: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
237
|
-
313: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"POST"</span>
|
238
|
-
314: <span class="ruby-identifier">post</span>
|
239
|
-
315: <span class="ruby-keyword kw">end</span>
|
240
|
-
316: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_ary</span>)
|
241
|
-
317: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">0</span>]
|
242
|
-
318: <span class="ruby-identifier">r</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
243
|
-
319: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
244
|
-
320: <span class="ruby-keyword kw">end</span>
|
245
|
-
321: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">2</span>]
|
246
|
-
322: <span class="ruby-keyword kw">else</span>
|
247
|
-
323: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
|
248
|
-
324: <span class="ruby-keyword kw">end</span>
|
249
|
-
325:
|
250
|
-
326: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
|
251
|
-
327: <span class="ruby-keyword kw">end</span>
|
252
|
-
328:
|
253
|
-
329: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
|
254
|
-
330: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
|
255
|
-
331: }
|
256
|
-
332: <span class="ruby-keyword kw">end</span>
|
257
|
-
</pre>
|
258
|
-
</div>
|
259
|
-
</div>
|
260
|
-
<h4 class="ruled">Public Class method:
|
261
|
-
<strong><a name="M000003">env()</a></strong> <a href="#M000003"><img src="../permalink.gif" border="0" title="Permalink to Public Class method: env" /></a></h4>
|
262
|
-
|
263
|
-
<p>
|
264
|
-
Hash containing all the environment variables
|
265
|
-
</p>
|
266
|
-
|
267
|
-
<div class="sourcecode">
|
268
|
-
<p class="source-link">[ <a href="javascript:toggleSource('M000003_source')" id="l_M000003_source">show source</a> ]</p>
|
269
|
-
<div id="M000003_source" class="dyn-source">
|
270
|
-
<pre>
|
271
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line 239</span>
|
272
|
-
239: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
273
|
-
240: <span class="ruby-ivar">@env</span>
|
274
|
-
241: <span class="ruby-keyword kw">end</span>
|
275
|
-
</pre>
|
276
|
-
</div>
|
277
|
-
</div>
|
278
|
-
<h4 class="ruled">Public Class method:
|
279
|
-
<strong><a name="M000007">map( r ) {|| ...}</a></strong> <a href="#M000007"><img src="../permalink.gif" border="0" title="Permalink to Public Class method: map" /></a></h4>
|
280
|
-
|
281
|
-
<p>
|
282
|
-
This method help you to <a href="Capcode.html#M000007">map</a> and URL to a
|
283
|
-
Rack or What you want Helper
|
284
|
-
</p>
|
285
|
-
<pre>
|
286
|
-
Capcode.map( "/file" ) do
|
287
|
-
Rack::File.new( "." )
|
288
|
-
end
|
289
|
-
</pre>
|
290
|
-
|
291
|
-
<div class="sourcecode">
|
292
|
-
<p class="source-link">[ <a href="javascript:toggleSource('M000007_source')" id="l_M000007_source">show source</a> ]</p>
|
293
|
-
<div id="M000007_source" class="dyn-source">
|
294
|
-
<pre>
|
295
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line 339</span>
|
296
|
-
339: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>( <span class="ruby-identifier">r</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span> )
|
297
|
-
340: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-keyword kw">yield</span>
|
298
|
-
341: <span class="ruby-keyword kw">end</span>
|
299
|
-
</pre>
|
300
|
-
</div>
|
301
|
-
</div>
|
302
|
-
<h4 class="ruled">Public Class method:
|
303
|
-
<strong><a name="M000002">params()</a></strong> <a href="#M000002"><img src="../permalink.gif" border="0" title="Permalink to Public Class method: params" /></a></h4>
|
304
|
-
|
305
|
-
<p>
|
306
|
-
Hash containing all the <a href="Capcode.html#M000005">request</a>
|
307
|
-
parameters (GET or POST)
|
308
|
-
</p>
|
309
|
-
|
310
|
-
<div class="sourcecode">
|
311
|
-
<p class="source-link">[ <a href="javascript:toggleSource('M000002_source')" id="l_M000002_source">show source</a> ]</p>
|
312
|
-
<div id="M000002_source" class="dyn-source">
|
313
|
-
<pre>
|
314
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line 234</span>
|
315
|
-
234: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
316
|
-
235: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
317
|
-
236: <span class="ruby-keyword kw">end</span>
|
318
|
-
</pre>
|
319
|
-
</div>
|
320
|
-
</div>
|
321
|
-
<h4 class="ruled">Public Class method:
|
322
|
-
<strong><a name="M000005">request()</a></strong> <a href="#M000005"><img src="../permalink.gif" border="0" title="Permalink to Public Class method: request" /></a></h4>
|
323
|
-
|
324
|
-
<p>
|
325
|
-
Return the Rack::Request object
|
326
|
-
</p>
|
327
|
-
|
328
|
-
<div class="sourcecode">
|
329
|
-
<p class="source-link">[ <a href="javascript:toggleSource('M000005_source')" id="l_M000005_source">show source</a> ]</p>
|
330
|
-
<div id="M000005_source" class="dyn-source">
|
331
|
-
<pre>
|
332
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line 249</span>
|
333
|
-
249: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
334
|
-
250: <span class="ruby-ivar">@request</span>
|
335
|
-
251: <span class="ruby-keyword kw">end</span>
|
336
|
-
</pre>
|
337
|
-
</div>
|
338
|
-
</div>
|
339
|
-
<h4 class="ruled">Public Class method:
|
340
|
-
<strong><a name="M000006">response()</a></strong> <a href="#M000006"><img src="../permalink.gif" border="0" title="Permalink to Public Class method: response" /></a></h4>
|
341
|
-
|
342
|
-
<p>
|
343
|
-
Return the Rack::Response object
|
344
|
-
</p>
|
345
|
-
|
346
|
-
<div class="sourcecode">
|
347
|
-
<p class="source-link">[ <a href="javascript:toggleSource('M000006_source')" id="l_M000006_source">show source</a> ]</p>
|
348
|
-
<div id="M000006_source" class="dyn-source">
|
349
|
-
<pre>
|
350
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line 254</span>
|
351
|
-
254: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
352
|
-
255: <span class="ruby-ivar">@response</span>
|
353
|
-
256: <span class="ruby-keyword kw">end</span>
|
354
|
-
</pre>
|
355
|
-
</div>
|
356
|
-
</div>
|
357
|
-
<h4 class="ruled">Public Class method:
|
358
|
-
<strong><a name="M000008">run( args = {} ) {|self| ...}</a></strong> <a href="#M000008"><img src="../permalink.gif" border="0" title="Permalink to Public Class method: run" /></a></h4>
|
359
|
-
|
360
|
-
<p>
|
361
|
-
Start your application.
|
362
|
-
</p>
|
363
|
-
<p>
|
364
|
-
Options :
|
365
|
-
</p>
|
366
|
-
<ul>
|
367
|
-
<li><tt>:port</tt> = Listen port
|
368
|
-
|
369
|
-
</li>
|
370
|
-
<li><tt>:host</tt> = Listen host
|
371
|
-
|
372
|
-
</li>
|
373
|
-
<li><tt>:server</tt> = Server type (webrick or mongrel)
|
374
|
-
|
375
|
-
</li>
|
376
|
-
<li><tt>:log</tt> = Output logfile (default: STDOUT)
|
377
|
-
|
378
|
-
</li>
|
379
|
-
<li><tt>:<a href="Capcode.html#M000004">session</a></tt> = Session parameters.
|
380
|
-
See Rack::Session for more informations
|
381
|
-
|
382
|
-
</li>
|
383
|
-
<li><tt>:pid</tt> = PID file (default: $0.pid)
|
384
|
-
|
385
|
-
</li>
|
386
|
-
<li><tt>:daemonize</tt> = Daemonize application (default: false)
|
387
|
-
|
388
|
-
</li>
|
389
|
-
<li><tt>:db_config</tt> = database configuration file (default: database.yml)
|
390
|
-
|
391
|
-
</li>
|
392
|
-
<li><tt>:static</tt> = Static directory (default: none — relative to the
|
393
|
-
working directory)
|
394
|
-
|
395
|
-
</li>
|
396
|
-
<li><tt>:root</tt> = Root directory (default: directory of the main.rb) —
|
397
|
-
This is also the working directory !
|
398
|
-
|
399
|
-
</li>
|
400
|
-
</ul>
|
401
|
-
|
402
|
-
<div class="sourcecode">
|
403
|
-
<p class="source-link">[ <a href="javascript:toggleSource('M000008_source')" id="l_M000008_source">show source</a> ]</p>
|
404
|
-
<div id="M000008_source" class="dyn-source">
|
405
|
-
<pre>
|
406
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line 356</span>
|
407
|
-
356: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
|
408
|
-
357: <span class="ruby-identifier">__VERBOSE</span> = <span class="ruby-keyword kw">false</span>
|
409
|
-
358:
|
410
|
-
359: <span class="ruby-identifier">conf</span> = {
|
411
|
-
360: <span class="ruby-identifier">:port</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:port</span>]<span class="ruby-operator">||</span><span class="ruby-value">3000</span>,
|
412
|
-
361: <span class="ruby-identifier">:host</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:host</span>]<span class="ruby-operator">||</span><span class="ruby-value str">"localhost"</span>,
|
413
|
-
362: <span class="ruby-identifier">:server</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:server</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>,
|
414
|
-
363: <span class="ruby-identifier">:log</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:log</span>]<span class="ruby-operator">||</span><span class="ruby-identifier">$stdout</span>,
|
415
|
-
364: <span class="ruby-identifier">:session</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:session</span>]<span class="ruby-operator">||</span>{},
|
416
|
-
365: <span class="ruby-identifier">:pid</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:pid</span>]<span class="ruby-operator">||</span><span class="ruby-node">"#{$0}.pid"</span>,
|
417
|
-
366: <span class="ruby-identifier">:daemonize</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:daemonize</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">false</span>,
|
418
|
-
367: <span class="ruby-identifier">:db_config</span> =<span class="ruby-operator">></span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">args</span>[<span class="ruby-identifier">:db_config</span>]<span class="ruby-operator">||</span><span class="ruby-value str">"database.yml"</span>),
|
419
|
-
368: <span class="ruby-identifier">:static</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:static</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>,
|
420
|
-
369: <span class="ruby-identifier">:root</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:root</span>]<span class="ruby-operator">||</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">$0</span>)),
|
421
|
-
370:
|
422
|
-
371: <span class="ruby-identifier">:console</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>
|
423
|
-
372: }
|
424
|
-
373:
|
425
|
-
374: <span class="ruby-comment cmt"># Parse options</span>
|
426
|
-
375: <span class="ruby-identifier">opts</span> = <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
|
427
|
-
376: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">"Usage: #{File.basename($0)} [options]"</span>
|
428
|
-
377: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
429
|
-
378: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Specific options:"</span>
|
430
|
-
379:
|
431
|
-
380: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-C"</span>, <span class="ruby-value str">"--console"</span>, <span class="ruby-value str">"Run in console mode with IRB (default: false)"</span> ) {
|
432
|
-
381: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>] = <span class="ruby-keyword kw">true</span>
|
433
|
-
382: }
|
434
|
-
383: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-h"</span>, <span class="ruby-value str">"--host HOSTNAME"</span>, <span class="ruby-node">"Host for web server to bind to (default: #{conf[:host]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
|
435
|
-
384: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>] = <span class="ruby-identifier">h</span>
|
436
|
-
385: }
|
437
|
-
386: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-p"</span>, <span class="ruby-value str">"--port NUM"</span>, <span class="ruby-node">"Port for web server (default: #{conf[:port]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
|
438
|
-
387: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>] = <span class="ruby-identifier">p</span>
|
439
|
-
388: }
|
440
|
-
389: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-d"</span>, <span class="ruby-value str">"--daemonize [true|false]"</span>, <span class="ruby-node">"Daemonize (default: #{conf[:daemonize]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
|
441
|
-
390: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>] = <span class="ruby-identifier">d</span>
|
442
|
-
391: }
|
443
|
-
392: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-r"</span>, <span class="ruby-value str">"--root PATH"</span>, <span class="ruby-node">"Working directory (default: #{conf[:root]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span>
|
444
|
-
393: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] = <span class="ruby-identifier">w</span>
|
445
|
-
394: }
|
446
|
-
395: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-s"</span>, <span class="ruby-value str">"--static PATH"</span>, <span class="ruby-node">"Static directory -- relative to the root directory (default: #{conf[:static]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
447
|
-
396: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] = <span class="ruby-identifier">r</span>
|
448
|
-
397: }
|
449
|
-
398:
|
450
|
-
399: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
451
|
-
400: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Common options:"</span>
|
452
|
-
401:
|
453
|
-
402: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-?"</span>, <span class="ruby-value str">"--help"</span>, <span class="ruby-value str">"Show this message"</span>) <span class="ruby-keyword kw">do</span>
|
454
|
-
403: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
|
455
|
-
404: <span class="ruby-identifier">exit</span>
|
456
|
-
405: <span class="ruby-keyword kw">end</span>
|
457
|
-
406: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-v"</span>, <span class="ruby-value str">"--version"</span>, <span class="ruby-value str">"Show versions"</span>) <span class="ruby-keyword kw">do</span>
|
458
|
-
407: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})"</span>
|
459
|
-
408: <span class="ruby-identifier">exit</span>
|
460
|
-
409: <span class="ruby-keyword kw">end</span>
|
461
|
-
410: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on_tail</span>( <span class="ruby-value str">"-V"</span>, <span class="ruby-value str">"--verbose"</span>, <span class="ruby-value str">"Run in verbose mode"</span> ) <span class="ruby-keyword kw">do</span>
|
462
|
-
411: <span class="ruby-identifier">__VERBOSE</span> = <span class="ruby-keyword kw">true</span>
|
463
|
-
412: <span class="ruby-keyword kw">end</span>
|
464
|
-
413: <span class="ruby-keyword kw">end</span>
|
465
|
-
414:
|
466
|
-
415: <span class="ruby-keyword kw">begin</span>
|
467
|
-
416: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
|
468
|
-
417: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">OptionParser</span><span class="ruby-operator">::</span><span class="ruby-constant">ParseError</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">ex</span>
|
469
|
-
418: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! #{ex.message}"</span>
|
470
|
-
419: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** use `#{File.basename($0)} --help` for more details..."</span>
|
471
|
-
420: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
|
472
|
-
421: <span class="ruby-keyword kw">end</span>
|
473
|
-
422:
|
474
|
-
423: <span class="ruby-comment cmt"># Run in the Working directory</span>
|
475
|
-
424: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Go on root directory (#{File.expand_path(conf[:root])})"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">__VERBOSE</span>
|
476
|
-
425: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] ) <span class="ruby-keyword kw">do</span>
|
477
|
-
426:
|
478
|
-
427: <span class="ruby-comment cmt"># Check that mongrel exists </span>
|
479
|
-
428: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"mongrel"</span>
|
480
|
-
429: <span class="ruby-keyword kw">begin</span>
|
481
|
-
430: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
|
482
|
-
431: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"mongrel"</span>
|
483
|
-
432: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
|
484
|
-
433: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"!! could not load mongrel. Falling back to webrick."</span>
|
485
|
-
434: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"webrick"</span>
|
486
|
-
435: <span class="ruby-keyword kw">end</span>
|
487
|
-
436: <span class="ruby-keyword kw">end</span>
|
488
|
-
437:
|
489
|
-
438: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
|
490
|
-
439: <span class="ruby-keyword kw">begin</span>
|
491
|
-
440: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">eval</span> <span class="ruby-node">"Capcode::#{k}.public_methods(true).include?( '__urls__' )"</span>
|
492
|
-
441: <span class="ruby-identifier">u</span>, <span class="ruby-identifier">m</span>, <span class="ruby-identifier">c</span> = <span class="ruby-identifier">eval</span> <span class="ruby-node">"Capcode::#{k}.__urls__"</span>
|
493
|
-
442: <span class="ruby-identifier">u</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">_u</span><span class="ruby-operator">|</span>
|
494
|
-
443: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">"Route `#{_u}' already define !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@@__ROUTES</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_u</span>)
|
495
|
-
444: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>
|
496
|
-
445: <span class="ruby-keyword kw">end</span>
|
497
|
-
446: <span class="ruby-keyword kw">end</span>
|
498
|
-
447: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
499
|
-
448: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
500
|
-
449: <span class="ruby-keyword kw">end</span>
|
501
|
-
450: <span class="ruby-keyword kw">end</span>
|
502
|
-
451:
|
503
|
-
452: <span class="ruby-comment cmt"># Set Static directory</span>
|
504
|
-
453: <span class="ruby-ivar">@@__STATIC_DIR</span> = (<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">chr</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"/"</span>)<span class="ruby-operator">?</span><span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>]<span class="ruby-operator">:</span><span class="ruby-value str">"/"</span><span class="ruby-operator">+</span><span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>].<span class="ruby-identifier">nil?</span>
|
505
|
-
454:
|
506
|
-
455: <span class="ruby-comment cmt"># Initialize Rack App</span>
|
507
|
-
456: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"** Map routes."</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">__VERBOSE</span>
|
508
|
-
457: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">URLMap</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@@__ROUTES</span>)
|
509
|
-
458: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Initialize static directory (#{conf[:static]})"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">__VERBOSE</span>
|
510
|
-
459: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Static</span>.<span class="ruby-identifier">new</span>(
|
511
|
-
460: <span class="ruby-identifier">app</span>,
|
512
|
-
461: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">></span> [<span class="ruby-ivar">@@__STATIC_DIR</span>],
|
513
|
-
462: <span class="ruby-identifier">:root</span> =<span class="ruby-operator">></span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>])
|
514
|
-
463: ) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>].<span class="ruby-identifier">nil?</span>
|
515
|
-
464: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"** Initialize session"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">__VERBOSE</span>
|
516
|
-
465: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span><span class="ruby-operator">::</span><span class="ruby-constant">Cookie</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:session</span>] )
|
517
|
-
466: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
518
|
-
467: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ContentLength</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
519
|
-
468: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Lint</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
520
|
-
469: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ShowExceptions</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
521
|
-
470: <span class="ruby-comment cmt"># app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
|
522
|
-
471: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">CommonLogger</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>]) )
|
523
|
-
472:
|
524
|
-
473: <span class="ruby-comment cmt"># From rackup !!!</span>
|
525
|
-
474: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
|
526
|
-
475: <span class="ruby-keyword kw">if</span> <span class="ruby-regexp re">/java/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-constant">RUBY_PLATFORM</span>).<span class="ruby-identifier">nil?</span>
|
527
|
-
476: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator"><</span> <span class="ruby-value str">"1.9"</span>
|
528
|
-
477: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
529
|
-
478: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
530
|
-
479: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
531
|
-
480: <span class="ruby-comment cmt"># Dir.chdir "/"</span>
|
532
|
-
481: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
|
533
|
-
482: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>
|
534
|
-
483: <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>, <span class="ruby-value str">"a"</span>
|
535
|
-
484: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>, <span class="ruby-value str">"a"</span>
|
536
|
-
485: <span class="ruby-keyword kw">else</span>
|
537
|
-
486: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
|
538
|
-
487: <span class="ruby-keyword kw">end</span>
|
539
|
-
488: <span class="ruby-keyword kw">else</span>
|
540
|
-
489: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! daemonize option unavailable on #{RUBY_PLATFORM} platform."</span>
|
541
|
-
490: <span class="ruby-keyword kw">end</span>
|
542
|
-
491:
|
543
|
-
492: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>], <span class="ruby-value str">'w'</span>){ <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">"#{Process.pid}"</span>) }
|
544
|
-
493: <span class="ruby-identifier">at_exit</span> { <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) }
|
545
|
-
494: <span class="ruby-keyword kw">end</span>
|
546
|
-
495:
|
547
|
-
496: <span class="ruby-comment cmt"># Start database</span>
|
548
|
-
497: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">methods</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value str">"db_connect"</span>
|
549
|
-
498: <span class="ruby-identifier">db_connect</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:db_config</span>], <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>] )
|
550
|
-
499: <span class="ruby-keyword kw">end</span>
|
551
|
-
500:
|
552
|
-
501: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
553
|
-
502: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
|
554
|
-
503: <span class="ruby-keyword kw">end</span>
|
555
|
-
504:
|
556
|
-
505: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>]
|
557
|
-
506: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"Run console..."</span>
|
558
|
-
507: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
|
559
|
-
508: <span class="ruby-identifier">exit</span>
|
560
|
-
509: <span class="ruby-keyword kw">end</span>
|
561
|
-
510:
|
562
|
-
511: <span class="ruby-comment cmt"># Start server</span>
|
563
|
-
512: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
|
564
|
-
513: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"mongrel"</span>
|
565
|
-
514: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Mongrel on #{conf[:host]}:#{conf[:port]}"</span>
|
566
|
-
515: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Mongrel</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
|
567
|
-
516: <span class="ruby-identifier">trap</span> <span class="ruby-value str">"SIGINT"</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">stop</span> }
|
568
|
-
517: }
|
569
|
-
518: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
570
|
-
519: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{conf[:host]}:#{conf[:port]}"</span>
|
571
|
-
520: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">WEBrick</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
|
572
|
-
521: <span class="ruby-identifier">trap</span> <span class="ruby-value str">"SIGINT"</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">shutdown</span> }
|
573
|
-
522: }
|
574
|
-
523: <span class="ruby-keyword kw">end</span>
|
575
|
-
524: <span class="ruby-keyword kw">end</span>
|
576
|
-
525: <span class="ruby-keyword kw">end</span>
|
577
|
-
</pre>
|
578
|
-
</div>
|
579
|
-
</div>
|
580
|
-
<h4 class="ruled">Public Class method:
|
581
|
-
<strong><a name="M000004">session()</a></strong> <a href="#M000004"><img src="../permalink.gif" border="0" title="Permalink to Public Class method: session" /></a></h4>
|
582
|
-
|
583
|
-
<p>
|
584
|
-
Hash <a href="Capcode.html#M000004">session</a>
|
585
|
-
</p>
|
586
|
-
|
587
|
-
<div class="sourcecode">
|
588
|
-
<p class="source-link">[ <a href="javascript:toggleSource('M000004_source')" id="l_M000004_source">show source</a> ]</p>
|
589
|
-
<div id="M000004_source" class="dyn-source">
|
590
|
-
<pre>
|
591
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line 244</span>
|
592
|
-
244: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
593
|
-
245: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
594
|
-
246: <span class="ruby-keyword kw">end</span>
|
595
|
-
</pre>
|
596
|
-
</div>
|
597
|
-
</div>
|
598
|
-
|
599
|
-
</div>
|
600
|
-
</div>
|
601
|
-
|
602
|
-
|
603
|
-
</div>
|
604
|
-
</body>
|
605
|
-
</html>
|