impression 0.10 → 0.13
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/.github/workflows/test.yml +3 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile +0 -5
- data/Gemfile.lock +18 -18
- data/README.md +78 -8
- data/impression.gemspec +4 -4
- data/lib/impression/app.rb +324 -3
- data/lib/impression/file_tree.rb +4 -2
- data/lib/impression/rack_app.rb +27 -0
- data/lib/impression/version.rb +1 -1
- data/lib/impression.rb +23 -11
- data/test/{jamstack → app}/_layouts/article.rb +0 -0
- data/test/{jamstack → app}/_layouts/default.rb +0 -0
- data/test/{jamstack → app}/articles/2008-06-14-manu.md +0 -0
- data/test/{jamstack → app}/articles/2009-06-12-noatche.md +0 -0
- data/test/{jamstack → app}/articles/a.md +0 -0
- data/test/{jamstack → app}/assets/js/a.js +0 -0
- data/test/{jamstack → app}/bar.html +0 -0
- data/test/{jamstack → app}/baz/index.md +0 -0
- data/test/{jamstack → app}/foo.rb +0 -0
- data/test/{jamstack → app}/foobar.rb +0 -0
- data/test/{jamstack → app}/index.md +0 -0
- data/test/{jamstack → app}/resources/greeter.rb +0 -0
- data/test/{jamstack → app}/resources/recurse.rb +1 -1
- data/test/test_app.rb +349 -6
- data/test/test_file_tree.rb +18 -0
- data/test/test_impression.rb +3 -3
- data/test/test_rack_app.rb +48 -0
- metadata +25 -25
- data/lib/impression/jamstack.rb +0 -276
- data/test/test_jamstack.rb +0 -350
data/lib/impression.rb
CHANGED
|
@@ -3,12 +3,10 @@
|
|
|
3
3
|
require 'polyphony'
|
|
4
4
|
|
|
5
5
|
require_relative './impression/request_extensions'
|
|
6
|
-
# require_relative './impression/file_watcher'
|
|
7
|
-
|
|
8
6
|
require_relative './impression/resource'
|
|
9
7
|
require_relative './impression/file_tree'
|
|
10
|
-
require_relative './impression/jamstack'
|
|
11
8
|
require_relative './impression/app'
|
|
9
|
+
require_relative './impression/rack_app'
|
|
12
10
|
|
|
13
11
|
# The Impression module contains convenience methods for creating resources.
|
|
14
12
|
module Impression
|
|
@@ -26,17 +24,31 @@ module Impression
|
|
|
26
24
|
|
|
27
25
|
# Creates a new `Impression::FileTree` instance with the given parameters.
|
|
28
26
|
#
|
|
29
|
-
# @param
|
|
27
|
+
# @param path [String] resource path (defaults to `"/"`)
|
|
28
|
+
# @param **props [Hash] other resource properties
|
|
29
|
+
# @param &block [Proc] optional block for overriding default request handler
|
|
30
30
|
# @return [Impression::FileTree] new resource
|
|
31
|
-
def self.file_tree(path: '/', **props)
|
|
32
|
-
FileTree.new(path: path, **props)
|
|
31
|
+
def self.file_tree(path: '/', **props, &block)
|
|
32
|
+
FileTree.new(path: path, **props, &block)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Creates a new `Impression::App` instance with the given parameters.
|
|
36
|
+
#
|
|
37
|
+
# @param path [String] resource path (defaults to `"/"`)
|
|
38
|
+
# @param **props [Hash] other resource properties
|
|
39
|
+
# @param &block [Proc] optional block for overriding default request handler
|
|
40
|
+
# @return [Impression::App] new resource
|
|
41
|
+
def self.app(path: '/', **props, &block)
|
|
42
|
+
App.new(path: path, **props, &block)
|
|
33
43
|
end
|
|
34
44
|
|
|
35
|
-
# Creates a new `Impression::
|
|
45
|
+
# Creates a new `Impression::RackApp` instance with the given parameters.
|
|
36
46
|
#
|
|
37
|
-
# @param
|
|
38
|
-
# @
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
# @param path [String] resource path (defaults to `"/"`)
|
|
48
|
+
# @param **props [Hash] other resource properties
|
|
49
|
+
# @param &block [Proc] Rack app proc (can also be passed using the `app:` parameter)
|
|
50
|
+
# @return [Impression::RackApp] new resource
|
|
51
|
+
def self.rack_app(path: '/', **props, &block)
|
|
52
|
+
RackApp.new(path: path, **props, &block)
|
|
41
53
|
end
|
|
42
54
|
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/test/test_app.rb
CHANGED
|
@@ -1,9 +1,356 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'helper'
|
|
4
|
+
require 'qeweney/test_adapter'
|
|
4
5
|
|
|
5
6
|
class AppTest < MiniTest::Test
|
|
6
|
-
|
|
7
|
+
APP_PATH = File.join(__dir__, 'app')
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
@app = Impression::App.new(path: '/', directory: APP_PATH)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_app_routing
|
|
14
|
+
req = mock_req(':method' => 'GET', ':path' => '/')
|
|
15
|
+
assert_equal @app, @app.route(req)
|
|
16
|
+
|
|
17
|
+
req = mock_req(':method' => 'GET', ':path' => '/nonexistent')
|
|
18
|
+
assert_equal @app, @app.route(req)
|
|
19
|
+
|
|
20
|
+
req = mock_req(':method' => 'GET', ':path' => '/index.html')
|
|
21
|
+
assert_equal @app, @app.route(req)
|
|
22
|
+
|
|
23
|
+
req = mock_req(':method' => 'GET', ':path' => '/foo')
|
|
24
|
+
assert_equal @app, @app.route(req)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def static(path)
|
|
28
|
+
IO.read(File.join(APP_PATH, path))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_app_response
|
|
32
|
+
req = mock_req(':method' => 'GET', ':path' => '/roo')
|
|
33
|
+
@app.route_and_call(req)
|
|
34
|
+
assert_equal Qeweney::Status::NOT_FOUND, req.response_status
|
|
35
|
+
|
|
36
|
+
req = mock_req(':method' => 'GET', ':path' => '/foo2')
|
|
37
|
+
@app.route_and_call(req)
|
|
38
|
+
assert_equal Qeweney::Status::NOT_FOUND, req.response_status
|
|
39
|
+
|
|
40
|
+
req = mock_req(':method' => 'GET', ':path' => '/bar2')
|
|
41
|
+
@app.route_and_call(req)
|
|
42
|
+
assert_equal Qeweney::Status::NOT_FOUND, req.response_status
|
|
43
|
+
|
|
44
|
+
req = mock_req(':method' => 'GET', ':path' => '/assets/js/a.js')
|
|
45
|
+
@app.route_and_call(req)
|
|
46
|
+
assert_response static('assets/js/a.js'), :js, req
|
|
47
|
+
|
|
48
|
+
req = mock_req(':method' => 'GET', ':path' => '/foo')
|
|
49
|
+
@app.route_and_call(req)
|
|
50
|
+
|
|
51
|
+
foo = Papercraft.html {
|
|
52
|
+
html5 {
|
|
53
|
+
head {
|
|
54
|
+
title 'Foo title'
|
|
55
|
+
}
|
|
56
|
+
body {
|
|
57
|
+
h1 'foo'
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
assert_response foo.render, :html, req
|
|
62
|
+
|
|
63
|
+
req = mock_req(':method' => 'GET', ':path' => '/index')
|
|
64
|
+
@app.route_and_call(req)
|
|
65
|
+
|
|
66
|
+
index = Papercraft.html {
|
|
67
|
+
html5 {
|
|
68
|
+
head {
|
|
69
|
+
title 'Hello'
|
|
70
|
+
}
|
|
71
|
+
body {
|
|
72
|
+
h1 'Index'
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
assert_response index.render, :html, req
|
|
77
|
+
|
|
78
|
+
req = mock_req(':method' => 'GET', ':path' => '/')
|
|
79
|
+
@app.route_and_call(req)
|
|
80
|
+
assert_response index.render, :html, req
|
|
81
|
+
|
|
82
|
+
req = mock_req(':method' => 'GET', ':path' => '/bar')
|
|
83
|
+
@app.route_and_call(req)
|
|
84
|
+
assert_response static('bar.html'), :html, req
|
|
85
|
+
|
|
86
|
+
req = mock_req(':method' => 'GET', ':path' => '/baz')
|
|
87
|
+
@app.route_and_call(req)
|
|
88
|
+
|
|
89
|
+
baz_index = Papercraft.html {
|
|
90
|
+
html5 {
|
|
91
|
+
head {
|
|
92
|
+
title 'BarBar'
|
|
93
|
+
}
|
|
94
|
+
body {
|
|
95
|
+
h1 'BarIndex'
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
assert_response baz_index.render, :html, req
|
|
100
|
+
|
|
101
|
+
req = mock_req(':method' => 'GET', ':path' => '/articles/a')
|
|
102
|
+
@app.route_and_call(req)
|
|
103
|
+
|
|
104
|
+
a = Papercraft.html {
|
|
105
|
+
html5 {
|
|
106
|
+
head {
|
|
107
|
+
title 'AAA'
|
|
108
|
+
}
|
|
109
|
+
body {
|
|
110
|
+
article {
|
|
111
|
+
h2 'ZZZ', id: 'zzz'
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
assert_response a.render, :html, req
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_non_root_app_response
|
|
120
|
+
@app = Impression::App.new(path: '/app', directory: APP_PATH)
|
|
121
|
+
|
|
122
|
+
req = mock_req(':method' => 'GET', ':path' => '/app/roo')
|
|
123
|
+
@app.route_and_call(req)
|
|
124
|
+
assert_equal Qeweney::Status::NOT_FOUND, req.response_status
|
|
125
|
+
|
|
126
|
+
req = mock_req(':method' => 'GET', ':path' => '/app/foo2')
|
|
127
|
+
@app.route_and_call(req)
|
|
128
|
+
assert_equal Qeweney::Status::NOT_FOUND, req.response_status
|
|
129
|
+
|
|
130
|
+
req = mock_req(':method' => 'GET', ':path' => '/app/bar2')
|
|
131
|
+
@app.route_and_call(req)
|
|
132
|
+
assert_equal Qeweney::Status::NOT_FOUND, req.response_status
|
|
133
|
+
|
|
134
|
+
req = mock_req(':method' => 'GET', ':path' => '/app/assets/js/a.js')
|
|
135
|
+
@app.route_and_call(req)
|
|
136
|
+
assert_response static('assets/js/a.js'), :js, req
|
|
137
|
+
|
|
138
|
+
req = mock_req(':method' => 'GET', ':path' => '/app/foo')
|
|
139
|
+
@app.route_and_call(req)
|
|
140
|
+
|
|
141
|
+
foo = Papercraft.html {
|
|
142
|
+
html5 {
|
|
143
|
+
head {
|
|
144
|
+
title 'Foo title'
|
|
145
|
+
}
|
|
146
|
+
body {
|
|
147
|
+
h1 'foo'
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
assert_response foo.render, :html, req
|
|
152
|
+
|
|
153
|
+
req = mock_req(':method' => 'GET', ':path' => '/app/index')
|
|
154
|
+
@app.route_and_call(req)
|
|
155
|
+
|
|
156
|
+
index = Papercraft.html {
|
|
157
|
+
html5 {
|
|
158
|
+
head {
|
|
159
|
+
title 'Hello'
|
|
160
|
+
}
|
|
161
|
+
body {
|
|
162
|
+
h1 'Index'
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
assert_response index.render, :html, req
|
|
167
|
+
|
|
168
|
+
req = mock_req(':method' => 'GET', ':path' => '/app/')
|
|
169
|
+
@app.route_and_call(req)
|
|
170
|
+
assert_response index.render, :html, req
|
|
171
|
+
|
|
172
|
+
req = mock_req(':method' => 'GET', ':path' => '/app/bar')
|
|
173
|
+
@app.route_and_call(req)
|
|
174
|
+
assert_response static('bar.html'), :html, req
|
|
175
|
+
|
|
176
|
+
req = mock_req(':method' => 'GET', ':path' => '/app/baz')
|
|
177
|
+
@app.route_and_call(req)
|
|
178
|
+
|
|
179
|
+
baz_index = Papercraft.html {
|
|
180
|
+
html5 {
|
|
181
|
+
head {
|
|
182
|
+
title 'BarBar'
|
|
183
|
+
}
|
|
184
|
+
body {
|
|
185
|
+
h1 'BarIndex'
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
assert_response baz_index.render, :html, req
|
|
190
|
+
|
|
191
|
+
req = mock_req(':method' => 'GET', ':path' => '/app/articles/a')
|
|
192
|
+
@app.route_and_call(req)
|
|
193
|
+
|
|
194
|
+
a = Papercraft.html {
|
|
195
|
+
html5 {
|
|
196
|
+
head {
|
|
197
|
+
title 'AAA'
|
|
198
|
+
}
|
|
199
|
+
body {
|
|
200
|
+
article {
|
|
201
|
+
h2 'ZZZ', id: 'zzz'
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
assert_response a.render, :html, req
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def test_page_list
|
|
210
|
+
@app = Impression::App.new(path: '/app', directory: APP_PATH)
|
|
211
|
+
|
|
212
|
+
list = @app.page_list('/')
|
|
213
|
+
assert_equal [
|
|
214
|
+
{ kind: :file, path: File.join(APP_PATH, 'bar.html'), ext: '.html', url: '/app/bar' },
|
|
215
|
+
{ kind: :markdown, path: File.join(APP_PATH, 'index.md'), ext: '.md', url: '/app',
|
|
216
|
+
title: 'Hello', foo: 'BarBar', html_content: "<h1>Index</h1>\n" },
|
|
217
|
+
], list
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
list = @app.page_list('/articles')
|
|
221
|
+
|
|
222
|
+
assert_equal [
|
|
223
|
+
{
|
|
224
|
+
kind: :markdown,
|
|
225
|
+
path: File.join(APP_PATH, 'articles/2008-06-14-manu.md'),
|
|
226
|
+
url: '/app/articles/2008-06-14-manu',
|
|
227
|
+
ext: '.md',
|
|
228
|
+
title: 'MMM',
|
|
229
|
+
layout: 'article',
|
|
230
|
+
foo: {
|
|
231
|
+
bar: {
|
|
232
|
+
baz: 42
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
html_content: "<h2 id=\"bbb\">BBB</h2>\n",
|
|
236
|
+
date: Date.new(2008, 06, 14)
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
kind: :markdown,
|
|
240
|
+
path: File.join(APP_PATH, 'articles/2009-06-12-noatche.md'),
|
|
241
|
+
url: '/app/articles/2009-06-12-noatche',
|
|
242
|
+
ext: '.md',
|
|
243
|
+
title: 'NNN',
|
|
244
|
+
layout: 'article',
|
|
245
|
+
html_content: "<h2 id=\"ccc\">CCC</h2>\n",
|
|
246
|
+
date: Date.new(2009, 06, 12)
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
kind: :markdown,
|
|
250
|
+
path: File.join(APP_PATH, 'articles/a.md'),
|
|
251
|
+
url: '/app/articles/a',
|
|
252
|
+
ext: '.md',
|
|
253
|
+
title: 'AAA',
|
|
254
|
+
layout: 'article',
|
|
255
|
+
html_content: "<h2 id=\"zzz\">ZZZ</h2>\n",
|
|
256
|
+
},
|
|
257
|
+
], list
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
def test_template_resource_and_request
|
|
261
|
+
req = mock_req(':method' => 'GET', ':path' => '/foobar?q=42')
|
|
262
|
+
@app.route_and_call(req)
|
|
263
|
+
|
|
264
|
+
foo = Papercraft.html {
|
|
265
|
+
html5 {
|
|
266
|
+
head {
|
|
267
|
+
title 'Foobar'
|
|
268
|
+
}
|
|
269
|
+
body {
|
|
270
|
+
h1 '42'
|
|
271
|
+
a 'MMM', href: '/articles/2008-06-14-manu'
|
|
272
|
+
a 'NNN', href: '/articles/2009-06-12-noatche'
|
|
273
|
+
a 'AAA', href: '/articles/a'
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
assert_response foo.render, :html, req
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def path_info(path)
|
|
281
|
+
@app.send(:get_path_info, path)
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def test_path_info
|
|
285
|
+
assert_equal({
|
|
286
|
+
kind: :markdown,
|
|
287
|
+
path: File.join(APP_PATH, 'index.md'),
|
|
288
|
+
ext: '.md',
|
|
289
|
+
url: '/',
|
|
290
|
+
title: 'Hello',
|
|
291
|
+
foo: 'BarBar',
|
|
292
|
+
html_content: "<h1>Index</h1>\n"
|
|
293
|
+
}, path_info('/index'))
|
|
294
|
+
|
|
295
|
+
assert_equal({
|
|
296
|
+
kind: :markdown,
|
|
297
|
+
path: File.join(APP_PATH, 'index.md'),
|
|
298
|
+
ext: '.md',
|
|
299
|
+
url: '/',
|
|
300
|
+
title: 'Hello',
|
|
301
|
+
foo: 'BarBar',
|
|
302
|
+
html_content: "<h1>Index</h1>\n"
|
|
303
|
+
}, path_info('/'))
|
|
304
|
+
|
|
305
|
+
assert_equal({
|
|
306
|
+
kind: :file,
|
|
307
|
+
path: File.join(APP_PATH, 'assets/js/a.js'),
|
|
308
|
+
ext: '.js',
|
|
309
|
+
url: '/assets/js/a.js'
|
|
310
|
+
}, path_info('/assets/js/a.js'))
|
|
311
|
+
|
|
312
|
+
assert_equal({
|
|
313
|
+
kind: :not_found,
|
|
314
|
+
}, path_info('/js/b.js'))
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def test_resource_loading
|
|
318
|
+
req = mock_req(':method' => 'GET', ':path' => '/resources/greeter?name=world')
|
|
319
|
+
route = @app.route(req)
|
|
320
|
+
assert_equal @app, route
|
|
321
|
+
|
|
322
|
+
req = mock_req(':method' => 'GET', ':path' => '/resources/greeter?name=world')
|
|
323
|
+
@app.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
|
+
@app.route_and_call(req)
|
|
328
|
+
assert_response 'Hello, foo!', :text, req
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
def test_recursive_resource_loading_on_non_root_app
|
|
332
|
+
app = Impression::App.new(path: '/foo/bar', directory: APP_PATH)
|
|
333
|
+
|
|
334
|
+
req = mock_req(':method' => 'GET', ':path' => '/foo/bar/resources/greeter?name=world')
|
|
335
|
+
route = app.route(req)
|
|
336
|
+
assert_equal app, route
|
|
337
|
+
|
|
338
|
+
req = mock_req(':method' => 'GET', ':path' => '/foo/bar/resources/greeter?name=world')
|
|
339
|
+
app.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
|
+
app.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
|
+
# @app.route_and_call(req)
|
|
348
|
+
# assert_response static('bar.html'), :html, req
|
|
349
|
+
end
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
class AbstractAppTest < MiniTest::Test
|
|
353
|
+
def test_abstract_app_default_response
|
|
7
354
|
app = Impression::App.new(path: '/')
|
|
8
355
|
req = mock_req(':method' => 'GET', ':path' => '/')
|
|
9
356
|
|
|
@@ -11,7 +358,7 @@ class AppTest < MiniTest::Test
|
|
|
11
358
|
assert_equal Qeweney::Status::NOT_FOUND, req.adapter.status
|
|
12
359
|
end
|
|
13
360
|
|
|
14
|
-
def
|
|
361
|
+
def test_abstract_app_each
|
|
15
362
|
app = Impression::App.new(path: '/')
|
|
16
363
|
|
|
17
364
|
buffer = []
|
|
@@ -33,10 +380,6 @@ class AppTest < MiniTest::Test
|
|
|
33
380
|
foo = PathRenderingResource.new(parent: app, path: 'foo')
|
|
34
381
|
bar = PathRenderingResource.new(parent: app, path: 'bar')
|
|
35
382
|
|
|
36
|
-
# req = mock_req(':method' => 'GET', ':path' => '/')
|
|
37
|
-
# app_proc.(req)
|
|
38
|
-
# assert_equal Qeweney::Status::NOT_FOUND, req.adapter.status
|
|
39
|
-
|
|
40
383
|
req = mock_req(':method' => 'GET', ':path' => '/foo')
|
|
41
384
|
app_proc.(req)
|
|
42
385
|
assert_equal '/foo', req.adapter.body
|
data/test/test_file_tree.rb
CHANGED
|
@@ -151,4 +151,22 @@ class FileTreeTest < MiniTest::Test
|
|
|
151
151
|
kind: :not_found,
|
|
152
152
|
}, path_info('/js/b.js'))
|
|
153
153
|
end
|
|
154
|
+
|
|
155
|
+
def test_file_tree_with_default_handler_block
|
|
156
|
+
@file_tree = Impression::FileTree.new(path: '/', directory: STATIC_PATH)
|
|
157
|
+
|
|
158
|
+
req = mock_req(':method' => 'GET', ':path' => '/foobar')
|
|
159
|
+
@file_tree.route_and_call(req)
|
|
160
|
+
assert_equal Qeweney::Status::NOT_FOUND, req.response_status
|
|
161
|
+
|
|
162
|
+
@file_tree = Impression::FileTree.new(path: '/', directory: STATIC_PATH) { |req|
|
|
163
|
+
req.respond('foobar', 'Foo' => 'bar')
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
req = mock_req(':method' => 'GET', ':path' => '/foobar')
|
|
167
|
+
@file_tree.route_and_call(req)
|
|
168
|
+
assert_equal Qeweney::Status::OK, req.response_status
|
|
169
|
+
assert_equal 'foobar', req.response_body
|
|
170
|
+
assert_equal 'bar', req.response_headers['Foo']
|
|
171
|
+
end
|
|
154
172
|
end
|
data/test/test_impression.rb
CHANGED
|
@@ -22,10 +22,10 @@ class ImpressionModuleTest < MiniTest::Test
|
|
|
22
22
|
assert_equal '/bar', r1.directory
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def
|
|
26
|
-
r1 = Impression.
|
|
25
|
+
def test_app_method
|
|
26
|
+
r1 = Impression.app(path: '/foo', directory: '/bar')
|
|
27
27
|
|
|
28
|
-
assert_kind_of Impression::
|
|
28
|
+
assert_kind_of Impression::App, r1
|
|
29
29
|
assert_equal '/foo', r1.path
|
|
30
30
|
assert_equal '/bar', r1.directory
|
|
31
31
|
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'helper'
|
|
4
|
+
|
|
5
|
+
class RackAppTest < MiniTest::Test
|
|
6
|
+
def test_basic_rack_app
|
|
7
|
+
app = Impression.rack_app(path: '/etc/rack') { |env|
|
|
8
|
+
[
|
|
9
|
+
200,
|
|
10
|
+
{'Content-Type' => 'text/plain'},
|
|
11
|
+
['Hello, world!']
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
req = mock_req(':method' => 'GET', ':path' => '/foobar')
|
|
16
|
+
assert_nil app.route(req)
|
|
17
|
+
|
|
18
|
+
req = mock_req(':method' => 'GET', ':path' => '/etc/rack')
|
|
19
|
+
app.route_and_call(req)
|
|
20
|
+
assert_equal '200', req.response_status
|
|
21
|
+
assert_equal 'text/plain', req.response_headers['Content-Type']
|
|
22
|
+
assert_equal 'Hello, world!', req.response_body
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_path_rewriting
|
|
26
|
+
app = Impression.rack_app(path: '/') { |env|
|
|
27
|
+
[200, {}, ["path: #{env['PATH_INFO']}"]]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
req = mock_req(':method' => 'GET', ':path' => '/foo/bar')
|
|
31
|
+
app.route_and_call(req)
|
|
32
|
+
assert_equal 'path: /foo/bar', req.response_body
|
|
33
|
+
|
|
34
|
+
###
|
|
35
|
+
|
|
36
|
+
app = Impression.rack_app(path: '/etc/rack') { |env|
|
|
37
|
+
[200, {}, ["path: #{env['PATH_INFO']}"]]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
req = mock_req(':method' => 'GET', ':path' => '/etc/rack')
|
|
41
|
+
app.route_and_call(req)
|
|
42
|
+
assert_equal 'path: /', req.response_body
|
|
43
|
+
|
|
44
|
+
req = mock_req(':method' => 'GET', ':path' => '/etc/rack/foo/bar')
|
|
45
|
+
app.route_and_call(req)
|
|
46
|
+
assert_equal 'path: /foo/bar', req.response_body
|
|
47
|
+
end
|
|
48
|
+
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.13'
|
|
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-
|
|
11
|
+
date: 2022-04-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: polyphony
|
|
@@ -16,56 +16,56 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0.
|
|
19
|
+
version: '0.93'
|
|
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.93'
|
|
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.52'
|
|
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.52'
|
|
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.18'
|
|
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.18'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: papercraft
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0.
|
|
61
|
+
version: '0.23'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0.
|
|
68
|
+
version: '0.23'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: modulation
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -150,26 +150,26 @@ files:
|
|
|
150
150
|
- lib/impression/errors.rb
|
|
151
151
|
- lib/impression/file_tree.rb
|
|
152
152
|
- lib/impression/file_watcher.rb
|
|
153
|
-
- lib/impression/
|
|
153
|
+
- lib/impression/rack_app.rb
|
|
154
154
|
- lib/impression/request_extensions.rb
|
|
155
155
|
- lib/impression/request_extensions/responses.rb
|
|
156
156
|
- lib/impression/request_extensions/routing.rb
|
|
157
157
|
- lib/impression/resource.rb
|
|
158
158
|
- lib/impression/version.rb
|
|
159
|
+
- test/app/_layouts/article.rb
|
|
160
|
+
- test/app/_layouts/default.rb
|
|
161
|
+
- test/app/articles/2008-06-14-manu.md
|
|
162
|
+
- test/app/articles/2009-06-12-noatche.md
|
|
163
|
+
- test/app/articles/a.md
|
|
164
|
+
- test/app/assets/js/a.js
|
|
165
|
+
- test/app/bar.html
|
|
166
|
+
- test/app/baz/index.md
|
|
167
|
+
- test/app/foo.rb
|
|
168
|
+
- test/app/foobar.rb
|
|
169
|
+
- test/app/index.md
|
|
170
|
+
- test/app/resources/greeter.rb
|
|
171
|
+
- test/app/resources/recurse.rb
|
|
159
172
|
- test/helper.rb
|
|
160
|
-
- test/jamstack/_layouts/article.rb
|
|
161
|
-
- test/jamstack/_layouts/default.rb
|
|
162
|
-
- test/jamstack/articles/2008-06-14-manu.md
|
|
163
|
-
- test/jamstack/articles/2009-06-12-noatche.md
|
|
164
|
-
- test/jamstack/articles/a.md
|
|
165
|
-
- test/jamstack/assets/js/a.js
|
|
166
|
-
- test/jamstack/bar.html
|
|
167
|
-
- test/jamstack/baz/index.md
|
|
168
|
-
- test/jamstack/foo.rb
|
|
169
|
-
- test/jamstack/foobar.rb
|
|
170
|
-
- test/jamstack/index.md
|
|
171
|
-
- test/jamstack/resources/greeter.rb
|
|
172
|
-
- test/jamstack/resources/recurse.rb
|
|
173
173
|
- test/run.rb
|
|
174
174
|
- test/static/bar/index.html
|
|
175
175
|
- test/static/foo.html
|
|
@@ -179,7 +179,7 @@ files:
|
|
|
179
179
|
- test/test_file_tree.rb
|
|
180
180
|
- test/test_file_watcher.rb
|
|
181
181
|
- test/test_impression.rb
|
|
182
|
-
- test/
|
|
182
|
+
- test/test_rack_app.rb
|
|
183
183
|
- test/test_resource.rb
|
|
184
184
|
homepage: http://github.com/digital-fabric/impression
|
|
185
185
|
licenses:
|