roda-unpoly 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -6
  3. data/lib/roda/plugins/unpoly.rb +23 -65
  4. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5df7078e07d240b65ffbb5381e68546a884ee6b
4
- data.tar.gz: bed8ccfde1acb5f461898117d2844e0d652d93f0
3
+ metadata.gz: a6aa4aa5d22dd462b8af5b7141c607554853ea0b
4
+ data.tar.gz: eb7a5ec8bd812bf877cd6b77bcf099a1cd55dfdc
5
5
  SHA512:
6
- metadata.gz: af2aca067de6df3eb85e80c066b99a645dadfa85af173e1197957c8223f55eeeab57fcd26300d6c02068bb86769834311c0ce808b272a9a9f802cfe53470ad31
7
- data.tar.gz: e5bfadde3b72ade0784dad68b54f2fa56dcd7292510cc3467513c6b6e0439e39104cb3fb7c3a8f328a8ed00dc602f3f0c80c8c7ad0360bf4dee85ebb11992e1a
6
+ metadata.gz: 1bf9e69fbbb78e3255af81e9cc2bc442b412c79d617e3cf4f26e29f3734eb52788f0a356a1e867f6e248eaf2ee29d1f901b49d05620b7ebda55e68f96d74cf7e
7
+ data.tar.gz: 8bb5ccebfe90e8a48800164fc6b9f9ea2ee36e8220df4cb3331e97840bd683a57a5d2369c38faa69a8b0dfc348ec317b0c6df5f57e6a2568d3d9ebf7c1ee7261
data/README.md CHANGED
@@ -20,18 +20,14 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- In order for roda-unpoly to satisfy the server protocol expected by Unpoly, the
24
- `r.unpoly` method will need to be called once during your routing tree. Preferably
25
- near the top.
23
+ Simply enable the plugin through the `plugin` mechanism.
26
24
 
27
25
  ```ruby
28
26
  class App < Roda
29
27
  plugin :unpoly
30
28
 
31
29
  route do |r|
32
- r.unpoly
33
-
34
- # Rest of routing tree
30
+ # Routing tree
35
31
  end
36
32
  end
37
33
  ```
@@ -1,67 +1,35 @@
1
1
  # frozen-string-literal: true
2
-
3
2
  require "forwardable"
3
+ require "rack/unpoly/middleware"
4
4
 
5
5
  class Roda
6
6
  module RodaPlugins
7
7
  # The unpoly plugin provides the necessary sugar to make Unpoly work seamlessly
8
8
  # with Roda.
9
9
  #
10
+ # = Example
11
+ #
10
12
  # plugin :unpoly
13
+ #
14
+ # route do |r|
15
+ # if r.up?
16
+ # "Unpoly request! :)"
17
+ # else
18
+ # "Not an Unpoly request :("
19
+ # end
20
+ # end
11
21
  module Unpoly
12
- class Inspector
13
- extend Forwardable
14
-
15
- def_delegators :@context, :get_header, :response
22
+ class RodaInspector < DelegateClass(Rack::Unpoly::Inspector)
23
+ attr_accessor :response # :nodoc:
16
24
 
17
- def initialize(context) # :nodoc:
18
- @context = context
19
- end
20
-
21
- # Determine if this is an Unpoly request.
22
- def unpoly?
23
- target.to_s.strip != ""
24
- end
25
- alias up? unpoly?
26
-
27
- # Identify if the +tested_target+ will match the actual target requested.
28
- def target?(tested_target)
29
- if up?
30
- actual_target = target
31
-
32
- if actual_target == tested_target
33
- true
34
- elsif actual_target == "html"
35
- true
36
- elsif actual_target == "body"
37
- !%w(head title meta).include?(tested_target)
38
- else
39
- false
40
- end
41
- else
42
- true
43
- end
44
- end
45
-
46
- # The actual target as requested by Unpoly.
47
- def target
48
- get_header("HTTP_X_UP_TARGET")
25
+ def initialize(obj, response) # :nodoc:
26
+ super(obj)
27
+ @response = response
49
28
  end
50
29
 
51
30
  # Set the page title.
52
- def title=(new_title)
53
- response.headers["X-Up-Title"] = new_title
54
- end
55
-
56
- # Determine if this is a validate request.
57
- def validate?
58
- validate_name.to_s.strip != ""
59
- end
60
-
61
- # The name attribute of the form field that triggered
62
- # the validation.
63
- def validate_name
64
- get_header("HTTP_X_UP_VALIDATE")
31
+ def title=(value)
32
+ set_title(response, value)
65
33
  end
66
34
  end
67
35
 
@@ -70,25 +38,15 @@ class Roda
70
38
 
71
39
  def_delegators :up, :unpoly?, :up?
72
40
 
73
- # Send the appropriate headers and cookies back to the client in order
74
- # to satisfy the contract of the Unpoly library. Called early in your
75
- # routing tree.
76
- def unpoly
77
- response.headers["X-Up-Location"] = url
78
- response.headers["X-Up-Method"] = request_method
79
-
80
- if !get? && !unpoly?
81
- Rack::Utils.set_cookie_header!(response.headers, "_up_method", { value: request_method, path: "/" })
82
- else
83
- Rack::Utils.delete_cookie_header!(response.headers, "_up_method", { path: "/" })
84
- end
85
- end
86
-
87
41
  # An instance of the +Inspector+.
88
42
  def up
89
- Inspector.new(self)
43
+ RodaInspector.new(env["rack.unpoly"], response)
90
44
  end
91
45
  end
46
+
47
+ def self.configure(app, _opts={}) # :nodoc:
48
+ app.use Rack::Unpoly::Middleware
49
+ end
92
50
  end
93
51
 
94
52
  register_plugin :unpoly, Unpoly
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-unpoly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Daniels
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-02 00:00:00.000000000 Z
11
+ date: 2018-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack-unpoly
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: roda
15
29
  requirement: !ruby/object:Gem::Requirement