impression 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helper'
4
+ require 'qeweney/test_adapter'
5
+
6
+ class FileTreeTest < MiniTest::Test
7
+ STATIC_PATH = File.join(__dir__, 'static')
8
+
9
+ def setup
10
+ @file_tree = Impression::FileTree.new(path: '/', directory: STATIC_PATH)
11
+ end
12
+
13
+ def test_file_tree_routing
14
+ req = mock_req(':method' => 'GET', ':path' => '/')
15
+ assert_equal @file_tree, @file_tree.route(req)
16
+
17
+ req = mock_req(':method' => 'GET', ':path' => '/nonexistent')
18
+ assert_equal @file_tree, @file_tree.route(req)
19
+
20
+ req = mock_req(':method' => 'GET', ':path' => '/index.html')
21
+ assert_equal @file_tree, @file_tree.route(req)
22
+
23
+ req = mock_req(':method' => 'GET', ':path' => '/foo')
24
+ assert_equal @file_tree, @file_tree.route(req)
25
+ end
26
+
27
+ def static(path)
28
+ IO.read(File.join(STATIC_PATH, path))
29
+ end
30
+
31
+ def test_file_tree_response
32
+ req = mock_req(':method' => 'GET', ':path' => '/roo')
33
+ @file_tree.route_and_respond(req)
34
+ assert_equal Qeweney::Status::NOT_FOUND, req.response_status
35
+
36
+ req = mock_req(':method' => 'GET', ':path' => '/foo2')
37
+ @file_tree.route_and_respond(req)
38
+ assert_equal Qeweney::Status::NOT_FOUND, req.response_status
39
+
40
+ req = mock_req(':method' => 'GET', ':path' => '/bar2')
41
+ @file_tree.route_and_respond(req)
42
+ assert_equal Qeweney::Status::NOT_FOUND, req.response_status
43
+
44
+ req = mock_req(':method' => 'GET', ':path' => '/js/a.js')
45
+ @file_tree.route_and_respond(req)
46
+ assert_response static('js/a.js'), :js, req
47
+
48
+ req = mock_req(':method' => 'GET', ':path' => '/foo.html')
49
+ @file_tree.route_and_respond(req)
50
+ assert_response static('foo.html'), :html, req
51
+
52
+ req = mock_req(':method' => 'GET', ':path' => '/foo')
53
+ @file_tree.route_and_respond(req)
54
+ assert_response static('foo.html'), :html, req
55
+
56
+ req = mock_req(':method' => 'GET', ':path' => '/index.html')
57
+ @file_tree.route_and_respond(req)
58
+ assert_response static('index.html'), :html, req
59
+
60
+ req = mock_req(':method' => 'GET', ':path' => '/')
61
+ @file_tree.route_and_respond(req)
62
+ assert_response static('index.html'), :html, req
63
+
64
+ req = mock_req(':method' => 'GET', ':path' => '/bar/index.html')
65
+ @file_tree.route_and_respond(req)
66
+ assert_response static('bar/index.html'), :html, req
67
+
68
+ req = mock_req(':method' => 'GET', ':path' => '/bar')
69
+ @file_tree.route_and_respond(req)
70
+ assert_response static('bar/index.html'), :html, req
71
+ end
72
+
73
+ def test_non_root_file_tree_response
74
+ @file_tree = Impression::FileTree.new(path: '/app', directory: STATIC_PATH)
75
+
76
+ req = mock_req(':method' => 'GET', ':path' => '/app/roo')
77
+ @file_tree.route_and_respond(req)
78
+ assert_equal Qeweney::Status::NOT_FOUND, req.response_status
79
+
80
+ req = mock_req(':method' => 'GET', ':path' => '/app/foo2')
81
+ @file_tree.route_and_respond(req)
82
+ assert_equal Qeweney::Status::NOT_FOUND, req.response_status
83
+
84
+ req = mock_req(':method' => 'GET', ':path' => '/app/bar2')
85
+ @file_tree.route_and_respond(req)
86
+ assert_equal Qeweney::Status::NOT_FOUND, req.response_status
87
+
88
+ req = mock_req(':method' => 'GET', ':path' => '/app/js/a.js')
89
+ @file_tree.route_and_respond(req)
90
+ assert_response static('js/a.js'), :js, req
91
+
92
+ req = mock_req(':method' => 'GET', ':path' => '/app/foo.html')
93
+ @file_tree.route_and_respond(req)
94
+ assert_response static('foo.html'), :html, req
95
+
96
+ req = mock_req(':method' => 'GET', ':path' => '/app/foo')
97
+ @file_tree.route_and_respond(req)
98
+ assert_response static('foo.html'), :html, req
99
+
100
+ req = mock_req(':method' => 'GET', ':path' => '/app/index.html')
101
+ @file_tree.route_and_respond(req)
102
+ assert_response static('index.html'), :html, req
103
+
104
+ req = mock_req(':method' => 'GET', ':path' => '/app/')
105
+ @file_tree.route_and_respond(req)
106
+ assert_response static('index.html'), :html, req
107
+
108
+ req = mock_req(':method' => 'GET', ':path' => '/app/bar/index.html')
109
+ @file_tree.route_and_respond(req)
110
+ assert_response static('bar/index.html'), :html, req
111
+
112
+ req = mock_req(':method' => 'GET', ':path' => '/app/bar')
113
+ @file_tree.route_and_respond(req)
114
+ assert_response static('bar/index.html'), :html, req
115
+ end
116
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helper'
4
+ require 'fileutils'
5
+
6
+ # class FileWatcherTest < MiniTest::Test
7
+ # def setup
8
+ # @tmp_path = File.expand_path('../tmp', __dir__)
9
+ # FileUtils.mkdir(@tmp_path)
10
+ # end
11
+
12
+ # def teardown
13
+ # FileUtils.rm_rf(@tmp_path)
14
+ # end
15
+
16
+ # def test_directory_watcher
17
+ # watcher = Impression::FileWatcher.new(@tmp_path)
18
+ # file_path = File.join(@tmp_path, 'foo')
19
+
20
+ # buffer = []
21
+ # spin do
22
+ # watcher.each { |kind, path| buffer << [kind, path] }
23
+ # end
24
+
25
+ # assert_equal [], buffer
26
+
27
+ # # create
28
+ # buffer.clear
29
+ # IO.write(file_path, 'bar')
30
+ # sleep 0.01
31
+ # assert_equal [[:create, file_path]], buffer
32
+
33
+ # # modify
34
+ # buffer.clear
35
+ # IO.write(file_path, 'baz')
36
+ # sleep 0.01
37
+ # assert_equal [[:modify, file_path]], buffer
38
+
39
+ # # move
40
+ # tmp_file_path = File.join("/tmp/#{rand(1024)}")
41
+ # file2_path = File.join(@tmp_path, 'foo2')
42
+ # buffer.clear
43
+ # IO.write(tmp_file_path, '---')
44
+ # FileUtils.mv(tmp_file_path, file2_path)
45
+ # sleep 0.01
46
+ # assert_equal [[:moved_to, file2_path]], buffer
47
+
48
+ # # delete
49
+ # buffer.clear
50
+ # FileUtils.rm(file_path)
51
+ # sleep 0.01
52
+ # assert_equal [[:delete, file_path]], buffer
53
+ # end
54
+
55
+ # def test_recursive_directory_watcher
56
+ # end
57
+ # end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helper'
4
+
5
+ class ResourceTest < MiniTest::Test
6
+ def test_absolute_path
7
+ r1 = Impression::Resource.new(path: 'foo')
8
+ assert_equal '/foo', r1.absolute_path
9
+
10
+ r2 = Impression::Resource.new(parent: r1, path: 'bar')
11
+ assert_equal '/foo/bar', r2.absolute_path
12
+ end
13
+
14
+ def test_each
15
+ r1 = Impression::Resource.new(path: 'foo')
16
+ r2 = Impression::Resource.new(parent: r1, path: 'bar')
17
+ r3 = Impression::Resource.new(parent: r1, path: 'baz')
18
+
19
+ assert_equal [r2, r3], r1.children.values
20
+
21
+ buffer = []
22
+ r1.each { |r| buffer << r }
23
+ assert_equal [r1, r2, r3], buffer
24
+ end
25
+
26
+ def test_route
27
+ r1 = Impression::Resource.new(path: 'foo')
28
+ r2 = Impression::Resource.new(parent: r1, path: 'bar')
29
+ r3 = Impression::Resource.new(parent: r1, path: 'baz')
30
+ r4 = Impression::Resource.new(parent: r2, path: 'littlebar')
31
+
32
+ assert_equal [r2, r3], r1.children.values
33
+ assert_equal [r4], r2.children.values
34
+
35
+ req = mock_req(':method' => 'GET', ':path' => '/')
36
+ assert_nil r1.route(req)
37
+ assert_equal '/', req.resource_relative_path
38
+
39
+ req = mock_req(':method' => 'GET', ':path' => '/foo2')
40
+ assert_nil r1.route(req)
41
+ assert_equal '/foo2', req.resource_relative_path
42
+
43
+ req = mock_req(':method' => 'GET', ':path' => '/foo')
44
+ assert_equal r1, r1.route(req)
45
+ assert_equal '/', req.resource_relative_path
46
+
47
+ req = mock_req(':method' => 'GET', ':path' => '/foo/bar')
48
+ assert_equal r2, r1.route(req)
49
+ assert_equal '/', req.resource_relative_path
50
+
51
+ req = mock_req(':method' => 'GET', ':path' => '/foo/baz')
52
+ assert_equal r3, r1.route(req)
53
+ assert_equal '/', req.resource_relative_path
54
+
55
+ req = mock_req(':method' => 'GET', ':path' => '/foo/bar/littlebar')
56
+ assert_equal r4, r1.route(req)
57
+ assert_equal '/', req.resource_relative_path
58
+
59
+ req = mock_req(':method' => 'GET', ':path' => '/foo/bar/littlebar/littlebaz')
60
+ assert_equal r4, r1.route(req)
61
+ assert_equal '/littlebaz', req.resource_relative_path
62
+
63
+ req = mock_req(':method' => 'GET', ':path' => '/foo/hi')
64
+ assert_equal r1, r1.route(req)
65
+ assert_equal '/hi', req.resource_relative_path
66
+
67
+ req = mock_req(':method' => 'GET', ':path' => '/foo/hi/bye')
68
+ assert_equal r1, r1.route(req)
69
+ assert_equal '/hi/bye', req.resource_relative_path
70
+ end
71
+
72
+ def test_nested_resource_rendering
73
+ r1 = Impression::Resource.new(path: 'foo')
74
+ r2 = PathRenderingResource.new(parent: r1, path: 'bar')
75
+ r3 = PathRenderingResource.new(parent: r1, path: 'baz')
76
+
77
+ req = mock_req(':method' => 'GET', ':path' => '/')
78
+ assert_nil r1.route(req)
79
+
80
+ req = mock_req(':method' => 'GET', ':path' => '/foo')
81
+ r1.route(req).respond(req)
82
+ # default reply
83
+ assert_equal Qeweney::Status::NOT_FOUND, req.response_status
84
+
85
+ req = mock_req(':method' => 'GET', ':path' => '/foo/bar')
86
+ r1.route(req).respond(req)
87
+ assert_equal '/foo/bar', req.response_body
88
+
89
+ req = mock_req(':method' => 'GET', ':path' => '/foo/baz')
90
+ r1.route(req).respond(req)
91
+ assert_equal '/foo/baz', req.response_body
92
+
93
+ req = mock_req(':method' => 'GET', ':path' => '/foo/bbb')
94
+ assert_equal r1, r1.route(req)
95
+ end
96
+
97
+ def test_relative_path
98
+ r1 = CompletePathInfoRenderingResource.new(path: 'foo')
99
+ r2 = CompletePathInfoRenderingResource.new(parent: r1, path: 'bar')
100
+ r3 = CompletePathInfoRenderingResource.new(parent: r1, path: 'baz')
101
+
102
+ req = mock_req(':method' => 'GET', ':path' => '/')
103
+ assert_nil r1.route(req)
104
+
105
+ req = mock_req(':method' => 'GET', ':path' => '/foo')
106
+ r1.route(req).respond(req)
107
+ assert_equal '/foo /', req.response_body
108
+
109
+ req = mock_req(':method' => 'GET', ':path' => '/foo/zzz')
110
+ r1.route(req).respond(req)
111
+ assert_equal '/foo /zzz', req.response_body
112
+
113
+ req = mock_req(':method' => 'GET', ':path' => '/foo/bar')
114
+ r1.route(req).respond(req)
115
+ assert_equal '/foo/bar /', req.response_body
116
+
117
+ req = mock_req(':method' => 'GET', ':path' => '/foo/bar/zzz')
118
+ r1.route(req).respond(req)
119
+ assert_equal '/foo/bar /zzz', req.response_body
120
+
121
+ req = mock_req(':method' => 'GET', ':path' => '/foo/baz')
122
+ r1.route(req).respond(req)
123
+ assert_equal '/foo/baz /', req.response_body
124
+
125
+ req = mock_req(':method' => 'GET', ':path' => '/foo/baz/xxx/yyy')
126
+ r1.route(req).respond(req)
127
+ assert_equal '/foo/baz /xxx/yyy', req.response_body
128
+ end
129
+ 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.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-24 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: polyphony
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.51.0
19
+ version: 0.73.1
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.51.0
26
+ version: 0.73.1
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.37'
33
+ version: '0.45'
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.37'
40
+ version: '0.45'
41
+ - !ruby/object:Gem::Dependency
42
+ name: qeweney
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.15'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.15'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: kramdown
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -81,47 +95,47 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: 1.1.0
83
97
  - !ruby/object:Gem::Dependency
