rack-unpoly 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: '098a6137f012df7a85d6e681805d1051c39cd929'
4
- data.tar.gz: 0d89558009d7382033b662c29b7db77888116d01
2
+ SHA256:
3
+ metadata.gz: b1d00fdd137f06a92af615b824a865a04a2537727b20b08ab297668c2470897f
4
+ data.tar.gz: 2858a34eea2cfdf57f3bd222fe060727555bc64afde20b8a0e4c738911f4e1dd
5
5
  SHA512:
6
- metadata.gz: 74e384be3125a6c1261d82af9e14f600a4f7622d3a2e36d960f3b27a82b326c342abe87c3c183d78acc522245632a29517c3ef2e062ccab67b1ad9a274796deb
7
- data.tar.gz: 66aad412ab1a9cef65fdfb356df68f851efb3a1477433ce65945fd5e2caa80a51f24bac5adb01fd675e90f1b4a4666981d3447d0f4c6f1081cbf11257bf6ca02
6
+ metadata.gz: 2aa9bb0072d7b35c8b457a4416c9e270ed55ee84ee88f04562f6d7746cec2ef681935ad61f63a6b7cfbdfd1a3ae12c3acaf369462d4675ed7210a1e4233d2a28
7
+ data.tar.gz: 5fe455a5a6db850ecf4bb8d2d00b48f2b16d115020f17b5991e87d9b37f46cc42dc9b6b6b828a33416c242c7dae47f3658402cb6c8032f2fe82a287ba30e9339
data/README.md CHANGED
@@ -51,7 +51,15 @@ require "rack/unpoly/middleware"
51
51
 
52
52
  use Rack::Unpoly::Middleware
53
53
 
54
- run ->(env) { [200, {}, ["Hello World"]] }
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 "rake/testtask"
1
+ require "minitest/test_task"
2
2
  require "rdoc/task"
3
3
  require "rubygems/tasks"
4
+ require "standard/rake"
4
5
 
5
- Rake::TestTask.new do |t|
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 # :nodoc:
5
- module Unpoly # :nodoc:
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
- def_delegators :request, :get_header # :nodoc:
14
+ # @api private
15
+ def_delegators :request, :get_header
14
16
 
15
- attr_reader :request # :nodoc:
17
+ attr_reader :request
18
+ private :request
16
19
 
17
- def initialize(request) # :nodoc:
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
- alias up? unpoly?
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 provided target is the current target for a failed request.
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 provided target is the current target for a successful or failed request.
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
- def query_target(actual_target, tested_target) # :nodoc:
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(head title meta).include?(tested_target)
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 # :nodoc:
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
- def initialize(app) # :nodoc:
27
+ # @api private
28
+ def initialize(app)
27
29
  @app = app
28
30
  end
29
31
 
30
- def call(env) # :nodoc:
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
- headers["X-Up-Method"] = request.request_method
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!(headers, "_up_method",
50
- { value: request.request_method, path: "/" })
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", { path: "/" })
56
+ Rack::Utils.delete_cookie_header!(headers, "_up_method", {path: "/"})
53
57
  end
54
58
  end
55
59
  end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module Unpoly
3
+ VERSION = "0.5.0"
4
+ end
5
+ end
data/lib/rack/unpoly.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  # frozen-string-literal: true
2
+
3
+ require_relative "unpoly/version"
2
4
  require_relative "unpoly/middleware"
3
5
  require_relative "unpoly/inspector"
4
6
 
5
- module Rack # :nodoc:
6
- module Unpoly # :nodoc:
7
+ module Rack
8
+ module Unpoly
7
9
  end
8
10
  end
@@ -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 # :nodoc:
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
- attr_accessor :response # :nodoc:
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 ::Rack::Unpoly inspector for this request.
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
- alias up unpoly
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
- alias up? unpoly?
62
+ alias_method :up?, :unpoly?
54
63
  end
55
64
 
56
- def self.registered(app) # :nodoc:
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.0
4
+ version: 0.5.0
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: 2018-01-19 00:00:00.000000000 Z
11
+ date: 2024-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '2.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '3.0'
22
+ version: '4.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '2.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '3.0'
32
+ version: '4.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: minitest
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '10.0'
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: '10.0'
60
+ version: '13.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rubygems-tasks
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -92,15 +92,29 @@ dependencies:
92
92
  requirements:
93
93
  - - ">="
94
94
  - !ruby/object:Gem::Version
95
- version: '2.0'
95
+ version: '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: '2.0'
103
- description:
102
+ version: '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
- rubyforge_project:
135
- rubygems_version: 2.6.13
136
- signing_key:
149
+ rubygems_version: 3.5.5
150
+ signing_key:
137
151
  specification_version: 4
138
152
  summary: Integrate Unpoly with any Rack or Sinatra application
139
153
  test_files: []