impression 0.5 → 0.6
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 +5 -0
- data/Gemfile.lock +10 -10
- data/examples/hello.rb +13 -0
- data/impression.gemspec +2 -2
- data/lib/impression/file_tree.rb +33 -3
- data/lib/impression/jamstack.rb +30 -43
- data/lib/impression/version.rb +1 -1
- data/test/jamstack/articles/2009-06-12-noatche.md +1 -1
- data/test/jamstack/articles/a.md +1 -1
- data/test/jamstack/index.md +1 -0
- data/test/test_file_tree.rb +38 -0
- data/test/test_jamstack.rb +53 -5
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79fca9e0a9d2a2e782bd3168384e752009776b82d50c285f14f7a2951dae0e5c
|
4
|
+
data.tar.gz: 9d2d433216ca25fcd23b66e7f545520b8433abc076efde2c919d4e0dc8fd980c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84105ef65c86fefc2babdb7d44e3c89f9b6562d8c1bd4e3bdffa62b279e6e3b236841c5574de57fba4e7fe870f7a183659c636834af93b6d93df3d60f1818fcc
|
7
|
+
data.tar.gz: df125e64c903affa9946704e0c559d45848c89879621d764aa98b66fecaa1fcf27ff899ddb36c11e489f816792345252fe4e08df85c2796773affc88b0f95e9a
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -3,9 +3,9 @@ PATH
|
|
3
3
|
specs:
|
4
4
|
impression (0.5)
|
5
5
|
modulation (~> 1.1)
|
6
|
-
papercraft (~> 0.
|
6
|
+
papercraft (~> 0.15)
|
7
7
|
polyphony (~> 0.73.1)
|
8
|
-
qeweney (~> 0.
|
8
|
+
qeweney (~> 0.16)
|
9
9
|
tipi (~> 0.45)
|
10
10
|
|
11
11
|
GEM
|
@@ -50,20 +50,20 @@ GEM
|
|
50
50
|
localhost (1.1.9)
|
51
51
|
minitest (5.11.3)
|
52
52
|
modulation (1.1)
|
53
|
-
msgpack (1.4.
|
53
|
+
msgpack (1.4.4)
|
54
54
|
multipart-post (2.1.1)
|
55
|
-
papercraft (0.
|
56
|
-
escape_utils (
|
57
|
-
kramdown (~> 2.3.
|
55
|
+
papercraft (0.15)
|
56
|
+
escape_utils (~> 1.2.1)
|
57
|
+
kramdown (~> 2.3.1)
|
58
58
|
kramdown-parser-gfm (~> 1.1.0)
|
59
|
-
rouge (~> 3.
|
59
|
+
rouge (~> 3.27.0)
|
60
60
|
polyphony (0.73.1)
|
61
|
-
qeweney (0.
|
61
|
+
qeweney (0.16)
|
62
62
|
escape_utils (~> 1.2.1)
|
63
63
|
rack (2.2.3)
|
64
64
|
rake (12.3.3)
|
65
65
|
rexml (3.2.5)
|
66
|
-
rouge (3.
|
66
|
+
rouge (3.27.0)
|
67
67
|
ruby2_keywords (0.0.5)
|
68
68
|
simplecov (0.17.1)
|
69
69
|
docile (~> 1.1)
|
@@ -85,7 +85,7 @@ GEM
|
|
85
85
|
websocket (1.2.9)
|
86
86
|
|
87
87
|
PLATFORMS
|
88
|
-
|
88
|
+
ruby
|
89
89
|
|
90
90
|
DEPENDENCIES
|
91
91
|
impression!
|
data/examples/hello.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'impression'
|
2
|
+
|
3
|
+
app = Impression.app do
|
4
|
+
mount '/' => text_response('Hello, world!')
|
5
|
+
end
|
6
|
+
|
7
|
+
# class App < Impression::Resource
|
8
|
+
# def route(req)
|
9
|
+
# @response ||= text_response('Hello, world!')
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
|
13
|
+
# run { |req| req.respond_text('Hello, world!') }
|
data/impression.gemspec
CHANGED
@@ -24,10 +24,10 @@ Gem::Specification.new do |s|
|
|
24
24
|
|
25
25
|
s.add_runtime_dependency 'polyphony', '~>0.73.1'
|
26
26
|
s.add_runtime_dependency 'tipi', '~>0.45'
|
27
|
-
s.add_runtime_dependency 'qeweney', '~>0.
|
27
|
+
s.add_runtime_dependency 'qeweney', '~>0.16'
|
28
28
|
|
29
29
|
# s.add_runtime_dependency 'rb-inotify', '~>0.10.1'
|
30
|
-
s.add_runtime_dependency 'papercraft', '~>0.
|
30
|
+
s.add_runtime_dependency 'papercraft', '~>0.15'
|
31
31
|
s.add_runtime_dependency 'modulation', '~>1.1'
|
32
32
|
|
33
33
|
|
data/lib/impression/file_tree.rb
CHANGED
@@ -27,8 +27,6 @@ module Impression
|
|
27
27
|
render_from_path_info(req, path_info)
|
28
28
|
end
|
29
29
|
|
30
|
-
private
|
31
|
-
|
32
30
|
# Renders a response from the given response kind and path.
|
33
31
|
#
|
34
32
|
# @param req [Qeweney::Request] request
|
@@ -47,6 +45,9 @@ module Impression
|
|
47
45
|
|
48
46
|
private
|
49
47
|
|
48
|
+
PAGE_EXT_REGEXP = /^(.+)\.html$/.freeze
|
49
|
+
INDEX_PAGE_REGEXP = /^(.+)?\/index$/.freeze
|
50
|
+
|
50
51
|
# Renders a file response for the given request and the given path info.
|
51
52
|
#
|
52
53
|
# @param req [Qeweney::Request] request
|
@@ -89,8 +90,37 @@ module Impression
|
|
89
90
|
elsif stat.directory?
|
90
91
|
return directory_path_info(path)
|
91
92
|
else
|
92
|
-
|
93
|
+
file_info(path)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns the path info for the given file path.
|
98
|
+
#
|
99
|
+
# @param path [String] file path
|
100
|
+
# @return [Hash] path info
|
101
|
+
def file_info(path)
|
102
|
+
relative_path = path.gsub(/^#{@directory}/, '')
|
103
|
+
{
|
104
|
+
kind: :file,
|
105
|
+
path: path,
|
106
|
+
ext: File.extname(path),
|
107
|
+
url: pretty_url(relative_path)
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
# Returns the pretty URL for the given relative path. For pages, the
|
112
|
+
# extension is removed. For index pages, the index suffix is removed.
|
113
|
+
#
|
114
|
+
# @param relative_path [String] relative path
|
115
|
+
# @return [String] pretty URL
|
116
|
+
def pretty_url(relative_path)
|
117
|
+
if (m = relative_path.match(PAGE_EXT_REGEXP))
|
118
|
+
relative_path = m[1]
|
119
|
+
end
|
120
|
+
if (m = relative_path.match(INDEX_PAGE_REGEXP))
|
121
|
+
relative_path = m[1] || '/'
|
93
122
|
end
|
123
|
+
relative_path == '/' ? absolute_path : File.join(absolute_path, relative_path)
|
94
124
|
end
|
95
125
|
|
96
126
|
# Calculates the path info for a directory. If an index file exists, its
|
data/lib/impression/jamstack.rb
CHANGED
@@ -29,39 +29,36 @@ module Impression
|
|
29
29
|
def page_list(dir)
|
30
30
|
base = File.join(@directory, dir)
|
31
31
|
Dir.glob('*.{html,md}', base: base)
|
32
|
-
.map { |fn| page_entry(fn, dir) }
|
32
|
+
.map { |fn| get_path_info(File.join(dir, fn)) }# page_entry(fn, dir) }
|
33
33
|
.sort_by { |i| i[:path] }
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
37
37
|
|
38
|
-
DATE_REGEXP =
|
38
|
+
DATE_REGEXP = /(\d{4}\-\d{2}\-\d{2})/.freeze
|
39
39
|
MARKDOWN_PAGE_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m.freeze
|
40
40
|
MD_EXT_REGEXP = /\.md$/.freeze
|
41
41
|
PAGE_EXT_REGEXP = /^(.+)\.(md|html|rb)$/.freeze
|
42
|
-
INDEX_PAGE_REGEXP = /^(.+)
|
42
|
+
INDEX_PAGE_REGEXP = /^(.+)?\/index$/.freeze
|
43
43
|
|
44
|
-
# Returns
|
44
|
+
# Returns the path info for the given file path.
|
45
45
|
#
|
46
|
-
# @param
|
47
|
-
# @
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
atts, _ = parse_markdown_file(absolute_path)
|
58
|
-
info.merge!(atts)
|
46
|
+
# @param path [String] file path
|
47
|
+
# @return [Hash] path info
|
48
|
+
def file_info(path)
|
49
|
+
info = super
|
50
|
+
case info[:ext]
|
51
|
+
when '.md'
|
52
|
+
atts, content = parse_markdown_file(path)
|
53
|
+
info = info.merge(atts)
|
54
|
+
info[:markdown_content] = content
|
55
|
+
when '.rb'
|
56
|
+
info[:module] = import(path)
|
59
57
|
end
|
60
|
-
|
61
|
-
if (m = fn.match(DATE_REGEXP))
|
58
|
+
if (m = path.match(DATE_REGEXP))
|
62
59
|
info[:date] ||= Date.parse(m[1])
|
63
60
|
end
|
64
|
-
|
61
|
+
|
65
62
|
info
|
66
63
|
end
|
67
64
|
|
@@ -75,9 +72,9 @@ module Impression
|
|
75
72
|
relative_path = m[1]
|
76
73
|
end
|
77
74
|
if (m = relative_path.match(INDEX_PAGE_REGEXP))
|
78
|
-
relative_path = m[1]
|
75
|
+
relative_path = m[1] || '/'
|
79
76
|
end
|
80
|
-
File.join(absolute_path, relative_path)
|
77
|
+
relative_path == '/' ? absolute_path : File.join(absolute_path, relative_path)
|
81
78
|
end
|
82
79
|
|
83
80
|
# Renders a file response for the given request and the given path info.
|
@@ -88,9 +85,9 @@ module Impression
|
|
88
85
|
def render_file(req, path_info)
|
89
86
|
case path_info[:ext]
|
90
87
|
when '.rb'
|
91
|
-
render_papercraft_module(req, path_info
|
88
|
+
render_papercraft_module(req, path_info)
|
92
89
|
when '.md'
|
93
|
-
render_markdown_file(req, path_info
|
90
|
+
render_markdown_file(req, path_info)
|
94
91
|
else
|
95
92
|
req.serve_file(path_info[:path])
|
96
93
|
end
|
@@ -99,26 +96,24 @@ module Impression
|
|
99
96
|
# Renders a Papercraft module. The module is loaded using Modulation.
|
100
97
|
#
|
101
98
|
# @param req [Qeweney::Request] reqest
|
102
|
-
# @param
|
99
|
+
# @param path_info [Hash] path info
|
103
100
|
# @return [void]
|
104
|
-
def render_papercraft_module(req,
|
105
|
-
|
106
|
-
|
107
|
-
html = H(mod).render(request: req, resource: self)
|
101
|
+
def render_papercraft_module(req, path_info)
|
102
|
+
html = H(path_info[:module]).render(request: req, resource: self)
|
108
103
|
req.respond(html, 'Content-Type' => Qeweney::MimeTypes[:html])
|
109
104
|
end
|
110
105
|
|
111
106
|
# Renders a markdown file using a layout.
|
112
107
|
#
|
113
108
|
# @param req [Qeweney::Request] reqest
|
114
|
-
# @param
|
109
|
+
# @param path_info [Hash] path info
|
115
110
|
# @return [void]
|
116
|
-
def render_markdown_file(req,
|
117
|
-
|
118
|
-
|
119
|
-
layout = get_layout(attributes[:layout])
|
111
|
+
def render_markdown_file(req, path_info)
|
112
|
+
layout = get_layout(path_info[:layout])
|
120
113
|
|
121
|
-
html = layout.render(request: req, resource: self, **
|
114
|
+
html = layout.render(request: req, resource: self, **path_info) {
|
115
|
+
emit_markdown path_info[:markdown_content]
|
116
|
+
}
|
122
117
|
req.respond(html, 'Content-Type' => Qeweney::MimeTypes[:html])
|
123
118
|
end
|
124
119
|
|
@@ -160,14 +155,6 @@ module Impression
|
|
160
155
|
[atts, data]
|
161
156
|
end
|
162
157
|
|
163
|
-
# Converts a hash with string keys to one with symbol keys.
|
164
|
-
#
|
165
|
-
# @param hash [Hash] input hash
|
166
|
-
# @return [Hash] output hash
|
167
|
-
def symbolize_keys(hash)
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
158
|
# Returns the supported path extensions used for searching for files based
|
172
159
|
# on pretty URLs.
|
173
160
|
#
|
data/lib/impression/version.rb
CHANGED
data/test/jamstack/articles/a.md
CHANGED
data/test/jamstack/index.md
CHANGED
data/test/test_file_tree.rb
CHANGED
@@ -113,4 +113,42 @@ class FileTreeTest < MiniTest::Test
|
|
113
113
|
@file_tree.route_and_call(req)
|
114
114
|
assert_response static('bar/index.html'), :html, req
|
115
115
|
end
|
116
|
+
|
117
|
+
def path_info(path)
|
118
|
+
@file_tree.send(:get_path_info, path)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_path_info
|
122
|
+
assert_equal({
|
123
|
+
kind: :file,
|
124
|
+
path: File.join(__dir__, 'static/index.html'),
|
125
|
+
ext: '.html',
|
126
|
+
url: '/'
|
127
|
+
}, path_info('/index.html'))
|
128
|
+
|
129
|
+
assert_equal({
|
130
|
+
kind: :file,
|
131
|
+
path: File.join(__dir__, 'static/index.html'),
|
132
|
+
ext: '.html',
|
133
|
+
url: '/'
|
134
|
+
}, path_info('/index'))
|
135
|
+
|
136
|
+
assert_equal({
|
137
|
+
kind: :file,
|
138
|
+
path: File.join(__dir__, 'static/index.html'),
|
139
|
+
ext: '.html',
|
140
|
+
url: '/'
|
141
|
+
}, path_info('/'))
|
142
|
+
|
143
|
+
assert_equal({
|
144
|
+
kind: :file,
|
145
|
+
path: File.join(__dir__, 'static/js/a.js'),
|
146
|
+
ext: '.js',
|
147
|
+
url: '/js/a.js'
|
148
|
+
}, path_info('/js/a.js'))
|
149
|
+
|
150
|
+
assert_equal({
|
151
|
+
kind: :not_found,
|
152
|
+
}, path_info('/js/b.js'))
|
153
|
+
end
|
116
154
|
end
|
data/test/test_jamstack.rb
CHANGED
@@ -108,7 +108,7 @@ class JamstackTest < MiniTest::Test
|
|
108
108
|
}
|
109
109
|
body {
|
110
110
|
article {
|
111
|
-
h2 '
|
111
|
+
h2 'ZZZ', id: 'zzz'
|
112
112
|
}
|
113
113
|
}
|
114
114
|
}
|
@@ -198,7 +198,7 @@ class JamstackTest < MiniTest::Test
|
|
198
198
|
}
|
199
199
|
body {
|
200
200
|
article {
|
201
|
-
h2 '
|
201
|
+
h2 'ZZZ', id: 'zzz'
|
202
202
|
}
|
203
203
|
}
|
204
204
|
}
|
@@ -211,32 +211,43 @@ class JamstackTest < MiniTest::Test
|
|
211
211
|
|
212
212
|
list = @jamstack.page_list('/')
|
213
213
|
assert_equal [
|
214
|
-
{ path: File.join(JAMSTACK_PATH, 'bar.html'), url: '/app/bar' },
|
215
|
-
{ path: File.join(JAMSTACK_PATH, 'index.md'),
|
214
|
+
{ kind: :file, path: File.join(JAMSTACK_PATH, 'bar.html'), ext: '.html', url: '/app/bar' },
|
215
|
+
{ kind: :file, path: File.join(JAMSTACK_PATH, 'index.md'), ext: '.md', url: '/app',
|
216
|
+
title: 'Hello', foo: 'BarBar', markdown_content: '<h1>Index</h1>' },
|
216
217
|
], list
|
217
218
|
|
218
219
|
|
219
220
|
list = @jamstack.page_list('/articles')
|
221
|
+
|
220
222
|
assert_equal [
|
221
223
|
{
|
224
|
+
kind: :file,
|
222
225
|
path: File.join(JAMSTACK_PATH, 'articles/2008-06-14-manu.md'),
|
223
226
|
url: '/app/articles/2008-06-14-manu',
|
227
|
+
ext: '.md',
|
224
228
|
title: 'MMM',
|
225
229
|
layout: 'article',
|
230
|
+
markdown_content: "## BBB\n",
|
226
231
|
date: Date.new(2008, 06, 14)
|
227
232
|
},
|
228
233
|
{
|
234
|
+
kind: :file,
|
229
235
|
path: File.join(JAMSTACK_PATH, 'articles/2009-06-12-noatche.md'),
|
230
236
|
url: '/app/articles/2009-06-12-noatche',
|
237
|
+
ext: '.md',
|
231
238
|
title: 'NNN',
|
232
239
|
layout: 'article',
|
240
|
+
markdown_content: "## CCC\n",
|
233
241
|
date: Date.new(2009, 06, 12)
|
234
242
|
},
|
235
243
|
{
|
244
|
+
kind: :file,
|
236
245
|
path: File.join(JAMSTACK_PATH, 'articles/a.md'),
|
237
246
|
url: '/app/articles/a',
|
247
|
+
ext: '.md',
|
238
248
|
title: 'AAA',
|
239
|
-
layout: 'article'
|
249
|
+
layout: 'article',
|
250
|
+
markdown_content: "## ZZZ\n"
|
240
251
|
},
|
241
252
|
], list
|
242
253
|
end
|
@@ -260,4 +271,41 @@ class JamstackTest < MiniTest::Test
|
|
260
271
|
}
|
261
272
|
assert_response foo.render, :html, req
|
262
273
|
end
|
274
|
+
|
275
|
+
def path_info(path)
|
276
|
+
@jamstack.send(:get_path_info, path)
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_path_info
|
280
|
+
assert_equal({
|
281
|
+
kind: :file,
|
282
|
+
path: File.join(JAMSTACK_PATH, 'index.md'),
|
283
|
+
ext: '.md',
|
284
|
+
url: '/',
|
285
|
+
title: 'Hello',
|
286
|
+
foo: 'BarBar',
|
287
|
+
markdown_content: '<h1>Index</h1>'
|
288
|
+
}, path_info('/index'))
|
289
|
+
|
290
|
+
assert_equal({
|
291
|
+
kind: :file,
|
292
|
+
path: File.join(JAMSTACK_PATH, 'index.md'),
|
293
|
+
ext: '.md',
|
294
|
+
url: '/',
|
295
|
+
title: 'Hello',
|
296
|
+
foo: 'BarBar',
|
297
|
+
markdown_content: '<h1>Index</h1>'
|
298
|
+
}, path_info('/'))
|
299
|
+
|
300
|
+
assert_equal({
|
301
|
+
kind: :file,
|
302
|
+
path: File.join(JAMSTACK_PATH, 'assets/js/a.js'),
|
303
|
+
ext: '.js',
|
304
|
+
url: '/assets/js/a.js'
|
305
|
+
}, path_info('/assets/js/a.js'))
|
306
|
+
|
307
|
+
assert_equal({
|
308
|
+
kind: :not_found,
|
309
|
+
}, path_info('/js/b.js'))
|
310
|
+
end
|
263
311
|
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.6'
|
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-01-
|
11
|
+
date: 2022-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: polyphony
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.16'
|
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.16'
|
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.15'
|
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.15'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: modulation
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- README.md
|
140
140
|
- Rakefile
|
141
141
|
- TODO.md
|
142
|
+
- examples/hello.rb
|
142
143
|
- examples/markdown/_assets/style.css
|
143
144
|
- examples/markdown/app.rb
|
144
145
|
- examples/markdown/docs/index.md
|