impression 0.4 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -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 +90 -29
- data/lib/impression/version.rb +1 -1
- data/test/jamstack/_layouts/default.rb +1 -1
- data/test/jamstack/articles/2008-06-14-manu.md +9 -0
- data/test/jamstack/articles/2009-06-12-noatche.md +6 -0
- data/test/jamstack/articles/a.md +1 -1
- data/test/jamstack/foobar.rb +10 -0
- data/test/jamstack/index.md +1 -0
- data/test/test_file_tree.rb +38 -0
- data/test/test_jamstack.rb +119 -11
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27ba311a12a9ce237fd7eaef9102d859bd419471815b58ddea49f5d2879965f7
|
4
|
+
data.tar.gz: 4bf89153122f79e8c11ebf9f66f6ebc2d1c33858d0393fcfa3ff1698f9feab8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d49af3a42dd499957344bc1b53275841909b793f3ae0e181fbd4a4ebf46f7ea279ae1ac666ff9692bf57579378fd1441acdb9fff100ed41822d5aef128b7ad93
|
7
|
+
data.tar.gz: 0a316777f8a8020da38136f587aed8d29fdae45b2216a85a0a1ece6452ab4439f70ffc198878028d8e50449b1a17bef0b1e5b59e1a6925fe35116ac142a6a6b7
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
# 0.7.1 2022-01-24
|
2
|
+
|
3
|
+
- Improve YAML front matter loading
|
4
|
+
|
5
|
+
# 0.7 2022-01-23
|
6
|
+
|
7
|
+
- Update Papercraft, Refactor Jamstack resource
|
8
|
+
|
9
|
+
# 0.6 2022-01-22
|
10
|
+
|
11
|
+
- Unify page_list entries and page_info cache entries (#10)
|
12
|
+
- Refactor FileTree#path_info to return more information
|
13
|
+
|
14
|
+
# 0.5 2022-01-20
|
15
|
+
|
16
|
+
- Pass resource and request to rendered templates (#8)
|
17
|
+
- Implement Jamstack#page_list method (#7)
|
18
|
+
|
1
19
|
# 0.4 2022-01-19
|
2
20
|
|
3
21
|
- Remove deprecated Pages code (#6)
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
impression (0.
|
4
|
+
impression (0.7.1)
|
5
5
|
modulation (~> 1.1)
|
6
|
-
papercraft (~> 0.
|
6
|
+
papercraft (~> 0.17)
|
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.17)
|
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)
|
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.17'
|
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
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
|
+
require 'date'
|
4
5
|
require 'yaml'
|
5
6
|
require 'modulation'
|
6
7
|
require 'papercraft'
|
@@ -17,8 +18,70 @@ module Impression
|
|
17
18
|
@layouts = {}
|
18
19
|
end
|
19
20
|
|
21
|
+
# Returns a list of pages found in the given directory (relative to the base
|
22
|
+
# directory). Each entry containins the absolute file path, the pretty URL,
|
23
|
+
# the possible date parsed from the file name, and any other front matter
|
24
|
+
# attributes (for .md files). This method will detect only pages with the
|
25
|
+
# extensions .html, .md, .rb. The returned entries are sorted by file path.
|
26
|
+
#
|
27
|
+
# @param dir [String] relative directory
|
28
|
+
# @return [Array<Hash>] array of page entries
|
29
|
+
def page_list(dir)
|
30
|
+
base = File.join(@directory, dir)
|
31
|
+
Dir.glob('*.{html,md}', base: base)
|
32
|
+
.map { |fn| get_path_info(File.join(dir, fn)) }# page_entry(fn, dir) }
|
33
|
+
.sort_by { |i| i[:path] }
|
34
|
+
end
|
35
|
+
|
20
36
|
private
|
21
37
|
|
38
|
+
DATE_REGEXP = /(\d{4}\-\d{2}\-\d{2})/.freeze
|
39
|
+
FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m.freeze
|
40
|
+
MD_EXT_REGEXP = /\.md$/.freeze
|
41
|
+
PAGE_EXT_REGEXP = /^(.+)\.(md|html|rb)$/.freeze
|
42
|
+
INDEX_PAGE_REGEXP = /^(.+)?\/index$/.freeze
|
43
|
+
|
44
|
+
YAML_OPTS = {
|
45
|
+
permitted_classes: [Date],
|
46
|
+
symbolize_names: true
|
47
|
+
}.freeze
|
48
|
+
|
49
|
+
# Returns the path info for the given file path.
|
50
|
+
#
|
51
|
+
# @param path [String] file path
|
52
|
+
# @return [Hash] path info
|
53
|
+
def file_info(path)
|
54
|
+
info = super
|
55
|
+
case info[:ext]
|
56
|
+
when '.md'
|
57
|
+
atts, content = parse_markdown_file(path)
|
58
|
+
info = info.merge(atts)
|
59
|
+
info[:html_content] = Papercraft.markdown(content)
|
60
|
+
when '.rb'
|
61
|
+
info[:module] = import(path)
|
62
|
+
end
|
63
|
+
if (m = path.match(DATE_REGEXP))
|
64
|
+
info[:date] ||= Date.parse(m[1])
|
65
|
+
end
|
66
|
+
|
67
|
+
info
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns the pretty URL for the given relative path. For pages, the
|
71
|
+
# extension is removed. For index pages, the index suffix is removed.
|
72
|
+
#
|
73
|
+
# @param relative_path [String] relative path
|
74
|
+
# @return [String] pretty URL
|
75
|
+
def pretty_url(relative_path)
|
76
|
+
if (m = relative_path.match(PAGE_EXT_REGEXP))
|
77
|
+
relative_path = m[1]
|
78
|
+
end
|
79
|
+
if (m = relative_path.match(INDEX_PAGE_REGEXP))
|
80
|
+
relative_path = m[1] || '/'
|
81
|
+
end
|
82
|
+
relative_path == '/' ? absolute_path : File.join(absolute_path, relative_path)
|
83
|
+
end
|
84
|
+
|
22
85
|
# Renders a file response for the given request and the given path info.
|
23
86
|
#
|
24
87
|
# @param req [Qeweney::Request] request
|
@@ -27,9 +90,9 @@ module Impression
|
|
27
90
|
def render_file(req, path_info)
|
28
91
|
case path_info[:ext]
|
29
92
|
when '.rb'
|
30
|
-
render_papercraft_module(req, path_info
|
93
|
+
render_papercraft_module(req, path_info)
|
31
94
|
when '.md'
|
32
|
-
render_markdown_file(req, path_info
|
95
|
+
render_markdown_file(req, path_info)
|
33
96
|
else
|
34
97
|
req.serve_file(path_info[:path])
|
35
98
|
end
|
@@ -38,26 +101,25 @@ module Impression
|
|
38
101
|
# Renders a Papercraft module. The module is loaded using Modulation.
|
39
102
|
#
|
40
103
|
# @param req [Qeweney::Request] reqest
|
41
|
-
# @param
|
104
|
+
# @param path_info [Hash] path info
|
42
105
|
# @return [void]
|
43
|
-
def render_papercraft_module(req,
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
req.respond(html, 'Content-Type' => Qeweney::MimeTypes[:html])
|
106
|
+
def render_papercraft_module(req, path_info)
|
107
|
+
template = Papercraft.html(path_info[:module])
|
108
|
+
body = template.render(request: req, resource: self)
|
109
|
+
req.respond(body, 'Content-Type' => template.mime_type)
|
48
110
|
end
|
49
111
|
|
50
112
|
# Renders a markdown file using a layout.
|
51
113
|
#
|
52
114
|
# @param req [Qeweney::Request] reqest
|
53
|
-
# @param
|
115
|
+
# @param path_info [Hash] path info
|
54
116
|
# @return [void]
|
55
|
-
def render_markdown_file(req,
|
56
|
-
|
117
|
+
def render_markdown_file(req, path_info)
|
118
|
+
layout = get_layout(path_info[:layout])
|
57
119
|
|
58
|
-
|
59
|
-
|
60
|
-
|
120
|
+
html = layout.render(request: req, resource: self, **path_info) {
|
121
|
+
emit path_info[:html_content]
|
122
|
+
}
|
61
123
|
req.respond(html, 'Content-Type' => Qeweney::MimeTypes[:html])
|
62
124
|
end
|
63
125
|
|
@@ -73,30 +135,29 @@ module Impression
|
|
73
135
|
|
74
136
|
import path
|
75
137
|
end
|
76
|
-
|
77
|
-
MARKDOWN_PAGE_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m.freeze
|
78
138
|
|
79
139
|
# Parses the markdown file at the given path.
|
80
140
|
#
|
81
141
|
# @param path [String] file path
|
82
142
|
# @return [Array] an tuple containing properties<Hash>, contents<String>
|
83
143
|
def parse_markdown_file(path)
|
84
|
-
|
85
|
-
|
86
|
-
front_matter = m[1]
|
144
|
+
content = IO.read(path) || ''
|
145
|
+
atts = {}
|
87
146
|
|
88
|
-
|
89
|
-
|
90
|
-
[
|
147
|
+
# Parse date from file name
|
148
|
+
if (m = path.match(DATE_REGEXP))
|
149
|
+
atts[:date] ||= Date.parse(m[1])
|
91
150
|
end
|
92
|
-
end
|
93
151
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
152
|
+
if (m = content.match(FRONT_MATTER_REGEXP))
|
153
|
+
front_matter = m[1]
|
154
|
+
content = m.post_match
|
155
|
+
|
156
|
+
yaml = YAML.safe_load(front_matter, **YAML_OPTS)
|
157
|
+
atts = atts.merge(yaml)
|
158
|
+
end
|
159
|
+
|
160
|
+
[atts, content]
|
100
161
|
end
|
101
162
|
|
102
163
|
# Returns the supported path extensions used for searching for files based
|
data/lib/impression/version.rb
CHANGED
data/test/jamstack/articles/a.md
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
layout = import('./_layouts/default')
|
4
|
+
|
5
|
+
export_default layout.apply(title: 'Foobar') { |resource:, request:, **props|
|
6
|
+
h1 request.query[:q]
|
7
|
+
resource.page_list('/articles').each do |i|
|
8
|
+
a i[:title], href: i[:url]
|
9
|
+
end
|
10
|
+
}
|
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
@@ -48,7 +48,7 @@ class JamstackTest < MiniTest::Test
|
|
48
48
|
req = mock_req(':method' => 'GET', ':path' => '/foo')
|
49
49
|
@jamstack.route_and_call(req)
|
50
50
|
|
51
|
-
foo =
|
51
|
+
foo = Papercraft.html {
|
52
52
|
html5 {
|
53
53
|
head {
|
54
54
|
title 'Foo title'
|
@@ -63,7 +63,7 @@ class JamstackTest < MiniTest::Test
|
|
63
63
|
req = mock_req(':method' => 'GET', ':path' => '/index')
|
64
64
|
@jamstack.route_and_call(req)
|
65
65
|
|
66
|
-
index =
|
66
|
+
index = Papercraft.html {
|
67
67
|
html5 {
|
68
68
|
head {
|
69
69
|
title 'Hello'
|
@@ -86,7 +86,7 @@ class JamstackTest < MiniTest::Test
|
|
86
86
|
req = mock_req(':method' => 'GET', ':path' => '/baz')
|
87
87
|
@jamstack.route_and_call(req)
|
88
88
|
|
89
|
-
baz_index =
|
89
|
+
baz_index = Papercraft.html {
|
90
90
|
html5 {
|
91
91
|
head {
|
92
92
|
title 'BarBar'
|
@@ -101,14 +101,14 @@ class JamstackTest < MiniTest::Test
|
|
101
101
|
req = mock_req(':method' => 'GET', ':path' => '/articles/a')
|
102
102
|
@jamstack.route_and_call(req)
|
103
103
|
|
104
|
-
a =
|
104
|
+
a = Papercraft.html {
|
105
105
|
html5 {
|
106
106
|
head {
|
107
107
|
title 'AAA'
|
108
108
|
}
|
109
109
|
body {
|
110
110
|
article {
|
111
|
-
h2 '
|
111
|
+
h2 'ZZZ', id: 'zzz'
|
112
112
|
}
|
113
113
|
}
|
114
114
|
}
|
@@ -116,7 +116,7 @@ class JamstackTest < MiniTest::Test
|
|
116
116
|
assert_response a.render, :html, req
|
117
117
|
end
|
118
118
|
|
119
|
-
def
|
119
|
+
def test_non_root_jamstack_response
|
120
120
|
@jamstack = Impression::Jamstack.new(path: '/app', directory: JAMSTACK_PATH)
|
121
121
|
|
122
122
|
req = mock_req(':method' => 'GET', ':path' => '/app/roo')
|
@@ -138,7 +138,7 @@ class JamstackTest < MiniTest::Test
|
|
138
138
|
req = mock_req(':method' => 'GET', ':path' => '/app/foo')
|
139
139
|
@jamstack.route_and_call(req)
|
140
140
|
|
141
|
-
foo =
|
141
|
+
foo = Papercraft.html {
|
142
142
|
html5 {
|
143
143
|
head {
|
144
144
|
title 'Foo title'
|
@@ -153,7 +153,7 @@ class JamstackTest < MiniTest::Test
|
|
153
153
|
req = mock_req(':method' => 'GET', ':path' => '/app/index')
|
154
154
|
@jamstack.route_and_call(req)
|
155
155
|
|
156
|
-
index =
|
156
|
+
index = Papercraft.html {
|
157
157
|
html5 {
|
158
158
|
head {
|
159
159
|
title 'Hello'
|
@@ -176,7 +176,7 @@ class JamstackTest < MiniTest::Test
|
|
176
176
|
req = mock_req(':method' => 'GET', ':path' => '/app/baz')
|
177
177
|
@jamstack.route_and_call(req)
|
178
178
|
|
179
|
-
baz_index =
|
179
|
+
baz_index = Papercraft.html {
|
180
180
|
html5 {
|
181
181
|
head {
|
182
182
|
title 'BarBar'
|
@@ -191,18 +191,126 @@ class JamstackTest < MiniTest::Test
|
|
191
191
|
req = mock_req(':method' => 'GET', ':path' => '/app/articles/a')
|
192
192
|
@jamstack.route_and_call(req)
|
193
193
|
|
194
|
-
a =
|
194
|
+
a = Papercraft.html {
|
195
195
|
html5 {
|
196
196
|
head {
|
197
197
|
title 'AAA'
|
198
198
|
}
|
199
199
|
body {
|
200
200
|
article {
|
201
|
-
h2 '
|
201
|
+
h2 'ZZZ', id: 'zzz'
|
202
202
|
}
|
203
203
|
}
|
204
204
|
}
|
205
205
|
}
|
206
206
|
assert_response a.render, :html, req
|
207
207
|
end
|
208
|
+
|
209
|
+
def test_page_list
|
210
|
+
@jamstack = Impression::Jamstack.new(path: '/app', directory: JAMSTACK_PATH)
|
211
|
+
|
212
|
+
list = @jamstack.page_list('/')
|
213
|
+
assert_equal [
|
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', html_content: "<h1>Index</h1>\n" },
|
217
|
+
], list
|
218
|
+
|
219
|
+
|
220
|
+
list = @jamstack.page_list('/articles')
|
221
|
+
|
222
|
+
assert_equal [
|
223
|
+
{
|
224
|
+
kind: :file,
|
225
|
+
path: File.join(JAMSTACK_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: :file,
|
240
|
+
path: File.join(JAMSTACK_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: :file,
|
250
|
+
path: File.join(JAMSTACK_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
|
+
@jamstack.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
|
+
@jamstack.send(:get_path_info, path)
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_path_info
|
285
|
+
assert_equal({
|
286
|
+
kind: :file,
|
287
|
+
path: File.join(JAMSTACK_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: :file,
|
297
|
+
path: File.join(JAMSTACK_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(JAMSTACK_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
|
208
316
|
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:
|
4
|
+
version: 0.7.1
|
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-24 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.17'
|
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.17'
|
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
|
@@ -158,11 +159,14 @@ files:
|
|
158
159
|
- test/helper.rb
|
159
160
|
- test/jamstack/_layouts/article.rb
|
160
161
|
- test/jamstack/_layouts/default.rb
|
162
|
+
- test/jamstack/articles/2008-06-14-manu.md
|
163
|
+
- test/jamstack/articles/2009-06-12-noatche.md
|
161
164
|
- test/jamstack/articles/a.md
|
162
165
|
- test/jamstack/assets/js/a.js
|
163
166
|
- test/jamstack/bar.html
|
164
167
|
- test/jamstack/baz/index.md
|
165
168
|
- test/jamstack/foo.rb
|
169
|
+
- test/jamstack/foobar.rb
|
166
170
|
- test/jamstack/index.md
|
167
171
|
- test/run.rb
|
168
172
|
- test/static/bar/index.html
|