utopia 0.9.28 → 0.9.29
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
|
|
1
|
+
# This file is part of the "Utopia Framework" project, and is licensed under the GNU AGPLv3.
|
2
|
+
# Copyright 2010 Samuel Williams. All rights reserved.
|
3
|
+
# See <utopia.rb> for licensing details.
|
4
|
+
|
5
|
+
module Utopia
|
6
|
+
|
7
|
+
HTTP_STATUS_CODES = {
|
8
|
+
:success => 200,
|
9
|
+
:created => 201,
|
10
|
+
:accepted => 202,
|
11
|
+
:moved => 301,
|
12
|
+
:found => 302,
|
13
|
+
:see_other => 303,
|
14
|
+
:not_modified => 304,
|
15
|
+
:redirect => 307,
|
16
|
+
:bad_request => 400,
|
17
|
+
:unauthorized => 401,
|
18
|
+
:forbidden => 403,
|
19
|
+
:not_found => 404,
|
20
|
+
:unsupported_method => 405,
|
21
|
+
:gone => 410,
|
22
|
+
:teapot => 418,
|
23
|
+
:error => 500,
|
24
|
+
:unimplemented => 501,
|
25
|
+
:unavailable => 503
|
26
|
+
}
|
27
|
+
|
28
|
+
HTTP_STATUS_DESCRIPTIONS = {
|
29
|
+
400 => "Bad Request",
|
30
|
+
401 => "Permission Denied",
|
31
|
+
403 => "Access Forbidden",
|
32
|
+
404 => "Resource Not Found",
|
33
|
+
405 => "Unsupported Method",
|
34
|
+
500 => "Internal Server Error",
|
35
|
+
501 => "Not Implemented",
|
36
|
+
503 => "Service Unavailable"
|
37
|
+
}
|
38
|
+
end
|
@@ -141,7 +141,6 @@ module Utopia
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def parent
|
144
|
-
# @begin_tags[-2]
|
145
144
|
end_tags[-2]
|
146
145
|
end
|
147
146
|
|
@@ -281,7 +280,7 @@ module Utopia
|
|
281
280
|
@controller.lookup_node(path)
|
282
281
|
end
|
283
282
|
|
284
|
-
def local_path(path, base = nil)
|
283
|
+
def local_path(path = ".", base = nil)
|
285
284
|
path = Path.create(path)
|
286
285
|
root = Pathname.new(@controller.root)
|
287
286
|
|
@@ -301,7 +300,7 @@ module Utopia
|
|
301
300
|
uri_path.dirname
|
302
301
|
end
|
303
302
|
|
304
|
-
def links(path, options = {}, &block)
|
303
|
+
def links(path = ".", options = {}, &block)
|
305
304
|
path = uri_path.dirname + Path.create(path)
|
306
305
|
links = Links.index(@controller.root, path, options)
|
307
306
|
|
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
require 'utopia/middleware'
|
6
6
|
require 'utopia/path'
|
7
|
+
require 'utopia/http_status_codes'
|
7
8
|
|
8
9
|
class Rack::Request
|
9
10
|
def controller(&block)
|
@@ -75,29 +76,61 @@ module Utopia
|
|
75
76
|
action = lookup(path)
|
76
77
|
|
77
78
|
if action
|
78
|
-
action.call(path, request)
|
79
|
-
else
|
80
|
-
return nil
|
79
|
+
return respond_with(action.call(path, request))
|
81
80
|
end
|
82
|
-
|
83
|
-
|
84
|
-
def permission_denied
|
85
|
-
[403, {}, ["Permission Denied!"]]
|
81
|
+
|
82
|
+
return nil
|
86
83
|
end
|
87
84
|
|
88
85
|
def call(env)
|
89
86
|
@controller.app.call(env)
|
90
87
|
end
|
91
88
|
|
92
|
-
def redirect(target, status=302)
|
93
|
-
|
89
|
+
def redirect(target, status = 302)
|
90
|
+
{:redirect => target, :status => status}
|
94
91
|
end
|
95
92
|
|
96
|
-
def
|
97
|
-
[
|
93
|
+
def respond_with(*args)
|
94
|
+
return args[0] if args[0] == nil || Array === args[0]
|
95
|
+
|
96
|
+
status = 200
|
97
|
+
options = nil
|
98
|
+
|
99
|
+
if Numeric === args[0] || Symbol === args[0]
|
100
|
+
status = args[0]
|
101
|
+
options = args[1] || {}
|
102
|
+
else
|
103
|
+
options = args[0]
|
104
|
+
status = options[:status] || status
|
105
|
+
end
|
106
|
+
|
107
|
+
status = Utopia::HTTP_STATUS_CODES[status] || status
|
108
|
+
headers = options[:headers] || {}
|
109
|
+
|
110
|
+
if options[:type]
|
111
|
+
headers['Content-Type'] ||= options[:type]
|
112
|
+
end
|
113
|
+
|
114
|
+
body = []
|
115
|
+
if options[:body]
|
116
|
+
body = options[:body]
|
117
|
+
elsif options[:content]
|
118
|
+
body = [options[:content]]
|
119
|
+
elsif status >= 300
|
120
|
+
body = [Utopia::HTTP_STATUS_DESCRIPTIONS[status] || 'Status #{status}']
|
121
|
+
end
|
122
|
+
|
123
|
+
if options[:redirect]
|
124
|
+
headers["Location"] = options[:redirect]
|
125
|
+
status = 302 if status < 300 || status >= 400
|
126
|
+
end
|
127
|
+
|
128
|
+
# Utopia::LOG.debug([status, headers, body].inspect)
|
129
|
+
return [status, headers, body]
|
98
130
|
end
|
99
131
|
|
100
132
|
def process!(path, request)
|
133
|
+
passthrough(path, request)
|
101
134
|
end
|
102
135
|
|
103
136
|
def self.require_local(path)
|
@@ -112,7 +145,7 @@ module Utopia
|
|
112
145
|
LOG.info "#{self.class.name}: Running in #{@root}"
|
113
146
|
|
114
147
|
@controllers = {}
|
115
|
-
@cache_controllers =
|
148
|
+
@cache_controllers = (UTOPIA_ENV == :production)
|
116
149
|
|
117
150
|
if options[:controller_file]
|
118
151
|
@controller_file = options[:controller_file]
|
data/lib/utopia/tags/gallery.rb
CHANGED
@@ -73,8 +73,6 @@ class Utopia::Tags::Gallery
|
|
73
73
|
def initialize(node, path)
|
74
74
|
@node = node
|
75
75
|
@path = path
|
76
|
-
|
77
|
-
Utopia::LOG.debug("node: #{node.inspect} path: #{path}")
|
78
76
|
end
|
79
77
|
|
80
78
|
def metadata
|
@@ -93,13 +91,9 @@ class Utopia::Tags::Gallery
|
|
93
91
|
paths = []
|
94
92
|
local_path = @node.local_path(@path)
|
95
93
|
|
96
|
-
Utopia::LOG.debug("Scanning #{local_path}")
|
97
|
-
|
98
94
|
Dir.entries(local_path).each do |filename|
|
99
95
|
next unless filename.match(options[:filter])
|
100
96
|
|
101
|
-
Utopia::LOG.debug("Filename #{filename} matched filter...")
|
102
|
-
|
103
97
|
fullpath = File.join(local_path, filename)
|
104
98
|
|
105
99
|
paths << ImagePath.new(@path + filename)
|
data/lib/utopia/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 29
|
9
|
+
version: 0.9.29
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Samuel Williams
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-16 00:00:00 +12:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- ext/utopia/xnode/fast_scanner/parser.c
|
103
103
|
- lib/utopia/etanni.rb
|
104
104
|
- lib/utopia/extensions.rb
|
105
|
+
- lib/utopia/http_status_codes.rb
|
105
106
|
- lib/utopia/link.rb
|
106
107
|
- lib/utopia/middleware/all.rb
|
107
108
|
- lib/utopia/middleware/benchmark.rb
|
@@ -117,7 +118,6 @@ files:
|
|
117
118
|
- lib/utopia/middleware/static.rb
|
118
119
|
- lib/utopia/middleware.rb
|
119
120
|
- lib/utopia/path.rb
|
120
|
-
- lib/utopia/response_helper.rb
|
121
121
|
- lib/utopia/session/encrypted_cookie.rb
|
122
122
|
- lib/utopia/tag.rb
|
123
123
|
- lib/utopia/tags/all.rb
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# This file is part of the "Utopia Framework" project, and is licensed under the GNU AGPLv3.
|
2
|
-
# Copyright 2010 Samuel Williams. All rights reserved.
|
3
|
-
# See <utopia.rb> for licensing details.
|
4
|
-
|
5
|
-
module Rack
|
6
|
-
class Response
|
7
|
-
def self.create(response, &block)
|
8
|
-
self.new(response[2], response[0], response[1], &block)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|