84
- name: rake
98
+ name: papercraft
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 12.3.3
90
- type: :development
103
+ version: '0.12'
104
+ type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 12.3.3
110
+ version: '0.12'
97
111
  - !ruby/object:Gem::Dependency
98
- name: minitest
112
+ name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 5.11.3
117
+ version: 12.3.3
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: 5.11.3
124
+ version: 12.3.3
111
125
  - !ruby/object:Gem::Dependency
112
- name: minitest-reporters
126
+ name: minitest
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: 1.4.2
131
+ version: 5.11.3
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: 1.4.2
138
+ version: 5.11.3
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: simplecov
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -136,34 +150,54 @@ dependencies:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
152
  version: 0.17.1
139
- description:
153
+ description:
140
154
  email: sharon@noteflakes.com
141
155
  executables: []
142
156
  extensions: []
143
157
  extra_rdoc_files:
144
158
  - README.md
145
159
  files:
160
+ - ".github/FUNDING.yml"
161
+ - ".github/workflows/test.yml"
146
162
  - ".gitignore"
147
163
  - CHANGELOG.md
148
164
  - Gemfile
149
165
  - Gemfile.lock
150
166
  - LICENSE
151
167
  - README.md
168
+ - Rakefile
152
169
  - TODO.md
170
+ - examples/markdown/_assets/style.css
153
171
  - examples/markdown/app.rb
