impression 0.9 → 0.10
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 +6 -0
- data/Gemfile.lock +10 -10
- data/impression.gemspec +3 -3
- data/lib/impression/file_tree.rb +11 -5
- data/lib/impression/jamstack.rb +117 -12
- data/lib/impression/request_extensions/routing.rb +11 -1
- data/lib/impression/resource.rb +28 -2
- data/lib/impression/version.rb +1 -1
- data/lib/impression.rb +31 -0
- data/test/helper.rb +4 -0
- data/test/jamstack/resources/greeter.rb +9 -0
- data/test/jamstack/resources/recurse.rb +9 -0
- data/test/test_impression.rb +32 -0
- data/test/test_jamstack.rb +40 -6
- data/test/test_resource.rb +11 -0
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 718a8a8eba181a00e5519e970d34bfc2e666ea15bacf0e72bffba450f3c9788d
|
4
|
+
data.tar.gz: fd665341a6fdcf66af4c564a269022f5fce014243a8736cf228188f9b3ca3e1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32ce3395a8f74e463b935e48711ae2b3fccd756b1bd3ec11912539ed2d969e0691dc044933548c5321a89749ad4faf3ddfc546958a83716d339b6fbeea0739b8
|
7
|
+
data.tar.gz: c33b519b8fd5a2a5da76e0d1a4a78854a0178dee62d90b143bf7cd8358150e69127af9d42832cb6158b41835cf6fa08cb6fc3efc09d0caa437e03b1e43722cde
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
impression (0.
|
4
|
+
impression (0.10)
|
5
5
|
modulation (~> 1.1)
|
6
6
|
papercraft (~> 0.19)
|
7
|
-
polyphony (~> 0.
|
8
|
-
qeweney (~> 0.
|
9
|
-
tipi (~> 0.
|
7
|
+
polyphony (~> 0.77)
|
8
|
+
qeweney (~> 0.17)
|
9
|
+
tipi (~> 0.49)
|
10
10
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
@@ -57,8 +57,8 @@ GEM
|
|
57
57
|
kramdown (~> 2.3.1)
|
58
58
|
kramdown-parser-gfm (~> 1.1.0)
|
59
59
|
rouge (~> 3.27.0)
|
60
|
-
polyphony (0.
|
61
|
-
qeweney (0.
|
60
|
+
polyphony (0.77)
|
61
|
+
qeweney (0.17)
|
62
62
|
escape_utils (~> 1.2.1)
|
63
63
|
rack (2.2.3)
|
64
64
|
rake (12.3.3)
|
@@ -70,16 +70,16 @@ GEM
|
|
70
70
|
json (>= 1.8, < 3)
|
71
71
|
simplecov-html (~> 0.10.0)
|
72
72
|
simplecov-html (0.10.2)
|
73
|
-
tipi (0.
|
74
|
-
acme-client (~> 2.0.
|
73
|
+
tipi (0.49)
|
74
|
+
acme-client (~> 2.0.9)
|
75
75
|
ever (~> 0.1)
|
76
76
|
extralite (~> 1.2)
|
77
77
|
h1p (~> 0.3)
|
78
78
|
http-2 (~> 0.11)
|
79
79
|
localhost (~> 1.1.4)
|
80
80
|
msgpack (~> 1.4.2)
|
81
|
-
polyphony (~> 0.
|
82
|
-
qeweney (~> 0.
|
81
|
+
polyphony (~> 0.77)
|
82
|
+
qeweney (~> 0.16)
|
83
83
|
rack (>= 2.0.8, < 2.3.0)
|
84
84
|
websocket (~> 1.2.8)
|
85
85
|
websocket (1.2.9)
|
data/impression.gemspec
CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
s.required_ruby_version = '>= 2.6'
|
22
22
|
|
23
|
-
s.add_runtime_dependency 'polyphony', '~>0.
|
24
|
-
s.add_runtime_dependency 'tipi', '~>0.
|
25
|
-
s.add_runtime_dependency 'qeweney', '~>0.
|
23
|
+
s.add_runtime_dependency 'polyphony', '~>0.77'
|
24
|
+
s.add_runtime_dependency 'tipi', '~>0.49'
|
25
|
+
s.add_runtime_dependency 'qeweney', '~>0.17'
|
26
26
|
|
27
27
|
s.add_runtime_dependency 'papercraft', '~>0.19'
|
28
28
|
s.add_runtime_dependency 'modulation', '~>1.1'
|
data/lib/impression/file_tree.rb
CHANGED
@@ -8,6 +8,8 @@ module Impression
|
|
8
8
|
# `FileTree` implements a resource that maps to a static file hierarchy.
|
9
9
|
class FileTree < Resource
|
10
10
|
|
11
|
+
attr_reader :directory
|
12
|
+
|
11
13
|
# Initializes a `FileTree` resource.
|
12
14
|
#
|
13
15
|
# @param directory [String] static directory path
|
@@ -27,11 +29,11 @@ module Impression
|
|
27
29
|
render_from_path_info(req, path_info)
|
28
30
|
end
|
29
31
|
|
30
|
-
# Renders a response from the given
|
32
|
+
# Renders a response from the given path info.
|
31
33
|
#
|
32
34
|
# @param req [Qeweney::Request] request
|
33
|
-
# @param
|
34
|
-
# @
|
35
|
+
# @param path_info [Hash] path info
|
36
|
+
# @return [void]
|
35
37
|
def render_from_path_info(req, path_info)
|
36
38
|
case path_info[:kind]
|
37
39
|
when :not_found
|
@@ -39,7 +41,7 @@ module Impression
|
|
39
41
|
when :file
|
40
42
|
render_file(req, path_info)
|
41
43
|
else
|
42
|
-
raise "Invalid path info kind #{kind.inspect}"
|
44
|
+
raise "Invalid path info kind #{path_info[:kind].inspect}"
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
@@ -73,7 +75,11 @@ module Impression
|
|
73
75
|
def calculate_path_info(path)
|
74
76
|
full_path = File.join(@directory, path)
|
75
77
|
|
76
|
-
|
78
|
+
(
|
79
|
+
path_info(full_path) ||
|
80
|
+
search_path_info_with_extension(full_path) ||
|
81
|
+
{ kind: :not_found }
|
82
|
+
)
|
77
83
|
end
|
78
84
|
|
79
85
|
# Returns the path info for the given path. If the path refers to a file,
|
data/lib/impression/jamstack.rb
CHANGED
@@ -57,8 +57,10 @@ module Impression
|
|
57
57
|
atts, content = parse_markdown_file(path)
|
58
58
|
info = info.merge(atts)
|
59
59
|
info[:html_content] = Papercraft.markdown(content)
|
60
|
+
info[:kind] = :markdown
|
60
61
|
when '.rb'
|
61
62
|
info[:module] = import(path)
|
63
|
+
info[:kind] = :module
|
62
64
|
end
|
63
65
|
if (m = path.match(DATE_REGEXP))
|
64
66
|
info[:date] ||= Date.parse(m[1])
|
@@ -82,29 +84,132 @@ module Impression
|
|
82
84
|
relative_path == '/' ? absolute_path : File.join(absolute_path, relative_path)
|
83
85
|
end
|
84
86
|
|
85
|
-
# Renders a
|
86
|
-
#
|
87
|
+
# Renders a response according to the given path info.
|
88
|
+
#
|
87
89
|
# @param req [Qeweney::Request] request
|
88
90
|
# @param path_info [Hash] path info
|
89
91
|
# @return [void]
|
90
|
-
def
|
91
|
-
case path_info[:
|
92
|
-
when
|
93
|
-
|
94
|
-
|
92
|
+
def render_from_path_info(req, path_info)
|
93
|
+
case (kind = path_info[:kind])
|
94
|
+
when :not_found
|
95
|
+
mod_path_info = up_tree_resource_module_path_info(req, path_info)
|
96
|
+
if mod_path_info
|
97
|
+
render_module(req, mod_path_info)
|
98
|
+
else
|
99
|
+
req.respond(nil, ':status' => Qeweney::Status::NOT_FOUND)
|
100
|
+
end
|
101
|
+
when :module
|
102
|
+
render_module(req, path_info)
|
103
|
+
when :markdown
|
95
104
|
render_markdown_file(req, path_info)
|
105
|
+
when :file
|
106
|
+
render_file(req, path_info)
|
96
107
|
else
|
97
|
-
|
108
|
+
raise "Invalid path info kind #{kind.inspect}"
|
98
109
|
end
|
99
110
|
end
|
100
111
|
|
101
|
-
#
|
112
|
+
# Returns the path info for an up-tree resource module, or false if not
|
113
|
+
# found. the :up_tree_resource_module_path_info KV can be either:
|
114
|
+
# - nil (default): up tree module search has not been performed.
|
115
|
+
# - false: no up tree module was found.
|
116
|
+
# - module path info: up tree module info (subsequent requests will be
|
117
|
+
# directly routed to the module).
|
102
118
|
#
|
103
|
-
# @param req [Qeweney::Request]
|
119
|
+
# @param req [Qeweney::Request] request
|
120
|
+
# @param path_info [Hash] path info
|
121
|
+
# @return [Hash, false] up-tree resource module path info
|
122
|
+
def up_tree_resource_module_path_info(req, path_info)
|
123
|
+
if path_info[:up_tree_resource_module_path_info].nil?
|
124
|
+
if (mod_path_info = find_up_tree_resource_module(req, path_info))
|
125
|
+
path_info[:up_tree_resource_module_path_info] = mod_path_info
|
126
|
+
return mod_path_info;
|
127
|
+
else
|
128
|
+
path_info[:up_tree_resource_module_path_info] = false
|
129
|
+
return false
|
130
|
+
end
|
131
|
+
end
|
132
|
+
path_info[:up_tree_resource_module_path_info]
|
133
|
+
end
|
134
|
+
|
135
|
+
# Performs a recursive search for an up-tree resource module from the given
|
136
|
+
# path info. If a resource module is found up the tree, its path_info is
|
137
|
+
# returned, otherwise returns nil.
|
138
|
+
#
|
139
|
+
# @param req [Qeweney::Request] request
|
140
|
+
# @param path_info [Hash] path info
|
141
|
+
# @return [Hash, nil] up-tree resource module path info
|
142
|
+
def find_up_tree_resource_module(req, path_info)
|
143
|
+
relative_path = req.resource_relative_path
|
144
|
+
|
145
|
+
while relative_path != path
|
146
|
+
up_tree_path = File.expand_path('..', relative_path)
|
147
|
+
up_tree_path_info = get_path_info(up_tree_path)
|
148
|
+
|
149
|
+
case up_tree_path_info[:kind]
|
150
|
+
when :not_found
|
151
|
+
relative_path = up_tree_path
|
152
|
+
next
|
153
|
+
when :module
|
154
|
+
return up_tree_path_info
|
155
|
+
else
|
156
|
+
return nil
|
157
|
+
end
|
158
|
+
end
|
159
|
+
nil
|
160
|
+
end
|
161
|
+
|
162
|
+
# Renders a file response for the given request and the given path info,
|
163
|
+
# according to the file type.
|
164
|
+
#
|
165
|
+
# @param req [Qeweney::Request] request
|
166
|
+
# @param path_info [Hash] path info
|
167
|
+
# @return [void]
|
168
|
+
# def render_file(req, path_info)
|
169
|
+
# case path_info[:kind]
|
170
|
+
# else
|
171
|
+
# req.serve_file(path_info[:path])
|
172
|
+
# end
|
173
|
+
# end
|
174
|
+
|
175
|
+
# Renders a module. If the module is a Resource, it is mounted, and then the
|
176
|
+
# request is rerouted from the new resource and rendered. If the module is a
|
177
|
+
# Proc or a Papercraft::Template, it is rendered as such. Otherwise, an
|
178
|
+
# error is raised.
|
179
|
+
#
|
180
|
+
# @param req [Qeweney::Request] request
|
181
|
+
# @param path_info [Hash] path info
|
182
|
+
# @return [void]
|
183
|
+
def render_module(req, path_info)
|
184
|
+
# p render_module: path_info
|
185
|
+
case (mod = path_info[:module])
|
186
|
+
when Module
|
187
|
+
resource = mod.resource
|
188
|
+
resource.remount(self, path_info[:url])
|
189
|
+
# p path_info_url: path_info[:url], relative_path: req.resource_relative_path
|
190
|
+
relative_url = path_info[:url].gsub(/^#{path}/, '')
|
191
|
+
# p relative_url: relative_url
|
192
|
+
req.recalc_resource_relative_path(relative_url)
|
193
|
+
# p resource_relative_path: req.resource_relative_path
|
194
|
+
resource.route(req).call(req)
|
195
|
+
when Impression::Resource
|
196
|
+
mod.remount(self, path_info[:url])
|
197
|
+
req.recalc_resource_relative_path(path_info[:url])
|
198
|
+
mod.route(req).call(req)
|
199
|
+
when Proc, Papercraft::Template
|
200
|
+
render_papercraft_module(req, mod)
|
201
|
+
else
|
202
|
+
raise "Unsupported module type #{mod.class}"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# Renders a Papercraft module.
|
207
|
+
#
|
208
|
+
# @param mod [Module] Papercraft module
|
104
209
|
# @param path_info [Hash] path info
|
105
210
|
# @return [void]
|
106
|
-
def render_papercraft_module(req,
|
107
|
-
template = Papercraft.html(
|
211
|
+
def render_papercraft_module(req, mod)
|
212
|
+
template = Papercraft.html(mod)
|
108
213
|
body = template.render(request: req, resource: self)
|
109
214
|
req.respond(body, 'Content-Type' => template.mime_type)
|
110
215
|
end
|
@@ -31,7 +31,17 @@ module Impression
|
|
31
31
|
#
|
32
32
|
# @return [String]
|
33
33
|
def resource_relative_path
|
34
|
-
@resource_relative_path ||= path
|
34
|
+
@resource_relative_path ||= path
|
35
|
+
end
|
36
|
+
|
37
|
+
# Recalculates the relative_path from the given base path
|
38
|
+
#
|
39
|
+
# @param base_path [String] base path
|
40
|
+
# @return [String] new relative path
|
41
|
+
def recalc_resource_relative_path(base_path)
|
42
|
+
@resource_relative_path = @resource_relative_path.gsub(
|
43
|
+
/^#{base_path}/, ''
|
44
|
+
)
|
35
45
|
end
|
36
46
|
|
37
47
|
private
|
data/lib/impression/resource.rb
CHANGED
@@ -26,18 +26,35 @@ module Impression
|
|
26
26
|
# A hash mapping relative paths to child resources
|
27
27
|
attr_reader :children
|
28
28
|
|
29
|
-
# Initalizes a new resource instance.
|
29
|
+
# Initalizes a new resource instance. If a block is given, it is used as the
|
30
|
+
# request handler instead of the default one, which returns `404 NOT FOUND`.
|
30
31
|
#
|
31
32
|
# @param parent [Impression::Resource, nil] the parent resource (or nil)
|
32
33
|
# @param path [String] the resource's relative path
|
34
|
+
# @param &block [Proc] default request handler
|
33
35
|
# @return [void]
|
34
|
-
def initialize(parent: nil, path
|
36
|
+
def initialize(parent: nil, path:, &block)
|
35
37
|
@parent = parent
|
36
38
|
@path = normalize_route_path(path)
|
37
39
|
@route_regexp = @path == '/' ? nil : /^#{@path}(\/.*)?$/.freeze
|
38
40
|
@children = {}
|
39
41
|
|
40
42
|
@parent&.add_child(self)
|
43
|
+
|
44
|
+
if block
|
45
|
+
singleton_class.define_method(:call, &block)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Remounts the resource on a different parent and path.
|
50
|
+
#
|
51
|
+
# @param parent [Resource, nil] new parent
|
52
|
+
# @param path [String] new path relative to new parent
|
53
|
+
# @return [void]
|
54
|
+
def remount(parent, path)
|
55
|
+
@parent&.remove_child(self)
|
56
|
+
@parent = parent
|
57
|
+
@path = normalize_route_path(path)
|
41
58
|
end
|
42
59
|
|
43
60
|
# Returns the resource's absolute path, according to its location in the
|
@@ -67,6 +84,15 @@ module Impression
|
|
67
84
|
self
|
68
85
|
end
|
69
86
|
|
87
|
+
# Removes a child reference from the children map.
|
88
|
+
#
|
89
|
+
# @param child [Impression::Resource] child resource
|
90
|
+
# @return [Impression::Resource] self
|
91
|
+
def remove_child(child)
|
92
|
+
@children.delete(child.path)
|
93
|
+
self
|
94
|
+
end
|
95
|
+
|
70
96
|
# Responds to the given request by rendering a 404 Not found response.
|
71
97
|
#
|
72
98
|
# @param req [Qeweney::Request] request
|
data/lib/impression/version.rb
CHANGED
data/lib/impression.rb
CHANGED
@@ -9,3 +9,34 @@ require_relative './impression/resource'
|
|
9
9
|
require_relative './impression/file_tree'
|
10
10
|
require_relative './impression/jamstack'
|
11
11
|
require_relative './impression/app'
|
12
|
+
|
13
|
+
# The Impression module contains convenience methods for creating resources.
|
14
|
+
module Impression
|
15
|
+
|
16
|
+
# Creates a new `Impression::Resource` instance with the given parameters and
|
17
|
+
# block.
|
18
|
+
#
|
19
|
+
# @param path [String] resource path (defaults to `"/"`)
|
20
|
+
# @param **props [Hash] other resource properties
|
21
|
+
# @param &block [Proc] optional block for overriding default request handler
|
22
|
+
# @return [Impression::Resource] new resource
|
23
|
+
def self.resource(path: '/', **props, &block)
|
24
|
+
Resource.new(path: path, **props, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Creates a new `Impression::FileTree` instance with the given parameters.
|
28
|
+
#
|
29
|
+
# @param **props [Hash] properties
|
30
|
+
# @return [Impression::FileTree] new resource
|
31
|
+
def self.file_tree(path: '/', **props)
|
32
|
+
FileTree.new(path: path, **props)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Creates a new `Impression::Jamstack` instance with the given parameters.
|
36
|
+
#
|
37
|
+
# @param **props [Hash] properties
|
38
|
+
# @return [Impression::Jamstack] new resource
|
39
|
+
def self.jamstack(path: '/', **props)
|
40
|
+
Jamstack.new(path: path, **props)
|
41
|
+
end
|
42
|
+
end
|
data/test/helper.rb
CHANGED
@@ -41,6 +41,10 @@ module Minitest::Assertions
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def assert_response exp_body, exp_content_type, req
|
44
|
+
status = req.response_status
|
45
|
+
msg = message(msg) { "Expected HTTP status 200 OK, but instead got #{status}" }
|
46
|
+
assert_equal 200, status, msg
|
47
|
+
|
44
48
|
actual = req.response_body
|
45
49
|
assert_equal exp_body.gsub("\n", ''), actual&.gsub("\n", '')
|
46
50
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
class ImpressionModuleTest < MiniTest::Test
|
6
|
+
def test_resource_method
|
7
|
+
r1 = Impression.resource do |req|
|
8
|
+
req.respond('foobar', ':status' => Qeweney::Status::TEAPOT)
|
9
|
+
end
|
10
|
+
|
11
|
+
req = mock_req(':method' => 'GET', ':path' => '/')
|
12
|
+
r1.route_and_call(req)
|
13
|
+
assert_equal 'foobar', req.response_body
|
14
|
+
assert_equal Qeweney::Status::TEAPOT, req.response_status
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_file_tree_method
|
18
|
+
r1 = Impression.file_tree(path: '/foo', directory: '/bar')
|
19
|
+
|
20
|
+
assert_kind_of Impression::FileTree, r1
|
21
|
+
assert_equal '/foo', r1.path
|
22
|
+
assert_equal '/bar', r1.directory
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_jamstack_method
|
26
|
+
r1 = Impression.jamstack(path: '/foo', directory: '/bar')
|
27
|
+
|
28
|
+
assert_kind_of Impression::Jamstack, r1
|
29
|
+
assert_equal '/foo', r1.path
|
30
|
+
assert_equal '/bar', r1.directory
|
31
|
+
end
|
32
|
+
end
|
data/test/test_jamstack.rb
CHANGED
@@ -212,7 +212,7 @@ class JamstackTest < MiniTest::Test
|
|
212
212
|
list = @jamstack.page_list('/')
|
213
213
|
assert_equal [
|
214
214
|
{ kind: :file, path: File.join(JAMSTACK_PATH, 'bar.html'), ext: '.html', url: '/app/bar' },
|
215
|
-
{ kind: :
|
215
|
+
{ kind: :markdown, path: File.join(JAMSTACK_PATH, 'index.md'), ext: '.md', url: '/app',
|
216
216
|
title: 'Hello', foo: 'BarBar', html_content: "<h1>Index</h1>\n" },
|
217
217
|
], list
|
218
218
|
|
@@ -221,7 +221,7 @@ class JamstackTest < MiniTest::Test
|
|
221
221
|
|
222
222
|
assert_equal [
|
223
223
|
{
|
224
|
-
kind: :
|
224
|
+
kind: :markdown,
|
225
225
|
path: File.join(JAMSTACK_PATH, 'articles/2008-06-14-manu.md'),
|
226
226
|
url: '/app/articles/2008-06-14-manu',
|
227
227
|
ext: '.md',
|
@@ -236,7 +236,7 @@ class JamstackTest < MiniTest::Test
|
|
236
236
|
date: Date.new(2008, 06, 14)
|
237
237
|
},
|
238
238
|
{
|
239
|
-
kind: :
|
239
|
+
kind: :markdown,
|
240
240
|
path: File.join(JAMSTACK_PATH, 'articles/2009-06-12-noatche.md'),
|
241
241
|
url: '/app/articles/2009-06-12-noatche',
|
242
242
|
ext: '.md',
|
@@ -246,7 +246,7 @@ class JamstackTest < MiniTest::Test
|
|
246
246
|
date: Date.new(2009, 06, 12)
|
247
247
|
},
|
248
248
|
{
|
249
|
-
kind: :
|
249
|
+
kind: :markdown,
|
250
250
|
path: File.join(JAMSTACK_PATH, 'articles/a.md'),
|
251
251
|
url: '/app/articles/a',
|
252
252
|
ext: '.md',
|
@@ -283,7 +283,7 @@ class JamstackTest < MiniTest::Test
|
|
283
283
|
|
284
284
|
def test_path_info
|
285
285
|
assert_equal({
|
286
|
-
kind: :
|
286
|
+
kind: :markdown,
|
287
287
|
path: File.join(JAMSTACK_PATH, 'index.md'),
|
288
288
|
ext: '.md',
|
289
289
|
url: '/',
|
@@ -293,7 +293,7 @@ class JamstackTest < MiniTest::Test
|
|
293
293
|
}, path_info('/index'))
|
294
294
|
|
295
295
|
assert_equal({
|
296
|
-
kind: :
|
296
|
+
kind: :markdown,
|
297
297
|
path: File.join(JAMSTACK_PATH, 'index.md'),
|
298
298
|
ext: '.md',
|
299
299
|
url: '/',
|
@@ -313,4 +313,38 @@ class JamstackTest < MiniTest::Test
|
|
313
313
|
kind: :not_found,
|
314
314
|
}, path_info('/js/b.js'))
|
315
315
|
end
|
316
|
+
|
317
|
+
def test_resource_loading
|
318
|
+
req = mock_req(':method' => 'GET', ':path' => '/resources/greeter?name=world')
|
319
|
+
route = @jamstack.route(req)
|
320
|
+
assert_equal @jamstack, route
|
321
|
+
|
322
|
+
req = mock_req(':method' => 'GET', ':path' => '/resources/greeter?name=world')
|
323
|
+
@jamstack.route_and_call(req)
|
324
|
+
assert_response 'Hello, world!', :text, req
|
325
|
+
|
326
|
+
req = mock_req(':method' => 'GET', ':path' => '/resources/recurse/resources/greeter?name=foo')
|
327
|
+
@jamstack.route_and_call(req)
|
328
|
+
assert_response 'Hello, foo!', :text, req
|
329
|
+
end
|
330
|
+
|
331
|
+
def test_recursive_resource_loading_on_non_root_jamstack
|
332
|
+
jamstack = Impression::Jamstack.new(path: '/foo/bar', directory: JAMSTACK_PATH)
|
333
|
+
|
334
|
+
req = mock_req(':method' => 'GET', ':path' => '/foo/bar/resources/greeter?name=world')
|
335
|
+
route = jamstack.route(req)
|
336
|
+
assert_equal jamstack, route
|
337
|
+
|
338
|
+
req = mock_req(':method' => 'GET', ':path' => '/foo/bar/resources/greeter?name=world')
|
339
|
+
jamstack.route_and_call(req)
|
340
|
+
assert_response 'Hello, world!', :text, req
|
341
|
+
|
342
|
+
req = mock_req(':method' => 'GET', ':path' => '/foo/bar/resources/recurse/resources/greeter?name=foo')
|
343
|
+
jamstack.route_and_call(req)
|
344
|
+
assert_response 'Hello, foo!', :text, req
|
345
|
+
|
346
|
+
# req = mock_req(':method' => 'GET', ':path' => '/foo/bar/resources/recurse/bar')
|
347
|
+
# @jamstack.route_and_call(req)
|
348
|
+
# assert_response static('bar.html'), :html, req
|
349
|
+
end
|
316
350
|
end
|
data/test/test_resource.rb
CHANGED
@@ -198,4 +198,15 @@ class ResourceTest < MiniTest::Test
|
|
198
198
|
assert_equal '{"baz":123}', req.response_body
|
199
199
|
assert_equal 'application/json', req.response_content_type
|
200
200
|
end
|
201
|
+
|
202
|
+
def test_resource_with_block
|
203
|
+
r1 = Impression::Resource.new(path: '/') do |req|
|
204
|
+
req.respond('foobar', ':status' => Qeweney::Status::TEAPOT)
|
205
|
+
end
|
206
|
+
|
207
|
+
req = mock_req(':method' => 'GET', ':path' => '/')
|
208
|
+
r1.route_and_call(req)
|
209
|
+
assert_equal 'foobar', req.response_body
|
210
|
+
assert_equal Qeweney::Status::TEAPOT, req.response_status
|
211
|
+
end
|
201
212
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: impression
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.10'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: polyphony
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.77'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.77'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: tipi
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.49'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.49'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: qeweney
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.17'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.17'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: papercraft
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,6 +168,8 @@ files:
|
|
168
168
|
- test/jamstack/foo.rb
|
169
169
|
- test/jamstack/foobar.rb
|
170
170
|
- test/jamstack/index.md
|
171
|
+
- test/jamstack/resources/greeter.rb
|
172
|
+
- test/jamstack/resources/recurse.rb
|
171
173
|
- test/run.rb
|
172
174
|
- test/static/bar/index.html
|
173
175
|
- test/static/foo.html
|
@@ -176,6 +178,7 @@ files:
|
|
176
178
|
- test/test_app.rb
|
177
179
|
- test/test_file_tree.rb
|
178
180
|
- test/test_file_watcher.rb
|
181
|
+
- test/test_impression.rb
|
179
182
|
- test/test_jamstack.rb
|
180
183
|
- test/test_resource.rb
|
181
184
|
homepage: http://github.com/digital-fabric/impression
|