rack-unpoly 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +9 -1
- data/Rakefile +3 -6
- data/lib/rack/unpoly/inspector.rb +37 -10
- data/lib/rack/unpoly/middleware.rb +11 -7
- data/lib/rack/unpoly/version.rb +5 -0
- data/lib/rack/unpoly.rb +4 -2
- data/lib/sinatra/unpoly.rb +18 -8
- metadata +28 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f1aece4170c9dd2428b5f290fa9d157a4fed1172af19c043879d9125d9e69971
|
4
|
+
data.tar.gz: '008b057c819435065a6dd6bd9fa7389769bfef2708f62003d48d45dc44d449a8'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ede8e4810fd20598e99cc8b24704d2804592bfd450445a96e3ec4bbeb4e047c6482980db46861b318c5741c6a626a57b569795031a0bd9823990119751507644
|
7
|
+
data.tar.gz: 66d658948a3df18ebee16615290eb66098282782eb823543bce931f0b679e2907aa94c886783b4f3d89d5e36fd20052da0141610838a48c703bb3edaceab52e0
|
data/README.md
CHANGED
@@ -51,7 +51,15 @@ require "rack/unpoly/middleware"
|
|
51
51
|
|
52
52
|
use Rack::Unpoly::Middleware
|
53
53
|
|
54
|
-
|
54
|
+
app = ->(env) {
|
55
|
+
if env["rack.unpoly"].up?
|
56
|
+
[200, {}, ["Unpoly request!"]]
|
57
|
+
else
|
58
|
+
[200, {}, ["Not Unpoly :("]]
|
59
|
+
end
|
60
|
+
}
|
61
|
+
|
62
|
+
run app
|
55
63
|
```
|
56
64
|
|
57
65
|
## Where are the Javascript and CSS assets?
|
data/Rakefile
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
require "
|
1
|
+
require "minitest/test_task"
|
2
2
|
require "rdoc/task"
|
3
3
|
require "rubygems/tasks"
|
4
|
+
require "standard/rake"
|
4
5
|
|
5
|
-
|
6
|
-
t.libs << "test"
|
7
|
-
t.test_files = FileList["test/test*.rb"]
|
8
|
-
t.verbose = true
|
9
|
-
end
|
6
|
+
Minitest::TestTask.create
|
10
7
|
|
11
8
|
RDoc::Task.new do |rdoc|
|
12
9
|
rdoc.main = "README.md"
|
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
|
+
|
2
3
|
require "forwardable"
|
3
4
|
|
4
|
-
module Rack
|
5
|
-
module Unpoly
|
5
|
+
module Rack
|
6
|
+
module Unpoly
|
6
7
|
# Easily inspect the Unpoly environment of the current request.
|
7
8
|
# Inspectors are not normally instantiated by users, but accessed
|
8
9
|
# through +env["rack.unpoly"]+ or one of the convenience wrappers
|
@@ -10,71 +11,97 @@ module Rack # :nodoc:
|
|
10
11
|
class Inspector
|
11
12
|
extend Forwardable
|
12
13
|
|
13
|
-
|
14
|
+
# @api private
|
15
|
+
def_delegators :request, :get_header
|
14
16
|
|
15
|
-
attr_reader :request
|
17
|
+
attr_reader :request
|
18
|
+
private :request
|
16
19
|
|
17
|
-
|
20
|
+
# @api private
|
21
|
+
def initialize(request)
|
18
22
|
@request = request
|
19
23
|
end
|
20
24
|
|
21
25
|
# Determine if this is an Unpoly request.
|
26
|
+
# @return [Boolean]
|
22
27
|
def unpoly?
|
23
28
|
target.to_s.strip != ""
|
24
29
|
end
|
25
|
-
|
30
|
+
alias_method :up?, :unpoly?
|
26
31
|
|
27
32
|
# Identify if the +tested_target+ will match the actual target requested.
|
33
|
+
#
|
34
|
+
# @param tested_target [String]
|
35
|
+
# @return [Boolean]
|
28
36
|
def target?(tested_target)
|
29
37
|
query_target(target, tested_target)
|
30
38
|
end
|
31
39
|
|
32
40
|
# The actual target as requested by Unpoly.
|
41
|
+
#
|
42
|
+
# @return [String, nil]
|
33
43
|
def target
|
34
44
|
get_header("HTTP_X_UP_TARGET")
|
35
45
|
end
|
36
46
|
|
37
47
|
# The CSS selector for the fragment Unpoly will update if the request fails.
|
38
48
|
# Requires Unpoly >= 0.50
|
49
|
+
#
|
50
|
+
# @return [String, nil]
|
39
51
|
def fail_target
|
40
52
|
get_header("HTTP_X_UP_FAIL_TARGET")
|
41
53
|
end
|
42
54
|
|
43
|
-
# Determine if the
|
55
|
+
# Determine if the +tested_target+ is the current target for a failed request.
|
44
56
|
# Requires Unpoly >= 0.50
|
57
|
+
#
|
58
|
+
# @return [Boolean]
|
45
59
|
def fail_target?(tested_target)
|
46
60
|
query_target(fail_target, tested_target)
|
47
61
|
end
|
48
62
|
|
49
|
-
# Determine if the
|
63
|
+
# Determine if the +tested_target+ is the current target for a successful or failed request.
|
64
|
+
#
|
65
|
+
# @return [Boolean]
|
50
66
|
def any_target?(tested_target)
|
51
67
|
target?(tested_target) || fail_target?(tested_target)
|
52
68
|
end
|
53
69
|
|
54
70
|
# Set the page title.
|
71
|
+
#
|
72
|
+
# @param response [Rack::Response]
|
73
|
+
# @param new_title [String]
|
74
|
+
# the title to set
|
55
75
|
def set_title(response, new_title)
|
56
76
|
response.headers["X-Up-Title"] = new_title
|
57
77
|
end
|
58
78
|
|
59
79
|
# Determine if this is a validate request.
|
80
|
+
#
|
81
|
+
# @return [Boolean]
|
60
82
|
def validate?
|
61
83
|
validate_name.to_s.strip != ""
|
62
84
|
end
|
63
85
|
|
64
86
|
# The name attribute of the form field that triggered
|
65
87
|
# the validation.
|
88
|
+
#
|
89
|
+
# @return [String, nil]
|
66
90
|
def validate_name
|
67
91
|
get_header("HTTP_X_UP_VALIDATE")
|
68
92
|
end
|
69
93
|
|
70
|
-
|
94
|
+
# @api private
|
95
|
+
# @param actual_target [String]
|
96
|
+
# @param tested_target [String]
|
97
|
+
def query_target(actual_target, tested_target)
|
71
98
|
if up?
|
72
99
|
if actual_target == tested_target
|
73
100
|
true
|
74
101
|
elsif actual_target == "html"
|
75
102
|
true
|
76
103
|
elsif actual_target == "body"
|
77
|
-
!%w
|
104
|
+
!%w[head title meta].include?(tested_target)
|
78
105
|
else
|
79
106
|
false
|
80
107
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
|
+
|
2
3
|
require_relative "inspector"
|
3
4
|
|
4
|
-
module Rack
|
5
|
+
module Rack
|
5
6
|
module Unpoly
|
6
7
|
# Rack Middleware that implements the server protocol expected by Unpoly,
|
7
8
|
# and provides an entry point into the Rack::Unpoly::Inspector for the current
|
@@ -23,11 +24,13 @@ module Rack # :nodoc:
|
|
23
24
|
#
|
24
25
|
# run ->(env) { [200, {}, ["Hello World"]] }
|
25
26
|
class Middleware
|
26
|
-
|
27
|
+
# @api private
|
28
|
+
def initialize(app)
|
27
29
|
@app = app
|
28
30
|
end
|
29
31
|
|
30
|
-
|
32
|
+
# @api private
|
33
|
+
def call(env)
|
31
34
|
request = Rack::Request.new(env)
|
32
35
|
env["rack.unpoly"] = Inspector.new(request)
|
33
36
|
|
@@ -41,15 +44,16 @@ module Rack # :nodoc:
|
|
41
44
|
|
42
45
|
# Implement the *Unpoly* server protocol.
|
43
46
|
# Used internally by the middleware. Not required for normal use.
|
47
|
+
# @api private
|
44
48
|
def setup_protocol(request, headers)
|
45
|
-
headers["X-Up-Location"] = request.url
|
46
49
|
headers["X-Up-Method"] = request.request_method
|
47
50
|
|
48
51
|
if !request.get? && !request.env["rack.unpoly"].unpoly?
|
49
|
-
Rack::Utils.set_cookie_header!(
|
50
|
-
|
52
|
+
Rack::Utils.set_cookie_header!(
|
53
|
+
headers, "_up_method", {value: request.request_method, path: "/"}
|
54
|
+
)
|
51
55
|
else
|
52
|
-
Rack::Utils.delete_cookie_header!(headers, "_up_method", {
|
56
|
+
Rack::Utils.delete_cookie_header!(headers, "_up_method", {path: "/"})
|
53
57
|
end
|
54
58
|
end
|
55
59
|
end
|
data/lib/rack/unpoly.rb
CHANGED
data/lib/sinatra/unpoly.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
|
+
|
2
3
|
require "rack/unpoly/middleware"
|
3
4
|
require "delegate"
|
4
5
|
|
5
|
-
module Sinatra
|
6
|
+
module Sinatra
|
6
7
|
# The Unpoly extension for Sinatra provides a little bit of sugar to make
|
7
8
|
# Unpoly work seamlessly with Roda.
|
8
9
|
#
|
@@ -26,34 +27,43 @@ module Sinatra # :nodoc:
|
|
26
27
|
#
|
27
28
|
module Unpoly
|
28
29
|
class SinatraInspector < DelegateClass(Rack::Unpoly::Inspector)
|
29
|
-
|
30
|
-
|
31
|
-
def initialize(obj, response) # :nodoc:
|
30
|
+
# @api private
|
31
|
+
def initialize(obj, response)
|
32
32
|
super(obj)
|
33
33
|
@response = response
|
34
34
|
end
|
35
35
|
|
36
36
|
# Set the page title.
|
37
|
+
# @param value [String]
|
37
38
|
def title=(value)
|
38
39
|
set_title(response, value)
|
39
40
|
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# @api private
|
45
|
+
attr_reader :response
|
40
46
|
end
|
41
47
|
|
42
48
|
module Helpers
|
43
|
-
# The
|
49
|
+
# The inspector for this request.
|
50
|
+
# @see Rack::Unpoly::Inspector
|
51
|
+
# @return [Rack::Unpoly::Inspector]
|
44
52
|
def unpoly
|
45
53
|
SinatraInspector.new(env["rack.unpoly"], response)
|
46
54
|
end
|
47
|
-
|
55
|
+
alias_method :up, :unpoly
|
48
56
|
|
49
57
|
# Determine if this is an Unpoly request.
|
58
|
+
# @return [Boolean]
|
50
59
|
def unpoly?
|
51
60
|
unpoly.unpoly?
|
52
61
|
end
|
53
|
-
|
62
|
+
alias_method :up?, :unpoly?
|
54
63
|
end
|
55
64
|
|
56
|
-
|
65
|
+
# @api private
|
66
|
+
def self.registered(app)
|
57
67
|
app.use Rack::Unpoly::Middleware
|
58
68
|
app.helpers Unpoly::Helpers
|
59
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-unpoly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Daniels
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '13.0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '13.0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rubygems-tasks
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,17 +90,31 @@ dependencies:
|
|
90
90
|
name: sinatra
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - "
|
93
|
+
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
95
|
+
version: '3.0'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- - "
|
100
|
+
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
103
|
-
|
102
|
+
version: '3.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: standard
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.26'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.26'
|
117
|
+
description:
|
104
118
|
email: adam@mediadrive.ca
|
105
119
|
executables: []
|
106
120
|
extensions: []
|
@@ -111,12 +125,13 @@ files:
|
|
111
125
|
- lib/rack/unpoly.rb
|
112
126
|
- lib/rack/unpoly/inspector.rb
|
113
127
|
- lib/rack/unpoly/middleware.rb
|
128
|
+
- lib/rack/unpoly/version.rb
|
114
129
|
- lib/sinatra/unpoly.rb
|
115
130
|
homepage: https://github.com/adam12/rack-unpoly
|
116
131
|
licenses:
|
117
132
|
- MIT
|
118
133
|
metadata: {}
|
119
|
-
post_install_message:
|
134
|
+
post_install_message:
|
120
135
|
rdoc_options: []
|
121
136
|
require_paths:
|
122
137
|
- lib
|
@@ -131,9 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
146
|
- !ruby/object:Gem::Version
|
132
147
|
version: '0'
|
133
148
|
requirements: []
|
134
|
-
|
135
|
-
|
136
|
-
signing_key:
|
149
|
+
rubygems_version: 3.4.8
|
150
|
+
signing_key:
|
137
151
|
specification_version: 4
|
138
152
|
summary: Integrate Unpoly with any Rack or Sinatra application
|
139
153
|
test_files: []
|