sansom 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/changelog.md +10 -1
- data/lib/rack/fastlint.rb +18 -14
- data/lib/sansom/pine.rb +40 -35
- data/lib/sansom.rb +20 -18
- data/sansom.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1548d457d044bae13692b07bcb7a8374212be88
|
4
|
+
data.tar.gz: 13e2ea4214d1b6a3c5b7c2c05421776f20dd9c92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e097de2bf1ea1b34754d9fde63983bc374d72e36a9cb446d275302824b1fc04183f1282b944add46b364ce1b5c7241520ce388eb53a4c09b702886748ce8a51e
|
7
|
+
data.tar.gz: 13503646c81f33fb6ad3cb9004859fa3bd9036781ed5ac7a1b05c5797d0777303575d578b7231353e99803246736ff49ae833ba9c506d053d717b869772dc002
|
data/changelog.md
CHANGED
@@ -37,4 +37,13 @@ Here's an example
|
|
37
37
|
|
38
38
|
- Parameterized URLs!!! (Stuff like `/user/:id/profile`)
|
39
39
|
* Parameterized URLs work with mounted Rack/Sansom apps
|
40
|
-
- Improved matching efficiency
|
40
|
+
- Improved matching efficiency
|
41
|
+
|
42
|
+
0.0.6
|
43
|
+
|
44
|
+
- Before block response checking
|
45
|
+
|
46
|
+
0.0.7
|
47
|
+
|
48
|
+
- Fixed bug where a wilcard path component would be ignored if it came last in the URL
|
49
|
+
- Fixed a bug where async responses would be marked as bad by the fastlinter.
|
data/lib/rack/fastlint.rb
CHANGED
@@ -4,32 +4,36 @@ require "rack"
|
|
4
4
|
|
5
5
|
module Rack
|
6
6
|
class Fastlint
|
7
|
+
LintError = Class.new StandardError
|
7
8
|
def self.response res
|
8
|
-
# Check response format
|
9
9
|
return false unless res.kind_of?(Array) && res.count == 3
|
10
10
|
|
11
11
|
status, headers, body = res
|
12
12
|
|
13
|
-
return false unless status.to_i >= 100
|
14
|
-
|
13
|
+
return false unless status.to_i >= 100 || status.to_i == -1
|
15
14
|
return false unless headers.respond_to? :each
|
16
|
-
headers.each { |k,v|
|
17
|
-
next if key =~ /^rack\..+$/
|
18
|
-
return false unless k.kind_of? String
|
19
|
-
return false unless v.kind_of? String
|
20
|
-
return false if k.downcase == "status"
|
21
|
-
return false unless k !~ /[:\n]/
|
22
|
-
return false unless k !~ /[-_]\z/
|
23
|
-
return false unless k =~ /\A[a-zA-Z][a-zA-Z0-9_-]*\z/
|
24
|
-
}
|
25
|
-
|
26
15
|
return false unless body.respond_to? :each
|
27
|
-
body.each { |part| return false unless part.kind_of? String }
|
28
16
|
|
29
17
|
if body.respond_to? :to_path
|
30
18
|
return false unless File.exist? body.to_path
|
31
19
|
end
|
32
20
|
|
21
|
+
begin
|
22
|
+
headers.each { |k,v|
|
23
|
+
next if key =~ /^rack\..+$/
|
24
|
+
throw LintError unless k.kind_of? String
|
25
|
+
throw LintError unless v.kind_of? String
|
26
|
+
throw LintError if k.downcase == "status"
|
27
|
+
throw LintError unless k !~ /[:\n]/
|
28
|
+
throw LintError unless k !~ /[-_]\z/
|
29
|
+
throw LintError unless k =~ /\A[a-zA-Z][a-zA-Z0-9_-]*\z/
|
30
|
+
}
|
31
|
+
|
32
|
+
body.each { |part| throw LintError unless part.kind_of? String }
|
33
|
+
rescue StandardError
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
|
33
37
|
true
|
34
38
|
end
|
35
39
|
end
|
data/lib/sansom/pine.rb
CHANGED
@@ -3,6 +3,27 @@
|
|
3
3
|
# Path routing tree
|
4
4
|
|
5
5
|
module Pine
|
6
|
+
Result = Struct.new :item, :remaining_path, :url_params
|
7
|
+
|
8
|
+
class Content
|
9
|
+
attr_accessor :items, :map
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@items = []
|
13
|
+
@map = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def []= k,v
|
17
|
+
@items << v if k == :map
|
18
|
+
@map[k] = v unless k == :map
|
19
|
+
end
|
20
|
+
|
21
|
+
def [] k
|
22
|
+
@items[k] if Numeric === k
|
23
|
+
@map[k] unless Numeric === k
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
6
27
|
class Node
|
7
28
|
attr_reader :name, :parent
|
8
29
|
attr_accessor :content
|
@@ -23,15 +44,16 @@ module Pine
|
|
23
44
|
end
|
24
45
|
|
25
46
|
def wildcard?
|
26
|
-
@
|
47
|
+
@name.start_with? ":"
|
27
48
|
end
|
28
49
|
|
29
50
|
def [] k
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
51
|
+
child = @children[k]
|
52
|
+
return child unless child.nil?
|
53
|
+
child = @children.values.first
|
54
|
+
return child if child.wildcard?
|
55
|
+
nil
|
56
|
+
# return @children[k] || @children.values.first
|
35
57
|
end
|
36
58
|
|
37
59
|
def create_and_save comp
|
@@ -41,9 +63,8 @@ module Pine
|
|
41
63
|
child
|
42
64
|
end
|
43
65
|
|
44
|
-
def << comp
|
66
|
+
def << comp
|
45
67
|
if comp.start_with? ":"
|
46
|
-
@wildcard = true
|
47
68
|
@children.clear
|
48
69
|
create_and_save comp
|
49
70
|
else
|
@@ -53,9 +74,13 @@ module Pine
|
|
53
74
|
end
|
54
75
|
end
|
55
76
|
|
56
|
-
def parse_path path
|
77
|
+
def parse_path path, include_root=true
|
57
78
|
c = path.split "/"
|
58
|
-
|
79
|
+
if include_root
|
80
|
+
c[0] = '/'
|
81
|
+
else
|
82
|
+
c.delete_at(0) if c[0].empty?
|
83
|
+
end
|
59
84
|
c.delete_at(-1) if c[-1].empty?
|
60
85
|
c
|
61
86
|
end
|
@@ -70,14 +95,15 @@ module Pine
|
|
70
95
|
matched_params = {}
|
71
96
|
|
72
97
|
walk = parse_path(path).inject self do |node, comp|
|
73
|
-
|
74
|
-
matched_comps << comp unless
|
98
|
+
next node[comp] if node.name == "ROOT"
|
99
|
+
matched_comps << comp unless node.leaf?
|
75
100
|
child = node[comp]
|
76
|
-
matched_params[child.name[1..-1]] = comp if
|
101
|
+
matched_params[child.name[1..-1]] = comp if child.wildcard?
|
77
102
|
child
|
78
103
|
end
|
79
104
|
|
80
|
-
return nil if walk.
|
105
|
+
return nil if walk.nil?
|
106
|
+
return nil if walk.root? #rescue true
|
81
107
|
|
82
108
|
c = walk.content
|
83
109
|
subpath = path.sub "/#{matched_comps.join("/")}", ""
|
@@ -95,25 +121,4 @@ module Pine
|
|
95
121
|
obj.singleton_class.include? Sansomable
|
96
122
|
end
|
97
123
|
end
|
98
|
-
|
99
|
-
Result = Struct.new :item, :remaining_path, :url_params
|
100
|
-
|
101
|
-
class Content
|
102
|
-
attr_accessor :items, :map
|
103
|
-
|
104
|
-
def initialize
|
105
|
-
@items = []
|
106
|
-
@map = {}
|
107
|
-
end
|
108
|
-
|
109
|
-
def []= k,v
|
110
|
-
@items << v if k == :map
|
111
|
-
@map[k] = v unless k == :map
|
112
|
-
end
|
113
|
-
|
114
|
-
def [] k
|
115
|
-
@items[k] if Numeric === k
|
116
|
-
@map[k] unless Numeric === k
|
117
|
-
end
|
118
|
-
end
|
119
124
|
end
|
data/lib/sansom.rb
CHANGED
@@ -21,7 +21,7 @@ module Sansomable
|
|
21
21
|
def call env
|
22
22
|
return NOT_FOUND if tree.leaf?
|
23
23
|
|
24
|
-
r = Rack::Request.new env
|
24
|
+
r = Rack::Request.new env
|
25
25
|
|
26
26
|
if @before_block
|
27
27
|
res = @before_block.call r
|
@@ -29,25 +29,27 @@ module Sansomable
|
|
29
29
|
end
|
30
30
|
|
31
31
|
m = tree.match r.path_info, r.request_method
|
32
|
-
|
33
|
-
if m.url_params.count > 0
|
34
|
-
q = r.params.merge(m.url_params)
|
35
|
-
s = q.map { |p| p.join '=' }.join("&")
|
36
|
-
r.env["rack.request.query_hash"] = q
|
37
|
-
r.env["rack.request.query_string"] = s
|
38
|
-
r.env["QUERY_STRING"] = s
|
39
|
-
r.instance_variable_set "@params", r.POST.merge(q)
|
40
|
-
end
|
41
32
|
|
42
|
-
if
|
33
|
+
if m.nil?
|
43
34
|
NOT_FOUND
|
44
|
-
|
45
|
-
m.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
35
|
+
else
|
36
|
+
if m.url_params.count > 0
|
37
|
+
q = r.params.merge(m.url_params)
|
38
|
+
s = q.map { |p| p.join '=' }.join("&")
|
39
|
+
r.env["rack.request.query_hash"] = q
|
40
|
+
r.env["rack.request.query_string"] = s
|
41
|
+
r.env["QUERY_STRING"] = s
|
42
|
+
r.instance_variable_set "@params", r.POST.merge(q)
|
43
|
+
end
|
44
|
+
|
45
|
+
if m.item.is_a? Proc
|
46
|
+
m.item.call r
|
47
|
+
elsif m.item.respond_to? :call
|
48
|
+
r.env["PATH_INFO"] = m.remaining_path
|
49
|
+
m.item.call r.env
|
50
|
+
else
|
51
|
+
raise InvalidRouteError, "Route handlers must be blocks or valid rack apps."
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
data/sansom.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "sansom"
|
7
|
-
s.version = "0.0.
|
7
|
+
s.version = "0.0.7"
|
8
8
|
s.authors = ["Nathaniel Symer"]
|
9
9
|
s.email = ["nate@natesymer.com"]
|
10
10
|
s.summary = "Scientific, philosophical, abstract web 'picowork' named after Sansom street in Philly, near where it was made."
|