roda-unpoly 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -2
  3. data/Rakefile +15 -0
  4. data/lib/roda/plugins/unpoly.rb +67 -1
  5. metadata +44 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 750f490bc31f40dedde2a2494094561c8b865d07
4
- data.tar.gz: 6fcaf19eaa0dd9aaf62e2a39e982cdbfaea8b3fb
3
+ metadata.gz: 2851514cb992b5c57576513afac1309557eb6127
4
+ data.tar.gz: 7c25677023ad826e5d3ee7263d162429c10c211d
5
5
  SHA512:
6
- metadata.gz: 3bca31e586e66f5351528d0c11289e72e474ec0204f97b56a3103759c71376338682e691eaa50508ade5ae8b31932918ebec7ac3d206041e09a4e9d4554ee4a4
7
- data.tar.gz: 2702023eba6cd543c20ddb40532e282a6fd8675228f1563d9c87ce22938aa052555a46b184a8c4caec234a8afdb4c499a1ccc8e18b30757a7f03d66d1ff7f477
6
+ metadata.gz: 7a07c1bfba4d348e9126cc5e4e967ce3209af6ba685d1b0a99e0e7737085f7224d7db6163495271245f9ff8bcf7b3663d4e2215ae19b306f693f63cf17e58ecc
7
+ data.tar.gz: 294899218a907c5f7d7c422302917d13da65162fd1442eebdbf3126b384e6b6b4fa1f9e56a72c5375d4dd91b6721435d0e348ecd5e780a09f3b9ab6d990133b1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Unpoly for Roda
2
2
 
3
- Easily add support for the server protocol expected by Unpoly.
3
+ Easily add support for the server protocol expected by [Unpoly](http://unpoly.com).
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,7 +20,41 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Fill me in
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.
26
+
27
+ ```ruby
28
+ class App < Roda
29
+ plugin :unpoly
30
+
31
+ route do |r|
32
+ r.unpoly
33
+
34
+ # Rest of routing tree
35
+ end
36
+ end
37
+ ```
38
+
39
+ Inside the routing tree, some convenience methods are made available to work with
40
+ the Unpoly request.
41
+
42
+ ### Testing for Unpoly request
43
+
44
+ Use the methods `r.up?`, `r.unpoly?`, `r.up.up?`, or `r.up.unpoly?` (they are
45
+ all aliases of the same method).
46
+
47
+ ### Testing the Unpoly target
48
+
49
+ Use the method `r.up.target?(your_target)`.
50
+
51
+ ### Testing for Unpoly validate request
52
+
53
+ Use the method `r.up.validate?`.
54
+
55
+ ### Setting page title
56
+
57
+ Use the method `r.up.title=`.
24
58
 
25
59
  ## Where are the Javascript and CSS assets?
26
60
 
data/Rakefile CHANGED
@@ -1,3 +1,18 @@
1
+ require "rake/testtask"
2
+ require "rdoc/task"
1
3
  require "rubygems/tasks"
2
4
 
5
+ RDoc::Task.new do |rdoc|
6
+ rdoc.main = "README.md"
7
+ rdoc.rdoc_files.include("README.md", "lib/**/*.rb")
8
+ end
9
+
10
+ Rake::TestTask.new do |t|
11
+ t.libs << "test"
12
+ t.test_files = FileList["test/test*.rb"]
13
+ t.verbose = true
14
+ end
15
+
3
16
  Gem::Tasks.new
17
+
18
+ task default: :test
@@ -1,11 +1,72 @@
1
+ # frozen-string-literal: true
2
+
3
+ require "forwardable"
4
+
1
5
  class Roda
2
6
  module RodaPlugins
7
+ # The unpoly plugin provides the necessary sugar to make Unpoly work seamlessly
8
+ # with Roda.
9
+ #
10
+ # plugin :unpoly
3
11
  module Unpoly
4
- module RequestMethods
12
+ class Inspector
13
+ extend Forwardable
14
+
15
+ def_delegators :@context, :get_header, :response
16
+
17
+ def initialize(context) # :nodoc:
18
+ @context = context
19
+ end
20
+
21
+ # Determine if this is an Unpoly request.
5
22
  def unpoly?
6
23
  get_header("X-Up-Target").to_s.strip != ""
7
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
8
45
 
46
+ # The actual target as requested by Unpoly.
47
+ def target
48
+ get_header("X-Up-Target")
49
+ end
50
+
51
+ # 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
+ get_header("X-Up-Validate").to_s.strip != ""
59
+ end
60
+ end
61
+
62
+ module RequestMethods
63
+ extend Forwardable
64
+
65
+ def_delegators :up, :unpoly?, :up?
66
+
67
+ # Send the appropriate headers and cookies back to the client in order
68
+ # to satisfy the contract of the Unpoly library. Called early in your
69
+ # routing tree.
9
70
  def unpoly
10
71
  response.headers["X-Up-Location"] = path
11
72
  response.headers["X-Up-Method"] = request_method
@@ -16,6 +77,11 @@ class Roda
16
77
  Rack::Utils.delete_cookie_header!(response.headers, "_up_method")
17
78
  end
18
79
  end
80
+
81
+ # An instance of the +Inspector+.
82
+ def up
83
+ Inspector.new(self)
84
+ end
19
85
  end
20
86
  end
21
87
 
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-unpoly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-03-05 00:00:00.000000000 Z
11
+ date: 2017-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: roda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: rake
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +66,20 @@ dependencies:
38
66
  - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
41
83
  description:
42
84
  email: adam@mediadrive.ca
43
85
  executables: []