rackful 0.1.2 → 0.1.3

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/example/config2.ru DELETED
@@ -1,41 +0,0 @@
1
- require 'rack'
2
- require 'rackful/header_spoofing'
3
- require 'rackful/method_spoofing'
4
- require 'rackful/relative_location'
5
-
6
- # The class of the object we're going to serve:
7
- class Root
8
- include Rackful::Resource
9
- def initialize *args
10
- super
11
- @content = 'Hello world!'
12
- end
13
- def do_GET request, response
14
- response['Content-Type'] = 'text/plain'
15
- response.write @content
16
- end
17
- def do_PUT request, response
18
- @content = request.body.read
19
- response.status = status_code :no_content
20
- end
21
- def etag
22
- '"' + Digest::MD5.new.update(@content).to_s + '"'
23
- end
24
- end
25
- $root_resource = Root.new '/'
26
-
27
- # Rackful::Server needs a resource factory which can map URIs to resource objects:
28
- class ResourceFactory
29
- def [] uri
30
- case uri
31
- when '/'; $root_resource
32
- else; nil
33
- end
34
- end
35
- end
36
-
37
- use Rackful::MethodSpoofing
38
- use Rackful::HeaderSpoofing
39
- use Rackful::RelativeLocation
40
-
41
- run Rackful::Server.new ResourceFactory.new
data/lib/rackful_path.rb DELETED
@@ -1,119 +0,0 @@
1
- # Required for parsing:
2
-
3
- # Required for running:
4
- require 'rack/utils'
5
-
6
-
7
- # A String monkeypatch
8
- # @private
9
- class String
10
-
11
- def to_path; Rackful::Path.new(self); end
12
-
13
- end
14
-
15
-
16
- module Rackful
17
-
18
-
19
- # Relative URI (a path)
20
- class Path < String
21
-
22
- def slashify
23
- r = self.dup
24
- r << '/' if '/' != r[-1,1]
25
- r
26
- end
27
-
28
- def slashify!
29
- if '/' != self[-1,1]
30
- self << '/'
31
- else
32
- nil
33
- end
34
- end
35
-
36
- def unslashify
37
- r = self.dup
38
- r = r.chomp( '/' ) if '/' == r[-1,1]
39
- r
40
- end
41
-
42
- def unslashify!
43
- if '/' == self[-1,1]
44
- self.chomp! '/'
45
- else
46
- nil
47
- end
48
- end
49
-
50
- # An alias for Rack::Utils.unescape
51
- def unescape( encoding = Encoding::UTF_8 ); Rack::Utils.unescape(self, encoding); end
52
-
53
- # @return [Array<String>] An array of unencoded segments
54
- def segments
55
- r = self.split('/').collect { |s| Rack::Utils.unescape( s, Encoding::UTF_8 ) }
56
- r.shift
57
- r
58
- end
59
-
60
- end # class Path
61
-
62
-
63
- end # module Rackful
64
-
65
- =begin comment
66
- # Monkeypatch to this stdlib class.
67
- class URI::Generic
68
-
69
- # @see http://www.w3.org/TR/html401/struct/links.html#adef-rel the HTML `rel` attribute.
70
- attr_accessor :rel
71
-
72
- # @see http://www.w3.org/TR/html401/struct/links.html#adef-rev the HTML `rev` attribute.
73
- attr_accessor :rev
74
-
75
- def to_xhtml base_path, encoding = Encoding::UTF_8
76
- retval = "<a href=\"#{self.route_from(base_path)}\"".encode encoding
77
- retval << " rel=\"#{self.rel}\"" if self.rel
78
- retval << " rev=\"#{self.rev}\"" if self.rev
79
- retval << '>'
80
- if self.relative? && ! self.query && ! self.fragment
81
- retval << Rack::Utils.escape_html(
82
- Rack::Utils.unescape( self.route_from(base_path).to_s, encoding )
83
- )
84
- else
85
- retval << self.to_s
86
- end
87
- retval << '</a>'
88
- retval
89
- end
90
-
91
- # @return [URI::Generic]
92
- def slashify
93
- r = self.dup
94
- r.path = r.path.unslashify
95
- r
96
- end
97
-
98
- # @return [self, nil]
99
- def slashify!
100
- self.path.slashify! && self
101
- end
102
-
103
- # @return [URI::Generic]
104
- def unslashify
105
- r = self.dup
106
- r.path = r.path.unslashify
107
- r
108
- end
109
-
110
- # @return [self, nil]
111
- def unslashify!
112
- self.path.unslashify! && self
113
- end
114
-
115
- end # class ::URI::Generic
116
- =end
117
-
118
-
119
-