154
172
  - examples/markdown/docs/index.md
173
+ - examples/markdown/docs/tutorial.md
155
174
  - impression.gemspec
156
175
  - lib/impression.rb
176
+ - lib/impression/app.rb
157
177
  - lib/impression/errors.rb
178
+ - lib/impression/file_tree.rb
179
+ - lib/impression/file_watcher.rb
158
180
  - lib/impression/pages.rb
159
181
  - lib/impression/request_extensions.rb
182
+ - lib/impression/request_routing.rb
183
+ - lib/impression/resource.rb
160
184
  - lib/impression/version.rb
185
+ - test/helper.rb
186
+ - test/run.rb
187
+ - test/static/bar/index.html
188
+ - test/static/foo.html
189
+ - test/static/index.html
190
+ - test/static/js/a.js
191
+ - test/test_app.rb
192
+ - test/test_file_tree.rb
193
+ - test/test_file_watcher.rb
194
+ - test/test_resource.rb
161
195
  homepage: http://github.com/digital-fabric/impression
162
196
  licenses:
163
197
  - MIT
164
198
  metadata:
165
199
  source_code_uri: https://github.com/digital-fabric/impression
166
- post_install_message:
200
+ post_install_message:
167
201
  rdoc_options:
168
202
  - "--title"
169
203
  - impression
@@ -182,8 +216,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
216
  - !ruby/object:Gem::Version
183
217
  version: '0'
184
218
  requirements: []
185
- rubygems_version: 3.1.4
186
- signing_key:
219
+ rubygems_version: 3.3.3
220
+ signing_key:
187
221
  specification_version: 4
188
222
  summary: Impression - a modern web framework for Ruby
189
223
  test_files: []